]> andersk Git - moira.git/blobdiff - afssync/sync.dc
Oracle and Solaris/POSIX changes
[moira.git] / afssync / sync.dc
index 03e4c2940bfe0860fe2b08f5c4979d13260c6f98..ba9e540de6e3789ea60044891c691a7d93497a03 100644 (file)
@@ -9,7 +9,7 @@
 #include <mit-copyright.h>
 #include <stdio.h>
 #include <sys/file.h>
-#include <strings.h>
+#include <string.h>
 
 #include <rx/xdr.h>
 #include "ptint.h"
@@ -29,7 +29,9 @@ EXEC SQL BEGIN DECLARE SECTION;
 char db[33] = "moira";
 EXEC SQL END DECLARE SECTION;
 
+#ifndef min
 #define min(x,y)       ((x) < (y) ? (x) : (y))
+#endif
 char *whoami = "sync";
 
 int dbase_fd;
@@ -63,6 +65,8 @@ char **argv;
     int status;
     long t;
 
+    setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
+
     if (argc > 2 && !strcmp(argv[1], "-db")) {
        strncpy(db, argv[2], sizeof(db)-1);
        argc -= 2;
@@ -82,7 +86,6 @@ char **argv;
     initialize_sms_error_table();
     initialize_pt_error_table();
     Initdb();                                  /* Initialize prdb */
-    setlinebuf(stdout);
     
     users = create_hash(10000);
     groups = create_hash(15000);
@@ -90,14 +93,8 @@ char **argv;
     strings = create_hash(1000);
 #endif
 
-    EXEC SQL WHENEVER SQLERROR CALL sqlerr;
-#ifsql INGRES
-    EXEC SQL CONNECT :db;
-    EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
-#endsql
-#ifsql INFORMIX
-    EXEC SQL DATABASE :db;
-#endsql
+    EXEC SQL WHENEVER SQLERROR DO sqlerr();
+    EXEC SQL CONNECT :db IDENTIFIED BY :db;
 
     do_passwd();
     do_groups();
@@ -106,12 +103,7 @@ char **argv;
     fprintf(stderr, "Done (%d users, %d groups, %d kerberos, %d members): %s",
            ucount, gcount, kcount, mcount, ctime(&t));
 
-#ifsql INGRES
-    EXEC SQL DISCONNECT;
-#endsql
-#ifsql INFORMIX
-    EXEC SQL CLOSE DATABASE;
-#endsql
+    EXEC SQL COMMIT;
 
     exit(MR_SUCCESS);
 }
@@ -131,14 +123,11 @@ do_passwd()
     t = time(0);
     fprintf(stderr, "Doing users: %s", ctime(&t));
 
-    /* get locks */
-    EXEC SQL SELECT modtime INTO :name FROM users WHERE users_id = 0;
-    
     EXEC SQL DECLARE u_cursor CURSOR FOR
-       SELECT u.login, u.uid, u.users_id
+       SELECT u.login, u.unix_uid, u.users_id
        FROM users u
-       WHERE u.uid > 0 AND (u.status = 1 OR u.status = 2)
-       ORDER BY uid;
+       WHERE u.unix_uid > 0 AND (u.status = 1 OR u.status = 2)
+       ORDER BY unix_uid;
     EXEC SQL OPEN u_cursor;
     while (1) {
        EXEC SQL FETCH u_cursor INTO :login, :uid, :id;
@@ -186,9 +175,6 @@ do_groups()
     t = time(0);
     fprintf(stderr, "Doing groups: %s", ctime(&t));
 
-    /* get locks */
-    EXEC SQL SELECT modtime INTO :name FROM list WHERE list_id = 0;
-
     EXEC SQL DECLARE l_cursor CURSOR FOR
        SELECT l.name, l.gid, l.list_id, l.hidden
        FROM list l
@@ -290,10 +276,10 @@ do_groups()
 
                if (aid == 0) {
                    EXEC SQL DECLARE k_cursor2 CURSOR FOR
-                       SELECT uid, status
+                       SELECT unix_uid, status
                        FROM users
                        WHERE login = :name
-                       ORDER BY uid;
+                       ORDER BY unix_uid;
                    EXEC SQL OPEN k_cursor2;
                    while (1) {
                        if (sqlca.sqlcode) break;
@@ -411,6 +397,11 @@ do_groups()
     
 sqlerr()
 {
-    com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
-    exit(MR_INGRES_ERR);
+    char buf[256];
+    int size=256, len=0;
+
+    sqlglm(buf, &size, &len);
+    buf[len]='\0';
+    com_err(whoami, MR_DBMS_ERR, " code %d\n%s", sqlca.sqlcode, buf);
+    exit(MR_DBMS_ERR);
 }
This page took 0.041214 seconds and 4 git commands to generate.