Use unsigned addresses in the NFS exporter
[openafs.git] / src / afs / afs_nfsclnt.c
index 59aaa45..3abc982 100644 (file)
@@ -10,8 +10,6 @@
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
@@ -24,7 +22,7 @@ RCSID
 void afs_nfsclient_hold(), afs_PutNfsClientPag(), afs_nfsclient_GC();
 static void afs_nfsclient_getcreds();
 int afs_nfsclient_sysname(), afs_nfsclient_stats(), afs_nfsclient_checkhost();
-afs_int32 afs_nfsclient_gethost();
+afs_uint32 afs_nfsclient_gethost();
 #ifdef AFS_AIX_IAUTH_ENV
 int afs_allnfsreqs, afs_nfscalls;
 #endif
@@ -46,10 +44,10 @@ struct nfsclientpag *afs_nfspags[NNFSCLIENTS];
 afs_lock_t afs_xnfspag /*, afs_xnfsreq */ ;
 extern struct afs_exporter *afs_nfsexporter;
 
-/* Creates an nfsclientpag structure for the (uid, host) pair if one doesn't exist. RefCount is incremented and it's time stamped. */
+/* Creates an nfsclientpag structure for the (uid, host) pair if one doesn't 
+ * exist. RefCount is incremented and it's time stamped. */
 static struct nfsclientpag *
-afs_GetNfsClientPag(uid, host)
-     register afs_int32 uid, host;
+afs_GetNfsClientPag(register afs_int32 uid, register afs_uint32 host)
 {
     register struct nfsclientpag *np;
     register afs_int32 i, now;
@@ -60,12 +58,12 @@ afs_GetNfsClientPag(uid, host)
     AFS_STATCNT(afs_GetNfsClientPag);
     i = NHash(host);
     now = osi_Time();
-    MObtainWriteLock(&afs_xnfspag, 314);
+    ObtainWriteLock(&afs_xnfspag, 314);
     for (np = afs_nfspags[i]; np; np = np->next) {
        if (np->uid == uid && np->host == host) {
            np->refCount++;
            np->lastcall = now;
-           MReleaseWriteLock(&afs_xnfspag);
+           ReleaseWriteLock(&afs_xnfspag);
            return np;
        }
     }
@@ -74,12 +72,12 @@ afs_GetNfsClientPag(uid, host)
        if (np->uid == NOPAG && np->host == host) {
            np->refCount++;
            np->lastcall = now;
-           MReleaseWriteLock(&afs_xnfspag);
+           ReleaseWriteLock(&afs_xnfspag);
            return np;
        }
     }
     np = (struct nfsclientpag *)afs_osi_Alloc(sizeof(struct nfsclientpag));
-    memset((char *)np, 0, sizeof(struct nfsclientpag));
+    memset(np, 0, sizeof(struct nfsclientpag));
     /* Copy the necessary afs_exporter fields */
     memcpy((char *)np, (char *)afs_nfsexporter, sizeof(struct afs_exporter));
     np->next = afs_nfspags[i];
@@ -88,7 +86,7 @@ afs_GetNfsClientPag(uid, host)
     np->host = host;
     np->refCount = 1;
     np->lastcall = now;
-    MReleaseWriteLock(&afs_xnfspag);
+    ReleaseWriteLock(&afs_xnfspag);
     return np;
 }
 
@@ -107,10 +105,11 @@ afs_PutNfsClientPag(np)
 }
 
 
-/* Return the nfsclientpag structure associated with the (uid, host) or {pag, host} pair, if pag is nonzero. RefCount is incremented and it's time stamped. */
+/* Return the nfsclientpag structure associated with the (uid, host) or 
+ * {pag, host} pair, if pag is nonzero. RefCount is incremented and it's 
+ * time stamped. */
 static struct nfsclientpag *
-afs_FindNfsClientPag(uid, host, pag)
-     register afs_int32 uid, host, pag;
+afs_FindNfsClientPag(afs_int32 uid, afs_uint32 host, afs_int32 pag)
 {
     register struct nfsclientpag *np;
     register afs_int32 i;
@@ -120,13 +119,13 @@ afs_FindNfsClientPag(uid, host, pag)
 #endif
     AFS_STATCNT(afs_FindNfsClientPag);
     i = NHash(host);
-    MObtainWriteLock(&afs_xnfspag, 315);
+    ObtainWriteLock(&afs_xnfspag, 315);
     for (np = afs_nfspags[i]; np; np = np->next) {
        if (np->host == host) {
            if ((pag && pag == np->pag) || (!pag && (uid == np->uid))) {
                np->refCount++;
                np->lastcall = osi_Time();
-               MReleaseWriteLock(&afs_xnfspag);
+               ReleaseWriteLock(&afs_xnfspag);
                return np;
            }
        }
@@ -137,12 +136,12 @@ afs_FindNfsClientPag(uid, host, pag)
            if (np->uid == NOPAG) {
                np->refCount++;
                np->lastcall = osi_Time();
-               MReleaseWriteLock(&afs_xnfspag);
+               ReleaseWriteLock(&afs_xnfspag);
                return np;
            }
        }
     }
