libadmin: Don't use undefined value
[openafs.git] / src / libadmin / pts / afs_ptsAdmin.c
index 965fc64..c74e897 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 #include <stdio.h>
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-
+#include <ctype.h>
 #include <afs/stds.h>
+#include <rx/rx.h>
+#include <rx/rxstat.h>
 #include "afs_ptsAdmin.h"
 #include "../adminutil/afs_AdminInternal.h"
 #include <afs/afs_AdminErrors.h>
@@ -32,27 +24,6 @@ RCSID
 #include <afs/ptserver.h>
 
 /*
- * The list of external functions that aren't prototyped anywhere
- */
-
-extern int PR_NameToID();
-extern int PR_AddToGroup();
-extern int PR_ChangeEntry();
-extern int PR_RemoveFromGroup();
-extern int PR_INewEntry();
-extern int PR_NewEntry();
-extern int PR_Delete();
-extern int PR_IDToName();
-extern int PR_ListEntry();
-extern int PR_SetMax();
-extern int PR_ListElements();
-extern int PR_SetFieldsEntry();
-extern int PR_IsAMemberOf();
-extern int PR_ListMax();
-extern int PR_ListOwned();
-extern int PR_ListEntries();
-
-/*
  * IsValidCellHandle - validate the cell handle for making pts
  * requests.
  *
@@ -145,7 +116,7 @@ TranslatePTSNames(const afs_cell_handle_p cellHandle, namelist * names,
        }
     }
 
-    tst = ubik_Call(PR_NameToID, cellHandle->pts, 0, names, ids);
+    tst = ubik_PR_NameToID(cellHandle->pts, 0, names, ids);
 
     if (tst) {
        goto fail_TranslatePTSNames;
@@ -221,7 +192,9 @@ TranslateTwoNames(const afs_cell_handle_p c_handle, const char *id1,
     names.namelist_val = (prname *) & tmp_array[0];
 
     strncpy(names.namelist_val[0], id1, PTS_MAX_NAME_LEN);
+    names.namelist_val[0][PTS_MAX_NAME_LEN - 1] = '\0';
     strncpy(names.namelist_val[1], id2, PTS_MAX_NAME_LEN);
+    names.namelist_val[1][PTS_MAX_NAME_LEN - 1] = '\0';
     ids->idlist_val = 0;
     ids->idlist_len = 0;
 
@@ -298,7 +271,8 @@ TranslateOneName(const afs_cell_handle_p c_handle, const char *ptsName,
     names[0].namelist_len = 1;
     names[0].namelist_val = (prname *) & tmp_array[0];
 
-    strncpy(names[0].namelist_val, ptsName, PTS_MAX_NAME_LEN);
+    strncpy((char *)names[0].namelist_val, ptsName, PTS_MAX_NAME_LEN);
+    ((char *)names[0].namelist_val)[PTS_MAX_NAME_LEN - 1] = '\0';
     ids.idlist_val = 0;
     ids.idlist_len = 0;
 
@@ -365,7 +339,7 @@ TranslatePTSIds(const afs_cell_handle_p cellHandle, namelist * names,
     int rc = 0;
     afs_status_t tst = 0;
 
-    tst = ubik_Call(PR_IDToName, cellHandle->pts, 0, ids, names);
+    tst = ubik_PR_IDToName(cellHandle->pts, 0, ids, names);
 
     if (tst) {
        goto fail_TranslatePTSIds;
@@ -409,7 +383,7 @@ pts_GroupMemberAdd(const void *cellHandle, const char *userName,
     int rc = 0;
     afs_status_t tst = 0;
     afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
-    idlist ids;
+       idlist ids = {0,0};
 
     /*
      * Validate arguments
@@ -440,7 +414,7 @@ pts_GroupMemberAdd(const void *cellHandle, const char *userName,
      */
 
     tst =
