Fix build for FreeBSD 10.0
[openafs.git] / src / afs / FBSD / osi_groups.c
index 9a8984a..e897f46 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 #include <sys/param.h>
-#ifdef AFS_FBSD50_ENV
 #include <sys/sysproto.h>
-#endif
 
-RCSID("$Header$");
 
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
-#include "afs/afs_stats.h"  /* statistics */
+#include "afs/afs_stats.h"     /* statistics */
 
 static int
-afs_getgroups(
-    struct ucred *cred,
-    int ngroups,
-    gid_t *gidset);
+  afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset);
 
 static int
-afs_setgroups(
-    struct proc *proc,
-    struct ucred **cred,
-    int ngroups,
-    gid_t *gidset,
-    int change_parent);
-
-#ifdef AFS_FBSD50_ENV
-/*
- * This does nothing useful yet.
- * In 5.0, creds are associated not with a process, but with a thread.
- * Probably the right thing to do is replace struct proc with struct thread
- * everywhere, including setpag.
- * That will be a tedious undertaking.
- * For now, I'm just passing curproc to AddPag.
- * This is probably wrong and I don't know what the consequences might be.
- */
+  afs_setgroups(struct thread *td, struct ucred **cred, int ngroups,
+               gid_t * gidset, int change_parent);
+
 
 int
 Afs_xsetgroups(struct thread *td, struct setgroups_args *uap)
@@ -67,9 +47,18 @@ Afs_xsetgroups(struct thread *td, struct setgroups_args *uap)
     code = afs_InitReq(&treq, cr);
     AFS_GUNLOCK();
     crfree(cr);
-    if (code) return setgroups(td, uap); /* afs has shut down */
+    if (code)
+#if (__FreeBSD_version >= 900044)
+       return sys_setgroups(td, uap);  /* afs has shut down */
+#else
+       return setgroups(td, uap);      /* afs has shut down */
+#endif
 
+#if (__FreeBSD_version >= 900044)
+    code = sys_setgroups(td, uap);
+#else
     code = setgroups(td, uap);
+#endif
     /* Note that if there is a pag already in the new groups we don't
      * overwrite it with the old pag.
      */
@@ -79,90 +68,59 @@ Afs_xsetgroups(struct thread *td, struct setgroups_args *uap)
        if (((treq.uid >> 24) & 0xff) == 'A') {
            AFS_GLOCK();
            /* we've already done a setpag, so now we redo it */
-           AddPag(curproc, treq.uid, &cr);
-           AFS_GUNLOCK();
-       }
-    }
-    crfree(cr);
-    return code;
-}
-#else /* FBSD50 */
-int
-Afs_xsetgroups(p, args, retval)
-    struct proc *p;
-    void *args;
-    int *retval;
-{
-    int code = 0;
-    struct vrequest treq;
-    struct ucred *cr;
-
-    cr=crdup(p->p_cred->pc_ucred);
-
-    AFS_STATCNT(afs_xsetgroups);
-    AFS_GLOCK();
-    
-    code = afs_InitReq(&treq, cr);
-    AFS_GUNLOCK();
-    crfree(cr);
-    if (code) return setgroups(p, args, retval); /* afs has shut down */
-
-    code = setgroups(p, args, retval);
-    /* Note that if there is a pag already in the new groups we don't
-     * overwrite it with the old pag.
-     */
-    cr=crdup(p->p_cred->pc_ucred);
-
-    if (PagInCred(cr) == NOPAG) {
-       if (((treq.uid >> 24) & 0xff) == 'A') {
-           AFS_GLOCK();
-           /* we've already done a setpag, so now we redo it */
-           AddPag(p, treq.uid, &cr );
+           AddPag(td, treq.uid, &cr);
            AFS_GUNLOCK();
        }
     }
     crfree(cr);
     return code;
 }
-#endif
 
 
 int
-setpag(proc, cred, pagvalue, newpag, change_parent)
-    struct proc *proc;
-    struct ucred **cred;
-    afs_uint32 pagvalue;
-    afs_uint32 *newpag;
-    afs_uint32 change_parent;
+setpag(struct thread *td, struct ucred **cred, afs_uint32 pagvalue,
+       afs_uint32 * newpag, int change_parent)
 {
+#if defined(AFS_FBSD81_ENV)
+    gid_t *gidset;
+    int gidset_len = ngroups_max + 1;
+#elif defined(AFS_FBSD80_ENV)
+    gid_t *gidset;
+    int gidset_len = NGROUPS;  /* 1024 */
+#else
     gid_t gidset[NGROUPS];
+    int gidset_len = NGROUPS;  /* 16 */
+#endif
     int ngroups, code;
     int j;
 
     AFS_STATCNT(setpag);
-    ngroups = afs_getgroups(*cred, NGROUPS, gidset);
+#ifdef AFS_FBSD80_ENV
+    gidset = osi_Alloc(gidset_len * sizeof(gid_t));
+#endif
+    ngroups = afs_getgroups(*cred, gidset_len, gidset);
     if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
        /* We will have to shift grouplist to make room for pag */
-       if (ngroups + 2 > NGROUPS) {
+       if (ngroups + 2 > gidset_len) {
            return (E2BIG);
        }
-       for (j = ngroups -1; j >= 1; j--) {
-           gidset[j+2] = gidset[j];
+       for (j = ngroups - 1; j >= 1; j--) {
+           gidset[j + 2] = gidset[j];
        }
        ngroups += 2;
     }
-    *newpag = (pagvalue == -1 ? genpag(): pagvalue);
+    *newpag = (pagvalue == -1 ? genpag() : pagvalue);
     afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
-    code = afs_setgroups(proc, cred, ngroups, gidset, change_parent);
+    code = afs_setgroups(td, cred, ngroups, gidset, change_parent);
+#ifdef AFS_FBSD80_ENV
+    osi_Free(gidset, gidset_len * sizeof(gid_t));
+#endif
     return code;
 }
 
 
 static int
-afs_getgroups(
-    struct ucred *cred,
-    int ngroups,
-    gid_t *gidset)
+afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
 {
     int ngrps, savengrps;
     gid_t *gp;
@@ -171,47 +129,14 @@ afs_getgroups(
     savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
     gp = cred->cr_groups;
     while (ngrps--)
-       *gidset++ = *gp++;   
+       *gidset++ = *gp++;
     return savengrps;
 }
 
 
 static int
-afs_setgroups(
-    struct proc *proc,
-    struct ucred **cred,
-    int ngroups,
-    gid_t *gidset,
-    int change_parent)
+afs_setgroups(struct thread *td, struct ucred **cred, int ngroups,
+             gid_t * gidset, int change_parent)
 {
-#ifndef AFS_FBSD50_ENV
-    int ngrps;
-    int i;
-    gid_t *gp;
-    struct ucred *oldcr, *cr;
-
-    AFS_STATCNT(afs_setgroups);
-    /*
-     * The real setgroups() call does this, so maybe we should too.
-     *
-     */
-    if (ngroups > NGROUPS)
-       return EINVAL;
-    cr = *cred;
-    cr->cr_ngroups = ngroups;
-    gp = cr->cr_groups;
-    while (ngroups--)
-       *gp++ = *gidset++;
-    if (change_parent) {
-       crhold(cr);
-       oldcr=proc->p_pptr->p_cred->pc_ucred;
-       proc->p_pptr->p_cred->pc_ucred=cr;
-       crfree(oldcr);
-    }
-    crhold(cr);
-    oldcr=proc->p_cred->pc_ucred;
-    proc->p_cred->pc_ucred=cr;
-    crfree(oldcr);
-#endif
-    return(0);
+    return (0);
 }