]> andersk Git - moira.git/blame - afssync/sync.qc
Preserve hidden status of groups
[moira.git] / afssync / sync.qc
CommitLineData
62b40972 1/* $Header$
2 *
62b40972 3 *
f00f36ed 4 * (c) Copyright 1989 by the Massachusetts Institute of Technology.
62b40972 5 * For copying and distribution information, please see the file
6 * <mit-copyright.h>.
7 */
8
9#include <mit-copyright.h>
10#include <stdio.h>
11#include <sys/file.h>
8ec23c21 12
62b40972 13#include <rx/xdr.h>
8ec23c21 14#include "ptint.h"
15#include "ptserver.h"
16#include "pterror.h"
17
f00f36ed 18#include <moira.h>
19#include <moira_site.h>
62b40972 20#include <ctype.h>
21
62b40972 22#define min(x,y) ((x) < (y) ? (x) : (y))
23struct hash *users = NULL;
24char *whoami = "sync";
25
26char *malloc(), *strsave();
27int dbase_fd;
28
29
30main(argc, argv)
31int argc;
32char **argv;
33{
278dd826 34 int status;
62b40972 35 int ingerr();
36
37 if (argc != 2) {
38 fprintf(stderr, "usage: %s outfile\n", argv[0]);
f00f36ed 39 exit(MR_ARGS);
62b40972 40 }
41
42 dbase_fd = open(argv[1], O_RDWR|O_CREAT, 0660);
43 if (dbase_fd < 0) {
44 perror("opening file %s", argv[1]);
45 exit(1);
46 }
47 IIseterr(ingerr);
48 initialize_sms_error_table ();
49
50## ingres sms
51## set lockmode session where level = table
52## begin transaction
53
54 do_passwd();
8ec23c21 55#if 0
56#define USERSMS 14487
278dd826 57 status = PR_AddToGroup(NULL, USERSMS, SYSADMINID);
58 if (status) {
f00f36ed 59 prserror(status, "adding MR to system:administrators", 0, 0);
278dd826 60 }
8ec23c21 61#endif
62b40972 62 do_groups();
63
64## end transaction
65## exit
66
f00f36ed 67 exit(MR_SUCCESS);
62b40972 68}
69
70
71/*
72 * ingerr: (supposedly) called when Ingres indicates an error.
73 * I have not yet been able to get this to work to intercept a
74 * database open error.
75 */
76#define INGRES_DEADLOCK 4700
77
78static int ingerr(num)
79 int *num;
80{
81 char buf[256];
82 int ingres_errno;
83
84 switch (*num) {
85 case INGRES_DEADLOCK:
f00f36ed 86 ingres_errno = MR_DEADLOCK;
62b40972 87 break;
88 default:
f00f36ed 89 ingres_errno = MR_INGRES_ERR;
62b40972 90 }
f00f36ed 91 com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
62b40972 92 exit(ingres_errno);
93}
94
95
96prserror(status, msg, arg1, arg2)
97int status;
98char *msg;
99unsigned long arg1, arg2;
100{
101 char buf[512];
102
103 sprintf(buf, msg, arg1, arg2);
104 switch (status) {
105 case PREXIST:
106 msg = "name already exists";
107 break;
108 case PRIDEXIST:
109 msg = "ID already exists";
110 break;
111 case PRNOIDS:
112 msg = "no IDs available";
113 break;
114 case PRDBFAIL:
115 msg = "database failed";
116 break;
117 case PRNOENT:
118 msg = "no space left in database";
119 break;
120 case PRPERM:
121 msg = "permission denied";
122 break;
123 case PRNOTGROUP:
124 msg = "not a group";
125 break;
126 case PRNOTUSER:
127 msg = "not a user";
128 break;
129 case PRBADNAM:
130 msg = "bad name";
131 break;
132 case 0:
133 msg = "no error";
134 break;
135 default:
136 msg = "unknown code";
137 break;
138 }
139 fprintf(stderr, "%s (%d): %s\n", msg, status, buf);
140}
141
142
143
144do_passwd()
145##{
146## char login[9];
147## int uid, id, status;
148
149 fprintf(stderr, "Doing users\n");
150 users = create_hash(10000);
151## range of u is users
152## retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
153## where u.#status = 1 {
154 strtrim(login);
155 hash_store(users, id, uid);
156 status = PR_INewEntry(NULL, login, uid, 0);
157 if (status) {
158 prserror(status, "adding user %s uid %d", login, uid);
159 }
160## }
161##}
162
163
164
165do_groups()
166##{
167 struct hash *groups;
168 long u, g, status;
169## char name[33], namebuf[128];
8ec23c21 170## int gid, id, lid, hide;
62b40972 171
172 fprintf(stderr, "Doing groups\n");
173
174 /* make space for group list */
175 groups = create_hash(15000);
176
177 /* retrieve simple groups */
178## range of l is list
179## range of m is imembers
180 /* get lock records */
181## retrieve (name = l.modtime) where l.list_id = 0
182## retrieve (name = users.modtime) where users.users_id = 0
183
8ec23c21 184## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden)
62b40972 185## where l.group != 0 and l.active != 0 {
186 strtrim(name);
187 sprintf(namebuf, "system:%s", name);
188 hash_store(groups, lid, -gid);
189 status = PR_INewEntry(NULL, namebuf, -gid, SYSADMINID);
190 if (status)
8ec23c21 191 prserror(status, "adding list %s gid %d", namebuf, -gid);
192 else {
193 if (hide) {
194 status = PR_SetFieldsEntry
195 (NULL/*call*/, -gid,
196 PR_SF_ALLBITS/*mask*/,
197 PRP_STATUS_MEM >> PRIVATE_SHIFT /*flags*/,
198 0/*ngroups*/, 0/*nusers*/, 0/*spare1*/, 0/*spare2*/);
199 }
200 if (status)
201 prserror(status, "setting flags on list %s", namebuf);
202 }
62b40972 203## }
204
205
206 fprintf(stderr, "Doing members\n");
207
208## retrieve (lid = m.list_id, id = m.member_id)
209## where m.member_type = "USER" {
210 if ((u = (long) hash_lookup(users, id)) &&
211 (g = (long) hash_lookup(groups, lid))) {
212 status = PR_AddToGroup(NULL, u, g);
213 if (status) {
214 prserror(status, "adding %d to group %d", u, -g);
215 }
216 }
217## }
218
219##}
220
This page took 0.092721 seconds and 5 git commands to generate.