3 * This generates the user, list, list membership, filesys data
4 * for windows active directory update
6 * (c) Copyright 1988-2001 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
13 #include <moira_site.h>
22 EXEC SQL INCLUDE sqlca;
25 #define WINAD_SUBDIR "winad"
28 char winad_dir[MAXPATHLEN];
29 char *whoami = "winad.gen";
30 char *db = "moira/moira";
34 int do_groupmembership(void);
35 int do_containers(void);
37 int main(int argc, char **argv)
45 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
49 initialize_sms_error_table();
50 sprintf(winad_dir, "%s/%s", DCM_DIR, WINAD_SUBDIR);
55 changed += do_groups();
56 changed += do_groupmembership();
57 changed += do_containers();
61 fprintf(stderr, "No files updated.\n");
62 if (argc == 2 && stat(argv[1], &sb) == 0)
68 fprintf(stderr, "Building tar file.\n");
69 sprintf(cmd, "cd %s; tar cf %s .", winad_dir, argv[1]);
81 char foutf[MAXPATHLEN];
82 char foutft[MAXPATHLEN];
83 EXEC SQL BEGIN DECLARE SECTION;
84 char login[USERS_LOGIN_SIZE];
85 char mit_id[USERS_CLEARID_SIZE];
86 int users_id, unix_uid, status;
87 char type[FILESYS_TYPE_SIZE];
88 char name[FILESYS_NAME_SIZE];
90 EXEC SQL END DECLARE SECTION;
92 sprintf(foutf, "%s/winuser.db", winad_dir);
93 sprintf(foutft, "%s~", foutf);
95 fout = fopen(foutft, "w");
98 perror("cannot open winuser.db for write");
102 EXEC SQL DECLARE u_cursor CURSOR FOR
103 SELECT users_id, login, unix_uid, status, clearid
106 EXEC SQL OPEN u_cursor;
109 EXEC SQL FETCH u_cursor INTO :users_id, :login, :unix_uid, :status,
116 EXEC SQL SELECT filsys_id into :fid
118 WHERE lockertype = 'HOMEDIR'
120 AND type = 'FSGROUP';
122 if (sqlca.sqlcode == 0)
124 EXEC SQL DECLARE f_cursor CURSOR FOR
126 FROM filesys a, fsgroup b
127 WHERE a.filsys_id=b.filsys_id
131 EXEC SQL OPEN f_cursor;
133 EXEC SQL FETCH f_cursor INTO :type, :name;
135 if (sqlca.sqlcode == 0)
142 strcpy(type, "NONE");
143 strcpy(name, "NONE");
146 EXEC SQL CLOSE f_cursor;
152 EXEC SQL SELECT type, name into :type, :name
154 WHERE lockertype = 'HOMEDIR'
157 if (sqlca.sqlcode == 0)
164 strcpy(type, "NONE");
165 strcpy(name, "NONE");
169 fprintf(fout, "%d %s %d %d %s %s %s\n",
170 users_id, login, unix_uid, status, mit_id,
174 if (sqlca.sqlcode < 0)
175 db_error(sqlca.sqlcode);
176 EXEC SQL CLOSE u_cursor;
181 fprintf(stderr, "Unsuccessful file close of winuser.db\n");
193 char foutf[MAXPATHLEN];
194 char foutft[MAXPATHLEN];
195 EXEC SQL BEGIN DECLARE SECTION;
196 char listname[LIST_NAME_SIZE];
197 char description[LIST_DESCRIPTION_SIZE];
198 char acltype[LIST_ACL_TYPE_SIZE];
200 char aclname[STRINGS_STRING_SIZE];
201 int list_id, active, maillist, grouplist;
202 EXEC SQL END DECLARE SECTION;
204 sprintf(foutf, "%s/wingroup.db", winad_dir);
205 sprintf(foutft, "%s~", foutf);
207 fout = fopen(foutft, "w");
210 perror("cannot open wingroup.db for write");
214 EXEC SQL DECLARE l_cursor CURSOR FOR
215 SELECT list_id, name, active, maillist, grouplist, description,
219 EXEC SQL OPEN l_cursor;
222 EXEC SQL FETCH l_cursor INTO :list_id, :listname, :active, :maillist,
224 :description, :acltype, :aclid;
230 strtrim(description);
234 strcpy(aclname, "NONE");
235 if (strcmp(acltype, "LIST") == 0)
237 EXEC SQL SELECT name into :aclname
239 WHERE list_id = :aclid;
241 else if (strcmp(acltype, "USER") == 0)
243 EXEC SQL SELECT login into :aclname
245 WHERE users_id = :aclid;
247 else if (strcmp(acltype, "KERBEROS") == 0)
249 EXEC SQL SELECT string into :aclname
251 WHERE string_id = :aclid;
256 fprintf(fout, "%d %s %d %d %d %s %s %s\n",
257 list_id, listname, active, maillist, grouplist, acltype, aclname,
261 if (sqlca.sqlcode < 0)
262 db_error(sqlca.sqlcode);
263 EXEC SQL CLOSE l_cursor;
268 fprintf(stderr, "Unsuccessful file close of wingroup.db\n");
276 int do_groupmembership(void)
279 char foutf[MAXPATHLEN];
280 char foutft[MAXPATHLEN];
281 EXEC SQL BEGIN DECLARE SECTION;
282 char member_type[IMEMBERS_MEMBER_TYPE_SIZE];
283 char member_name[STRINGS_STRING_SIZE];
285 EXEC SQL END DECLARE SECTION;
287 sprintf(foutf, "%s/wingmember.db", winad_dir);
288 sprintf(foutft, "%s~", foutf);
290 fout = fopen(foutft, "w");
293 perror("cannot open wingmember.db for write");
297 EXEC SQL DECLARE list_cursor CURSOR FOR
302 EXEC SQL OPEN list_cursor;
305 EXEC SQL FETCH list_cursor INTO :list_id;
310 /* get all the users */
311 EXEC SQL DECLARE csr001 CURSOR FOR
312 SELECT i.member_type, u.login
313 FROM users u, imembers i
314 WHERE i.list_id = :list_id AND i.member_type = 'USER'
315 AND i.member_id = u.users_id
318 EXEC SQL OPEN csr001;
321 EXEC SQL FETCH csr001 into :member_type, :member_name;
324 fprintf(fout, "%d %s %s\n",
325 list_id, member_type, member_name);
328 if (sqlca.sqlcode < 0)
329 db_error(sqlca.sqlcode);
330 EXEC SQL CLOSE csr001;
332 /* get all the KERBEROS AND STRINGS */
333 EXEC SQL DECLARE csr002 CURSOR FOR
334 SELECT i.member_type, s.string
335 FROM strings s, imembers i
336 WHERE i.list_id = :list_id AND
337 (i.member_type = 'KERBEROS' OR i.member_type = 'STRING')
338 AND i.member_id = s.string_id
341 EXEC SQL OPEN csr002;
344 EXEC SQL FETCH csr002 into :member_type, :member_name;
347 fprintf(fout, "%d %s %s\n",
348 list_id, member_type, member_name);
351 if (sqlca.sqlcode < 0)
352 db_error(sqlca.sqlcode);
354 EXEC SQL CLOSE csr002;
357 if (sqlca.sqlcode < 0)
358 db_error(sqlca.sqlcode);
360 EXEC SQL CLOSE list_cursor;
365 fprintf(stderr, "Unsuccessful file close of wingmember.db\n");
373 int do_containers(void)
376 char foutf[MAXPATHLEN];
377 char foutft[MAXPATHLEN];
378 EXEC SQL BEGIN DECLARE SECTION;
379 char container_name[CONTAINERS_NAME_SIZE];
380 char acl_type[CONTAINERS_ACL_TYPE_SIZE];
381 char acl_name[STRINGS_STRING_SIZE];
382 char description[CONTAINERS_DESCRIPTION_SIZE];
385 EXEC SQL END DECLARE SECTION;
387 sprintf(foutf, "%s/wincontainer.db", winad_dir);
388 sprintf(foutft, "%s~", foutf);
390 fout = fopen(foutft, "w");
393 perror("cannot open wincontainer.db for write");
397 EXEC SQL DECLARE container_cursor CURSOR FOR
398 SELECT name, cnt_id, acl_type, acl_id, description
400 ORDER BY cnt_id, name;
401 EXEC SQL OPEN container_cursor;
404 EXEC SQL FETCH container_cursor INTO :container_name, :cnt_id,
405 :acl_type, :acl_id, :description ;
410 strtrim(container_name);
412 strtrim(description);
414 strcpy(acl_name, "NONE");
415 if (strcmp(acl_type, "LIST") == 0)
417 EXEC SQL SELECT name into :acl_name
419 WHERE list_id = :acl_id;
421 else if (strcmp(acl_type, "USER") == 0)
423 EXEC SQL SELECT login into :acl_name
425 WHERE users_id = :acl_id;
427 else if (strcmp(acl_type, "KERBEROS") == 0)
429 EXEC SQL SELECT string into :acl_name
431 WHERE string_id = :acl_id;
436 fprintf(fout, "%d,%s,%s,%s,%s\n",
437 cnt_id, container_name, acl_type, acl_name,
440 if (sqlca.sqlcode < 0)
441 db_error(sqlca.sqlcode);
443 EXEC SQL CLOSE container_cursor;
448 fprintf(stderr, "Unsuccessful file close of wincontainer.db\n");