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);
36 int main(int argc, char **argv)
44 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
48 initialize_sms_error_table();
49 sprintf(winad_dir, "%s/%s", DCM_DIR, WINAD_SUBDIR);
54 changed += do_groups();
55 changed += do_groupmembership();
59 fprintf(stderr, "No files updated.\n");
60 if (argc == 2 && stat(argv[1], &sb) == 0)
66 fprintf(stderr, "Building tar file.\n");
67 sprintf(cmd, "cd %s; tar cf %s .", winad_dir, argv[1]);
79 char foutf[MAXPATHLEN];
80 char foutft[MAXPATHLEN];
81 EXEC SQL BEGIN DECLARE SECTION;
82 char login[USERS_LOGIN_SIZE];
83 char mit_id[USERS_CLEARID_SIZE];
84 int users_id, unix_uid, status;
85 char type[FILESYS_TYPE_SIZE];
86 char name[FILESYS_NAME_SIZE];
88 EXEC SQL END DECLARE SECTION;
90 sprintf(foutf, "%s/winuser.db", winad_dir);
91 sprintf(foutft, "%s~", foutf);
93 fout = fopen(foutft, "w");
96 perror("cannot open winuser.db for write");
100 EXEC SQL DECLARE u_cursor CURSOR FOR
101 SELECT users_id, login, unix_uid, status, clearid
104 EXEC SQL OPEN u_cursor;
107 EXEC SQL FETCH u_cursor INTO :users_id, :login, :unix_uid, :status,
114 EXEC SQL SELECT filsys_id into :fid
116 WHERE lockertype = 'HOMEDIR'
118 AND type = 'FSGROUP';
120 if (sqlca.sqlcode == 0)
122 EXEC SQL DECLARE f_cursor CURSOR FOR
124 FROM filesys a, fsgroup b
125 WHERE a.filsys_id=b.filsys_id
129 EXEC SQL OPEN f_cursor;
131 EXEC SQL FETCH f_cursor INTO :type, :name;
133 if (sqlca.sqlcode == 0)
144 EXEC SQL CLOSE f_cursor;
150 EXEC SQL SELECT type, name into :type, :name
152 WHERE lockertype = 'HOMEDIR'
155 if (sqlca.sqlcode == 0)
167 fprintf(fout, "%d %s %d %d %s %s %s\n",
168 users_id, login, unix_uid, status, mit_id,
172 if (sqlca.sqlcode < 0)
173 db_error(sqlca.sqlcode);
174 EXEC SQL CLOSE u_cursor;
179 fprintf(stderr, "Unsuccessful file close of winuser.db\n");
191 char foutf[MAXPATHLEN];
192 char foutft[MAXPATHLEN];
193 EXEC SQL BEGIN DECLARE SECTION;
194 char listname[LIST_NAME_SIZE];
195 char description[LIST_DESCRIPTION_SIZE];
196 char acltype[LIST_ACL_TYPE_SIZE];
198 char aclname[STRINGS_STRING_SIZE];
199 int list_id, active, maillist, grouplist;
200 EXEC SQL END DECLARE SECTION;
202 sprintf(foutf, "%s/wingroup.db", winad_dir);
203 sprintf(foutft, "%s~", foutf);
205 fout = fopen(foutft, "w");
208 perror("cannot open wingroup.db for write");
212 EXEC SQL DECLARE l_cursor CURSOR FOR
213 SELECT list_id, name, active, maillist, grouplist, description,
217 EXEC SQL OPEN l_cursor;
220 EXEC SQL FETCH l_cursor INTO :list_id, :listname, :active, :maillist,
222 :description, :acltype, :aclid;
228 strtrim(description);
233 if (strcmp(acltype, "LIST") == 0)
235 EXEC SQL SELECT name into :aclname
237 WHERE list_id = :aclid;
239 else if (strcmp(acltype, "USER") == 0)
241 EXEC SQL SELECT login into :aclname
243 WHERE users_id = :aclid;
245 else if (strcmp(acltype, "KERBEROS") == 0)
247 EXEC SQL SELECT string into :aclname
249 WHERE string_id = :aclid;
254 fprintf(fout, "%d %s %d %d %d %s %s %s\n",
255 list_id, listname, active, maillist, grouplist, acltype, aclname,
259 if (sqlca.sqlcode < 0)
260 db_error(sqlca.sqlcode);
261 EXEC SQL CLOSE l_cursor;
266 fprintf(stderr, "Unsuccessful file close of wingroup.db\n");
274 int do_groupmembership(void)
277 char foutf[MAXPATHLEN];
278 char foutft[MAXPATHLEN];
279 EXEC SQL BEGIN DECLARE SECTION;
280 char member_type[IMEMBERS_MEMBER_TYPE_SIZE];
281 char member_name[STRINGS_STRING_SIZE];
283 EXEC SQL END DECLARE SECTION;
285 sprintf(foutf, "%s/wingmember.db", winad_dir);
286 sprintf(foutft, "%s~", foutf);
288 fout = fopen(foutft, "w");
291 perror("cannot open wingmember.db for write");
295 EXEC SQL DECLARE list_cursor CURSOR FOR
300 EXEC SQL OPEN list_cursor;
303 EXEC SQL FETCH list_cursor INTO :list_id;
308 /* get all the users */
309 EXEC SQL DECLARE csr001 CURSOR FOR
310 SELECT i.member_type, u.login
311 FROM users u, imembers i
312 WHERE i.list_id = :list_id AND i.member_type = 'USER'
313 AND i.member_id = u.users_id
316 EXEC SQL OPEN csr001;
319 EXEC SQL FETCH csr001 into :member_type, :member_name;
322 fprintf(fout, "%d %s %s\n",
323 list_id, member_type, member_name);
326 if (sqlca.sqlcode < 0)
327 db_error(sqlca.sqlcode);
328 EXEC SQL CLOSE csr001;
330 /* get all the KERBEROS AND STRINGS */
331 EXEC SQL DECLARE csr002 CURSOR FOR
332 SELECT i.member_type, s.string
333 FROM strings s, imembers i
334 WHERE i.list_id = :list_id AND
335 (i.member_type = 'KERBEROS' OR i.member_type = 'STRING')
336 AND i.member_id = s.string_id
339 EXEC SQL OPEN csr002;
342 EXEC SQL FETCH csr002 into :member_type, :member_name;
345 fprintf(fout, "%d %s %s\n",
346 list_id, member_type, member_name);
349 if (sqlca.sqlcode < 0)
350 db_error(sqlca.sqlcode);
352 EXEC SQL CLOSE csr002;
355 if (sqlca.sqlcode < 0)
356 db_error(sqlca.sqlcode);
358 EXEC SQL CLOSE list_cursor;
363 fprintf(stderr, "Unsuccessful file close of wingmember.db\n");