-       ubik_Call(PR_AddToGroup, c_handle->pts, 0, ids.idlist_val[0],
+       ubik_PR_AddToGroup(c_handle->pts, 0, ids.idlist_val[0],
                  ids.idlist_val[1]);
 
     if (tst != 0) {
@@ -520,7 +494,7 @@ pts_GroupOwnerChange(const void *cellHandle, const char *targetGroup,
      */
 
     tst =
-       ubik_Call(PR_ChangeEntry, c_handle->pts, 0, ids.idlist_val[1], "",
+       ubik_PR_ChangeEntry(c_handle->pts, 0, ids.idlist_val[1], "",
                  ids.idlist_val[0], 0);
 
     if (tst != 0) {
@@ -569,8 +543,8 @@ pts_GroupOwnerChange(const void *cellHandle, const char *targetGroup,
  */
 
 int ADMINAPI
-pts_GroupCreate(const void *cellHandle, const char *newGroup,
-               const char *newOwner, int *newGroupId, afs_status_p st)
+pts_GroupCreate(const void *cellHandle, char *newGroup,
+               char *newOwner, int *newGroupId, afs_status_p st)
 {
     int rc = 0;
     afs_status_t tst = 0;
@@ -617,11 +591,11 @@ pts_GroupCreate(const void *cellHandle, const char *newGroup,
 
     if (*newGroupId != 0) {
        tst =
-           ubik_Call(PR_INewEntry, c_handle->pts, 0, newGroup, *newGroupId,
+           ubik_PR_INewEntry(c_handle->pts, 0, newGroup, *newGroupId,
                      newOwnerId);
     } else {
        tst =
-           ubik_Call(PR_NewEntry, c_handle->pts, 0, newGroup, PRGRP,
+           ubik_PR_NewEntry(c_handle->pts, 0, newGroup, PRGRP,
                      newOwnerId, newGroupId);
     }
 
@@ -743,7 +717,7 @@ pts_GroupGet(const void *cellHandle, const char *groupName,
      * Retrieve information about the group
      */
 
-    tst = ubik_Call(PR_ListEntry, c_handle->pts, 0, groupId, &groupEntry);
+    tst = ubik_PR_ListEntry(c_handle->pts, 0, groupId, &groupEntry);
 
     if (tst != 0) {
        goto fail_pts_GroupGet;
@@ -753,7 +727,8 @@ pts_GroupGet(const void *cellHandle, const char *groupName,
     groupP->nameUid = groupEntry.id;
     groupP->ownerUid = groupEntry.owner;
     groupP->creatorUid = groupEntry.creator;
-    strcpy(groupP->name, groupEntry.name);
+    strncpy(groupP->name, groupEntry.name, PTS_MAX_NAME_LEN);
+    groupP->name[PTS_MAX_NAME_LEN - 1] = '\0';
     /*
      * Set the access rights based upon the value of the flags member
      * of the groupEntry struct.
@@ -842,8 +817,10 @@ pts_GroupGet(const void *cellHandle, const char *groupName,
        goto fail_pts_GroupGet;
     }
 
-    strcpy(groupP->owner, names.namelist_val[0]);
-    strcpy(groupP->creator, names.namelist_val[1]);
+    strncpy(groupP->owner, names.namelist_val[0], PTS_MAX_NAME_LEN);
+    groupP->owner[PTS_MAX_NAME_LEN - 1] = '\0';
+    strncpy(groupP->creator, names.namelist_val[1], PTS_MAX_NAME_LEN);
+    groupP->creator[PTS_MAX_NAME_LEN - 1] = '\0';
     free(names.namelist_val);
     rc = 1;
 
@@ -915,7 +892,7 @@ EntryDelete(const void *cellHandle, const char *entryName,
      * Make the rpc
      */
 
-    tst = ubik_Call(PR_Delete, c_handle->pts, 0, entryId);
+    tst = ubik_PR_Delete(c_handle->pts, 0, entryId);
 
     if (tst != 0) {
        goto fail_EntryDelete;
@@ -1002,7 +979,7 @@ pts_GroupMaxGet(const void *cellHandle, int *maxGroupId, afs_status_p st)
        goto fail_pts_GroupMaxGet;
     }
 
-    tst = ubik_Call(PR_ListMax, c_handle->pts, 0, &maxUserId, maxGroupId);
+    tst = ubik_PR_ListMax(c_handle->pts, 0, &maxUserId, maxGroupId);
 
     if (tst != 0) {
        goto fail_pts_GroupMaxGet;
@@ -1052,7 +1029,7 @@ pts_GroupMaxSet(const void *cellHandle, int maxGroupId, afs_status_p st)
        goto fail_pts_GroupMaxSet;
     }
 
-    tst = ubik_Call(PR_SetMax, c_handle->pts, 0, maxGroupId, PRGRP);
+    tst = ubik_PR_SetMax(c_handle->pts, 0, maxGroupId, PRGRP);
 
     if (tst != 0) {
        goto fail_pts_GroupMaxSet;
@@ -1223,7 +1200,7 @@ MemberListBegin(const void *cellHandle, const char *name, afs_status_t error1,
     iter->ids.prlist_val = 0;
 
     tst =
-       ubik_Call(PR_ListElements, c_handle->pts, 0, groupId, &iter->ids,
+       ubik_PR_ListElements(c_handle->pts, 0, groupId, &iter->ids,
                  &exceeded);
 
     if (tst != 0) {
@@ -1502,6 +1479,8 @@ pts_GroupMemberRemove(const void *cellHandle, const char *userName,
     afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
     idlist ids;
 
+    ids.idlist_val = NULL;
+
     /*
      * Validate arguments
      */
@@ -1531,7 +1510,7 @@ pts_GroupMemberRemove(const void *cellHandle, const char *userName,
      */
 
     tst =
-       ubik_Call(PR_RemoveFromGroup, c_handle->pts, 0, ids.idlist_val[0],
+       ubik_PR_RemoveFromGroup(c_handle->pts, 0, ids.idlist_val[0],
                  ids.idlist_val[1]);
 
     if (tst != 0) {
@@ -1575,7 +1554,7 @@ pts_GroupMemberRemove(const void *cellHandle, const char *userName,
 
 int ADMINAPI
 pts_GroupRename(const void *cellHandle, const char *oldName,
-               const char *newName, afs_status_p st)
+               char *newName, afs_status_p st)
 {
     int rc = 0;
     afs_status_t tst = 0;
@@ -1613,7 +1592,7 @@ pts_GroupRename(const void *cellHandle, const char *oldName,
      * Make the rpc
      */
 
-    tst = ubik_Call(PR_ChangeEntry, c_handle->pts, 0, groupId, newName, 0, 0);
+    tst = ubik_PR_ChangeEntry(c_handle->pts, 0, groupId, newName, 0, 0);
 
     if (tst != 0) {
        goto fail_pts_GroupRename;
@@ -1772,7 +1751,7 @@ pts_GroupModify(const void *cellHandle, const char *groupName,
      */
 
     tst =
-       ubik_Call(PR_SetFieldsEntry, c_handle->pts, 0, groupId, PR_SF_ALLBITS,
+       ubik_PR_SetFieldsEntry(c_handle->pts, 0, groupId, PR_SF_ALLBITS,
                  flags, 0, 0, 0, 0);
 
     if (tst != 0) {
@@ -1812,13 +1791,12 @@ pts_GroupModify(const void *cellHandle, const char *groupName,
  */
 
 int ADMINAPI
-pts_UserCreate(const void *cellHandle, const char *userName, int *newUserId,
+pts_UserCreate(const void *cellHandle, char *userName, int *newUserId,
               afs_status_p st)
 {
     int rc = 0;
     afs_status_t tst = 0;
     afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
-    afs_int32 userId = 0;
 
     /*
      * Validate arguments
@@ -1844,11 +1822,11 @@ pts_UserCreate(const void *cellHandle, const char *userName, int *newUserId,
 
     if (*newUserId != 0) {
        tst =
-           ubik_Call(PR_INewEntry, c_handle->pts, 0, userName, *newUserId,
+           ubik_PR_INewEntry(c_handle->pts, 0, userName, *newUserId,
                      0);
     } else {
        tst =
-           ubik_Call(PR_NewEntry, c_handle->pts, 0, userName, 0, 0,
+           ubik_PR_NewEntry(c_handle->pts, 0, userName, 0, 0,
                      newUserId);
     }
 
@@ -1966,7 +1944,7 @@ IsAdministrator(const afs_cell_handle_p c_handle, afs_int32 userId,
            goto fail_IsAdministrator;
        }
        tst =
-           ubik_Call(PR_IsAMemberOf, c_handle->pts, 0, userId, adminId,
+           ubik_PR_IsAMemberOf(c_handle->pts, 0, userId, adminId,
                      &isAdmin);
        if (tst != 0) {
            goto fail_IsAdministrator;
@@ -2056,7 +2034,7 @@ pts_UserGet(const void *cellHandle, const char *userName,
      * Retrieve information about the group
      */
 
-    tst = ubik_Call(PR_ListEntry, c_handle->pts, 0, userId, &userEntry);
+    tst = ubik_PR_ListEntry(c_handle->pts, 0, userId, &userEntry);
 
     if (tst != 0) {
        goto fail_pts_UserGet;
@@ -2081,7 +2059,8 @@ pts_UserGet(const void *cellHandle, const char *userName,
     userP->nameUid = userEntry.id;
     userP->ownerUid = userEntry.owner;
     userP->creatorUid = userEntry.creator;
-    strcpy(userP->name, userEntry.name);
+    strncpy(userP->name, userEntry.name, PTS_MAX_NAME_LEN);
+    userP->name[PTS_MAX_NAME_LEN - 1] = '\0';
 
     /*
      * The permission bits are described in the GroupGet function above.
@@ -2125,8 +2104,10 @@ pts_UserGet(const void *cellHandle, const char *userName,
        goto fail_pts_UserGet;
     }
 
-    strcpy(userP->owner, names.namelist_val[0]);
-    strcpy(userP->creator, names.namelist_val[1]);
+    strncpy(userP->owner, names.namelist_val[0], PTS_MAX_NAME_LEN);
+    userP->owner[PTS_MAX_NAME_LEN - 1] ='\0';
+    strncpy(userP->creator, names.namelist_val[1], PTS_MAX_NAME_LEN);
+    userP->creator[PTS_MAX_NAME_LEN - 1] = '\0';
     free(names.namelist_val);
     rc = 1;
 
@@ -2162,7 +2143,7 @@ pts_UserGet(const void *cellHandle, const char *userName,
 
 int ADMINAPI
 pts_UserRename(const void *cellHandle, const char *oldName,
-              const char *newName, afs_status_p st)
+              char *newName, afs_status_p st)
 {
     int rc = 0;
     afs_status_t tst = 0;
@@ -2200,7 +2181,7 @@ pts_UserRename(const void *cellHandle, const char *oldName,
      * Make the rpc
      */
 
-    tst = ubik_Call(PR_ChangeEntry, c_handle->pts, 0, userId, newName, 0, 0);
+    tst = ubik_PR_ChangeEntry(c_handle->pts, 0, userId, newName, 0, 0);
 
     if (tst != 0) {
        goto fail_pts_UserRename;
@@ -2257,8 +2238,6 @@ SetUserAccess(const pts_UserUpdateEntry_p userP, afs_int32 * flags,
     }
     rc = 1;
 
-  fail_SetUserAccess:
-
     if (st != NULL) {
        *st = tst;
     }
@@ -2346,7 +2325,7 @@ pts_UserModify(const void *cellHandle, const char *userName,
      */
 
     tst =
-       ubik_Call(PR_SetFieldsEntry, c_handle->pts, 0, userId, mask, flags,
+       ubik_PR_SetFieldsEntry(c_handle->pts, 0, userId, mask, flags,
                  newQuota, 0, 0, 0);
 
     if (tst != 0) {
@@ -2403,7 +2382,7 @@ pts_UserMaxGet(const void *cellHandle, int *maxUserId, afs_status_p st)
        goto fail_pts_UserMaxGet;
     }
 
-    tst = ubik_Call(PR_ListMax, c_handle->pts, 0, maxUserId, &maxGroupId);
+    tst = ubik_PR_ListMax(c_handle->pts, 0, maxUserId, &maxGroupId);
 
     if (tst != 0) {
        goto fail_pts_UserMaxGet;
@@ -2453,7 +2432,7 @@ pts_UserMaxSet(const void *cellHandle, int maxUserId, afs_status_p st)
        goto fail_pts_UserMaxSet;
     }
 
-    tst = ubik_Call(PR_SetMax, c_handle->pts, 0, maxUserId, 0);
+    tst = ubik_PR_SetMax(c_handle->pts, 0, maxUserId, 0);
 
     if (tst != 0) {
        goto fail_pts_UserMaxSet;
@@ -2618,7 +2597,7 @@ GetOwnedGroupRPC(void *rpc_specific, int slot, int *last_item,
 
     if ((!list->finished_retrieving) && (list->owned_names.namelist_len == 0)) {
        tst =
-           ubik_Call(PR_ListOwned, list->c_handle->pts, 0, list->owner,
+           ubik_PR_ListOwned(list->c_handle->pts, 0, list->owner,
                      &list->owned_ids, &list->more);
        if (tst != 0) {
            goto fail_GetOwnedGroupRPC;
@@ -2963,7 +2942,7 @@ GetPTSRPC(void *rpc_specific, int slot, int *last_item,
        bulkentries.prentries_len = 0;
 
        tst =
-           ubik_Call(PR_ListEntries, list->c_handle->pts, 0, list->flag,
+           ubik_PR_ListEntries(list->c_handle->pts, 0, list->flag,
                      start, &bulkentries, &(list->nextstartindex));
 
        if (tst != 0) {