pr_Initialize-fix-20050707
[openafs.git] / src / ptserver / ptuser.c
index 8df66fd..6bda96a 100644 (file)
@@ -29,6 +29,7 @@ RCSID
 #include "afs/cellconfig.h"
 #include "afs/afsutil.h"
 #include "afs/ptclient.h"
+#include "afs/ptuser.h"
 #include "afs/pterror.h"
 #else /* defined(UKERNEL) */
 #include <afs/stds.h>
@@ -54,6 +55,7 @@ RCSID
 #include <afs/cellconfig.h>
 #include <afs/afsutil.h>
 #include "ptclient.h"
+#include "ptuser.h"
 #include "pterror.h"
 #endif /* defined(UKERNEL) */
 
@@ -64,59 +66,88 @@ static afs_int32 lastLevel; /* security level pruclient, if any */
 static char *whoami = "libprot";
 
 afs_int32
-pr_Initialize(secLevel, confDir, cell)
-     IN afs_int32 secLevel;
-     IN char *confDir;
-     IN char *cell;
+pr_Initialize(IN afs_int32 secLevel, IN char *confDir, IN char *cell)
 {
     afs_int32 code;
     struct rx_connection *serverconns[MAXSERVERS];
     struct rx_securityClass *sc[3];
-    static struct afsconf_dir *tdir = 0;       /* only do this once */
-    static char tconfDir[100];
+    static struct afsconf_dir *tdir = (struct afsconf_dir *)0; /* only do this once */
+    static char tconfDir[100] = "";
+    static char tcell[64] = "";
     struct ktc_token ttoken;
     afs_int32 scIndex;
     static struct afsconf_cell info;
     afs_int32 i;
     char cellstr[64];
+    afs_int32 gottdir = 0;
+    afs_int32 refresh = 0;
 
     initialize_PT_error_table();
     initialize_RXK_error_table();
     initialize_ACFG_error_table();
     initialize_KTC_error_table();
 
-    if (strcmp(confDir, tconfDir)) {
+#if defined(UKERNEL)
+    if (!cell) {
+        cell = afs_LclCellName;
+    }
+#else /* defined(UKERNEL) */
+    if (!cell) {
+        if (!tdir) 
+            tdir = afsconf_Open(confDir);
+       if (!tdir) {
+           if (confDir && strcmp(confDir, ""))
+               fprintf(stderr,
+                       "libprot: Could not open configuration directory: %s.\n",
+                       confDir);
+            else
+               fprintf(stderr,
+                       "libprot: No configuration directory specified.\n");
+           return -1;
+       }
+        gottdir = 1;
+
+        code = afsconf_GetLocalCell(tdir, cellstr, sizeof(cellstr));
+        if (code) {
+            fprintf(stderr,
+                     "libprot: Could not get local cell. [%d]\n", code);
+            return code;
+        }
+        cell = cellstr;
+    }
+#endif /* defined(UKERNEL) */
+
+    if (tdir == 0 || strcmp(confDir, tconfDir) || strcmp(cell, tcell)) {
        /*
-        * Different conf dir; force re-evaluation.
+        * force re-evaluation.  we either don't have an afsconf_dir,
+         * the directory has changed or the cell has changed.
         */
-       tdir = (struct afsconf_dir *)0;
+       if (tdir && !gottdir) {
+           afsconf_Close(tdir);
+            tdir = (struct afsconf_dir *)0;
+        }
        pruclient = (struct ubik_client *)0;
+        refresh = 1;
     }
-    if (tdir == 0) {
+
+    if (refresh) {
        strncpy(tconfDir, confDir, sizeof(tconfDir));
+        strncpy(tcell, cell, sizeof(tcell));
+
 #if defined(UKERNEL)
        tdir = afs_cdir;
-       if (!cell) {
-           cell = afs_LclCellName;
-       }
 #else /* defined(UKERNEL) */
-       tdir = afsconf_Open(confDir);
+        if (!gottdir)
+            tdir = afsconf_Open(confDir);
        if (!tdir) {
-           fprintf(stderr,
-                   "libprot: Could not open configuration directory: %s.\n",
-                   confDir);
-           return -1;
-       }
-
-       if (!cell) {
-           code = afsconf_GetLocalCell(tdir, cellstr, sizeof(cellstr));
-           if (code) {
+           if (confDir && strcmp(confDir, ""))
                fprintf(stderr,
-                       "vos: can't get local cell name - check %s/%s\n",
-                       confDir, AFSDIR_THISCELL_FILE);
-               exit(1);
-           }
-           cell = cellstr;
+                       "libprot: Could not open configuration directory: %s.\n",
+                       confDir);
+            else
+               fprintf(stderr,
+                       "libprot: No configuration directory specified.\n");
+           return -1;
        }
 #endif /* defined(UKERNEL) */
 
@@ -170,7 +201,7 @@ pr_Initialize(secLevel, confDir, cell)
        if (code)
            scIndex = 0;
        else {
-           if (ttoken.kvno >= 0 && ttoken.kvno <= 255)
+           if (ttoken.kvno >= 0 && ttoken.kvno <= 256)
                /* this is a kerberos ticket, set scIndex accordingly */
                scIndex = 2;
            else {
@@ -180,7 +211,7 @@ pr_Initialize(secLevel, confDir, cell)
                scIndex = 2;
            }
            sc[2] =
-               rxkad_NewClientSecurityObject(secLevel, &ttoken.sessionKey,
+               rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
                                              ttoken.kvno, ttoken.ticketLen,
                                              ttoken.ticket);
        }
@@ -211,7 +242,7 @@ pr_Initialize(secLevel, confDir, cell)
     return code;
 }
 
-
+int
 pr_End()
 {
     int code = 0;
@@ -225,9 +256,8 @@ pr_End()
 
 
 
-pr_CreateUser(name, id)
-     char name[PR_MAXNAMELEN];
-     afs_int32 *id;
+int
+pr_CreateUser(char name[PR_MAXNAMELEN], afs_int32 *id)
 {
     register afs_int32 code;
 
@@ -242,10 +272,8 @@ pr_CreateUser(name, id)
 
 }
 
-pr_CreateGroup(name, owner, id)
-     char name[PR_MAXNAMELEN];
-     char owner[PR_MAXNAMELEN];
-     afs_int32 *id;
+int 
+pr_CreateGroup(char name[PR_MAXNAMELEN], char owner[PR_MAXNAMELEN], afs_int32 *id)
 {
     register afs_int32 code;
     afs_int32 oid = 0;
@@ -269,8 +297,8 @@ pr_CreateGroup(name, owner, id)
     }
 }
 
-pr_Delete(name)
-     char *name;
+int
+pr_Delete(char *name)
 {
     register afs_int32 code;
     afs_int32 id;
@@ -285,8 +313,8 @@ pr_Delete(name)
     return code;
 }
 
-pr_DeleteByID(id)
-     afs_int32 id;
+int
+pr_DeleteByID(afs_int32 id)
 {
     register afs_int32 code;
 
@@ -294,9 +322,8 @@ pr_DeleteByID(id)
     return code;
 }
 
-pr_AddToGroup(user, group)
-     char *user;
-     char *group;
+int
+pr_AddToGroup(char *user, char *group)
 {
     register afs_int32 code;
     namelist lnames;
@@ -328,9 +355,8 @@ pr_AddToGroup(user, group)
     return code;
 }
 
-pr_RemoveUserFromGroup(user, group)
-     char *user;
-     char *group;
+int
+pr_RemoveUserFromGroup(char *user, char *group)
 {
     register afs_int32 code;
     namelist lnames;
@@ -363,9 +389,8 @@ pr_RemoveUserFromGroup(user, group)
 
 }
 
-pr_NameToId(names, ids)
-     namelist *names;
-     idlist *ids;
+int
+pr_NameToId(namelist *names, idlist *ids)
 {
     register afs_int32 code;
     register afs_int32 i;
@@ -376,9 +401,8 @@ pr_NameToId(names, ids)
     return code;
 }
 
-pr_SNameToId(name, id)
-     char name[PR_MAXNAMELEN];
-     afs_int32 *id;
+int
+pr_SNameToId(char name[PR_MAXNAMELEN], afs_int32 *id)
 {
     namelist lnames;
     idlist lids;
@@ -400,11 +424,8 @@ pr_SNameToId(name, id)
     return code;
 }
 
-
-
-pr_IdToName(ids, names)
-     idlist *ids;
-     namelist *names;
+int
+pr_IdToName(idlist *ids, namelist *names)
 {
     register afs_int32 code;
 
@@ -412,9 +433,8 @@ pr_IdToName(ids, names)
     return code;
 }
 
-pr_SIdToName(id, name)
-     afs_int32 id;
-     char name[PR_MAXNAMELEN];
+int
+pr_SIdToName(afs_int32 id, char name[PR_MAXNAMELEN])
 {
     namelist lnames;
     idlist lids;
@@ -435,11 +455,8 @@ pr_SIdToName(id, name)
     return code;
 }
 
-
-
-pr_GetCPS(id, CPS)
-     afs_int32 id;
-     prlist *CPS;
+int
+pr_GetCPS(afs_int32 id, prlist *CPS)
 {
     register afs_int32 code;
     afs_int32 over;
@@ -457,11 +474,8 @@ pr_GetCPS(id, CPS)
     return 0;
 }
 
-
-pr_GetCPS2(id, host, CPS)
-     afs_int32 id;
-     afs_int32 host;
-     prlist *CPS;
+int
+pr_GetCPS2(afs_int32 id, afs_int32 host, prlist *CPS)
 {
     register afs_int32 code;
     afs_int32 over;
@@ -479,9 +493,8 @@ pr_GetCPS2(id, host, CPS)
     return 0;
 }
 
-pr_GetHostCPS(host, CPS)
-     afs_int32 host;
-     prlist *CPS;
+int
+pr_GetHostCPS(afs_int32 host, prlist *CPS)
 {
     register afs_int32 code;
     afs_int32 over;
@@ -500,10 +513,8 @@ pr_GetHostCPS(host, CPS)
     return 0;
 }
 
-
-pr_ListMembers(group, lnames)
-     char *group;
-     namelist *lnames;
+int
+pr_ListMembers(char *group, namelist *lnames)
 {
     register afs_int32 code;
     afs_int32 gid;
@@ -517,10 +528,8 @@ pr_ListMembers(group, lnames)
     return code;
 }
 
-pr_ListOwned(oid, lnames, moreP)
-     afs_int32 oid;
-     namelist *lnames;
-     afs_int32 *moreP;
+int
+pr_ListOwned(afs_int32 oid, namelist *lnames, afs_int32 *moreP)
 {
     register afs_int32 code;
     prlist alist;
@@ -546,9 +555,8 @@ pr_ListOwned(oid, lnames, moreP)
     return PRSUCCESS;
 }
 
-pr_IDListMembers(gid, lnames)
-     afs_int32 gid;
-     namelist *lnames;
+int
+pr_IDListMembers(afs_int32 gid, namelist *lnames)
 {
     register afs_int32 code;
     prlist alist;
@@ -573,10 +581,8 @@ pr_IDListMembers(gid, lnames)
     return PRSUCCESS;
 }
 
-
-pr_ListEntry(id, aentry)
-     afs_int32 id;
-     struct prcheckentry *aentry;
+int
+pr_ListEntry(afs_int32 id, struct prcheckentry *aentry)
 {
     register afs_int32 code;
 
@@ -585,11 +591,7 @@ pr_ListEntry(id, aentry)
 }
 
 afs_int32
-pr_ListEntries(flag, startindex, nentries, entries, nextstartindex)
-     afs_int32 startindex;
-     afs_int32 *nentries;
-     struct prlistentries **entries;
-     afs_int32 *nextstartindex;
+pr_ListEntries(int flag, afs_int32 startindex, afs_int32 *nentries, struct prlistentries **entries, afs_int32 *nextstartindex)
 {
     afs_int32 code;
     prentries bulkentries;
@@ -608,11 +610,8 @@ pr_ListEntries(flag, startindex, nentries, entries, nextstartindex)
     return code;
 }
 
-pr_CheckEntryByName(name, id, owner, creator)
-     char *name;
-     afs_int32 *id;
-     char *owner;
-     char *creator;
+int
+pr_CheckEntryByName(char *name, afs_int32 *id, char *owner, char *creator)
 {
     /* struct prcheckentry returns other things, which aren't useful to show at this time. */
     register afs_int32 code;
@@ -636,11 +635,8 @@ pr_CheckEntryByName(name, id, owner, creator)
     return PRSUCCESS;
 }
 
-pr_CheckEntryById(name, id, owner, creator)
-     char *name;
-     afs_int32 id;
-     char *owner;
-     char *creator;
+int
+pr_CheckEntryById(char *name, afs_int32 id, char *owner, char *creator)
 {
     /* struct prcheckentry returns other things, which aren't useful to show at this time. */
     register afs_int32 code;
@@ -664,11 +660,8 @@ pr_CheckEntryById(name, id, owner, creator)
     return PRSUCCESS;
 }
 
-pr_ChangeEntry(oldname, newname, newid, newowner)
-     char *oldname;
-     char *newname;
-     afs_int32 *newid;
-     char *newowner;
+int
+pr_ChangeEntry(char *oldname, char *newname, afs_int32 *newid, char *newowner)
 {
     register afs_int32 code;
     afs_int32 id;
@@ -690,10 +683,8 @@ pr_ChangeEntry(oldname, newname, newid, newowner)
     return code;
 }
 
-pr_IsAMemberOf(uname, gname, flag)
-     char *uname;
-     char *gname;
-     afs_int32 *flag;
+int
+pr_IsAMemberOf(char *uname, char *gname, afs_int32 *flag)
 {
     register afs_int32 code;
     namelist lnames;
@@ -725,9 +716,8 @@ pr_IsAMemberOf(uname, gname, flag)
     return code;
 }
 
-
-pr_ListMaxUserId(mid)
-     afs_int32 *mid;
+int
+pr_ListMaxUserId(afs_int32 *mid)
 {
     register afs_int32 code;
     afs_int32 gid;
@@ -735,8 +725,8 @@ pr_ListMaxUserId(mid)
     return code;
 }
 
-pr_SetMaxUserId(mid)
-     afs_int32 mid;
+int
+pr_SetMaxUserId(afs_int32 mid)
 {
     register afs_int32 code;
     afs_int32 flag = 0;
@@ -744,8 +734,8 @@ pr_SetMaxUserId(mid)
     return code;
 }
 
-pr_ListMaxGroupId(mid)
-     afs_int32 *mid;
+int
+pr_ListMaxGroupId(afs_int32 *mid)
 {
     register afs_int32 code;
     afs_int32 id;
@@ -753,8 +743,8 @@ pr_ListMaxGroupId(mid)
     return code;
 }
 
-pr_SetMaxGroupId(mid)
-     afs_int32 mid;
+int
+pr_SetMaxGroupId(afs_int32 mid)
 {
     register afs_int32 code;
     afs_int32 flag = 0;
@@ -765,10 +755,7 @@ pr_SetMaxGroupId(mid)
 }
 
 afs_int32
-pr_SetFieldsEntry(id, mask, flags, ngroups, nusers)
-     afs_int32 id;
-     afs_int32 mask;
-     afs_int32 flags, ngroups, nusers;
+pr_SetFieldsEntry(afs_int32 id, afs_int32 mask, afs_int32 flags, afs_int32 ngroups, afs_int32 nusers)
 {
     register afs_int32 code;
 
@@ -778,10 +765,8 @@ pr_SetFieldsEntry(id, mask, flags, ngroups, nusers)
     return code;
 }
 
-
 int
-stolower(s)
-     char *s;
+stolower(char *s)
 {
     while (*s) {
        if (isupper(*s))