pts-sysviewer-should-be-able-to-listowned-20020521
[openafs.git] / src / ptserver / ptutils.c
index e4596d4..c742867 100644 (file)
@@ -7,7 +7,11 @@
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
+#include <afsconfig.h>
 #include <afs/param.h>
+
+RCSID("$Header$");
+
 #include <afs/stds.h>
 #include <sys/types.h>
 #include <stdio.h>
 #include <winsock2.h>
 #else
 #include <netinet/in.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
+#endif
 #include <lock.h>
 #include <ubik.h>
 #include <rx/xdr.h>
 #include <afs/com_err.h>
+#include <afs/cellconfig.h>
 #include "ptserver.h"
 #include "pterror.h"
 #include <stdlib.h>
@@ -51,7 +62,7 @@ static int CorrectUserName (name)
     extern int pr_realmNameLen;
 
     /* We accept foreign names, so we will deal with '@' later */
-    if (index (name, ':') || index(name, '\n')) return 0;
+    if (strchr (name, ':') || strchr(name, '\n')) return 0;
     if (strlen (name) >= PR_MAXNAMELEN - pr_realmNameLen - 1) return 0; 
     return 1;
 }
@@ -99,7 +110,7 @@ static afs_int32 CorrectGroupName (ut, aname, cid, oid, cname)
        if (ntohl(tentry.flags) & PRGRP) {
            if ((tentry.count == 0) && !admin) return PRGROUPEMPTY;
            /* terminate prefix at colon if there is one */
-           if (prefix = index(tentry.name, ':')) *prefix = 0;
+           if ((prefix = strchr(tentry.name, ':'))) *prefix = 0;
        }
        prefix = tentry.name;
     }
@@ -107,7 +118,7 @@ static afs_int32 CorrectGroupName (ut, aname, cid, oid, cname)
     if ((strcmp (prefix, "system") == 0) && !admin) return PRPERM;
 
     strcpy (name, aname);              /* in case aname & cname are same */
-    suffix = index(name, ':');
+    suffix = strchr(name, ':');
     if (suffix == 0) {
        /* sysadmin can make groups w/o ':', but they must still look like
          * legal user names. */
@@ -121,10 +132,10 @@ static afs_int32 CorrectGroupName (ut, aname, cid, oid, cname)
     }
   done:
     /* check for legal name with either group rules or user rules */
-    if (suffix = index(cname, ':')) {
+    if ((suffix = strchr(cname, ':'))) {
        /* check for confusing characters */
-       if (index(cname, '\n') ||       /* restrict so recreate can work */
-           index(suffix+1, ':'))       /* avoid multiple colons */
+       if (strchr(cname, '\n') ||      /* restrict so recreate can work */
+           strchr(suffix+1, ':'))      /* avoid multiple colons */
            return PRBADNAM;
     } else {
        if (!CorrectUserName (cname)) return PRBADNAM;
@@ -151,11 +162,12 @@ int AccessOK (ut, cid, tentry, mem, any)
     } else {
        flags = oid = aid = 0;
     }
-    if (!(flags & PRACCESS))           /* provide default access */
+    if (!(flags & PRACCESS)) {         /* provide default access */
        if (flags & PRGRP)
            flags |= PRP_GROUP_DEFAULT;
        else
            flags |= PRP_USER_DEFAULT;
+    }
 
     if (flags & any) return 1;
     if (oid) {
@@ -168,7 +180,9 @@ int AccessOK (ut, cid, tentry, mem, any)
        if ((flags & mem) && IsAMemberOf (ut, cid, aid)) return 1;
     }
     /* Allow members of SYSVIEWERID to get membership and status only */
-    if (((mem == PRP_STATUS_MEM)||(mem == PRP_MEMBER_MEM))&&(IsAMemberOf (ut, cid, SYSVIEWERID))) return 1;
+    if (((mem == PRP_STATUS_MEM)||(mem == PRP_MEMBER_MEM)||
+        (any == PRP_OWNED_ANY))&&(IsAMemberOf (ut, cid, SYSVIEWERID))) 
+       return 1;
     if (IsAMemberOf (ut, cid, SYSADMINID)) return 1;
     return 0;                          /* no access */
 }
@@ -188,7 +202,7 @@ afs_int32 CreateEntry (at, aname, aid, idflag, flag, oid, creator)
     struct prentry tentry, tent;
     char *atsign;
     
-    bzero(&tentry, sizeof(tentry));
+    memset(&tentry, 0, sizeof(tentry));
 
     if ((oid == 0) || (oid == ANONYMOUSID)) oid = creator;
 
@@ -219,7 +233,7 @@ afs_int32 CreateEntry (at, aname, aid, idflag, flag, oid, creator)
         return PRBADARG;
     }
 
