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 <afsconfig.h>
19 #include <afs/param.h>
23 #include <afs/ptclient.h> /*Protection Server client interface */
24 #include <afs/pterror.h> /*Protection Server error codes */
25 #include <afs/ptuser.h>
26 #include <afs/com_err.h> /*Error code xlation */
28 #include "uss_ptserver.h" /*Module interface */
30 #undef USS_PTSERVER_DB
36 * ---------------------- Private definitions ---------------------
38 #define uss_ptserver_MAX_SIZE 2048
42 * ------------------------ Private globals -----------------------
44 static int initDone = 0; /*Module initialized? */
47 /*-----------------------------------------------------------------------
48 * static InitThisModule
51 * Set up this module, namely make the connection to the Protection
58 * 0 if everything went fine, or
59 * lower-level error code otherwise.
62 * This routine will only be called once.
66 *------------------------------------------------------------------------*/
72 #ifdef USS_PTSERVER_DB
73 static char rn[] = "uss_ptserver:InitThisModule"; /*Routine name */
75 afs_int32 code; /*Return code */
84 * Connect up with the Protection Server.
86 #ifdef USS_PTSERVER_DB
88 ("%s: Initializing Protection Server: security=1, confdir = '%s', cell = '%s'\n",
89 rn, uss_ConfDir, uss_Cell);
90 #endif /* USS_PTSERVER_DB */
91 code = pr_Initialize(1, /*Security level */
92 uss_ConfDir, /*Config directory */
93 uss_Cell); /*Cell to touch */
95 afs_com_err(uss_whoami, code,
96 "while initializing Protection Server library");
103 } /*InitThisModule */
106 /*-----------------------------------------------------------------------
107 * EXPORTED uss_ptserver_AddUser
110 * The common DesiredUID variable, if non-zero, is the value
111 * desired for the user's uid.
115 *------------------------------------------------------------------------*/
118 uss_ptserver_AddUser(char *a_user, char *a_uid)
119 { /*uss_ptserver_AddUser */
121 afs_int32 code; /*Various return codes */
122 afs_int32 id = uss_DesiredUID; /*ID desired for user, if any */
123 afs_int32 mappedUserID; /*ID user already has */
126 fprintf(stderr, "Adding user '%s' to the Protection DB\n", a_user);
128 fprintf(stderr, "\t[Presetting uid to %d]\n", id);
132 * Make sure we're initialized before doing anything.
135 code = InitThisModule();
141 * If this is a dry run, we still need to setup the uid before
145 fprintf(stderr, "\t[Dry run - user %d not created]\n",
147 sprintf(a_uid, "%d", uss_DesiredUID);
152 * Go ahead and create the user.
154 code = pr_CreateUser(a_user, &id);
156 if (code == PREXIST || code == PRIDEXIST) {
159 "%s: Warning: '%s' already in the Protection DB\n",
163 "%s: Warning: Id '%d' already in Protection DB\n",
167 * Make sure the user name given matches the id that has
168 * already been registered with the Protection Server.
170 * Note: pr_SNameToId ONLY returns a non-zero error code
171 * for a major problem, like a network partition, so we
172 * have to explicitly check the ID returned against
173 * ANONYMOUSID, which is what we get when there is no
174 * ID known for the user name.
177 if ((code = pr_SNameToId(a_user, &mappedUserID))) {
178 afs_com_err(uss_whoami, code,
179 "while getting uid from Protection Server");
182 if (mappedUserID == ANONYMOUSID) {
184 "%s: User '%s' unknown, yet given id (%d) already has a mapping!\n",
185 uss_whoami, a_user, id);
190 else if (mappedUserID != id) {
192 "%s: User '%s' already has id %d; won't assign id %d\n",
193 uss_whoami, a_user, mappedUserID, id);
200 afs_com_err(uss_whoami, code, "while accessing Protection Server");
204 /*Create the user's protection entry */
205 sprintf(a_uid, "%d", id);
207 fprintf(stderr, "The uid for user '%s' is %s\n", a_user, a_uid);
210 * Return sweetness & light.
214 } /*uss_ptserver_AddUser */
217 /*-----------------------------------------------------------------------
218 * EXPORTED uss_ptserver_DelUser
221 * Nothing interesting.
225 *------------------------------------------------------------------------*/
228 uss_ptserver_DelUser(char *a_name)
229 { /*uss_ptserver_DelUser */
231 afs_int32 code; /*Various return codes */
234 * Make sure we're initialized before doing anything.
237 code = InitThisModule();
244 "\t[Dry run - user '%s' not deleted from Protection DB]\n",
250 fprintf(stderr, "Deleting user '%s' from the Protection DB\n",
254 * Go ahead and delete the user.
256 code = pr_Delete(a_name);
258 if (code == PRNOENT) {
260 * There's no entry for that user in the Protection DB,
261 * so our job is done.
264 "%s: Warning: User '%s' not found in Protection DB\n",
266 } /*User not registered */
268 afs_com_err(uss_whoami, code,
269 "while deleting user from Protection DB");
271 } /*Fatal PTS error */
274 /*Error in deletion */
276 * Return sweetness & light.
280 } /*uss_ptserver_DelUser */
283 /*-----------------------------------------------------------------------
284 * EXPORTED uss_ptserver_XlateUser
287 * Nothing interesting.
291 *------------------------------------------------------------------------*/
294 uss_ptserver_XlateUser(char *a_user, afs_int32 *a_uidP)
295 { /*uss_ptserver_XlateUser */
296 #ifdef USS_PTSERVER_DB
297 static char rn[] = "uss_ptserver_XlateUser"; /*Routine name */
299 afs_int32 code; /*Various return codes */
302 fprintf(stderr, "Translating user '%s' via the Protection DB\n",
306 * Make sure we're initialized before doing anything.
309 code = InitThisModule();
315 * Note: pr_SNameToId ONLY returns a non-zero error code
316 * for a major problem, like a network partition, so we
317 * have to explicitly check the ID returned against
318 * ANONYMOUSID, which is what we get when there is no
319 * ID known for the user name.
322 code = pr_SNameToId(a_user, a_uidP);
324 afs_com_err(uss_whoami, code, "while getting uid from Protection DB");
327 if (*a_uidP == ANONYMOUSID) {
328 fprintf(stderr, "%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 */