]> andersk Git - moira.git/blobdiff - afssync/sync.qc
line buffer output; don't do it all in one transaction; trap
[moira.git] / afssync / sync.qc
index fb663a2ebad64e99fe90af541355484030948ec4..f6a5fbbb642296ba3d93b57d746b8fba1af87ef2 100644 (file)
@@ -1,10 +1,7 @@
 /* $Header$
  *
- * This generates the zone files necessary to load a hesiod server.
- * The following zones are generated: passwd, uid, pobox, group,
- * grplist, gid, filsys, cluster, pcap, sloc, service.
  *
- *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
+ *  (c) Copyright 1989 by the Massachusetts Institute of Technology.
  *  For copying and distribution information, please see the file
  *  <mit-copyright.h>.
  */
 #include <mit-copyright.h>
 #include <stdio.h>
 #include <sys/file.h>
+
 #include <rx/xdr.h>
-#include "print.h"
-#include "prserver.h"
-#include "prerror.h"
-#include <sms.h>
-#include <sms_app.h>
-#include <ctype.h>
+#include "ptint.h"
+#include "ptserver.h"
+#include "pterror.h"
 
+#include <moira.h>
+#include <moira_site.h>
+#include <ctype.h>
 
 #define min(x,y)       ((x) < (y) ? (x) : (y))
 struct hash *users = NULL;
@@ -33,11 +31,12 @@ main(argc, argv)
 int argc;
 char **argv;
 {
+    int status;
     int ingerr();
 
     if (argc != 2) {
        fprintf(stderr, "usage: %s outfile\n", argv[0]);
-       exit(SMS_ARGS);
+       exit(MR_ARGS);
     }
 
     dbase_fd = open(argv[1], O_RDWR|O_CREAT, 0660);
@@ -46,7 +45,9 @@ char **argv;
        exit(1);
     }  
     IIseterr(ingerr);
-    initialize_sms_error_table ();
+    initialize_sms_error_table();
+    initialize_pt_error_table();
+    Initdb();
 
 ##  ingres sms
 ##  set lockmode session where level = table
@@ -58,7 +59,7 @@ char **argv;
 ##  end transaction
 ##  exit
 
-    exit(SMS_SUCCESS);
+    exit(MR_SUCCESS);
 }
 
 
@@ -77,63 +78,16 @@ static int ingerr(num)
 
     switch (*num) {
     case INGRES_DEADLOCK:
-       ingres_errno = SMS_DEADLOCK;
+       ingres_errno = MR_DEADLOCK;
        break;
     default:
-       ingres_errno = SMS_INGRES_ERR;
+       ingres_errno = MR_INGRES_ERR;
     }
-    com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
+    com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
     exit(ingres_errno);
 }
 
 
-prserror(status, msg, arg1, arg2)
-int status;
-char *msg;
-unsigned long arg1, arg2;
-{
-    char buf[512];
-
-    sprintf(buf, msg, arg1, arg2);
-    switch (status) {
-    case PREXIST:
-       msg = "name already exists";
-       break;
-    case PRIDEXIST:
-       msg = "ID already exists";
-       break;
-    case PRNOIDS:
-       msg = "no IDs available";
-       break;
-    case PRDBFAIL:
-       msg = "database failed";
-       break;
-    case PRNOENT:
-       msg = "no space left in database";
-       break;
-    case PRPERM:
-       msg = "permission denied";
-       break;
-    case PRNOTGROUP:
-       msg = "not a group";
-       break;
-    case PRNOTUSER:
-       msg = "not a user";
-       break;
-    case PRBADNAM:
-       msg = "bad name";
-       break;
-    case 0:
-       msg = "no error";
-       break;
-    default:
-       msg = "unknown code";
-       break;
-    }
-    fprintf(stderr, "%s (%d): %s\n", msg, status, buf);
-}
-
-
 
 do_passwd()
 ##{
@@ -144,13 +98,17 @@ do_passwd()
     users = create_hash(10000);
 ##  range of u is users
 ##  retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
