2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Implementation of basic procedures for the AFS user account
16 * --------------------- Required definitions ---------------------
18 #include "uss_ptserver.h" /*Module interface*/
19 #include <afs/ptclient.h> /*Protection Server client interface*/
20 #include <afs/pterror.h> /*Protection Server error codes*/
21 #include <afs/com_err.h> /*Error code xlation*/
25 #undef USS_PTSERVER_DB
28 extern char *rindex();
32 * ---------------------- Private definitions ---------------------
34 #define uss_ptserver_MAX_SIZE 2048
38 * ------------------------ Private globals -----------------------
40 static int initDone = 0; /*Module initialized?*/
43 /*-----------------------------------------------------------------------
44 * static InitThisModule
47 * Set up this module, namely make the connection to the Protection
54 * 0 if everything went fine, or
55 * lower-level error code otherwise.
58 * This routine will only be called once.
62 *------------------------------------------------------------------------*/
64 static afs_int32 InitThisModule()
69 "uss_ptserver:InitThisModule"; /*Routine name*/
70 register afs_int32 code; /*Return code*/
79 * Connect up with the Protection Server.
81 #ifdef USS_PTSERVER_DB
82 printf("%s: Initializing Protection Server: security=1, confdir = '%s', cell = '%s'\n",
83 rn, uss_ConfDir, uss_Cell);
84 #endif /* USS_PTSERVER_DB */
85 code = pr_Initialize(1, /*Security level*/
86 uss_ConfDir, /*Config directory*/
87 uss_Cell); /*Cell to touch*/
89 com_err(uss_whoami, code,
90 "while initializing Protection Server library");
100 /*-----------------------------------------------------------------------
101 * EXPORTED uss_ptserver_AddUser
104 * The common DesiredUID variable, if non-zero, is the value
105 * desired for the user's uid.
109 *------------------------------------------------------------------------*/
111 afs_int32 uss_ptserver_AddUser(a_user, a_uid)
115 { /*uss_ptserver_AddUser*/
117 afs_int32 code; /*Various return codes*/
118 afs_int32 id = uss_DesiredUID; /*ID desired for user, if any*/
119 afs_int32 mappedUserID; /*ID user already has*/
122 fprintf(stderr, "Adding user '%s' to the Protection DB\n",
125 fprintf(stderr, "\t[Presetting uid to %d]\n", id);
129 * Make sure we're initialized before doing anything.
132 code = InitThisModule();
138 * If this is a dry run, we still need to setup the uid before
142 fprintf(stderr, "\t[Dry run - user %d not created]\n", uss_DesiredUID);
143 sprintf(a_uid, "%d", uss_DesiredUID);
148 * Go ahead and create the user.
150 code = pr_CreateUser(a_user, &id);
152 if (code == PREXIST || code == PRIDEXIST) {
155 "%s: Warning: '%s' already in the Protection DB\n",
159 "%s: Warning: Id '%d' already in Protection DB\n",
163 * Make sure the user name given matches the id that has
164 * already been registered with the Protection Server.
166 * Note: pr_SNameToId ONLY returns a non-zero error code
167 * for a major problem, like a network partition, so we
168 * have to explicitly check the ID returned against
169 * ANONYMOUSID, which is what we get when there is no
170 * ID known for the user name.
173 if (code = pr_SNameToId(a_user, &mappedUserID)) {
174 com_err(uss_whoami, code,
175 "while getting uid from Protection Server");
178 if (mappedUserID == ANONYMOUSID) {
180 "%s: User '%s' unknown, yet given id (%d) already has a mapping!\n",
181 uss_whoami, a_user, id);
187 if (mappedUserID != id) {
189 "%s: User '%s' already has id %d; won't assign id %d\n",
190 uss_whoami, a_user, mappedUserID, id);
198 com_err(uss_whoami, code, "while accessing Protection Server");
201 } /*Create the user's protection entry*/
203 sprintf(a_uid, "%d", id);
205 fprintf(stderr, "The uid for user '%s' is %s\n", a_user, a_uid);
208 * Return sweetness & light.
212 } /*uss_ptserver_AddUser*/
215 /*-----------------------------------------------------------------------
216 * EXPORTED uss_ptserver_DelUser
219 * Nothing interesting.
223 *------------------------------------------------------------------------*/
225 afs_int32 uss_ptserver_DelUser(a_name)
228 { /*uss_ptserver_DelUser*/
230 afs_int32 code; /*Various return codes*/
233 * Make sure we're initialized before doing anything.
236 code = InitThisModule();
243 "\t[Dry run - user '%s' not deleted from Protection DB]\n",
249 fprintf(stderr, "Deleting user '%s' from the Protection DB\n",
253 * Go ahead and delete the user.
255 code = pr_Delete(a_name);
257 if (code == PRNOENT) {
259 * There's no entry for that user in the Protection DB,
260 * so our job is done.
263 "%s: Warning: User '%s' not found in Protection DB\n",
265 } /*User not registered*/
267 com_err(uss_whoami, code,
268 "while deleting user from Protection DB");
270 } /*Fatal PTS error*/
271 } /*Error in deletion*/
274 * Return sweetness & light.
278 } /*uss_ptserver_DelUser*/
281 /*-----------------------------------------------------------------------
282 * EXPORTED uss_ptserver_XlateUser
285 * Nothing interesting.
289 *------------------------------------------------------------------------*/
291 afs_int32 uss_ptserver_XlateUser(a_user, a_uidP)
295 { /*uss_ptserver_XlateUser*/
297 static char rn[] = "uss_ptserver_XlateUser"; /*Routine name*/
298 register afs_int32 code; /*Various return codes*/
301 fprintf(stderr, "Translating user '%s' via the Protection DB\n",
305 * Make sure we're initialized before doing anything.
308 code = InitThisModule();
314 * Note: pr_SNameToId ONLY returns a non-zero error code
315 * for a major problem, like a network partition, so we
316 * have to explicitly check the ID returned against
317 * ANONYMOUSID, which is what we get when there is no
318 * ID known for the user name.
321 code = pr_SNameToId(a_user, a_uidP);
323 com_err(uss_whoami, code, "while getting uid from Protection DB");
326 if (*a_uidP == ANONYMOUSID) {
328 "%s: No entry for user '%s' in the Protection DB\n",
334 * Return sweetness & light.
336 #ifdef USS_PTSERVER_DB
337 printf("%s: User '%s' maps to uid %d\n", rn, a_user, *a_uidP);
338 #endif /* USS_PTSERVER_DB */
341 } /*uss_ptserver_XlateUser*/