]>
Commit | Line | Data |
---|---|---|
73cf66ba | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * For copying and distribution information, please see the file | |
8 | * <mit-copyright.h>. | |
9 | * | |
10 | */ | |
11 | ||
12 | #ifndef lint | |
13 | static char *rcsid_qsupport_dc = "$Header$"; | |
14 | #endif lint | |
15 | ||
16 | #include <mit-copyright.h> | |
17 | #include "query.h" | |
18 | #include "mr_server.h" | |
19 | #include <ctype.h> | |
20 | #ifdef GDSS | |
21 | #include "gdss.h" | |
22 | #endif /* GDSS */ | |
23 | EXEC SQL INCLUDE sqlca; | |
24 | EXEC SQL INCLUDE sqlda; | |
25 | #include "qrtn.h" | |
26 | ||
27 | extern char *whoami, *strsave(); | |
28 | extern int ingres_errno, mr_errcode; | |
29 | ||
30 | EXEC SQL BEGIN DECLARE SECTION; | |
31 | extern char stmt_buf[]; | |
32 | EXEC SQL END DECLARE SECTION; | |
33 | ||
34 | EXEC SQL WHENEVER SQLERROR CALL ingerr; | |
35 | ||
36 | ||
37 | /* Setup Routines */ | |
38 | ||
39 | /* Setup routine for add_user | |
40 | * | |
41 | * Inputs: argv[0] - login | |
42 | * argv[1] - uid | |
43 | * | |
44 | * Description: | |
45 | * | |
46 | * - if argv[1] == UNIQUE_UID then set argv[1] = next(uid) | |
47 | * - if argv[0] == UNIQUE_LOGIN then set argv[0] = "#<uid>" | |
48 | */ | |
49 | ||
50 | setup_ausr(q, argv, cl) | |
51 | struct query *q; | |
52 | register char *argv[]; | |
53 | client *cl; | |
54 | { | |
55 | int row; | |
56 | EXEC SQL BEGIN DECLARE SECTION; | |
57 | int nuid; | |
58 | EXEC SQL END DECLARE SECTION; | |
59 | ||
60 | if (!strcmp(q->shortname, "uusr") || !strcmp(q->shortname, "uuac")) | |
61 | row = 2; | |
62 | else | |
63 | row = 1; | |
64 | if (!strcmp(argv[row], UNIQUE_UID) || atoi(argv[row]) == -1) { | |
65 | if (set_next_object_id("uid", "users", 1)) | |
66 | return(MR_INGRES_ERR); | |
67 | EXEC SQL SELECT value INTO :nuid FROM numvalues WHERE name = 'uid'; | |
68 | if (sqlca.sqlerrd[2] != 1) | |
69 | return(MR_INTERNAL); | |
70 | sprintf(argv[row], "%d", nuid); | |
71 | } | |
72 | ||
73 | if (!strcmp(argv[0], UNIQUE_LOGIN) || atoi(argv[row]) == -1) { | |
74 | sprintf(argv[0], "#%s", argv[row]); | |
75 | } | |
76 | ||
77 | if((mr_errcode=prefetch_value(q,argv,cl))!=MR_SUCCESS) | |
78 | return(mr_errcode); | |
79 | ||
80 | return(MR_SUCCESS); | |
81 | } | |
82 | ||
83 | ||
84 | /* setup_dusr - verify that the user is no longer being referenced | |
85 | * and may safely be deleted. | |
86 | */ | |
87 | ||
88 | int setup_dusr(q, argv) | |
89 | struct query *q; | |
90 | char **argv; | |
91 | { | |
92 | EXEC SQL BEGIN DECLARE SECTION; | |
93 | int flag, id, cnt; | |
94 | EXEC SQL END DECLARE SECTION; | |
95 | ||
96 | id = *(int *)argv[0]; | |
97 | ||
98 | /* For now, only allow users to be deleted if their status is 0 */ | |
99 | EXEC SQL REPEATED SELECT status INTO :flag FROM users | |
100 | WHERE users_id = :id; | |
101 | if (flag != 0 && flag != 4) | |
102 | return(MR_IN_USE); | |
103 | ||
104 | EXEC SQL REPEATED DELETE FROM quota WHERE entity_id = :id AND type='USER'; | |
105 | EXEC SQL REPEATED DELETE FROM krbmap WHERE users_id = :id; | |
106 | EXEC SQL REPEATED SELECT COUNT(member_id) INTO :cnt FROM imembers | |
107 | WHERE member_id = :id AND member_type = 'USER'; | |
108 | if (cnt > 0) | |
109 | return(MR_IN_USE); | |
110 | EXEC SQL REPEATED SELECT COUNT(label) INTO :cnt FROM filesys | |
111 | WHERE owner = :id; | |
112 | if (cnt > 0) | |
113 | return(MR_IN_USE); | |
114 | EXEC SQL REPEATED SELECT COUNT(name) INTO :cnt FROM list | |
115 | WHERE acl_id = :id AND acl_type = 'USER'; | |
116 | if (cnt > 0) | |
117 | return(MR_IN_USE); | |
118 | EXEC SQL REPEATED SELECT COUNT(name) INTO :cnt FROM servers | |
119 | WHERE acl_id = :id AND acl_type = 'USER'; | |
120 | if (cnt > 0) | |
121 | return(MR_IN_USE); | |
122 | EXEC SQL REPEATED SELECT COUNT(acl_id) INTO :cnt FROM hostaccess | |
123 | WHERE acl_id = :id AND acl_type = 'USER'; | |
124 | if (cnt > 0) | |
125 | return(MR_IN_USE); | |
126 | if (ingres_errno) | |
127 | return(mr_errcode); | |
128 | return(MR_SUCCESS); | |
129 | } | |
130 | ||
131 | ||
132 | /* setup_spop: verify that there is already a valid POP machine_id in the | |
133 | * pop_id field. Also take care of keeping track of the post office usage. | |
134 | */ | |
135 | int setup_spop(q, argv) | |
136 | struct query *q; | |
137 | char **argv; | |
138 | { | |
139 | EXEC SQL BEGIN DECLARE SECTION; | |
140 | int id, mid, flag; | |
141 | char type[9]; | |
142 | EXEC SQL END DECLARE SECTION; | |
143 | ||
144 | id = *(int *)argv[0]; | |
145 | EXEC SQL REPEATED SELECT potype, pop_id INTO :type, :mid FROM users | |
146 | WHERE users_id = :id; | |
147 | if(sqlca.sqlerrd[2] = 0) | |
148 | return(MR_MACHINE); | |
149 | EXEC SQL REPEATED SELECT mach_id INTO :mid FROM machine | |
150 | WHERE mach_id = :mid; | |
151 | if (sqlca.sqlerrd[2] = 0) | |
152 | return(MR_MACHINE); | |
153 | if (strcmp(strtrim(type), "POP")) | |
154 | set_pop_usage(mid, 1); | |
155 | return(MR_SUCCESS); | |
156 | } | |
157 | ||
158 | ||
159 | /* setup_dpob: Take care of keeping track of the post office usage. | |
160 | */ | |
161 | int setup_dpob(q, argv) | |
162 | struct query *q; | |
163 | char **argv; | |
164 | { | |
165 | EXEC SQL BEGIN DECLARE SECTION; | |
166 | int id, user; | |
167 | char type[9]; | |
168 | EXEC SQL END DECLARE SECTION; | |
169 | ||
170 | user = *(int *)argv[0]; | |
171 | EXEC SQL REPEATED SELECT potype, pop_id INTO :type, :id FROM users | |
172 | WHERE users_id = :user; | |
173 | if (ingres_errno) return(mr_errcode); | |
174 | ||
175 | if (!strcmp(strtrim(type), "POP")) | |
176 | set_pop_usage(id, -1); | |
177 | return(MR_SUCCESS); | |
178 | } | |
179 | ||
180 | ||
181 | /* setup_dmac - verify that the machine is no longer being referenced | |
182 | * and may safely be deleted. | |
183 | */ | |
184 | ||
185 | int setup_dmac(q, argv) | |
186 | struct query *q; | |
187 | char **argv; | |
188 | { | |
189 | EXEC SQL BEGIN DECLARE SECTION; | |
190 | int flag, id, cnt; | |
191 | EXEC SQL END DECLARE SECTION; | |
192 | ||
193 | id = *(int *)argv[0]; | |
194 | EXEC SQL REPEATED SELECT COUNT(login) INTO :cnt FROM users | |
195 | WHERE potype='POP' AND pop_id = :id; | |
196 | if (cnt > 0) | |
197 | return(MR_IN_USE); | |
198 | EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM serverhosts | |
199 | WHERE mach_id = :id; | |
200 | if (cnt > 0) | |
201 | return(MR_IN_USE); | |
202 | EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM nfsphys | |
203 | WHERE mach_id = :id; | |
204 | if (cnt > 0) | |
205 | return(MR_IN_USE); | |
206 | EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM hostaccess | |
207 | WHERE mach_id = :id; | |
208 | if (cnt > 0) | |
209 | return(MR_IN_USE); | |
210 | EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM printcap | |
211 | WHERE mach_id = :id; | |
212 | if (cnt > 0) | |
213 | return(MR_IN_USE); | |
214 | EXEC SQL REPEATED SELECT COUNT(quotaserver) INTO :cnt FROM printcap | |
215 | WHERE quotaserver = :id; | |
216 | if (cnt > 0) | |
217 | return(MR_IN_USE); | |
218 | EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM palladium | |
219 | WHERE mach_id = :id; | |
220 | if (cnt > 0) | |
221 | return(MR_IN_USE); | |
222 | ||
223 | EXEC SQL REPEATED DELETE FROM mcmap WHERE mach_id = :id; | |
224 | if (ingres_errno) return(mr_errcode); | |
225 | return(MR_SUCCESS); | |
226 | } | |
227 | ||
228 | ||
229 | /* setup_dsnt - verify that the subnet is no longer being referenced | |
230 | * and may safely be deleted. | |
231 | */ | |
232 | ||
233 | int setup_dsnt(q, argv) | |
234 | struct query *q; | |
235 | char **argv; | |
236 | { | |
237 | EXEC SQL BEGIN DECLARE SECTION; | |
238 | int flag, id, cnt = 0; | |
239 | EXEC SQL END DECLARE SECTION; | |
240 | ||
241 | #ifdef notdef | |
242 | id = *(int *)argv[0]; | |
243 | EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM machine | |
244 | WHERE snet_id = :id; | |
245 | if (cnt > 0) | |
246 | return(MR_IN_USE); | |
247 | #endif | |
248 | return(MR_SUCCESS); | |
249 | } | |
250 | ||
251 | ||
252 | /* setup_dclu - verify that the cluster is no longer being referenced | |
253 | * and may safely be deleted. | |
254 | */ | |
255 | ||
256 | int setup_dclu(q, argv) | |
257 | struct query *q; | |
258 | char **argv; | |
259 | { | |
260 | EXEC SQL BEGIN DECLARE SECTION; | |
261 | int id, cnt; | |
262 | EXEC SQL END DECLARE SECTION; | |
263 | ||
264 | id = *(int *)argv[0]; | |
265 | EXEC SQL REPEATED SELECT COUNT(mach_id) INTO :cnt FROM mcmap | |
266 | WHERE clu_id = :id; | |
267 | if (cnt > 0) | |
268 | return(MR_IN_USE); | |
269 | EXEC SQL REPEATED SELECT COUNT(clu_id) INTO :cnt FROM svc | |
270 | WHERE clu_id = :id; | |
271 | if (cnt > 0) | |
272 | return(MR_IN_USE); | |
273 | if (ingres_errno) | |
274 | return(mr_errcode); | |
275 | return(MR_SUCCESS); | |
276 | } | |
277 | ||
278 | ||
279 | /* setup_alis - if argv[5] is non-zero and argv[6] is UNIQUE_ID, then allocate | |
280 | * a new gid and put it in argv[6]. Otherwise if argv[6] is UNIQUE_ID but | |
281 | * argv[5] is not, then remember that UNIQUE_ID is being stored by putting | |
282 | * a -1 there. Remember that this is also used for ulis, with the indexes | |
283 | * at 6 & 7. Also check that the list name does not contain uppercase | |
284 | * characters, control characters, @, or :. | |
285 | */ | |
286 | ||
287 | static int badlistchars[] = { | |
288 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */ | |
289 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */ | |
290 | 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */ | |
291 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, /* 0 - ? */ | |
292 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* @ - O */ | |
293 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* P - _ */ | |
294 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ | |
295 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - ^? */ | |
296 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
297 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
298 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
299 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
300 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
301 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
302 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
303 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
304 | }; | |
305 | ||
306 | int setup_alis(q, argv, cl) | |
307 | struct query *q; | |
308 | char *argv[]; | |
309 | client *cl; | |
310 | { | |
311 | EXEC SQL BEGIN DECLARE SECTION; | |
312 | int ngid; | |
313 | EXEC SQL END DECLARE SECTION; | |
314 | char *malloc(); | |
315 | unsigned char *p; | |
316 | int idx; | |
317 | ||
318 | if (!strcmp(q->shortname, "alis")) | |
319 | idx = 0; | |
320 | else if (!strcmp(q->shortname, "ulis")) | |
321 | idx = 1; | |
322 | ||
323 | for (p = (unsigned char *) argv[idx]; *p; p++) | |
324 | if (badlistchars[*p]) | |
325 | return(MR_BAD_CHAR); | |
326 | ||
327 | if (!strcmp(argv[6 + idx], UNIQUE_GID) || atoi(argv[6 + idx]) == -1) { | |
328 | if (atoi(argv[5 + idx])) { | |
329 | if (set_next_object_id("gid", "list", 1)) | |
330 | return(MR_INGRES_ERR); | |
331 | EXEC SQL REPEATED SELECT value INTO :ngid FROM numvalues | |
332 | WHERE name = 'gid'; | |
333 | if (ingres_errno) return(mr_errcode); | |
334 | sprintf(argv[6 + idx], "%d", ngid); | |
335 | } else { | |
336 | strcpy(argv[6 + idx], "-1"); | |
337 | } | |
338 | } | |
339 | ||
340 | if((mr_errcode=prefetch_value(q,argv,cl))!=MR_SUCCESS) | |
341 | return(mr_errcode); | |
342 | ||
343 | return(MR_SUCCESS); | |
344 | } | |
345 | ||
346 | ||
347 | /* setup_dlis - verify that the list is no longer being referenced | |
348 | * and may safely be deleted. | |
349 | */ | |
350 | ||
351 | int setup_dlis(q, argv) | |
352 | struct query *q; | |
353 | char *argv[]; | |
354 | { | |
355 | int flag, id, ec; | |
356 | ||
357 | id = *(int *)argv[0]; | |
358 | sprintf(stmt_buf,"SELECT member_id FROM imembers WHERE member_id = %d AND member_type='LIST'",id); | |
359 | if(ec=mr_select_any(stmt_buf)) { | |
360 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
361 | } | |
362 | ||
363 | sprintf(stmt_buf,"SELECT member_id FROM imembers WHERE list_id = %d",id); | |
364 | if(ec=mr_select_any(stmt_buf)) { | |
365 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
366 | } | |
367 | ||
368 | sprintf(stmt_buf,"SELECT label FROM filesys WHERE owners = %d",id); | |
369 | if(ec=mr_select_any(stmt_buf)) { | |
370 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
371 | } | |
372 | ||
373 | sprintf(stmt_buf,"SELECT tag FROM capacls WHERE list_id = %d",id); | |
374 | if(ec=mr_select_any(stmt_buf)) { | |
375 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
376 | } | |
377 | ||
378 | sprintf(stmt_buf,"SELECT name FROM list WHERE acl_id = %d AND acl_type='LIST' AND list_id != %d",id,id); | |
379 | if(ec=mr_select_any(stmt_buf)) { | |
380 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
381 | } | |
382 | ||
383 | sprintf(stmt_buf,"SELECT name FROM servers WHERE acl_id = %d AND acl_type='LIST'",id); | |
384 | if(ec=mr_select_any(stmt_buf)) { | |
385 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
386 | } | |
387 | ||
388 | sprintf(stmt_buf,"SELECT entity_id FROM quota WHERE entity_id = %d AND type='GROUP'",id); | |
389 | if(ec=mr_select_any(stmt_buf)) { | |
390 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
391 | } | |
392 | ||
393 | sprintf(stmt_buf,"SELECT acl_id FROM hostaccess WHERE acl_id = %d AND acl_type='LIST'",id); | |
394 | if(ec=mr_select_any(stmt_buf)) { | |
395 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
396 | } | |
397 | ||
398 | sprintf(stmt_buf,"SELECT class FROM zephyr z \ | |
399 | WHERE z.xmt_type = 'LIST' AND z.xmt_id = %d \ | |
400 | OR z.sub_type = 'LIST' AND z.sub_id = %d \ | |
401 | OR z.iws_type = 'LIST' AND z.iws_id = %d \ | |
402 | OR z.iui_type = 'LIST' AND z.iui_id = %d",id,id,id,id); | |
403 | if(ec=mr_select_any(stmt_buf)) { | |
404 | if(ec==MR_EXISTS) return(MR_IN_USE); else return(ec); | |
405 | } | |
406 | ||
407 | return(MR_SUCCESS); | |
408 | } | |
409 | ||
410 | ||
411 | /* setup_dsin - verify that the service is no longer being referenced | |
412 | * and may safely be deleted. | |
413 | */ | |
414 | ||
415 | int setup_dsin(q, argv) | |
416 | struct query *q; | |
417 | char **argv; | |
418 | { | |
419 | EXEC SQL BEGIN DECLARE SECTION; | |
420 | int ec; | |
421 | char *svrname; | |
422 | EXEC SQL END DECLARE SECTION; | |
423 | ||
424 | sprintf(stmt_buf,"SELECT service FROM serverhosts WHERE service = UPPERCASE('%s')",argv[0]); | |
425 | if(ec=mr_select_any(stmt_buf)) { | |
426 | if(ec==MR_EXISTS) | |
427 | return(MR_IN_USE); | |
428 | else | |
429 | return(ec); | |
430 | } | |
431 | ||
432 | svrname=argv[0]; | |
433 | EXEC SQL SELECT inprogress INTO :ec FROM servers | |
434 | WHERE name=UPPERCASE(:svrname); | |
435 | if(ingres_errno) | |
436 | return(mr_errcode); | |
437 | if(ec) | |
438 | return(MR_IN_USE); | |
439 | ||
440 | return(MR_SUCCESS); | |
441 | } | |
442 | ||
443 | ||
444 | /* setup_dshi - verify that the service-host is no longer being referenced | |
445 | * and may safely be deleted. | |
446 | */ | |
447 | ||
448 | int setup_dshi(q, argv) | |
449 | struct query *q; | |
450 | char **argv; | |
451 | { | |
452 | EXEC SQL BEGIN DECLARE SECTION; | |
453 | int id, ec; | |
454 | char *svrname; | |
455 | EXEC SQL END DECLARE SECTION; | |
456 | ||
457 | svrname=argv[0]; | |
458 | id = *(int *)argv[1]; | |
459 | ||
460 | EXEC SQL SELECT inprogress INTO :ec FROM serverhosts | |
461 | WHERE service=UPPERCASE(:svrname) AND mach_id = :id; | |
462 | if(ingres_errno) | |
463 | return(mr_errcode); | |
464 | if(ec) | |
465 | return(MR_IN_USE); | |
466 | ||
467 | ||
468 | return(MR_SUCCESS); | |
469 | } | |
470 | ||
471 | ||
472 | /** | |
473 | ** setup_add_filesys - verify existance of referenced file systems | |
474 | ** | |
475 | ** Inputs: Add | |
476 | ** argv[1] - type | |
477 | ** argv[2] - mach_id | |
478 | ** argv[3] - name | |
479 | ** argv[5] - access | |
480 | ** | |
481 | ** Description: | |
482 | ** - for type = RVD: | |
483 | ** * allow anything | |
484 | ** - for type = NFS: | |
485 | ** * extract directory prefix from name | |
486 | ** * verify mach_id/dir in nfsphys | |
487 | ** * verify access in {r, w, R, W} | |
488 | ** | |
489 | ** Side effect: sets variable _var_phys_id to the ID of the physical | |
490 | ** filesystem (nfsphys_id for NFS, 0 for RVD) | |
491 | ** | |
492 | ** Errors: | |
493 | ** MR_NFS - specified directory not exported | |
494 | ** MR_FILESYS_ACCESS - invalid filesys access | |
495 | ** | |
496 | **/ | |
497 | ||
498 | EXEC SQL BEGIN DECLARE SECTION; | |
499 | int _var_phys_id; | |
500 | EXEC SQL END DECLARE SECTION; | |
501 | ||
502 | setup_afil(q, argv, cl) | |
503 | struct query *q; | |
504 | char *argv[]; | |
505 | client *cl; | |
506 | { | |
507 | char *type, *name; | |
508 | int mach_id; | |
509 | EXEC SQL BEGIN DECLARE SECTION; | |
510 | int ok; | |
511 | char ftype[32], *access; | |
512 | EXEC SQL END DECLARE SECTION; | |
513 | ||
514 | type = argv[1]; | |
515 | mach_id = *(int *)argv[2]; | |
516 | name = argv[3]; | |
517 | access = argv[5]; | |
518 | _var_phys_id = 0; | |
519 | ||
520 | sprintf(ftype, "fs_access_%s", type); | |
521 | EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias | |
522 | WHERE name = :ftype AND type = 'TYPE' and trans = :access; | |
523 | if (ingres_errno) return(mr_errcode); | |
524 | if (ok == 0) return(MR_FILESYS_ACCESS); | |
525 | ||
526 | if((mr_errcode=prefetch_value(q,argv,cl))!=MR_SUCCESS) | |
527 | return(mr_errcode); | |
528 | ||
529 | if (!strcmp(type, "NFS")) | |
530 | return (check_nfs(mach_id, name, access)); | |
531 | ||
532 | return(MR_SUCCESS); | |
533 | } | |
534 | ||
535 | ||
536 | /* Verify the arguments, depending on the FStype. Also, if this is an | |
537 | * NFS filesystem, then update any quotas for that filesystem to reflect | |
538 | * the new phys_id. | |
539 | */ | |
540 | ||
541 | setup_ufil(q, argv, cl) | |
542 | struct query *q; | |
543 | char *argv[]; | |
544 | client *cl; | |
545 | { | |
546 | int mach_id, status; | |
547 | char *type, *name; | |
548 | EXEC SQL BEGIN DECLARE SECTION; | |
549 | int fid, total, who, ok; | |
550 | char *entity, ftype[32], *access; | |
551 | short int total_null; | |
552 | EXEC SQL END DECLARE SECTION; | |
553 | ||
554 | _var_phys_id = 0; | |
555 | type = argv[2]; | |
556 | mach_id = *(int *)argv[3]; | |
557 | name = argv[4]; | |
558 | access = argv[6]; | |
559 | fid = *(int *)argv[0]; | |
560 | who = cl->client_id; | |
561 | entity = cl->entity; | |
562 | ||
563 | sprintf(ftype, "fs_access_%s", type); | |
564 | EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias | |
565 | WHERE name = :ftype AND type='TYPE' AND trans = :access; | |
566 | if (ingres_errno) return(mr_errcode); | |
567 | if (ok == 0) return(MR_FILESYS_ACCESS); | |
568 | ||
569 | EXEC SQL SELECT type INTO :ftype FROM filesys | |
570 | WHERE filsys_id = :fid; | |
571 | strtrim(ftype); | |
572 | if (ingres_errno) return(mr_errcode); | |
573 | ||
574 | if (!strcmp(type, "NFS")) { | |
575 | status = check_nfs(mach_id, name, access); | |
576 | EXEC SQL UPDATE quota SET phys_id = :_var_phys_id | |
577 | WHERE filsys_id = :fid; | |
578 | if (ingres_errno) return(mr_errcode); | |
579 | return(status); | |
580 | } else if (!strcmp(type, "AFS") && strcmp(ftype, "AFS")) { | |
581 | total = 0; | |
582 | EXEC SQL REPEATED DELETE FROM quota | |
583 | WHERE type = 'ANY' AND filsys_id = :fid; | |
584 | EXEC SQL SELECT SUM (quota) INTO :total:total_null FROM quota | |
585 | WHERE filsys_id = :fid AND phys_id != 0; | |
586 | if (ingres_errno) return(mr_errcode); | |
587 | if (!total_null && (total != 0)) { | |
588 | /* | |
589 | * append quota (quota = total, filsys_id = fid, | |
590 | * phys_id = 0, entity_id = 0, type = "ANY", | |
591 | * modtime = "now", modby = who, modwith = entity) | |
592 | */ | |
593 | EXEC SQL INSERT INTO quota (quota, filsys_id, phys_id, entity_id, | |
594 | type, modtime, modby, modwith) | |
595 | VALUES (:total, :fid, 0, 0, | |
596 | 'ANY', 'now', :who, :entity) ; | |
597 | if (ingres_errno) return(mr_errcode); | |
598 | } | |
599 | } else { | |
600 | EXEC SQL UPDATE quota SET phys_id = 0 WHERE filsys_id = :fid; | |
601 | if (ingres_errno) return(mr_errcode); | |
602 | } | |
603 | return(MR_SUCCESS); | |
604 | } | |
605 | ||
606 | ||
607 | /* Find the NFS physical partition that the named directory is on. | |
608 | * This is done by comparing the dir against the mount point of the | |
609 | * partition. To make sure we get the correct match when there is | |
610 | * more than one, we sort the query in reverse order by dir name. | |
611 | */ | |
612 | ||
613 | check_nfs(mach_id, name, access) | |
614 | EXEC SQL BEGIN DECLARE SECTION; | |
615 | int mach_id; | |
616 | EXEC SQL END DECLARE SECTION; | |
617 | char *name; | |
618 | char *access; | |
619 | { | |
620 | EXEC SQL BEGIN DECLARE SECTION; | |
621 | char dir[81]; | |
622 | EXEC SQL END DECLARE SECTION; | |
623 | char caccess; | |
624 | register int status; | |
625 | register char *cp1; | |
626 | register char *cp2; | |
627 | ||
628 | status = MR_NFS; | |
629 | EXEC SQL DECLARE csr101 CURSOR FOR | |
630 | SELECT nfsphys_id, TRIM (dir) FROM nfsphys | |
631 | WHERE mach_id = :mach_id | |
632 | ORDER BY 2 DESC; | |
633 | if (ingres_errno) | |
634 | return(mr_errcode); | |
635 | EXEC SQL OPEN csr101; | |
636 | if (ingres_errno) | |
637 | return(mr_errcode); | |
638 | while(1) { | |
639 | EXEC SQL FETCH csr101 INTO :_var_phys_id, :dir; | |
640 | if(sqlca.sqlcode != 0) break; | |
641 | cp1 = name; | |
642 | cp2 = dir; | |
643 | while (*cp2) { | |
644 | if (*cp1++ != *cp2) break; | |
645 | cp2++; | |
646 | } | |
647 | if (*cp2 == 0) { | |
648 | status = MR_SUCCESS; | |
649 | break; | |
650 | } | |
651 | } | |
652 | EXEC SQL CLOSE csr101; | |
653 | if (ingres_errno) | |
654 | return(mr_errcode); | |
655 | return(status); | |
656 | } | |
657 | ||
658 | ||
659 | /* setup_dfil: free any quota records and fsgroup info associated with | |
660 | * a filesystem when it is deleted. Also adjust the allocation numbers. | |
661 | */ | |
662 | ||
663 | setup_dfil(q, argv, cl) | |
664 | struct query *q; | |
665 | char **argv; | |
666 | client *cl; | |
667 | { | |
668 | EXEC SQL BEGIN DECLARE SECTION; | |
669 | int id, total, phys_id; | |
670 | short int none; | |
671 | EXEC SQL END DECLARE SECTION; | |
672 | ||
673 | id = *(int *)argv[0]; | |
674 | EXEC SQL REPEATED SELECT SUM (quota) INTO :total:none FROM quota | |
675 | WHERE filsys_id = :id; | |
676 | ||
677 | if(none) total=0; | |
678 | ||
679 | /** What if there are multiple phys_id's per f/s? (bad data) **/ | |
680 | EXEC SQL REPEATED SELECT phys_id INTO :phys_id FROM filesys | |
681 | WHERE filsys_id = :id; | |
682 | EXEC SQL REPEATED UPDATE nfsphys SET allocated = allocated - :total | |
683 | WHERE nfsphys_id = :phys_id; | |
684 | ||
685 | if(!none) { | |
686 | EXEC SQL REPEATED DELETE FROM quota WHERE filsys_id = :id; | |
687 | } | |
688 | EXEC SQL REPEATED DELETE FROM fsgroup WHERE filsys_id = :id; | |
689 | EXEC SQL REPEATED DELETE FROM fsgroup WHERE group_id = :id; | |
690 | if (ingres_errno) return(mr_errcode); | |
691 | return(MR_SUCCESS); | |
692 | } | |
693 | ||
694 | ||
695 | /* setup_dnfp: check to see that the nfs physical partition does not have | |
696 | * any filesystems assigned to it before allowing it to be deleted. | |
697 | */ | |
698 | ||
699 | setup_dnfp(q, argv, cl) | |
700 | struct query *q; | |
701 | char **argv; | |
702 | client *cl; | |
703 | { | |
704 | EXEC SQL BEGIN DECLARE SECTION; | |
705 | int id, cnt; | |
706 | char *dir; | |
707 | EXEC SQL END DECLARE SECTION; | |
708 | ||
709 | id = *(int *)argv[0]; | |
710 | dir = argv[1]; | |
711 | EXEC SQL REPEATED SELECT fs.tid INTO :cnt FROM filesys fs, nfsphys np | |
712 | WHERE fs.mach_id = :id AND fs.phys_id = np.nfsphys_id | |
713 | AND np.mach_id = :id AND np.dir = :dir; | |
714 | if (cnt > 0) | |
715 | return(MR_IN_USE); | |
716 | if (ingres_errno) | |
717 | return(mr_errcode); | |
718 | return(MR_SUCCESS); | |
719 | } | |
720 | ||
721 | ||
722 | /* setup_dqot: Remove allocation from nfsphys before deleting quota. | |
723 | * argv[0] = filsys_id | |
724 | * argv[1] = type if "update_quota" or "delete_quota" | |
725 | * argv[2 or 1] = users_id or list_id | |
726 | */ | |
727 | ||
728 | setup_dqot(q, argv, cl) | |
729 | struct query *q; | |
730 | char **argv; | |
731 | client *cl; | |
732 | { | |
733 | EXEC SQL BEGIN DECLARE SECTION; | |
734 | int quota, fs, id, physid; | |
735 | char *qtype; | |
736 | EXEC SQL END DECLARE SECTION; | |
737 | ||
738 | fs = *(int *)argv[0]; | |
739 | if (!strcmp(q->name, "update_quota") || !strcmp(q->name, "delete_quota")) { | |
740 | qtype = argv[1]; | |
741 | id = *(int *)argv[2]; | |
742 | } else { | |
743 | qtype = "USER"; | |
744 | id = *(int *)argv[1]; | |
745 | } | |
746 | ||
747 | EXEC SQL REPEATED SELECT quota INTO :quota FROM quota | |
748 | WHERE type = :qtype AND entity_id = :id AND filsys_id = :fs; | |
749 | EXEC SQL REPEATED SELECT phys_id INTO :physid FROM filesys | |
750 | WHERE filsys_id = :fs; | |
751 | EXEC SQL REPEATED UPDATE nfsphys SET allocated = allocated - :quota | |
752 | WHERE nfsphys_id = :physid; | |
753 | ||
754 | if (ingres_errno) return(mr_errcode); | |
755 | return(MR_SUCCESS); | |
756 | } | |
757 | ||
758 | ||
759 | /* setup_sshi: don't exclusive lock the machine table during | |
760 | * set_server_host_internal. | |
761 | */ | |
762 | /** Not allowed under (INGRES) SQL **/ | |
763 | setup_sshi(q, argv, cl) | |
764 | struct query *q; | |
765 | char **argv; | |
766 | client *cl; | |
767 | { | |
768 | #if 0 | |
769 | #ifsql INGRES | |
770 | EXEC SQL set lockmode session where readlock = system; | |
771 | #endsql | |
772 | #endif | |
773 | return(MR_SUCCESS); | |
774 | } | |
775 | ||
776 | ||
777 | /* setup add_kerberos_user_mapping: add the string to the string | |
778 | * table if necessary. | |
779 | */ | |
780 | ||
781 | setup_akum(q, argv, cl) | |
782 | struct query *q; | |
783 | char **argv; | |
784 | client *cl; | |
785 | { | |
786 | EXEC SQL BEGIN DECLARE SECTION; | |
787 | int id, rowcount; | |
788 | char *name; | |
789 | EXEC SQL END DECLARE SECTION; | |
790 | ||
791 | name = argv[1]; | |
792 | if (name_to_id(name, "STRING", &id) != MR_SUCCESS) { | |
793 | if (q->type != APPEND) return(MR_STRING); | |
794 | id=add_string(name); | |
795 | cache_entry(name, "STRING", id); | |
796 | } | |
797 | if (ingres_errno) return(mr_errcode); | |
798 | *(int *)argv[1] = id; | |
799 | return(MR_SUCCESS); | |
800 | } | |
801 |