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 "uss_ptserver.h" /*Module interface*/
24 #include <afs/ptclient.h> /*Protection Server client interface*/
25 #include <afs/pterror.h> /*Protection Server error codes*/
26 #include <afs/com_err.h> /*Error code xlation*/
30 #undef USS_PTSERVER_DB
33 extern char *rindex();
37 * ---------------------- Private definitions ---------------------
39 #define uss_ptserver_MAX_SIZE 2048
43 * ------------------------ Private globals -----------------------
45 static int initDone = 0; /*Module initialized?*/
48 /*-----------------------------------------------------------------------
49 * static InitThisModule
52 * Set up this module, namely make the connection to the Protection
59 * 0 if everything went fine, or
60 * lower-level error code otherwise.
63 * This routine will only be called once.
67 *------------------------------------------------------------------------*/
69 static afs_int32 InitThisModule()
74 "uss_ptserver:InitThisModule"; /*Routine name*/
75 register afs_int32 code; /*Return code*/
84 * Connect up with the Protection Server.
86 #ifdef USS_PTSERVER_DB
87 printf("%s: Initializing Protection Server: security=1, confdir = '%s', cell = '%s'\n",
88 rn, uss_ConfDir, uss_Cell);
89 #endif /* USS_PTSERVER_DB */
90 code = pr_Initialize(1, /*Security level*/
91 uss_ConfDir, /*Config directory*/
92 uss_Cell); /*Cell to touch*/
94 com_err(uss_whoami, code,
95 "while initializing Protection Server library");
105 /*-----------------------------------------------------------------------
106 * EXPORTED uss_ptserver_AddUser
109 * The common DesiredUID variable, if non-zero, is the value
110 * desired for the user's uid.
114 *------------------------------------------------------------------------*/
116 afs_int32 uss_ptserver_AddUser(a_user, a_uid)
120 { /*uss_ptserver_AddUser*/
122 afs_int32 code; /*Various return codes*/
123 afs_int32 id = uss_DesiredUID; /*ID desired for user, if any*/
124 afs_int32 mappedUserID; /*ID user already has*/
127 fprintf(stderr, "Adding user '%s' to the Protection DB\n",
130 fprintf(stderr, "\t[Presetting uid to %d]\n", id);
134 * Make sure we're initialized before doing anything.
137 code = InitThisModule();
143 * If this is a dry run, we still need to setup the uid before
147 fprintf(stderr, "\t[Dry run - user %d not created]\n", uss_DesiredUID);
148 sprintf(a_uid, "%d", uss_DesiredUID);
153 * Go ahead and create the user.
155 code = pr_CreateUser(a_user, &id);
157 if (code == PREXIST || code == PRIDEXIST) {
160 "%s: Warning: '%s' already in the Protection DB\n",
164 "%s: Warning: Id '%d' already in Protection DB\n",
168 * Make sure the user name given matches the id that has
169 * already been registered with the Protection Server.
171 * Note: pr_SNameToId ONLY returns a non-zero error code
172 * for a major problem, like a network partition, so we
173 * have to explicitly check the ID returned against
174 * ANONYMOUSID, which is what we get when there is no
175 * ID known for the user name.
178 if (code = pr_SNameToId(a_user, &mappedUserID)) {
179 com_err(uss_whoami, code,
180 "while getting uid from Protection Server");
183 if (mappedUserID == ANONYMOUSID) {
185 "%s: User '%s' unknown, yet given id (%d) already has a mapping!\n",
186 uss_whoami, a_user, id);
192 if (mappedUserID != id) {
194 "%s: User '%s' already has id %d; won't assign id %d\n",
195 uss_whoami, a_user, mappedUserID, id);
203 com_err(uss_whoami, code, "while accessing Protection Server");
206 } /*Create the user's protection entry*/
208 sprintf(a_uid, "%d", id);
210 fprintf(stderr, "The uid for user '%s' is %s\n", a_user, a_uid);
213 * Return sweetness & light.
217 } /*uss_ptserver_AddUser*/
220 /*-----------------------------------------------------------------------
221 * EXPORTED uss_ptserver_DelUser
224 * Nothing interesting.
228 *------------------------------------------------------------------------*/
230 afs_int32 uss_ptserver_DelUser(a_name)
233 { /*uss_ptserver_DelUser*/
235 afs_int32 code; /*Various return codes*/
238 * Make sure we're initialized before doing anything.
241 code = InitThisModule();
248 "\t[Dry run - user '%s' not deleted from Protection DB]\n",
254 fprintf(stderr, "Deleting user '%s' from the Protection DB\n",
258 * Go ahead and delete the user.
260 code = pr_Delete(a_name);
262 if (code == PRNOENT) {
264 * There's no entry for that user in the Protection DB,
265 * so our job is done.
268 "%s: Warning: User '%s' not found in Protection DB\n",
270 } /*User not registered*/
272 com_err(uss_whoami, code,
273 "while deleting user from Protection DB");
275 } /*Fatal PTS error*/
276 } /*Error in deletion*/
279 * Return sweetness & light.
283 } /*uss_ptserver_DelUser*/
286 /*-----------------------------------------------------------------------
287 * EXPORTED uss_ptserver_XlateUser
290 * Nothing interesting.
294 *------------------------------------------------------------------------*/
296 afs_int32 uss_ptserver_XlateUser(a_user, a_uidP)
300 { /*uss_ptserver_XlateUser*/
302 static char rn[] = "uss_ptserver_XlateUser"; /*Routine name*/
303 register afs_int32 code; /*Various return codes*/
306 fprintf(stderr, "Translating user '%s' via the Protection DB\n",
310 * Make sure we're initialized before doing anything.
313 code = InitThisModule();
319 * Note: pr_SNameToId ONLY returns a non-zero error code
320 * for a major problem, like a network partition, so we
321 * have to explicitly check the ID returned against
322 * ANONYMOUSID, which is what we get when there is no
323 * ID known for the user name.
326 code = pr_SNameToId(a_user, a_uidP);
328 com_err(uss_whoami, code, "while getting uid from Protection DB");
331 if (*a_uidP == ANONYMOUSID) {
333 "%s: No entry for user '%s' in the Protection DB\n",
339 * Return sweetness & light.
341 #ifdef USS_PTSERVER_DB
342 printf("%s: User '%s' maps to uid %d\n", rn, a_user, *a_uidP);
343 #endif /* USS_PTSERVER_DB */
346 } /*uss_ptserver_XlateUser*/