]>
Commit | Line | Data |
---|---|---|
fb8809f4 | 1 | /* $Header$ |
2 | * | |
3 | * Do AFS incremental updates | |
4 | * | |
5 | * Copyright (C) 1989 by the Massachusetts Institute of Technology | |
6 | * for copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
8 | */ | |
9 | ||
2ce085d2 | 10 | #include <moira.h> |
11 | #include <moira_site.h> | |
f633445d | 12 | #include <sys/file.h> |
13 | ||
14 | #define file_exists(file) (access((file), F_OK) == 0) | |
fb8809f4 | 15 | |
bfaed7ce | 16 | char pts[64], fs[64]; |
fb8809f4 | 17 | |
18 | char *whoami; | |
19 | ||
20 | main(argc, argv) | |
21 | char **argv; | |
22 | int argc; | |
23 | { | |
a7fdf2de | 24 | int beforec, afterc, i; |
fb8809f4 | 25 | char *table, **before, **after; |
810d12a7 | 26 | #ifdef DEBUG |
27 | char buf[1024]; | |
810d12a7 | 28 | #endif |
fb8809f4 | 29 | |
a7fdf2de | 30 | for (i = getdtablesize() - 1; i > 2; i--) |
31 | close(i); | |
32 | ||
fb8809f4 | 33 | table = argv[1]; |
34 | beforec = atoi(argv[2]); | |
35 | before = &argv[4]; | |
36 | afterc = atoi(argv[3]); | |
37 | after = &argv[4 + beforec]; | |
38 | whoami = argv[0]; | |
39 | ||
810d12a7 | 40 | #ifdef DEBUG |
41 | sprintf(buf, "%s (", table); | |
42 | for (i = 0; i < beforec; i++) { | |
43 | if (i > 0) | |
44 | strcat(buf, ","); | |
45 | strcat(buf, before[i]); | |
46 | } | |
47 | strcat(buf, ")->("); | |
48 | for (i = 0; i < afterc; i++) { | |
49 | if (i > 0) | |
50 | strcat(buf, ","); | |
51 | strcat(buf, after[i]); | |
52 | } | |
53 | strcat(buf, ")\n"); | |
54 | write(1,buf,strlen(buf)); | |
55 | #endif | |
56 | ||
fb8809f4 | 57 | initialize_sms_error_table(); |
58 | initialize_krb_error_table(); | |
bfaed7ce | 59 | sprintf(pts, "%s/pts", BIN_DIR); |
a6be2cf4 | 60 | sprintf(fs, "%s/fs", BIN_DIR); |
fb8809f4 | 61 | |
62 | if (!strcmp(table, "users")) { | |
63 | do_user(before, beforec, after, afterc); | |
64 | } else if (!strcmp(table, "list")) { | |
65 | do_list(before, beforec, after, afterc); | |
66 | } else if (!strcmp(table, "members")) { | |
67 | do_member(before, beforec, after, afterc); | |
68 | } else if (!strcmp(table, "filesys")) { | |
69 | do_filesys(before, beforec, after, afterc); | |
1f377b55 | 70 | } else if (!strcmp(table, "quota")) { |
fb8809f4 | 71 | do_quota(before, beforec, after, afterc); |
72 | } | |
fb8809f4 | 73 | exit(0); |
74 | } | |
75 | ||
76 | ||
77 | do_cmd(cmd) | |
78 | char *cmd; | |
79 | { | |
a7fdf2de | 80 | int success = 0, tries = 0; |
fb8809f4 | 81 | |
82 | while (success == 0 && tries < 3) { | |
a7fdf2de | 83 | com_err(whoami, 0, "Executing command: %s", cmd); |
84 | if (system(cmd) == 0) | |
85 | success++; | |
fb8809f4 | 86 | if (!success) { |
87 | tries++; | |
88 | sleep(5 * 60); | |
89 | } | |
90 | } | |
91 | if (!success) | |
92 | critical_alert("incremental", "failed command: %s", cmd); | |
93 | } | |
94 | ||
95 | ||
96 | do_user(before, beforec, after, afterc) | |
97 | char **before; | |
98 | int beforec; | |
99 | char **after; | |
100 | int afterc; | |
101 | { | |
102 | int bstate, astate; | |
103 | char cmd[512]; | |
104 | ||
105 | cmd[0] = bstate = astate = 0; | |
106 | if (afterc > U_STATE) | |
107 | astate = atoi(after[U_STATE]); | |
108 | if (beforec > U_STATE) | |
109 | bstate = atoi(before[U_STATE]); | |
810d12a7 | 110 | if (astate == 2) astate = 1; |
111 | if (bstate == 2) bstate = 1; | |
fb8809f4 | 112 | |
113 | if (astate != 1 && bstate != 1) | |
114 | return; | |
115 | if (astate == 1 && bstate != 1) { | |
bfaed7ce | 116 | sprintf(cmd, "%s createuser -name %s -id %s", |
117 | pts, after[U_NAME], after[U_UID]); | |
fb8809f4 | 118 | do_cmd(cmd); |
119 | return; | |
120 | } else if (astate != 1 && bstate == 1) { | |
bfaed7ce | 121 | sprintf(cmd, "%s delete -name %s", pts, before[U_NAME]); |
fb8809f4 | 122 | do_cmd(cmd); |
123 | return; | |
124 | } | |
125 | ||
126 | if (beforec > U_UID && afterc > U_UID && | |
127 | strcmp(before[U_UID], after[U_UID])) { | |
128 | /* change UID, & possibly user name here */ | |
129 | exit(1); | |
130 | } | |
131 | ||
132 | if (beforec > U_NAME && afterc > U_NAME && | |
133 | strcmp(before[U_NAME], after[U_NAME])) { | |
bfaed7ce | 134 | sprintf(cmd, "%s rename -oldname %s -newname %s", |
135 | pts, before[U_NAME], after[U_NAME]); | |
fb8809f4 | 136 | do_cmd(cmd); |
137 | } | |
138 | } | |
139 | ||
140 | ||
141 | ||
142 | do_list(before, beforec, after, afterc) | |
143 | char **before; | |
144 | int beforec; | |
145 | char **after; | |
146 | int afterc; | |
147 | { | |
148 | char cmd[512]; | |
149 | int agid, bgid; | |
150 | ||
151 | cmd[0] = agid = bgid = 0; | |
152 | if (beforec > L_GID && atoi(before[L_ACTIVE]) && atoi(before[L_GROUP])) | |
153 | bgid = atoi(before[L_GID]); | |
154 | if (afterc > L_GID && atoi(after[L_ACTIVE]) && atoi(after[L_GROUP])) | |
155 | agid = atoi(after[L_GID]); | |
156 | ||
157 | if (bgid == 0 && agid != 0) { | |
810d12a7 | 158 | sprintf(cmd, |
bfaed7ce | 159 | "%s creategroup -name system:%s -owner system:administrators -id -%s", |
160 | pts, after[L_NAME], after[L_GID]); | |
fb8809f4 | 161 | do_cmd(cmd); |
162 | return; | |
163 | } | |
164 | if (agid == 0 && bgid != 0) { | |
bfaed7ce | 165 | sprintf(cmd, "%s delete -name system:%s", pts, before[L_NAME]); |
fb8809f4 | 166 | do_cmd(cmd); |
167 | return; | |
168 | } | |
169 | if (agid == 0 && bgid == 0) | |
170 | return; | |
171 | if (strcmp(before[L_NAME], after[L_NAME])) { | |
172 | sprintf(cmd, | |
bfaed7ce | 173 | "%s rename -oldname system:%s -newname system:%s", |
174 | pts, before[L_NAME], after[L_NAME]); | |
fb8809f4 | 175 | do_cmd(cmd); |
176 | return; | |
177 | } | |
178 | } | |
179 | ||
180 | ||
181 | do_member(before, beforec, after, afterc) | |
182 | char **before; | |
183 | int beforec; | |
184 | char **after; | |
185 | int afterc; | |
186 | { | |
57bc9f26 | 187 | char cmd[512], *p; |
fb8809f4 | 188 | |
bd70a79d | 189 | if ((beforec < 4 || !atoi(before[LM_END])) && |
190 | (afterc < 4 || !atoi(after[LM_END]))) | |
191 | return; | |
fb8809f4 | 192 | if (beforec == 0 && !strcmp(after[LM_TYPE], "USER")) { |
bfaed7ce | 193 | sprintf(cmd, "%s adduser -user %s -group system:%s", |
194 | pts, after[LM_MEMBER], after[LM_LIST]); | |
fb8809f4 | 195 | do_cmd(cmd); |
196 | return; | |
197 | } | |
198 | if (afterc == 0 && !strcmp(before[LM_TYPE], "USER")) { | |
bfaed7ce | 199 | sprintf(cmd, "%s removeuser -user %s -group system:%s", |
200 | pts, before[LM_MEMBER], before[LM_LIST]); | |
fb8809f4 | 201 | do_cmd(cmd); |
202 | return; | |
203 | } | |
57bc9f26 | 204 | if (beforec == 0 && !strcmp(after[LM_TYPE], "KERBEROS")) { |
205 | p = index(after[LM_MEMBER], '@'); | |
206 | if (p) *p = 0; | |
207 | sprintf(cmd, "%s adduser -user %s -group system:%s", | |
208 | pts, after[LM_MEMBER], after[LM_LIST]); | |
209 | do_cmd(cmd); | |
210 | return; | |
211 | } | |
212 | if (afterc == 0 && !strcmp(before[LM_TYPE], "KERBEROS")) { | |
213 | p = index(before[LM_MEMBER], '@'); | |
214 | if (p) *p = 0; | |
215 | sprintf(cmd, "%s removeuser -user %s -group system:%s", | |
216 | pts, before[LM_MEMBER], before[LM_LIST]); | |
217 | do_cmd(cmd); | |
218 | return; | |
219 | } | |
fb8809f4 | 220 | } |
221 | ||
222 | ||
223 | do_filesys(before, beforec, after, afterc) | |
224 | char **before; | |
225 | int beforec; | |
226 | char **after; | |
227 | int afterc; | |
228 | { | |
d43ba793 | 229 | char cmd[512]; |
230 | ||
231 | if (afterc < FS_CREATE || | |
232 | strcmp("AFS", after[FS_TYPE])) | |
f633445d | 233 | return; |
d43ba793 | 234 | if (beforec < FS_CREATE) { |
235 | /* new locker creation */ | |
236 | sprintf(cmd, "%s/afs_create.pl %s %s %s %s %s %s %s %s %s", | |
237 | BIN_DIR, after[FS_LABEL], after[FS_LOCKERTYPE], | |
238 | after[FS_MACHINE], after[FS_PACK], 2200, after[FS_OWNER], | |
239 | 0, after[FS_OWNERS], 0); | |
240 | do_cmd(cmd); | |
241 | return; | |
242 | } else if (strcmp(before[FS_TYPE], "AFS")) { | |
243 | /* moved from non-AFS */ | |
244 | } else { | |
245 | /* other modification */ | |
5ecdaa1f | 246 | !strncmp("/afs/", after[FS_PACK], 5) && |
247 | atoi(after[FS_CREATE]) && | |
248 | !file_exists(after[FS_PACK])) { | |
f633445d | 249 | critical_alert("incremental", "unable to create locker %s", |
250 | after[FS_PACK]); | |
251 | } | |
fb8809f4 | 252 | } |
253 | ||
254 | ||
255 | do_quota(before, beforec, after, afterc) | |
256 | char **before; | |
257 | int beforec; | |
258 | char **after; | |
259 | int afterc; | |
260 | { | |
261 | char cmd[512]; | |
262 | ||
1f377b55 | 263 | if (afterc < Q_DIRECTORY || strcmp("ANY", after[Q_TYPE]) || |
264 | strncmp("/afs", after[Q_DIRECTORY], 4)) | |
fb8809f4 | 265 | return; |
1f377b55 | 266 | |
bfaed7ce | 267 | sprintf(cmd, "%s setquota -dir %s -max %s", fs, |
1f377b55 | 268 | after[Q_DIRECTORY], after[Q_QUOTA]); |
269 | do_cmd(cmd); | |
270 | return; | |
fb8809f4 | 271 | } |