]> andersk Git - moira.git/blob - afssync/sync.qc
Attempt to preserve hidden status on all groups (not just those created)
[moira.git] / afssync / sync.qc
1 /* $Header$
2  *
3  *
4  *  (c) Copyright 1989 by the Massachusetts Institute of Technology.
5  *  For copying and distribution information, please see the file
6  *  <mit-copyright.h>.
7  */
8
9 #include <mit-copyright.h>
10 #include <stdio.h>
11 #include <sys/file.h>
12
13 #include <rx/xdr.h>
14 #include "ptint.h"
15 #include "ptserver.h"
16 #include "pterror.h"
17
18 #include <moira.h>
19 #include <moira_site.h>
20 #include <ctype.h>
21
22 #define min(x,y)        ((x) < (y) ? (x) : (y))
23 struct hash *users = NULL;
24 char *whoami = "sync";
25
26 char *malloc(), *strsave();
27 int dbase_fd;
28
29
30 main(argc, argv)
31 int argc;
32 char **argv;
33 {
34     int status;
35     int ingerr();
36
37     if (argc != 2) {
38         fprintf(stderr, "usage: %s outfile\n", argv[0]);
39         exit(MR_ARGS);
40     }
41
42     dbase_fd = open(argv[1], O_RDWR|O_CREAT, 0660);
43     if (dbase_fd < 0) {
44         perror("opening file %s", argv[1]);
45         exit(1);
46     }   
47     IIseterr(ingerr);
48     initialize_sms_error_table ();
49
50 ##  ingres sms
51 ##  set lockmode session where level = table
52 ##  begin transaction
53
54     do_passwd();
55 #if 0
56 #define USERSMS 14487
57     status = PR_AddToGroup(NULL, USERSMS, SYSADMINID);
58     if (status) {
59         prserror(status, "adding MR to system:administrators", 0, 0);
60     }
61 #endif
62     do_groups();
63
64 ##  end transaction
65 ##  exit
66
67     exit(MR_SUCCESS);
68 }
69
70
71 /*
72  * ingerr: (supposedly) called when Ingres indicates an error.
73  * I have not yet been able to get this to work to intercept a
74  * database open error.
75  */
76 #define INGRES_DEADLOCK 4700
77
78 static int ingerr(num)
79     int *num;
80 {
81     char buf[256];
82     int ingres_errno;
83
84     switch (*num) {
85     case INGRES_DEADLOCK:
86         ingres_errno = MR_DEADLOCK;
87         break;
88     default:
89         ingres_errno = MR_INGRES_ERR;
90     }
91     com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
92     exit(ingres_errno);
93 }
94
95
96 prserror(status, msg, arg1, arg2)
97 int status;
98 char *msg;
99 unsigned long arg1, arg2;
100 {
101     char buf[512];
102
103     sprintf(buf, msg, arg1, arg2);
104     switch (status) {
105     case PREXIST:
106         msg = "name already exists";
107         break;
108     case PRIDEXIST:
109         msg = "ID already exists";
110         break;
111     case PRNOIDS:
112         msg = "no IDs available";
113         break;
114     case PRDBFAIL:
115         msg = "database failed";
116         break;
117     case PRNOENT:
118         msg = "no space left in database";
119         break;
120     case PRPERM:
121         msg = "permission denied";
122         break;
123     case PRNOTGROUP:
124         msg = "not a group";
125         break;
126     case PRNOTUSER:
127         msg = "not a user";
128         break;
129     case PRBADNAM:
130         msg = "bad name";
131         break;
132     case 0:
133         msg = "no error";
134         break;
135     default:
136         msg = "unknown code";
137         break;
138     }
139     fprintf(stderr, "%s (%d): %s\n", msg, status, buf);
140 }
141
142
143
144 do_passwd()
145 ##{
146 ##  char login[9];
147 ##  int uid, id, status;
148
149     fprintf(stderr, "Doing users\n");
150     users = create_hash(10000);
151 ##  range of u is users
152 ##  retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
153 ##      where u.#status = 1 or u.#status = 2 {
154             strtrim(login);
155             hash_store(users, id, uid);
156             status = PR_INewEntry(NULL, login, uid, 0);
157             if (status) {
158                 prserror(status, "adding user %s uid %d", login, uid);
159             }
160 ##  }
161 ##}
162
163
164
165 do_groups()
166 ##{
167     struct hash *groups;
168     long u, g, status;
169 ##  char name[33], namebuf[128];
170 ##  int gid, id, lid, hide;
171
172     fprintf(stderr, "Doing groups\n");
173
174     /* make space for group list */
175     groups = create_hash(15000);
176
177     /* retrieve simple groups */
178 ##  range of l is list
179 ##  range of m is imembers
180     /* get lock records */
181 ##  retrieve (name = l.modtime) where l.list_id = 0
182 ##  retrieve (name = users.modtime) where users.users_id = 0
183
184 ##  retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden)
185 ##      where l.group != 0 and l.active != 0 {
186             strtrim(name);
187             sprintf(namebuf, "system:%s", name);
188             hash_store(groups, lid, -gid);
189             status = PR_INewEntry(NULL, namebuf, -gid, SYSADMINID);
190             if (status)
191                 prserror(status, "adding list %s gid %d", namebuf, -gid);
192             if (hide) {
193                 status = PR_SetFieldsEntry
194                     (NULL/*call*/, -gid,
195                      PR_SF_ALLBITS/*mask*/,
196                      PRP_STATUS_MEM >> PRIVATE_SHIFT /*flags*/,
197                      0/*ngroups*/, 0/*nusers*/, 0/*spare1*/, 0/*spare2*/);
198                 if (status)
199                     prserror(status, "setting flags on list %s", namebuf);
200             }
201 ##  }
202
203
204     fprintf(stderr, "Doing members\n");
205
206 ##  retrieve (lid = m.list_id, id = m.member_id)
207 ##      where m.member_type = "USER" {
208       if ((u = (long) hash_lookup(users, id)) &&
209           (g = (long) hash_lookup(groups, lid))) {
210           status = PR_AddToGroup(NULL, u, g);
211           if (status) {
212               prserror(status, "adding %d to group %d", u, -g);
213           }
214       }
215 ##  }
216
217 ##}
218
This page took 0.633363 seconds and 5 git commands to generate.