-    atsign = index(aname,'@');
+    atsign = strchr(aname, '@');
     if (!atsign) {
        /* A normal user or group. Pick an id for it */
        if (idflag) 
@@ -426,7 +440,7 @@ afs_int32 RemoveFromEntry (at, aid, bid)
     afs_int32 hloc;
     
     if (aid == bid) return PRINCONSISTENT;
-    bzero(&hentry,sizeof(hentry));
+    memset(&hentry, 0, sizeof(hentry));
     temp = FindByID(at,bid);
     if (temp == 0) return PRNOENT;
     code = pr_ReadEntry(at, 0, temp, &tentry);
@@ -482,7 +496,7 @@ afs_int32 RemoveFromEntry (at, aid, bid)
        } /* for all coentry slots */
        hloc = nptr;
        nptr = centry.next;
-       bcopy(&centry,&hentry,sizeof(centry));
+       memcpy(&hentry, &centry, sizeof(centry));
     } /* while there are coentries */
     return PRNOENT;
 }
@@ -500,7 +514,7 @@ afs_int32 DeleteEntry (at, tentry, loc)
     afs_int32  i;
     afs_int32 nptr;
 
-    if (index(tentry->name,'@')) {
+    if (strchr(tentry->name,'@')) {
        if (tentry->flags & PRGRP) {
        /* If there are still foreign user accounts from that cell
           don't delete the group */
@@ -589,7 +603,7 @@ afs_int32 DeleteEntry (at, tentry, loc)
        if (inc_header_word (at, instcount, -1)) return PRDBFAIL;
     }
     else {
-        if (index(tentry->name,'@')) {
+        if (strchr(tentry->name,'@')) {
           if (inc_header_word (at, foreigncount, -1)) return PRDBFAIL;
        } else {
           if (inc_header_word (at, usercount, -1)) return PRDBFAIL;
@@ -617,7 +631,7 @@ afs_int32 AddToEntry (tt, entry, loc, aid)
     afs_int32 nptr;
     afs_int32 last;                            /* addr of last cont. block */
     afs_int32 first = 0;
-    afs_int32 cloc;
+    afs_int32 cloc = 0;
     afs_int32 slot = -1;
 
     if (entry->id == aid) return PRINCONSISTENT;
@@ -693,7 +707,7 @@ afs_int32 AddToEntry (tt, entry, loc, aid)
     else {
        entry->next = nptr;
     }
-    bzero(&aentry,sizeof(aentry));
+    memset(&aentry, 0, sizeof(aentry));
     aentry.flags |= PRCONT;
     aentry.id = entry->id;
     aentry.next = 0;
@@ -791,7 +805,7 @@ afs_int32 GetList2 (at, tentry, tentry2 , alist, add)
   prlist *alist;
   afs_int32 add;
 {
-    afs_int32 code;
+    afs_int32 code = 0;
     afs_int32 i;
     struct contentry centry;
     afs_int32 nptr;
@@ -1086,8 +1100,8 @@ afs_int32 ChangeEntry (at, aid, cid, name, oid, newid)
     char oldname[PR_MAXNAMELEN];
     char *atsign;
 
-    bzero(holder,PR_MAXNAMELEN);
-    bzero(temp,PR_MAXNAMELEN);
+    memset(holder, 0, PR_MAXNAMELEN);
+    memset(temp, 0, PR_MAXNAMELEN);
     loc = FindByID(at,aid);
     if (!loc) return PRNOENT;
     code = pr_ReadEntry(at,0,loc,&tentry);
@@ -1158,7 +1172,7 @@ afs_int32 ChangeEntry (at, aid, cid, name, oid, newid)
        }
     }
 
-    atsign = index(tentry.name, '@'); /* check for foreign entry */
+    atsign = strchr(tentry.name, '@'); /* check for foreign entry */
 
     /* Change the owner */
     if (oid && (oid != tentry.owner)) {
@@ -1211,7 +1225,7 @@ afs_int32 ChangeEntry (at, aid, cid, name, oid, newid)
        {
             char *newatsign;
 
-           newatsign = index (name, '@');
+           newatsign = strchr(name, '@');
            if (newatsign != atsign){ /* if they are the same no problem*/
               /*if the pointers are not equal the strings better be */
               if ((atsign == NULL) || (newatsign == NULL) ||
@@ -1296,7 +1310,7 @@ AddAuthGroup(tentry, alist, size)
   prlist *alist;
   afs_int32 *size;
 {
-       if (!(index(tentry->name, '@'))) 
+       if (!(strchr(tentry->name, '@'))) 
              return (AddToPRList (alist, size, AUTHUSERID));
        else 
             return PRSUCCESS;