]> andersk Git - moira.git/blame - afssync/sync.qc
*** empty log message ***
[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);
da6101af 48 initialize_sms_error_table();
49 initialize_pt_error_table();
50 Initdb();
62b40972 51
52## ingres sms
53## set lockmode session where level = table
54## begin transaction
55
56 do_passwd();
57 do_groups();
58
59## end transaction
60## exit
61
f00f36ed 62 exit(MR_SUCCESS);
62b40972 63}
64
65
66/*
67 * ingerr: (supposedly) called when Ingres indicates an error.
68 * I have not yet been able to get this to work to intercept a
69 * database open error.
70 */
71#define INGRES_DEADLOCK 4700
72
73static int ingerr(num)
74 int *num;
75{
76 char buf[256];
77 int ingres_errno;
78
79 switch (*num) {
80 case INGRES_DEADLOCK:
f00f36ed 81 ingres_errno = MR_DEADLOCK;
62b40972 82 break;
83 default:
f00f36ed 84 ingres_errno = MR_INGRES_ERR;
62b40972 85 }
f00f36ed 86 com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
62b40972 87 exit(ingres_errno);
88}
89
90
62b40972 91
92do_passwd()
93##{
94## char login[9];
95## int uid, id, status;
96
97 fprintf(stderr, "Doing users\n");
98 users = create_hash(10000);
99## range of u is users
100## retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
da6101af 101## where u.#uid > 0 and (u.#status = 1 or u.#status = 2) {
62b40972 102 strtrim(login);
103 hash_store(users, id, uid);
da6101af 104 if (FindByID (0, uid))
105 status = PRIDEXIST;
106 else
107 status = CreateEntry(0, login, &uid, 1/*idflag*/, 0/*gflag*/,
108 SYSADMINID/*oid*/, SYSADMINID/*cid*/);
109 if (status)
110 fprintf(stderr, "Error adding user %s uid %d: %s\n",
111 login, uid, error_message(status));
62b40972 112## }
113##}
114
115
116
117do_groups()
118##{
119 struct hash *groups;
da6101af 120 long u, g, status, gpos, upos;
121 struct prentry gentry, uentry;
62b40972 122## char name[33], namebuf[128];
8ec23c21 123## int gid, id, lid, hide;
da6101af 124 int aid;
125
62b40972 126 fprintf(stderr, "Doing groups\n");
127
128 /* make space for group list */
129 groups = create_hash(15000);
130
131 /* retrieve simple groups */
132## range of l is list
133## range of m is imembers
134 /* get lock records */
135## retrieve (name = l.modtime) where l.list_id = 0
136## retrieve (name = users.modtime) where users.users_id = 0
137
8ec23c21 138## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden)
da6101af 139## where l.group != 0 and l.active != 0 and l.#gid > 0 {
62b40972 140 strtrim(name);
141 sprintf(namebuf, "system:%s", name);
142 hash_store(groups, lid, -gid);
da6101af 143 aid = -gid;
144 if (gpos = FindByID (0, aid))
145 status = PRIDEXIST;
146 else
147 status = CreateEntry(0,namebuf,&aid,1/*idflag*/,PRGRP/*gflag*/,
148 SYSADMINID/*oid*/, SYSADMINID/*cid*/);
62b40972 149 if (status)
da6101af 150 fprintf(stderr, "Error adding group %s id %d: %s\n",
151 namebuf, aid, error_message(status));
152
153 /* If this list is hidden, set the pts entry to be s---- */
154 if (hide && (status==0 || status==PRIDEXIST)) {
155 if (!gpos)
156 gpos = FindByID(0, aid);
157 status = pr_ReadEntry(0, 0, gpos, &gentry);
158 if (!status) {
159 gentry.flags = PRGRP|PRACCESS|PRP_STATUS_ANY;
160 status = pr_WriteEntry(0, 0, gpos, &gentry);
161 }
8ec23c21 162 if (status)
da6101af 163 fprintf(stderr, "Error setting flags on group %s: %s\n",
164 namebuf, error_message(status));
8ec23c21 165 }
62b40972 166## }
167
168
169 fprintf(stderr, "Doing members\n");
170
171## retrieve (lid = m.list_id, id = m.member_id)
172## where m.member_type = "USER" {
173 if ((u = (long) hash_lookup(users, id)) &&
174 (g = (long) hash_lookup(groups, lid))) {
da6101af 175 if (g==ANYUSERID || g==AUTHUSERID || u==ANONYMOUSID) {
176 status = PRPERM;
177 } else if ((gpos = FindByID(0, g)) && (upos = FindByID(0, u))) {
178 status = pr_ReadEntry(0,0,upos,&uentry);
179 if (!status) status = pr_ReadEntry(0,0,gpos,&gentry);
180 if (!status) status = AddToEntry (0, &gentry, gpos, u);
181 if (!status) status = AddToEntry (0, &uentry, upos, g);
182 } else {
183 status = PRNOENT;
62b40972 184 }
da6101af 185 if (status)
186 fprintf(stderr, "Error adding uid %d to group %d: %s\n",
187 u, -g, error_message(status));
62b40972 188 }
189## }
190
191##}
192
This page took 0.089107 seconds and 5 git commands to generate.