]> andersk Git - moira.git/blame - regtape/uidfix.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[moira.git] / regtape / uidfix.qc
CommitLineData
3fb06882 1/* $Header$
2 *
3 * This program will change UIDs on users who are not active so that
4 * no UIDs are > 32000.
5 */
6
7#include <stdio.h>
8#include <strings.h>
9#include <ctype.h>
10#include <sys/time.h>
11#include <moira.h>
12#include <moira_site.h>
13
14#define MAX_ID_VALUE 31999
15#define MIN_ID_VALUE 101
16
17
18char *program;
19
20main(argc, argv)
21int argc;
22char **argv;
23##{
24 char buf[BUFSIZ], *p;
25 struct save_queue *sq;
26 int found, status, wait, i;
27## int id, uid;
28
29 program = "uidfix";
30 init_krb_err_tbl();
31 init_sms_err_tbl();
32
33 for (i = 1; i < argc; i++) {
34 if (!strcmp(argv[i], "-w"))
35 wait++;
36 else if (!strcmp(argv[i], "-D"))
37 setenv("ING_SET", "set printqry");
38 else
39 fprintf(stderr, "Usage: %s [-w] [-D]\n", argv[0]);
40 }
41
42## ingres sms
43## range of u is users
44
45 found = 0;
46 sq = sq_create();
47
48## retrieve (id = u.users_id)
49## where u.#uid >= 32000 and (u.status = 0 or u.status = 4) {
50 sq_save_data(sq, id);
51 found++;
52## }
53
54 printf("Found %d users to change.\n", found);
55
56 while (sq_get_data(sq, &id)) {
57 uid = set_next_object_id("uid", 1);
58## replace u (#uid = uid) where u.users_id = id
59 if (wait) {
60 printf("Next");
61 fflush(stdout);
62 gets(buf);
63 }
64 }
65## exit
66 exit(0);
67##}
68
69
70set_next_object_id(object, limit)
71 char *object;
72 int limit;
73##{
74## char *name;
75## int rowcount, exists, value;
76
77 name = object;
78## begin transaction
79## repeat retrieve (value = values.#value) where values.#name = @name
80## inquire_equel(rowcount = "rowcount")
81 if (rowcount != 1) {
82## abort
83 return(0);
84 }
85
86## retrieve (exists = any(users.name where users.name = value))
87## inquire_equel(rowcount = "rowcount")
88 if (rowcount != 1) {
89## abort
90 return(0);
91 }
92 while (exists) {
93 value++;
94 if (limit && value > MAX_ID_VALUE)
95 value = MIN_ID_VALUE;
96## retrieve (exists = any(users.name where users.name = value))
97 }
98
99## repeat replace values (#value = @value) where values.#name = @name
100## end transaction
101 return(value);
102##}
This page took 0.073888 seconds and 5 git commands to generate.