-    MReleaseWriteLock(&afs_xnfspag);
+    ReleaseWriteLock(&afs_xnfspag);
     return NULL;
 }
 
@@ -175,8 +174,8 @@ afs_nfsclient_init(void)
  */
 int
 afs_nfsclient_reqhandler(struct afs_exporter *exporter,
-                        struct AFS_UCRED **cred,
-                        afs_int32 host, afs_int32 *pagparam,
+                        afs_ucred_t **cred,
+                        afs_uint32 host, afs_int32 *pagparam,
                         struct afs_exporter **outexporter)
 {
     register struct nfsclientpag *np, *tnp;
@@ -191,7 +190,10 @@ afs_nfsclient_reqhandler(struct afs_exporter *exporter,
 
     afs_nfsexporter->exp_stats.calls++;
     if (!(afs_nfsexporter->exp_states & EXP_EXPORTED)) {
-       /* No afs requests accepted as long as EXPORTED flag is turned 'off'. Set/Reset via a pioctl call (fs exportafs). Note that this is on top of the /etc/exports nfs requirement (i.e. /afs must be exported to all or whomever there too!)
+       /* No afs requests accepted as long as EXPORTED flag is turned 'off'. 
+        * Set/Reset via a pioctl call (fs exportafs). Note that this is on 
+        * top of the /etc/exports nfs requirement (i.e. /afs must be 
+        * exported to all or whomever there too!)
         */
        afs_nfsexporter->exp_stats.rejectedcalls++;
        return EINVAL;
@@ -201,8 +203,10 @@ afs_nfsclient_reqhandler(struct afs_exporter *exporter,
 #if defined(AFS_SUN510_ENV)
     uid = crgetuid(*cred);
 #else
-    uid = (*cred)->cr_uid;
+    uid = afs_cr_uid(*cred);
 #endif
+    /* Do this early, so pag management knows */
+    afs_set_cr_rgid(*cred, NFSXLATOR_CRED);    /* Identify it as nfs xlator call */
     if ((afs_nfsexporter->exp_states & EXP_CLIPAGS) && pag != NOPAG) {
        uid = pag;
     } else if (pag != NOPAG) {
@@ -222,7 +226,7 @@ afs_nfsclient_reqhandler(struct afs_exporter *exporter,
     }
     np = afs_FindNfsClientPag(uid, host, 0);
     afs_Trace4(afs_iclSetp, CM_TRACE_NFSREQH, ICL_TYPE_INT32, pag,
-              ICL_TYPE_LONG, (*cred)->cr_uid, ICL_TYPE_INT32, host,
+              ICL_TYPE_LONG, afs_cr_uid(*cred), ICL_TYPE_INT32, host,
               ICL_TYPE_POINTER, np);
     /* If remote-pags are enabled, we are no longer interested in what PAG
      * they claimed, and from here on we should behave as if they claimed
@@ -233,12 +237,12 @@ afs_nfsclient_reqhandler(struct afs_exporter *exporter,
     if ((afs_nfsexporter->exp_states & EXP_CLIPAGS))
                pag = NOPAG;
     if (!np) {
-       /* Even if there is a "good" pag coming in we don't accept it if no nfsclientpag struct exists for the user since that would mean that the translator rebooted and therefore we ignore all older pag values */
-#ifdef AFS_OSF_ENV
-       if (code = setpag(u.u_procp, cred, -1, &pag, 0)) {      /* XXX u.u_procp is a no-op XXX */
-#else
+       /* Even if there is a "good" pag coming in we don't accept it if no 
+        * nfsclientpag struct exists for the user since that would mean 
+        * that the translator rebooted and therefore we ignore all older 
+        * pag values 
+        */
        if ((code = setpag(cred, -1, &pag, 0))) {
-#endif
            if (au)
                afs_PutUser(au, READ_LOCK);
 /*         ReleaseWriteLock(&afs_xnfsreq);             */
@@ -249,14 +253,10 @@ afs_nfsclient_reqhandler(struct afs_exporter *exporter,
        }
        np = afs_GetNfsClientPag(uid, host);
        np->pag = pag;
-       np->client_uid = (*cred)->cr_uid;
+       np->client_uid = afs_cr_uid(*cred);
     } else {
        if (pag == NOPAG) {
-#ifdef AFS_OSF_ENV
-           if (code = setpag(u.u_procp, cred, np->pag, &pag, 0)) {     /* XXX u.u_procp is a no-op XXX */
-#else
            if ((code = setpag(cred, np->pag, &pag, 0))) {
-#endif
                afs_PutNfsClientPag(np);
 /*             ReleaseWriteLock(&afs_xnfsreq); */
 #if defined(KERNEL_HAVE_UERROR)
@@ -269,11 +269,7 @@ afs_nfsclient_reqhandler(struct afs_exporter *exporter,
            tnp = (struct nfsclientpag *)au->exporter;
            if (tnp->uid && (tnp->uid != (afs_int32) - 2)) {    /* allow "root" initiators */
                /* Pag doesn't belong to caller; treat it as an unpaged call too */
-#ifdef AFS_OSF_ENV
-               if (code = setpag(u.u_procp, cred, np->pag, &pag, 0)) { /* XXX u.u_procp is a no-op XXX */
-#else
                if ((code = setpag(cred, np->pag, &pag, 0))) {
-#endif
                    afs_PutNfsClientPag(np);
                    afs_PutUser(au, READ_LOCK);
                    /*      ReleaseWriteLock(&afs_xnfsreq);     */
@@ -300,18 +296,12 @@ afs_nfsclient_reqhandler(struct afs_exporter *exporter,
     *pagparam = pag;
     *outexporter = (struct afs_exporter *)np;
     afs_PutUser(au, WRITE_LOCK);
-#ifdef AFS_OSF_ENV
-    (*cred)->cr_ruid = NFSXLATOR_CRED; /* Identify it as nfs xlator call */
-#else
-    (*cred)->cr_rgid = NFSXLATOR_CRED; /* Identify it as nfs xlator call */
-#endif
 /*    ReleaseWriteLock(&afs_xnfsreq);  */
     return 0;
 }
 
 void
-afs_nfsclient_getcreds(au)
-    struct unixuser *au;
+afs_nfsclient_getcreds(struct unixuser *au)
 {
     struct nfsclientpag *np = (struct nfsclientpag *)(au->exporter);
     struct rx_securityClass *csec;
@@ -424,10 +414,10 @@ done:
 }
 
 
-/* It's called whenever a new unixuser structure is created for the remote user associated with the nfsclientpag structure, np */
+/* It's called whenever a new unixuser structure is created for the remote
+ * user associated with the nfsclientpag structure, np */
 void
-afs_nfsclient_hold(np)
-     register struct nfsclientpag *np;
+afs_nfsclient_hold(register struct nfsclientpag *np)
 {
 #if defined(AFS_SGIMP_ENV)
     osi_Assert(ISAFS_GLOCK());
@@ -439,8 +429,7 @@ afs_nfsclient_hold(np)
 
 /* check if this exporter corresponds to the specified host */
 int
-afs_nfsclient_checkhost(np, host)
-    register struct nfsclientpag *np;
+afs_nfsclient_checkhost(register struct nfsclientpag *np, afs_uint32 host)
 {
     if (np->type != EXP_NFS)
        return 0;
@@ -449,9 +438,8 @@ afs_nfsclient_checkhost(np, host)
 
 
 /* get the host for this exporter, or 0 if there is an error */
-afs_int32
-afs_nfsclient_gethost(np)
-    register struct nfsclientpag *np;
+afs_uint32
+afs_nfsclient_gethost(register struct nfsclientpag *np)
 {
     if (np->type != EXP_NFS)
        return 0;
@@ -459,7 +447,9 @@ afs_nfsclient_gethost(np)
 }
 
 
-/* if inname is non-null, a new system name value is set for the remote user (inname contains the new sysname). In all cases, outname returns the current sysname value for this remote user */
+/* if inname is non-null, a new system name value is set for the remote
+ * user (inname contains the new sysname). In all cases, outname returns
+ * the current sysname value for this remote user */
 int 
 afs_nfsclient_sysname(register struct nfsclientpag *np, char *inname, 
                      char ***outname, int *num, int allpags)
@@ -475,12 +465,12 @@ afs_nfsclient_sysname(register struct nfsclientpag *np, char *inname,
     if (allpags > 0) {
        /* update every client, not just the one making the request */
        i = NHash(np->host);
-       MObtainWriteLock(&afs_xnfspag, 315);
+       ObtainWriteLock(&afs_xnfspag, 315);
        for (tnp = afs_nfspags[i]; tnp; tnp = tnp->next) {
            if (tnp != np && tnp->host == np->host)
                afs_nfsclient_sysname(tnp, inname, outname, num, -1);
        }
-       MReleaseWriteLock(&afs_xnfspag);
+       ReleaseWriteLock(&afs_xnfspag);
     }
     if (inname) {
            for(count=0; count < np->sysnamecount;++count) {
@@ -502,16 +492,22 @@ afs_nfsclient_sysname(register struct nfsclientpag *np, char *inname,
        /* Don't touch our arguments when called recursively */
        *outname = np->sysname;
        *num = np->sysnamecount;
+       if (!np->sysname[0])
+           return ENODEV; /* XXX */
     }
     return 0;
 }
 
 
-/* Garbage collect routine for the nfs exporter. When pag is -1 then all entries are removed (used by the nfsclient_shutdown routine); else if it's non zero then only the entry with that pag is removed, else all "timedout" entries are removed. TimedOut entries are those who have no "unixuser" structures associated with them (i.e. unixusercnt == 0) and they haven't had any activity the last NFSCLIENTGC seconds */
+/* Garbage collect routine for the nfs exporter. When pag is -1 then all
+ * entries are removed (used by the nfsclient_shutdown routine); else if
+ * it's non zero then only the entry with that pag is removed, else all
+ * "timedout" entries are removed. TimedOut entries are those who have no
+ * "unixuser" structures associated with them (i.e. unixusercnt == 0) and
+ * they haven't had any activity the last NFSCLIENTGC seconds */
 void
-afs_nfsclient_GC(exporter, pag)
-     register struct afs_exporter *exporter;
-     register afs_int32 pag;
+afs_nfsclient_GC(register struct afs_exporter *exporter,
+                register afs_int32 pag)
 {
     register struct nfsclientpag *np, **tnp, *nnp;
     register afs_int32 i, delflag;
@@ -521,7 +517,7 @@ afs_nfsclient_GC(exporter, pag)
     osi_Assert(ISAFS_GLOCK());
 #endif
     AFS_STATCNT(afs_nfsclient_GC);
-    MObtainWriteLock(&afs_xnfspag, 316);
+    ObtainWriteLock(&afs_xnfspag, 316);
     for (i = 0; i < NNFSCLIENTS; i++) {
        for (tnp = &afs_nfspags[i], np = *tnp; np; np = nnp) {
            nnp = np->next;
@@ -540,15 +536,15 @@ afs_nfsclient_GC(exporter, pag)
            }
        }
     }
-    MReleaseWriteLock(&afs_xnfspag);
+    ReleaseWriteLock(&afs_xnfspag);
 }
 
 
 int
-afs_nfsclient_stats(export)
-     register struct afs_exporter *export;
+afs_nfsclient_stats(register struct afs_exporter *export)
 {
-    /* Nothing much to do here yet since most important stats are collected directly in the afs_exporter structure itself */
+    /* Nothing much to do here yet since most important stats are collected 
+     * directly in the afs_exporter structure itself */
     AFS_STATCNT(afs_nfsclient_stats);
     return 0;
 }
@@ -568,7 +564,7 @@ char *afs_nfs_id = "AFSNFSTRANS";
  */
 int
 afs_iauth_verify(long id, fsid_t * fsidp, long host, int uid,
-                struct AFS_UCRED *credp, struct exportinfo *exp)
+                afs_ucred_t *credp, struct exportinfo *exp)
 {
     int code;
     struct nfsclientpag *nfs_pag;
@@ -597,11 +593,12 @@ afs_iauth_verify(long id, fsid_t * fsidp, long host, int uid,
 
     if (code) {
        /* ensure anonymous cred. */
-       credp->cr_uid = credp->cr_ruid = (uid_t) - 2;   /* anonymous */
+       afs_set_cr_uid(credp, (uid_t) -2;       /* anonymous */
+       afs_set_cr_ruid(credp, (uid_t) -2;
     }
 
     /* Mark this thread as an NFS translator thread. */
-    credp->cr_rgid = NFSXLATOR_CRED;
+    afs_set_cr_rgid(credp, NFSXLATOR_CRED);
 
     AFS_GUNLOCK();
     return 0;
@@ -611,7 +608,7 @@ afs_iauth_verify(long id, fsid_t * fsidp, long host, int uid,
  * and -1 on failure. Can fail because DFS has already registered.
  */
 int
-afs_iauth_register()
+afs_iauth_register(void)
 {
     if (nfs_iauth_register((unsigned long)afs_nfs_id, afs_iauth_verify))
        return -1;
@@ -624,7 +621,7 @@ afs_iauth_register()
 /* afs_iauth_unregister - unregister the iauth verify routine. Called on shutdown. 
  */
 void
-afs_iauth_unregister()
+afs_iauth_unregister(void)
 {
     if (afs_iauth_initd)
        nfs_iauth_unregister((unsigned long)afs_nfs_id);
@@ -635,7 +632,7 @@ afs_iauth_unregister()
 
 
 void
-shutdown_nfsclnt()
+shutdown_nfsclnt(void)
 {
 #if defined(AFS_SGIMP_ENV)
     osi_Assert(ISAFS_GLOCK());