]> andersk Git - moira.git/blobdiff - afssync/sync.pc
Deal with pts groups with whitespace and other "weird" characters in
[moira.git] / afssync / sync.pc
index ba9e540de6e3789ea60044891c691a7d93497a03..a95eafea9afcb0047b85a527f271424e362b02f6 100644 (file)
@@ -79,7 +79,7 @@ char **argv;
 
     dbase_fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0660);
     if (dbase_fd < 0) {
-       perror("opening file %s", argv[1]);
+       perror("opening data file");
        exit(1);
     }
 
@@ -161,7 +161,7 @@ do_groups()
 {
     EXEC SQL BEGIN DECLARE SECTION;
     char name[33], string[129];
-    int gid, id, lid, hide, ustatus;
+    int gid, id, lid, hide, ustatus, root_flag;
     EXEC SQL END DECLARE SECTION;
 
     long status, pos;
@@ -260,19 +260,29 @@ do_groups()
                    FROM strings WHERE string_id = :id;
 
                aid = 0;
+               root_flag = 0;
+               ustatus = NULL;
                strtrim(string);
 
-               if (p = (char *)index(string, '@')) {
+               if (p = strchr(string, '@')) 
+                 {
                    *p = 0;
-                   if (strcmp(p+1, "ATHENA.MIT.EDU")) aid = -1;
-               } else aid = -1;
-
-               if ((p = (char *)index(string, '.')) && (p-string) < 9 &&
-                   !strcmp(p+1, "root"))
-               {
+                   if (strcmp(p+1, "ATHENA.MIT.EDU")) 
+                     aid = -1;
+                 } 
+               else aid = -1;
+
+               p = strchr(string, '.');
+               if ((!p) && (strlen(string) < 9))
+                 strcpy(name, string);
+               else if ((p-string) < 9 && !strcmp(p+1, "root"))
+                 {
                    strncpy(name, string, p-string);
                    name[p-string] = 0;
-               } else aid = -1;
+                   root_flag = 1;
+                 }
+               else
+                 aid = -1;
 
                if (aid == 0) {
                    EXEC SQL DECLARE k_cursor2 CURSOR FOR
@@ -281,10 +291,18 @@ do_groups()
                        WHERE login = :name
                        ORDER BY unix_uid;
                    EXEC SQL OPEN k_cursor2;
-                   while (1) {
-                       if (sqlca.sqlcode) break;
-                       EXEC SQL FETCH k_cursor2 INTO :lid, :ustatus;
-                       if (ustatus==1 || ustatus==2) aid = lid+65536;
+                   while (1) 
+                   {
+                     if (sqlca.sqlcode) 
+                       break;
+                     EXEC SQL FETCH k_cursor2 INTO :lid, :ustatus;
+                     if (ustatus==1 || ustatus==2)
+                         {
+                           if (root_flag == 1)
+                             aid = lid+65536;
+                           else
+                             aid = lid;
+                         }
                    }
                    EXEC SQL CLOSE k_cursor2;
                }
This page took 0.046653 seconds and 4 git commands to generate.