2 * (C) COPYRIGHT IBM CORPORATION 1987, 1988
3 * Copyright TRANSARC CORPORATION 1989
4 * LICENSED MATERIALS - PROPERTY OF IBM
7 * Implementation of basic procedures for the AFS user account
12 * --------------------- Required definitions ---------------------
14 #include "uss_ptserver.h" /*Module interface*/
15 #include <afs/ptclient.h> /*Protection Server client interface*/
16 #include <afs/pterror.h> /*Protection Server error codes*/
17 #include <afs/com_err.h> /*Error code xlation*/
21 #undef USS_PTSERVER_DB
24 extern char *rindex();
28 * ---------------------- Private definitions ---------------------
30 #define uss_ptserver_MAX_SIZE 2048
34 * ------------------------ Private globals -----------------------
36 static int initDone = 0; /*Module initialized?*/
39 /*-----------------------------------------------------------------------
40 * static InitThisModule
43 * Set up this module, namely make the connection to the Protection
50 * 0 if everything went fine, or
51 * lower-level error code otherwise.
54 * This routine will only be called once.
58 *------------------------------------------------------------------------*/
60 static afs_int32 InitThisModule()
65 "uss_ptserver:InitThisModule"; /*Routine name*/
66 register afs_int32 code; /*Return code*/
75 * Connect up with the Protection Server.
77 #ifdef USS_PTSERVER_DB
78 printf("%s: Initializing Protection Server: security=1, confdir = '%s', cell = '%s'\n",
79 rn, uss_ConfDir, uss_Cell);
80 #endif /* USS_PTSERVER_DB */
81 code = pr_Initialize(1, /*Security level*/
82 uss_ConfDir, /*Config directory*/
83 uss_Cell); /*Cell to touch*/
85 com_err(uss_whoami, code,
86 "while initializing Protection Server library");
96 /*-----------------------------------------------------------------------
97 * EXPORTED uss_ptserver_AddUser
100 * The common DesiredUID variable, if non-zero, is the value
101 * desired for the user's uid.
105 *------------------------------------------------------------------------*/
107 afs_int32 uss_ptserver_AddUser(a_user, a_uid)
111 { /*uss_ptserver_AddUser*/
113 afs_int32 code; /*Various return codes*/
114 afs_int32 id = uss_DesiredUID; /*ID desired for user, if any*/
115 afs_int32 mappedUserID; /*ID user already has*/
118 fprintf(stderr, "Adding user '%s' to the Protection DB\n",
121 fprintf(stderr, "\t[Presetting uid to %d]\n", id);
125 * Make sure we're initialized before doing anything.
128 code = InitThisModule();
134 * If this is a dry run, we still need to setup the uid before
138 fprintf(stderr, "\t[Dry run - user %d not created]\n", uss_DesiredUID);
139 sprintf(a_uid, "%d", uss_DesiredUID);
144 * Go ahead and create the user.
146 code = pr_CreateUser(a_user, &id);
148 if (code == PREXIST || code == PRIDEXIST) {
151 "%s: Warning: '%s' already in the Protection DB\n",
155 "%s: Warning: Id '%d' already in Protection DB\n",
159 * Make sure the user name given matches the id that has
160 * already been registered with the Protection Server.
162 * Note: pr_SNameToId ONLY returns a non-zero error code
163 * for a major problem, like a network partition, so we
164 * have to explicitly check the ID returned against
165 * ANONYMOUSID, which is what we get when there is no
166 * ID known for the user name.
169 if (code = pr_SNameToId(a_user, &mappedUserID)) {
170 com_err(uss_whoami, code,
171 "while getting uid from Protection Server");
174 if (mappedUserID == ANONYMOUSID) {
176 "%s: User '%s' unknown, yet given id (%d) already has a mapping!\n",
177 uss_whoami, a_user, id);
183 if (mappedUserID != id) {
185 "%s: User '%s' already has id %d; won't assign id %d\n",
186 uss_whoami, a_user, mappedUserID, id);
194 com_err(uss_whoami, code, "while accessing Protection Server");
197 } /*Create the user's protection entry*/
199 sprintf(a_uid, "%d", id);
201 fprintf(stderr, "The uid for user '%s' is %s\n", a_user, a_uid);
204 * Return sweetness & light.
208 } /*uss_ptserver_AddUser*/
211 /*-----------------------------------------------------------------------
212 * EXPORTED uss_ptserver_DelUser
215 * Nothing interesting.
219 *------------------------------------------------------------------------*/
221 afs_int32 uss_ptserver_DelUser(a_name)
224 { /*uss_ptserver_DelUser*/
226 afs_int32 code; /*Various return codes*/
229 * Make sure we're initialized before doing anything.
232 code = InitThisModule();
239 "\t[Dry run - user '%s' not deleted from Protection DB]\n",
245 fprintf(stderr, "Deleting user '%s' from the Protection DB\n",
249 * Go ahead and delete the user.
251 code = pr_Delete(a_name);
253 if (code == PRNOENT) {
255 * There's no entry for that user in the Protection DB,
256 * so our job is done.
259 "%s: Warning: User '%s' not found in Protection DB\n",
261 } /*User not registered*/
263 com_err(uss_whoami, code,
264 "while deleting user from Protection DB");
266 } /*Fatal PTS error*/
267 } /*Error in deletion*/
270 * Return sweetness & light.
274 } /*uss_ptserver_DelUser*/
277 /*-----------------------------------------------------------------------
278 * EXPORTED uss_ptserver_XlateUser
281 * Nothing interesting.
285 *------------------------------------------------------------------------*/
287 afs_int32 uss_ptserver_XlateUser(a_user, a_uidP)
291 { /*uss_ptserver_XlateUser*/
293 static char rn[] = "uss_ptserver_XlateUser"; /*Routine name*/
294 register afs_int32 code; /*Various return codes*/
297 fprintf(stderr, "Translating user '%s' via the Protection DB\n",
301 * Make sure we're initialized before doing anything.
304 code = InitThisModule();
310 * Note: pr_SNameToId ONLY returns a non-zero error code
311 * for a major problem, like a network partition, so we
312 * have to explicitly check the ID returned against
313 * ANONYMOUSID, which is what we get when there is no
314 * ID known for the user name.
317 code = pr_SNameToId(a_user, a_uidP);
319 com_err(uss_whoami, code, "while getting uid from Protection DB");
322 if (*a_uidP == ANONYMOUSID) {
324 "%s: No entry for user '%s' in the Protection DB\n",
330 * Return sweetness & light.
332 #ifdef USS_PTSERVER_DB
333 printf("%s: User '%s' maps to uid %d\n", rn, a_user, *a_uidP);
334 #endif /* USS_PTSERVER_DB */
337 } /*uss_ptserver_XlateUser*/