-##     where u.#status = 1 {
+##     where u.#uid > 0 and (u.#status = 1 or u.#status = 2) {
            strtrim(login);
            hash_store(users, id, uid);
-           status = PR_INewEntry(NULL, login, uid, 0);
-           if (status) {
-               prserror(status, "adding user %s uid %d", login, uid);
-           }
+           if (FindByID (0, uid))
+               status = PRIDEXIST;
+           else
+               status = CreateEntry(0, login, &uid, 1/*idflag*/, 0/*gflag*/,
+                                    SYSADMINID/*oid*/, SYSADMINID/*cid*/);
+           if (status)
+               fprintf(stderr, "Error adding user %s uid %d: %s\n",
+                       login, uid, error_message(status));
 ##  }
 ##}
 
@@ -159,10 +117,12 @@ do_passwd()
 do_groups()
 ##{
     struct hash *groups;
-    long u, g, status;
+    long u, g, status, gpos, upos;
+    struct prentry gentry, uentry;
 ##  char name[33], namebuf[128];
-##  int gid, id, lid;
-
+##  int gid, id, lid, hide;
+    int aid;
+    
     fprintf(stderr, "Doing groups\n");
 
     /* make space for group list */
@@ -175,14 +135,34 @@ do_groups()
 ##  retrieve (name = l.modtime) where l.list_id = 0
 ##  retrieve (name = users.modtime) where users.users_id = 0
 
-##  retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
-##     where l.group != 0 and l.active != 0 {
+##  retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden)
+##     where l.group != 0 and l.active != 0 and l.#gid > 0 {
            strtrim(name);
            sprintf(namebuf, "system:%s", name);
            hash_store(groups, lid, -gid);
-           status = PR_INewEntry(NULL, namebuf, -gid, SYSADMINID);
+           aid = -gid;
+           if (gpos = FindByID (0, aid))
+               status = PRIDEXIST;
+           else
+               status = CreateEntry(0,namebuf,&aid,1/*idflag*/,PRGRP/*gflag*/,
+                                    SYSADMINID/*oid*/, SYSADMINID/*cid*/);
            if (status)
-             prserror(status, "adding list %s gid %d", namebuf, -gid);
+               fprintf(stderr, "Error adding group %s id %d: %s\n",
+                       namebuf, aid, error_message(status));
+
+           /* If this list is hidden, set the pts entry to be s---- */
+           if (hide && (status==0 || status==PRIDEXIST)) {
+               if (!gpos)
+                   gpos = FindByID(0, aid);
+               status = pr_ReadEntry(0, 0, gpos, &gentry);
+               if (!status) {
+                   gentry.flags = PRGRP|PRACCESS|PRP_STATUS_ANY;
+                   status = pr_WriteEntry(0, 0, gpos, &gentry);
+               }
+               if (status)
+                   fprintf(stderr, "Error setting flags on group %s: %s\n",
+                           namebuf, error_message(status));
+           }
 ##  }
 
 
@@ -192,10 +172,19 @@ do_groups()
 ##     where m.member_type = "USER" {
       if ((u = (long) hash_lookup(users, id)) &&
          (g = (long) hash_lookup(groups, lid))) {
-         status = PR_AddToGroup(NULL, u, g);
-         if (status) {
-             prserror(status, "adding %d to group %d", u, -g);
+         if (g==ANYUSERID || g==AUTHUSERID || u==ANONYMOUSID) {
+             status = PRPERM;
+         } else if ((gpos = FindByID(0, g)) && (upos = FindByID(0, u))) {
+             status = pr_ReadEntry(0,0,upos,&uentry);
+             if (!status) status = pr_ReadEntry(0,0,gpos,&gentry);
+             if (!status) status = AddToEntry (0, &gentry, gpos, u);
+             if (!status) status = AddToEntry (0, &uentry, upos, g);
+         } else {
+             status = PRNOENT;
          }
+         if (status)
+             fprintf(stderr, "Error adding uid %d to group %d: %s\n",
+                     u, -g, error_message(status));
       }
 ##  }
 
This page took 0.045303 seconds and 4 git commands to generate.