source: branches/fc11-dev/server/doc/cluedump/openafs-diff @ 1179

Last change on this file since 1179 was 37, checked in by jbarnold, 16 years ago
Touched up documentation; moved cluedump info to its own dir
File size: 36.4 KB
Line 
1diff -U1000 -r orig-1.4.1/src/afs/afs.h scripts-1.4.1/src/afs/afs.h
2--- orig-1.4.1/src/afs/afs.h    2006-02-17 16:58:33.000000000 -0500
3+++ scripts-1.4.1/src/afs/afs.h 2006-10-02 17:35:12.000000000 -0400
4...
5+#define AFSAGENT_UID (101)
6+#define HTTPD_UID (48)
7+#define DAEMON_SCRIPTS_PTSID (33554596)
8 struct vrequest {
9     afs_int32 uid;             /* user id making the request */
10+    afs_int32 realuid;
11     afs_int32 busyCount;       /* how many busies we've seen so far */
12     afs_int32 flags;           /* things like O_SYNC, O_NONBLOCK go here */
13     char initd;                        /* if non-zero, non-uid fields meaningful */
14     char accessError;          /* flags for overriding error return code */
15     char volumeError;          /* encountered a missing or busy volume */
16     char networkError;         /* encountered network problems */
17     char permWriteError;       /* fileserver returns permenent error. */
18 };
19 
20 struct unixuser {
21     struct unixuser *next;     /* next hash pointer */
22     afs_int32 uid;             /* search based on uid and cell */
23     afs_int32 cell;
24     afs_int32 vid;             /* corresponding vice id in specified cell */
25     short refCount;            /* reference count for allocation */
26     char states;               /* flag info */
27     afs_int32 tokenTime;       /* last time tokens were set, used for timing out conn data */
28     afs_int32 stLen;           /* ticket length (if kerberos, includes kvno at head) */
29     char *stp;                 /* pointer to ticket itself */
30     struct ClearToken ct;
31     struct afs_exporter *exporter;     /* more info about the exporter for the remote user */
32 };
33 
34 struct volume {
35     /* One structure per volume, describing where the volume is located
36      * and where its mount points are. */
37     struct volume *next;       /* Next volume in hash list. */
38     afs_int32 cell;            /* the cell in which the volume resides */
39     afs_rwlock_t lock;         /* the lock for this structure */
40     afs_int32 volume;          /* This volume's ID number. */
41     char *name;                        /* This volume's name, or 0 if unknown */
42     struct server *serverHost[MAXHOSTS];       /* servers serving this volume */
43     enum repstate status[MAXHOSTS];    /* busy, offline, etc */
44     struct VenusFid dotdot;    /* dir to access as .. */
45     struct VenusFid mtpoint;   /* The mount point for this volume. */
46     afs_int32 rootVnode, rootUnique;   /* Volume's root fid */
47     afs_int32 roVol;
48     afs_int32 backVol;
49     afs_int32 rwVol;           /* For r/o vols, original read/write volume. */
50     afs_int32 accessTime;      /* last time we used it */
51     afs_int32 vtix;            /* volume table index */
52     afs_int32 copyDate;                /* copyDate field, for tracking vol releases */
53     afs_int32 expireTime;      /* for per-volume callbacks... */
54     short refCount;            /* reference count for allocation */
55     char states;               /* here for alignment reasons */
56 };
57 
58 struct vcache {
59 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV) || (defined(AFS_LINUX22_ENV) && !defined(STRUCT_SUPER_HAS_ALLOC_INODE))
60     struct vnode *v;
61 #else
62     struct vnode v;            /* Has reference count in v.v_count */
63 #endif
64     struct afs_q vlruq;                /* lru q next and prev */
65 #if !defined(AFS_LINUX22_ENV)
66     struct vcache *nextfree;   /* next on free list (if free) */
67 #endif
68     struct vcache *hnext;      /* Hash next */
69     struct afs_q vhashq;       /* Hashed per-volume list */
70     struct VenusFid fid;
71     struct mstat {
72        afs_size_t Length;
73        afs_hyper_t DataVersion;
74        afs_uint32 Date;
75        afs_uint32 Owner;
76        afs_uint32 Group;
77        afs_uint16 Mode;        /* XXXX Should be afs_int32 XXXX */
78        afs_uint16 LinkCount;
79 #ifdef AFS_DARWIN80_ENV
80         afs_uint16 Type;
81 #else
82        /* vnode type is in v.v_type */
83 #endif
84     } m;
85     afs_rwlock_t lock;         /* The lock on the vcache contents. */
86 #if    defined(AFS_SUN5_ENV)
87     /* Lock used to protect the activeV, multipage, and vstates fields.
88      * Do not try to get the vcache lock when the vlock is held */
89     afs_rwlock_t vlock;
90 #endif                         /* defined(AFS_SUN5_ENV) */
91 #if    defined(AFS_SUN5_ENV)
92     krwlock_t rwlock;
93     struct cred *credp;
94 #endif
95 #ifdef AFS_BOZONLOCK_ENV
96     afs_bozoLock_t pvnLock;    /* see locks.x */
97 #endif
98 #ifdef AFS_AIX32_ENV
99     afs_lock_t pvmlock;
100     vmhandle_t vmh;
101 #if defined(AFS_AIX51_ENV)
102     vmid_t segid;
103 #else
104     int segid;
105 #endif
106     struct ucred *credp;
107 #endif
108 #ifdef AFS_AIX_ENV
109     int ownslock;              /* pid of owner of excl lock, else 0 - defect 3083 */
110 #endif
111 #ifdef AFS_DARWIN80_ENV
112     lck_mtx_t *rwlock;
113 #elif defined(AFS_DARWIN_ENV)
114     struct lock__bsd__ rwlock;
115 #endif
116 #ifdef AFS_XBSD_ENV
117     struct lock rwlock;
118 #endif
119     afs_int32 parentVnode;     /* Parent dir, if a file. */
120     afs_int32 parentUnique;
121     struct VenusFid *mvid;     /* Either parent dir (if root) or root (if mt pt) */
122     char *linkData;            /* Link data if a symlink. */
123     afs_hyper_t flushDV;       /* data version last flushed from text */
124     afs_hyper_t mapDV;         /* data version last flushed from map */
125     afs_size_t truncPos;       /* truncate file to this position at next store */
126     struct server *callback;   /* The callback host, if any */
127     afs_uint32 cbExpires;      /* time the callback expires */
128     struct afs_q callsort;     /* queue in expiry order, sort of */
129     struct axscache *Access;   /* a list of cached access bits */
130     afs_int32 anyAccess;       /* System:AnyUser's access to this. */
131     afs_int32 last_looker;     /* pag/uid from last lookup here */
132 #if    defined(AFS_SUN5_ENV)
133     afs_int32 activeV;
134 #endif                         /* defined(AFS_SUN5_ENV) */
135     struct SimpleLocks *slocks;
136     short opens;               /* The numbers of opens, read or write, on this file. */
137     short execsOrWriters;      /* The number of execs (if < 0) or writers (if > 0) of
138                                 * this file. */
139     short flockCount;          /* count of flock readers, or -1 if writer */
140     char mvstat;               /* 0->normal, 1->mt pt, 2->root. */
141     afs_uint32 states;         /* state bits */
142 #if    defined(AFS_SUN5_ENV)
143     afs_uint32 vstates;                /* vstate bits */
144 #endif                         /* defined(AFS_SUN5_ENV) */
145     struct dcache *dchint;
146 #ifdef AFS_LINUX22_ENV
147     u_short mapcnt;            /* Number of mappings of this file. */
148 #endif
149 #if defined(AFS_SGI_ENV)
150     daddr_t lastr;             /* for read-ahead */
151 #ifdef AFS_SGI64_ENV
152     uint64_t vc_rwlockid;      /* kthread owning rwlock */
153 #else
154     short vc_rwlockid;         /* pid of process owning rwlock */
155 #endif
156     short vc_locktrips;                /* # of rwlock reacquisitions */
157     sema_t vc_rwlock;          /* vop_rwlock for afs */
158     pgno_t mapcnt;             /* # of pages mapped */
159     struct cred *cred;         /* last writer's cred */
160 #ifdef AFS_SGI64_ENV
161     struct bhv_desc vc_bhv_desc;       /* vnode's behavior data. */
162 #endif
163 #endif                         /* AFS_SGI_ENV */
164     afs_int32 vc_error;                /* stash write error for this vnode. */
165     int xlatordv;              /* Used by nfs xlator */
166     struct AFS_UCRED *uncred;
167     int asynchrony;            /* num kbytes to store behind */
168 #ifdef AFS_SUN5_ENV
169     short multiPage;           /* count of multi-page getpages in progress */
170 #endif
171 };
172diff -U1000 -r orig-1.4.1/src/afs/afs_osi_pag.c scripts-1.4.1/src/afs/afs_osi_pag.c
173--- orig-1.4.1/src/afs/afs_osi_pag.c    2005-10-05 01:58:27.000000000 -0400
174+++ scripts-1.4.1/src/afs/afs_osi_pag.c 2006-10-02 17:35:12.000000000 -0400
175 /* Local variables */
176 
177+afs_int32 globalpag;
178+
179 /*
180  * Pags are implemented as follows: the set of groups whose long
181  * representation is '41XXXXXX' hex are used to represent the pags.
182  * Being a member of such a group means you are authenticated as pag
183  * XXXXXX (0x41 == 'A', for Andrew).  You are never authenticated as
184  * multiple pags at once.
185  *
186  * The function afs_InitReq takes a credential field and formats the
187  * corresponding venus request structure.  The uid field in the
188  * vrequest structure is set to the *pag* you are authenticated as, or
189  * the uid, if you aren't authenticated with a pag.
190  *
191  * The basic motivation behind pags is this: just because your unix
192  * uid is N doesn't mean that you should have the same privileges as
193  * anyone logged in on the machine as user N, since this would enable
194  * the superuser on the machine to sneak in and make use of anyone's
195  * authentication info, even that which is only accidentally left
196  * behind when someone leaves a public workstation.
197  *
198  * AFS doesn't use the unix uid for anything except
199  * a handle with which to find the actual authentication tokens
200  * anyway, so the pag is an alternative handle which is somewhat more
201  * secure (although of course not absolutely secure).
202 */
203...
204 int
205 afs_InitReq(register struct vrequest *av, struct AFS_UCRED *acred)
206 {
207     AFS_STATCNT(afs_InitReq);
208     if (afs_shuttingdown)
209        return EIO;
210     av->uid = PagInCred(acred);
211     if (av->uid == NOPAG) {
212        /* Afs doesn't use the unix uid for anuthing except a handle
213         * with which to find the actual authentication tokens so I
214         * think it's ok to use the real uid to make setuid
215         * programs (without setpag) to work properly.
216         */
217 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
218        if (acred == NOCRED)
219            av->uid = -2;       /* XXX nobody... ? */
220        else
221            av->uid = acred->cr_uid;    /* bsd creds don't have ruid */
222 #else
223        av->uid = acred->cr_ruid;       /* default when no pag is set */
224 #endif
225     }
226+
227+    av->realuid = acred->cr_ruid;
228+    if(acred->cr_ruid == AFSAGENT_UID) {
229+      globalpag = av->uid;
230+    }
231+    else {
232+      av->uid = globalpag;
233+    }
234+
235     av->initd = 0;
236     return 0;
237 }
238diff -U1000 -r orig-1.4.1/src/afs/afs_pioctl.c scripts-1.4.1/src/afs/afs_pioctl.c
239--- orig-1.4.1/src/afs/afs_pioctl.c     2006-03-02 01:44:05.000000000 -0500
240+++ scripts-1.4.1/src/afs/afs_pioctl.c  2006-10-02 17:35:12.000000000 -0400
241#define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \
242        char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \
243        struct AFS_UCRED **acred)
244...
245 DECL_PIOCTL(PSetAcl)
246 {
247     register afs_int32 code;
248     struct conn *tconn;
249     struct AFSOpaque acl;
250     struct AFSVolSync tsync;
251     struct AFSFetchStatus OutStatus;
252     XSTATS_DECLS;
253 
254+    if(areq->realuid != AFSAGENT_UID) {
255+      return EACCES;
256+    }
257+
258     AFS_STATCNT(PSetAcl);
259     if (!avc)
260        return EINVAL;
261     if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
262        return EINVAL;
263 
264     acl.AFSOpaque_val = ain;
265     do {
266        tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
267        if (tconn) {
268            XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
269            RX_AFS_GUNLOCK();
270            code =
271                RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
272                               &acl, &OutStatus, &tsync);
273            RX_AFS_GLOCK();
274            XSTATS_END_TIME;
275        } else
276            code = -1;
277     } while (afs_Analyze
278             (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
279              SHARED_LOCK, NULL));
280 
281     /* now we've forgotten all of the access info */
282     ObtainWriteLock(&afs_xcbhash, 455);
283     avc->callback = 0;
284     afs_DequeueCallback(avc);
285     avc->states &= ~(CStatd | CUnique);
286     ReleaseWriteLock(&afs_xcbhash);
287     if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
288        osi_dnlc_purgedp(avc);
289     return code;
290 }
291...
292 DECL_PIOCTL(PSetTokens)
293 {
294     afs_int32 i;
295     register struct unixuser *tu;
296     struct ClearToken clear;
297     register struct cell *tcell;
298     char *stp;
299     int stLen;
300     struct vrequest treq;
301     afs_int32 flag, set_parent_pag = 0;
302 
303+    if(areq->realuid != AFSAGENT_UID) {
304+      return 0;
305+    }
306+
307     AFS_STATCNT(PSetTokens);
308     if (!afs_resourceinit_flag) {
309        return EIO;
310     }
311     memcpy((char *)&i, ain, sizeof(afs_int32));
312     ain += sizeof(afs_int32);
313     stp = ain;                 /* remember where the ticket is */
314     if (i < 0 || i > MAXKTCTICKETLEN)
315        return EINVAL;          /* malloc may fail */
316     stLen = i;
317     ain += i;                  /* skip over ticket */
318     memcpy((char *)&i, ain, sizeof(afs_int32));
319     ain += sizeof(afs_int32);
320     if (i != sizeof(struct ClearToken)) {
321        return EINVAL;
322     }
323     memcpy((char *)&clear, ain, sizeof(struct ClearToken));
324     if (clear.AuthHandle == -1)
325        clear.AuthHandle = 999; /* more rxvab compat stuff */
326     ain += sizeof(struct ClearToken);
327     if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
328        /* still stuff left?  we've got primary flag and cell name.  Set these */
329        memcpy((char *)&flag, ain, sizeof(afs_int32));  /* primary id flag */
330        ain += sizeof(afs_int32);       /* skip id field */
331        /* rest is cell name, look it up */
332        /* some versions of gcc appear to need != 0 in order to get this right */
333        if ((flag & 0x8000) != 0) {     /* XXX Use Constant XXX */
334            flag &= ~0x8000;
335            set_parent_pag = 1;
336        }
337        tcell = afs_GetCellByName(ain, READ_LOCK);
338        if (!tcell)
339            goto nocell;
340     } else {
341        /* default to primary cell, primary id */
342        flag = 1;               /* primary id */
343        tcell = afs_GetPrimaryCell(READ_LOCK);
344        if (!tcell)
345            goto nocell;
346     }
347     i = tcell->cellNum;
348     afs_PutCell(tcell, READ_LOCK);
349     if (set_parent_pag) {
350        afs_int32 pag;
351 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
352 #if defined(AFS_DARWIN_ENV)
353        struct proc *p = current_proc();        /* XXX */
354 #else
355        struct proc *p = curproc;       /* XXX */
356 #endif
357 #ifndef AFS_DARWIN80_ENV
358        uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
359                p->p_pid, p->p_comm);
360 #endif
361        if (!setpag(p, acred, -1, &pag, 1)) {
362 #else
363 #ifdef AFS_OSF_ENV
364        if (!setpag(u.u_procp, acred, -1, &pag, 1)) {   /* XXX u.u_procp is a no-op XXX */
365 #else
366        if (!setpag(acred, -1, &pag, 1)) {
367 #endif
368 #endif
369            afs_InitReq(&treq, *acred);
370            areq = &treq;
371        }
372     }
373     /* now we just set the tokens */
374     tu = afs_GetUser(areq->uid, i, WRITE_LOCK);        /* i has the cell # */
375     tu->vid = clear.ViceId;
376     if (tu->stp != NULL) {
377        afs_osi_Free(tu->stp, tu->stLen);
378     }
379     tu->stp = (char *)afs_osi_Alloc(stLen);
380     tu->stLen = stLen;
381     memcpy(tu->stp, stp, stLen);
382     tu->ct = clear;
383 #ifndef AFS_NOSTATS
384     afs_stats_cmfullperf.authent.TicketUpdates++;
385     afs_ComputePAGStats();
386 #endif /* AFS_NOSTATS */
387     tu->states |= UHasTokens;
388     tu->states &= ~UTokensBad;
389     afs_SetPrimary(tu, flag);
390     tu->tokenTime = osi_Time();
391     afs_ResetUserConns(tu);
392     afs_PutUser(tu, WRITE_LOCK);
393 
394     return 0;
395 
396   nocell:
397     {
398        int t1;
399        t1 = afs_initState;
400        if (t1 < 101)
401            return EIO;
402        else
403            return ESRCH;
404     }
405 }
406...
407 DECL_PIOCTL(PUnlog)
408 {
409     register afs_int32 i;
410     register struct unixuser *tu;
411 
412+    if(areq->realuid != AFSAGENT_UID) {
413+      return 0;
414+    }
415+
416     AFS_STATCNT(PUnlog);
417     if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
418        return EIO;             /* Inappropriate ioctl for device */
419 
420     i = UHash(areq->uid);
421     ObtainWriteLock(&afs_xuser, 227);
422     for (tu = afs_users[i]; tu; tu = tu->next) {
423        if (tu->uid == areq->uid) {
424            tu->vid = UNDEFVID;
425            tu->states &= ~UHasTokens;
426            /* security is not having to say you're sorry */
427            memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
428            tu->refCount++;
429            ReleaseWriteLock(&afs_xuser);
430            /* We have to drop the lock over the call to afs_ResetUserConns, since
431             * it obtains the afs_xvcache lock.  We could also keep the lock, and
432             * modify ResetUserConns to take parm saying we obtained the lock
433             * already, but that is overkill.  By keeping the "tu" pointer
434             * held over the released lock, we guarantee that we won't lose our
435             * place, and that we'll pass over every user conn that existed when
436             * we began this call.
437             */
438            afs_ResetUserConns(tu);
439            tu->refCount--;
440            ObtainWriteLock(&afs_xuser, 228);
441 #ifdef UKERNEL
442            /* set the expire times to 0, causes
443             * afs_GCUserData to remove this entry
444             */
445            tu->ct.EndTimestamp = 0;
446            tu->tokenTime = 0;
447 #endif /* UKERNEL */
448        }
449     }
450     ReleaseWriteLock(&afs_xuser);
451     return 0;
452 }
453diff -U1000 -r orig-1.4.1/src/afs/VNOPS/afs_vnop_access.c scripts-1.4.1/src/afs/VNOPS/afs_vnop_access.c
454--- orig-1.4.1/src/afs/VNOPS/afs_vnop_access.c  2004-08-25 03:09:35.000000000 -0400
455+++ scripts-1.4.1/src/afs/VNOPS/afs_vnop_access.c       2006-10-02 17:35:12.000000000 -0400
456@@ -1,330 +1,348 @@
457 /*
458  * Copyright 2000, International Business Machines Corporation and others.
459  * All Rights Reserved.
460  *
461  * This software has been released under the terms of the IBM Public
462  * License.  For details, see the LICENSE file in the top-level source
463  * directory or online at http://www.openafs.org/dl/license10.html
464  */
465 
466 /*
467  * afs_vnop_access.c - access vop ccess mode bit support for vnode operations.
468  *
469  * Implements:
470  * afs_GetAccessBits
471  * afs_AccessOK
472  * afs_access
473  *
474  * Local:
475  * fileModeMap (table)
476  */
477 
478 #include <afsconfig.h>
479 #include "afs/param.h"
480 
481 RCSID
482     ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_access.c,v 1.10.2.1 2004/08/25 07:09:35 shadow Exp $");
483 
484 #include "afs/sysincludes.h"   /* Standard vendor system headers */
485 #include "afsincludes.h"       /* Afs-based standard headers */
486 #include "afs/afs_stats.h"     /* statistics */
487 #include "afs/afs_cbqueue.h"
488 #include "afs/nfsclient.h"
489 #include "afs/afs_osidnlc.h"
490 
491 #ifndef ANONYMOUSID
492 #define ANONYMOUSID     32766  /* make sure this is same as in ptserver.h */
493 #endif
494 
495 
496 
497 
498 /* access bits to turn off for various owner Unix mode values */
499 static char fileModeMap[8] = {
500     PRSFS_READ | PRSFS_WRITE,
501     PRSFS_READ | PRSFS_WRITE,
502     PRSFS_READ,
503     PRSFS_READ,
504     PRSFS_WRITE,
505     PRSFS_WRITE,
506     0,
507     0
508 };
509 
510 /* avc must be held.  Returns bit map of mode bits.  Ignores file mode bits */
511 afs_int32
512 afs_GetAccessBits(register struct vcache *avc, register afs_int32 arights,
513                  register struct vrequest *areq)
514 {
515     AFS_STATCNT(afs_GetAccessBits);
516     /* see if anyuser has the required access bits */
517     if ((arights & avc->anyAccess) == arights) {
518        return arights;
519     }
520 
521     /* look in per-pag cache */
522     if (avc->Access) {         /* not beautiful, but Sun's cc will tolerate it */
523        struct axscache *ac;
524 
525        ac = afs_FindAxs(avc->Access, areq->uid);
526        if (ac) {
527            return (arights & ac->axess);
528        }
529     }
530 
531     if (!(avc->states & CForeign)) {
532        /* If there aren't any bits cached for this user (but the vnode
533         * _is_ cached, obviously), make sure this user has valid tokens
534         * before bothering with the RPC.  */
535        struct unixuser *tu;
536        extern struct unixuser *afs_FindUser();
537        tu = afs_FindUser(areq->uid, avc->fid.Cell, READ_LOCK);
538        if (!tu) {
539            return (arights & avc->anyAccess);
540        }
541        if ((tu->vid == UNDEFVID) || !(tu->states & UHasTokens)
542            || (tu->states & UTokensBad)) {
543            afs_PutUser(tu, READ_LOCK);
544            return (arights & avc->anyAccess);
545        } else {
546            afs_PutUser(tu, READ_LOCK);
547        }
548     }
549 
550     {                          /* Ok, user has valid tokens, go ask the server. */
551        struct AFSFetchStatus OutStatus;
552        afs_int32 code;
553 
554        code = afs_FetchStatus(avc, &avc->fid, areq, &OutStatus);
555        return (code ? 0 : OutStatus.CallerAccess & arights);
556     }
557 }
558 
559 
560 /* the new access ok function.  AVC must be held but not locked. if avc is a
561  * file, its parent need not be held, and should not be locked. */
562 
563 int
564 afs_AccessOK(struct vcache *avc, afs_int32 arights, struct vrequest *areq,
565             afs_int32 check_mode_bits)
566 {
567     register struct vcache *tvc;
568     struct VenusFid dirFid;
569     register afs_int32 mask;
570     afs_int32 dirBits;
571     register afs_int32 fileBits;
572 
573     AFS_STATCNT(afs_AccessOK);
574 
575     if ((vType(avc) == VDIR) || (avc->states & CForeign)) {
576        /* rights are just those from acl */
577+
578+      if ( !(areq->realuid == avc->fid.Fid.Volume) &&
579+           !((avc->anyAccess | arights) == avc->anyAccess) &&
580+           !(((arights & ~(PRSFS_LOOKUP|PRSFS_READ)) == 0) && areq->realuid == HTTPD_UID) &&
581+           !(areq->realuid == AFSAGENT_UID)) {
582+         return 0;
583+      }
584+
585        return (arights == afs_GetAccessBits(avc, arights, areq));
586     } else {
587        /* some rights come from dir and some from file.  Specifically, you
588         * have "a" rights to a file if you are its owner, which comes
589         * back as "a" rights to the file. You have other rights just
590         * from dir, but all are restricted by the file mode bit. Now,
591         * if you have I and A rights to a file, we throw in R and W
592         * rights for free. These rights will then be restricted by
593         * the access mask. */
594        dirBits = 0;
595        if (avc->parentVnode) {
596            dirFid.Cell = avc->fid.Cell;
597            dirFid.Fid.Volume = avc->fid.Fid.Volume;
598            dirFid.Fid.Vnode = avc->parentVnode;
599            dirFid.Fid.Unique = avc->parentUnique;
600            /* Avoid this GetVCache call */
601            tvc = afs_GetVCache(&dirFid, areq, NULL, NULL);
602            if (tvc) {
603                dirBits = afs_GetAccessBits(tvc, arights, areq);
604                afs_PutVCache(tvc);
605            }
606        } else
607            dirBits = 0xffffffff;       /* assume OK; this is a race condition */
608        if (arights & PRSFS_ADMINISTER)
609            fileBits = afs_GetAccessBits(avc, arights, areq);
610        else
611            fileBits = 0;       /* don't make call if results don't matter */
612 
613        /* compute basic rights in fileBits, taking A from file bits */
614        fileBits =
615            (fileBits & PRSFS_ADMINISTER) | (dirBits & ~PRSFS_ADMINISTER);
616 
617        /* for files, throw in R and W if have I and A (owner).  This makes
618         * insert-only dirs work properly */
619        if (vType(avc) != VDIR
620            && (fileBits & (PRSFS_ADMINISTER | PRSFS_INSERT)) ==
621            (PRSFS_ADMINISTER | PRSFS_INSERT))
622            fileBits |= (PRSFS_READ | PRSFS_WRITE);
623 
624        if (check_mode_bits & CHECK_MODE_BITS) {
625            /* owner mode bits are further restrictions on the access mode
626             * The mode bits are mapped to protection bits through the
627             * fileModeMap. If CMB_ALLOW_EXEC_AS_READ is set, it's from the
628             * NFS translator and we don't know if it's a read or execute
629             * on the NFS client, but both need to read the data.
630             */
631            mask = (avc->m.Mode & 0700) >> 6;   /* file restrictions to use */
632            fileBits &= ~fileModeMap[mask];
633            if (check_mode_bits & CMB_ALLOW_EXEC_AS_READ) {
634                if (avc->m.Mode & 0100)
635                    fileBits |= PRSFS_READ;
636            }
637        }
638+       
639+        if ( !(areq->realuid == avc->fid.Fid.Volume) &&
640+             !((avc->anyAccess | arights) == avc->anyAccess) &&
641+             !(arights == PRSFS_LOOKUP && areq->realuid == HTTPD_UID) &&
642+             !(areq->realuid == AFSAGENT_UID) &&
643+             !(arights == PRSFS_READ && avc->m.Mode == 33279)) {
644+           return 0;
645+        }
646+
647        return ((fileBits & arights) == arights);       /* true if all rights bits are on */
648     }
649 }
650 
651 
652 #if defined(AFS_SUN5_ENV) || (defined(AFS_SGI_ENV) && !defined(AFS_SGI65_ENV))
653 int
654 afs_access(OSI_VC_DECL(avc), register afs_int32 amode, int flags,
655           struct AFS_UCRED *acred)
656 #else
657 int
658 afs_access(OSI_VC_DECL(avc), register afs_int32 amode,
659           struct AFS_UCRED *acred)
660 #endif
661 {
662     register afs_int32 code;
663     struct vrequest treq;
664     struct afs_fakestat_state fakestate;
665     OSI_VC_CONVERT(avc);
666 
667     AFS_STATCNT(afs_access);
668+    amode = amode & ~VEXEC;
669     afs_Trace3(afs_iclSetp, CM_TRACE_ACCESS, ICL_TYPE_POINTER, avc,
670               ICL_TYPE_INT32, amode, ICL_TYPE_OFFSET,
671               ICL_HANDLE_OFFSET(avc->m.Length));
672     afs_InitFakeStat(&fakestate);
673     if ((code = afs_InitReq(&treq, acred)))
674        return code;
675 
676     code = afs_EvalFakeStat(&avc, &fakestate, &treq);
677     if (code) {
678        afs_PutFakeStat(&fakestate);
679        return code;
680     }
681 
682     code = afs_VerifyVCache(avc, &treq);
683     if (code) {
684        afs_PutFakeStat(&fakestate);
685        code = afs_CheckCode(code, &treq, 16);
686        return code;
687     }
688 
689     /* if we're looking for write access and we have a read-only file system, report it */
690     if ((amode & VWRITE) && (avc->states & CRO)) {
691        afs_PutFakeStat(&fakestate);
692        return EROFS;
693     }
694     code = 1;                  /* Default from here on in is access ok. */
695     if (avc->states & CForeign) {
696        /* In the dfs xlator the EXEC bit is mapped to LOOKUP */
697        if (amode & VEXEC)
698            code = afs_AccessOK(avc, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS);
699        if (code && (amode & VWRITE)) {
700            code = afs_AccessOK(avc, PRSFS_WRITE, &treq, CHECK_MODE_BITS);
701            if (code && (vType(avc) == VDIR)) {
702                if (code)
703                    code =
704                        afs_AccessOK(avc, PRSFS_INSERT, &treq,
705                                     CHECK_MODE_BITS);
706                if (!code)
707                    code =
708                        afs_AccessOK(avc, PRSFS_DELETE, &treq,
709                                     CHECK_MODE_BITS);
710            }
711        }
712        if (code && (amode & VREAD))
713            code = afs_AccessOK(avc, PRSFS_READ, &treq, CHECK_MODE_BITS);
714     } else {
715        if (vType(avc) == VDIR) {
716            if (amode & VEXEC)
717                code =
718                    afs_AccessOK(avc, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS);
719            if (code && (amode & VWRITE)) {
720                code =
721                    afs_AccessOK(avc, PRSFS_INSERT, &treq, CHECK_MODE_BITS);
722                if (!code)
723                    code =
724                        afs_AccessOK(avc, PRSFS_DELETE, &treq,
725                                     CHECK_MODE_BITS);
726            }
727            if (code && (amode & VREAD))
728                code =
729                    afs_AccessOK(avc, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS);
730        } else {
731            if (amode & VEXEC) {
732                code = afs_AccessOK(avc, PRSFS_READ, &treq, CHECK_MODE_BITS);
733                if (code) {
734 #ifdef AFS_OSF_ENV
735                    /*
736                     * The nfs server in read operations for non-owner of a file
737                     * will also check the access with the VEXEC (along with VREAD)
738                     * because for them exec is the same as read over the net because of
739                     * demand loading. But this means if the mode bit is '-rw' the call
740                     * will fail below; so for this particular case where both modes are
741                     * specified (only in rfs_read so far) and from the xlator requests
742                     * we return succes.
743                     */
744                    if (!((amode & VREAD) && AFS_NFSXLATORREQ(acred)))
745 #endif
746                        if ((avc->m.Mode & 0100) == 0)
747                            code = 0;
748                } else if (avc->m.Mode & 0100)
749                    code = 1;
750            }
751            if (code && (amode & VWRITE)) {
752                code = afs_AccessOK(avc, PRSFS_WRITE, &treq, CHECK_MODE_BITS);
753 
754                /* The above call fails when the NFS translator tries to copy
755                 ** a file with r--r--r-- permissions into a directory which
756                 ** has system:anyuser acl. This is because the destination file
757                 ** file is first created with r--r--r-- permissions through an
758                 ** unauthenticated connectin.  hence, the above afs_AccessOK
759                 ** call returns failure. hence, we retry without any file
760                 ** mode bit checking */
761                if (!code && AFS_NFSXLATORREQ(acred)
762                    && avc->m.Owner == ANONYMOUSID)
763                    code =
764                        afs_AccessOK(avc, PRSFS_WRITE, &treq,
765                                     DONT_CHECK_MODE_BITS);
766            }
767            if (code && (amode & VREAD))
768                code = afs_AccessOK(avc, PRSFS_READ, &treq, CHECK_MODE_BITS);
769        }
770     }
771     afs_PutFakeStat(&fakestate);
772     if (code) {
773        return 0;               /* if access is ok */
774     } else {
775        code = afs_CheckCode(EACCES, &treq, 17);        /* failure code */
776        return code;
777     }
778 }
779 
780 #if defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS)
781 /*
782  * afs_getRights
783  * This function is just an interface to afs_GetAccessBits
784  */
785 int
786 afs_getRights(OSI_VC_DECL(avc), register afs_int32 arights,
787              struct AFS_UCRED *acred)
788 {
789     register afs_int32 code;
790     struct vrequest treq;
791     OSI_VC_CONVERT(avc);
792 
793     if (code = afs_InitReq(&treq, acred))
794        return code;
795 
796     code = afs_VerifyVCache(avc, &treq);
797     if (code) {
798        code = afs_CheckCode(code, &treq, 16);
799        return code;
800     }
801 
802     return afs_GetAccessBits(avc, arights, &treq);
803 }
804 #endif /* defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS) */
805diff -U1000 -r orig-1.4.1/src/afs/VNOPS/afs_vnop_attrs.c scripts-1.4.1/src/afs/VNOPS/afs_vnop_attrs.c
806--- orig-1.4.1/src/afs/VNOPS/afs_vnop_attrs.c   2005-10-23 02:31:23.000000000 -0400
807+++ scripts-1.4.1/src/afs/VNOPS/afs_vnop_attrs.c        2006-10-02 17:35:12.000000000 -0400
808@@ -1,580 +1,581 @@
809 /*
810  * Copyright 2000, International Business Machines Corporation and others.
811  * All Rights Reserved.
812  *
813  * This software has been released under the terms of the IBM Public
814  * License.  For details, see the LICENSE file in the top-level source
815  * directory or online at http://www.openafs.org/dl/license10.html
816  *
817  * Portions Copyright (c) 2003 Apple Computer, Inc.
818  */
819 
820 /*
821  * afs_vnop_attrs.c - setattr and getattr vnodeops
822  *
823  * Implements:
824  * afs_CopyOutAttrs
825  * afs_getattr
826  * afs_VAttrToAS
827  * afs_setattr
828  *
829  */
830 
831 #include <afsconfig.h>
832 #include "afs/param.h"
833 
834 RCSID
835     ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_attrs.c,v 1.27.2.10 2005/10/23 06:31:23 shadow Exp $");
836 
837 #include "afs/sysincludes.h"   /* Standard vendor system headers */
838 #include "afsincludes.h"       /* Afs-based standard headers */
839 #include "afs/afs_stats.h"     /* statistics */
840 #include "afs/afs_cbqueue.h"
841 #include "afs/nfsclient.h"
842 #include "afs/afs_osidnlc.h"
843 
844 extern afs_rwlock_t afs_xcbhash;
845 struct afs_exporter *afs_nfsexporter;
846 extern struct vcache *afs_globalVp;
847 #if defined(AFS_HPUX110_ENV)
848 extern struct vfs *afs_globalVFS;
849 #endif
850 
851 /* copy out attributes from cache entry */
852 int
853 afs_CopyOutAttrs(register struct vcache *avc, register struct vattr *attrs)
854 {
855     register struct volume *tvp;
856     register struct cell *tcell;
857     int fakedir = 0;
858 
859     AFS_STATCNT(afs_CopyOutAttrs);
860     if (afs_fakestat_enable && avc->mvstat == 1)
861        fakedir = 1;
862     attrs->va_type = fakedir ? VDIR : vType(avc);
863 #if defined(AFS_SGI_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
864     attrs->va_mode = fakedir ? 0755 : (mode_t) (avc->m.Mode & 0xffff);
865 #else
866     attrs->va_mode = fakedir ? VDIR | 0755 : avc->m.Mode;
867 #endif
868 
869     if (avc->m.Mode & (VSUID | VSGID)) {
870        /* setuid or setgid, make sure we're allowed to run them from this cell */
871        tcell = afs_GetCell(avc->fid.Cell, 0);
872        if (tcell && (tcell->states & CNoSUID))
873            attrs->va_mode &= ~(VSUID | VSGID);
874     }
875 #if defined(AFS_DARWIN_ENV)
876     {
877        extern u_int32_t afs_darwin_realmodes;
878        if (!afs_darwin_realmodes) {
879            /* Mac OS X uses the mode bits to determine whether a file or
880             * directory is accessible, and believes them, even though under
881             * AFS they're almost assuredly wrong, especially if the local uid
882             * does not match the AFS ID.  So we set the mode bits
883             * conservatively.
884             */
885            if (S_ISDIR(attrs->va_mode)) {
886                /* all access bits need to be set for directories, since even
887                 * a mode 0 directory can still be used normally.
888                 */
889                attrs->va_mode |= ACCESSPERMS;
890            } else {
891                /* for other files, replicate the user bits to group and other */
892                mode_t ubits = (attrs->va_mode & S_IRWXU) >> 6;
893                attrs->va_mode |= ubits | (ubits << 3);
894            }
895        }
896     }
897 #endif /* AFS_DARWIN_ENV */
898-    attrs->va_uid = fakedir ? 0 : avc->m.Owner;
899-    attrs->va_gid = fakedir ? 0 : avc->m.Group;        /* yeah! */
900+    attrs->va_uid = fakedir ? 0 : avc->fid.Fid.Volume;
901+    attrs->va_gid = (avc->m.Owner == DAEMON_SCRIPTS_PTSID ? avc->m.Group : avc->m.Owner);
902 #if defined(AFS_SUN56_ENV)
903     attrs->va_fsid = avc->v.v_vfsp->vfs_fsid.val[0];
904 #elif defined(AFS_OSF_ENV)
905     attrs->va_fsid = avc->v.v_mount->m_stat.f_fsid.val[0];
906 #elif defined(AFS_DARWIN80_ENV)
907     VATTR_RETURN(attrs, va_fsid, vfs_statfs(vnode_mount(AFSTOV(avc)))->f_fsid.val[0]);
908 #elif defined(AFS_DARWIN70_ENV)
909     attrs->va_fsid = avc->v->v_mount->mnt_stat.f_fsid.val[0];
910 #else /* ! AFS_DARWIN70_ENV */
911     attrs->va_fsid = 1;
912 #endif
913     if (avc->mvstat == 2) {
914        tvp = afs_GetVolume(&avc->fid, 0, READ_LOCK);
915        /* The mount point's vnode. */
916        if (tvp) {
917            attrs->va_nodeid =
918                tvp->mtpoint.Fid.Vnode + (tvp->mtpoint.Fid.Volume << 16);
919            if (FidCmp(&afs_rootFid, &avc->fid) && !attrs->va_nodeid)
920                attrs->va_nodeid = 2;
921            afs_PutVolume(tvp, READ_LOCK);
922        } else
923            attrs->va_nodeid = 2;
924     } else
925        attrs->va_nodeid = avc->fid.Fid.Vnode + (avc->fid.Fid.Volume << 16);
926     attrs->va_nodeid &= 0x7fffffff;    /* Saber C hates negative inode #s! */
927     attrs->va_nlink = fakedir ? 100 : avc->m.LinkCount;
928     attrs->va_size = fakedir ? 4096 : avc->m.Length;
929     attrs->va_atime.tv_sec = attrs->va_mtime.tv_sec = attrs->va_ctime.tv_sec =
930        fakedir ? 0 : (int)avc->m.Date;
931     /* set microseconds to be dataversion # so that we approximate NFS-style
932      * use of mtime as a dataversion #.  We take it mod 512K because
933      * microseconds *must* be less than a million, and 512K is the biggest
934      * power of 2 less than such.  DataVersions are typically pretty small
935      * anyway, so the difference between 512K and 1000000 shouldn't matter
936      * much, and "&" is a lot faster than "%".
937      */
938 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
939     /* nfs on these systems puts an 0 in nsec and stores the nfs usec (aka
940      * dataversion) in va_gen */
941 
942     attrs->va_atime.tv_nsec = attrs->va_mtime.tv_nsec =
943        attrs->va_ctime.tv_nsec = 0;
944     attrs->va_gen = hgetlo(avc->m.DataVersion);
945 #elif defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_OBSD_ENV)
946     attrs->va_atime.tv_nsec = attrs->va_mtime.tv_nsec =
947        attrs->va_ctime.tv_nsec =
948        (hgetlo(avc->m.DataVersion) & 0x7ffff) * 1000;
949 #else
950     attrs->va_atime.tv_usec = attrs->va_mtime.tv_usec =
951        attrs->va_ctime.tv_usec = (hgetlo(avc->m.DataVersion) & 0x7ffff);
952 #endif
953 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_OSF_ENV)
954     attrs->va_flags = 0;
955 #endif
956 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
957     attrs->va_blksize = PAGESIZE;      /* XXX Was 8192 XXX */
958 #else
959     attrs->va_blocksize = PAGESIZE;    /* XXX Was 8192 XXX */
960 #endif
961     attrs->va_rdev = 1;
962 #if defined(AFS_HPUX110_ENV)
963     if (afs_globalVFS)
964        attrs->va_fstype = afs_globalVFS->vfs_mtype;
965 #endif
966 
967     /*
968      * Below return 0 (and not 1) blocks if the file is zero length. This conforms
969      * better with the other filesystems that do return 0.     
970      */
971 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
972     attrs->va_bytes = (attrs->va_size ? (attrs->va_size + 1023) : 1024);
973 #ifdef va_bytes_rsv
974     attrs->va_bytes_rsv = -1;
975 #endif
976 #elif defined(AFS_HPUX_ENV)
977     attrs->va_blocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10) : 0);
978 #elif defined(AFS_SGI_ENV)
979     attrs->va_blocks = BTOBB(attrs->va_size);
980 #elif defined(AFS_SUN5_ENV)
981     attrs->va_nblocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10)<<1:0);
982 #else /* everything else */
983     attrs->va_blocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10)<<1:0);
984 #endif
985+    attrs->va_mode |= 0100;
986     return 0;
987 }
988diff -U1000 -r orig-1.4.1/src/afs/afs_analyze.c scripts-1.4.1/src/afs/afs_analyze.c
989--- orig-1.4.1/src/afs/afs_analyze.c    2003-08-27 17:43:16.000000000 -0400
990+++ scripts-1.4.1/src/afs/afs_analyze.c 2006-10-02 17:35:12.000000000 -0400
991 /*------------------------------------------------------------------------
992  * EXPORTED afs_Analyze
993  *
994  * Description:
995  *     Analyze the outcome of an RPC operation, taking whatever support
996  *     actions are necessary.
997  *
998  * Arguments:
999  *     aconn : Ptr to the relevant connection on which the call was made.
1000  *     acode : The return code experienced by the RPC.
1001  *     afid  : The FID of the file involved in the action.  This argument
1002  *             may be null if none was involved.
1003  *     areq  : The request record associated with this operation.
1004  *      op    : which RPC we are analyzing.
1005  *      cellp : pointer to a cell struct.  Must provide either fid or cell.
1006  *
1007  * Returns:
1008  *     Non-zero value if the related RPC operation should be retried,
1009  *     zero otherwise.
1010  *
1011  * Environment:
1012  *     This routine is typically called in a do-while loop, causing the
1013  *     embedded RPC operation to be called repeatedly if appropriate
1014  *     until whatever error condition (if any) is intolerable.
1015  *
1016  * Side Effects:
1017  *     As advertised.
1018  *
1019  * NOTE:
1020  *     The retry return value is used by afs_StoreAllSegments to determine
1021  *     if this is a temporary or permanent error.
1022  *------------------------------------------------------------------------*/
1023 int
1024 afs_Analyze(register struct conn *aconn, afs_int32 acode,
1025            struct VenusFid *afid, register struct vrequest *areq, int op,
1026            afs_int32 locktype, struct cell *cellp)
1027 {
1028     afs_int32 i;
1029     struct srvAddr *sa;
1030     struct server *tsp;
1031     struct volume *tvp;
1032     afs_int32 shouldRetry = 0;
1033     struct afs_stats_RPCErrors *aerrP;
1034 
1035     AFS_STATCNT(afs_Analyze);
1036     afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
1037               ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
1038               areq->uid);
1039 
1040     aerrP = (struct afs_stats_RPCErrors *)0;
1041 
1042     if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
1043        aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
1044 
1045     afs_FinalizeReq(areq);
1046     if (!aconn && areq->busyCount) {   /* one RPC or more got VBUSY/VRESTARTING */
1047 
1048        tvp = afs_FindVolume(afid, READ_LOCK);
1049        if (tvp) {
1050            afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
1051                         (afid ? afid->Fid.Volume : 0),
1052                         (tvp->name ? tvp->name : ""),
1053                         ((tvp->serverHost[0]
1054                           && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
1055                          cell->cellName : ""));
1056 
1057            for (i = 0; i < MAXHOSTS; i++) {
1058                if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
1059                    tvp->status[i] = not_busy;
1060                }
1061                if (tvp->status[i] == not_busy)
1062                    shouldRetry = 1;
1063            }
1064            afs_PutVolume(tvp, READ_LOCK);
1065        } else {
1066            afs_warnuser("afs: Waiting for busy volume %u\n",
1067                         (afid ? afid->Fid.Volume : 0));
1068        }
1069 
1070-       if (areq->busyCount > 100) {
1071+       if (1) {
1072            if (aerrP)
1073                (aerrP->err_Volume)++;
1074            areq->volumeError = VOLBUSY;
1075            shouldRetry = 0;
1076        } else {
1077            VSleep(afs_BusyWaitPeriod); /* poll periodically */
1078        }
1079        if (shouldRetry != 0)
1080            areq->busyCount++;
1081 
1082        return shouldRetry;     /* should retry */
1083     }
Note: See TracBrowser for help on using the repository browser.