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>
24 #include "uss_ptserver.h" /*Module interface */
25 #include <afs/ptclient.h> /*Protection Server client interface */
26 #include <afs/pterror.h> /*Protection Server error codes */
27 #include <afs/ptuser.h>
28 #include <afs/com_err.h> /*Error code xlation */
31 #undef USS_PTSERVER_DB
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 *------------------------------------------------------------------------*/
73 static char rn[] = "uss_ptserver:InitThisModule"; /*Routine name */
74 register afs_int32 code; /*Return code */
83 * Connect up with the Protection Server.
85 #ifdef USS_PTSERVER_DB
87 ("%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 afs_com_err(uss_whoami, code,
95 "while initializing Protection Server library");
102 } /*InitThisModule */
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 *------------------------------------------------------------------------*/
117 uss_ptserver_AddUser(char *a_user, char *a_uid)
118 { /*uss_ptserver_AddUser */
120 afs_int32 code; /*Various return codes */
121 afs_int32 id = uss_DesiredUID; /*ID desired for user, if any */
122 afs_int32 mappedUserID; /*ID user already has */
125 fprintf(stderr, "Adding user '%s' to the Protection DB\n", a_user);
127 fprintf(stderr, "\t[Presetting uid to %d]\n", id);
131 * Make sure we're initialized before doing anything.
134 code = InitThisModule();
140 * If this is a dry run, we still need to setup the uid before
144 fprintf(stderr, "\t[Dry run - user %d not created]\n",
146 sprintf(a_uid, "%d", uss_DesiredUID);
151 * Go ahead and create the user.
153 code = pr_CreateUser(a_user, &id);
155 if (code == PREXIST || code == PRIDEXIST) {
158 "%s: Warning: '%s' already in the Protection DB\n",
162 "%s: Warning: Id '%d' already in Protection DB\n",
166 * Make sure the user name given matches the id that has
167 * already been registered with the Protection Server.
169 * Note: pr_SNameToId ONLY returns a non-zero error code
170 * for a major problem, like a network partition, so we
171 * have to explicitly check the ID returned against
172 * ANONYMOUSID, which is what we get when there is no
173 * ID known for the user name.
176 if ((code = pr_SNameToId(a_user, &mappedUserID))) {
177 afs_com_err(uss_whoami, code,
178 "while getting uid from Protection Server");
181 if (mappedUserID == ANONYMOUSID) {
183 "%s: User '%s' unknown, yet given id (%d) already has a mapping!\n",
184 uss_whoami, a_user, id);
189 else if (mappedUserID != id) {
191 "%s: User '%s' already has id %d; won't assign id %d\n",
192 uss_whoami, a_user, mappedUserID, id);
199 afs_com_err(uss_whoami, code, "while accessing Protection Server");
203 /*Create the user's protection entry */
204 sprintf(a_uid, "%d", id);
206 fprintf(stderr, "The uid for user '%s' is %s\n", a_user, a_uid);
209 * Return sweetness & light.
213 } /*uss_ptserver_AddUser */
216 /*-----------------------------------------------------------------------
217 * EXPORTED uss_ptserver_DelUser
220 * Nothing interesting.
224 *------------------------------------------------------------------------*/
227 uss_ptserver_DelUser(char *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 afs_com_err(uss_whoami, code,
268 "while deleting user from Protection DB");
270 } /*Fatal PTS error */
273 /*Error in deletion */
275 * Return sweetness & light.
279 } /*uss_ptserver_DelUser */
282 /*-----------------------------------------------------------------------
283 * EXPORTED uss_ptserver_XlateUser
286 * Nothing interesting.
290 *------------------------------------------------------------------------*/
293 uss_ptserver_XlateUser(char *a_user, afs_int32 *a_uidP)
294 { /*uss_ptserver_XlateUser */
295 #ifdef USS_PTSERVER_DB
296 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 afs_com_err(uss_whoami, code, "while getting uid from Protection DB");
326 if (*a_uidP == ANONYMOUSID) {
327 fprintf(stderr, "%s: No entry for user '%s' in the Protection DB\n",
333 * Return sweetness & light.
335 #ifdef USS_PTSERVER_DB
336 printf("%s: User '%s' maps to uid %d\n", rn, a_user, *a_uidP);
337 #endif /* USS_PTSERVER_DB */
340 } /*uss_ptserver_XlateUser */