tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

enum vtype forward reference


C99 section (Tags) Note 3 states that:

  A type specifier of the form

      enum identifier

  without an enumerator list shall only appear after the type it specifies
  is complete.

but the changes to "sys/sys/kauth.h" last year introduced an forward
declaration of "enum vtype;" which goes against that, since enum vtype is
properly defined in <sys/vnode.h>. This causes a problem with pcc, which
is being strict about it, and fixing this is a little problematic..

Initially I thought just including <sys/vnode.h> from "sys/sys/kauth.h"
would be enough, but this introduces an include-file loop, so I am not
sure how best to fix this, there are a few options I can think of

1. remove the "enum vtype" declaration to its own file, and include
   it directly to avoid the loop. this is too invasive, I think, and it is
   adding cruft to everywhere kauth is used (a lot, in the kernel)

2. replace the kauth_access_action() function which requires this
   forward declaration with a macro which doesn't require any such
   declaration, since it is only then used in files which include the
   <sys/vnode.h> file with the definition.

3. change the kauth_access_action() function to accept a struct vnode *
   instead; and have it find the vtype internally. This looks ok except
   for a couple of usages (nfs and hfs) which are providing the type
   from a vattr -- however, that has just been collected from the vnode
   directly, so perhaps the v_type can be used directly?

any preferences, or other ideas?

I think option 2 is cleanest, patch is attached (though I would also
s/kauth_access_action/KAUTH_ACCESS_ACTION/ throughout, to follow usual
macro naming conventions)

Index: sys/kern/kern_auth.c
RCS file: /cvsroot/src/sys/kern/kern_auth.c,v
retrieving revision 1.71
diff -u -p -r1.71 kern_auth.c
--- sys/kern/kern_auth.c        27 Jun 2012 12:28:28 -0000      1.71
+++ sys/kern/kern_auth.c        23 Sep 2012 11:20:38 -0000
@@ -1079,17 +1079,6 @@ kauth_mode_to_action(mode_t mode)
-kauth_access_action(mode_t access_mode, enum vtype vn_type, mode_t file_mode)
-       kauth_action_t action = kauth_mode_to_action(access_mode);
-       if (FS_OBJECT_CAN_EXEC(vn_type, file_mode))
-               action |= KAUTH_VNODE_IS_EXEC;
-       return action;
 kauth_extattr_action(mode_t access_mode)
        kauth_action_t action = 0;
Index: sys/sys/kauth.h
RCS file: /cvsroot/src/sys/sys/kauth.h,v
retrieving revision 1.70
diff -u -p -r1.70 kauth.h
--- sys/sys/kauth.h     27 Jun 2012 12:28:28 -0000      1.70
+++ sys/sys/kauth.h     23 Sep 2012 11:20:43 -0000
@@ -45,7 +45,6 @@ struct proc;
 struct tty;
 struct vnode;
 struct cwdinfo;
-enum vtype;
 /* Types. */
 typedef struct kauth_scope     *kauth_scope_t;
@@ -483,9 +482,12 @@ void kauth_cred_toucred(kauth_cred_t, st
 void kauth_cred_topcred(kauth_cred_t, struct ki_pcred *);
 kauth_action_t kauth_mode_to_action(mode_t);
-kauth_action_t kauth_access_action(mode_t, enum vtype, mode_t);
 kauth_action_t kauth_extattr_action(mode_t);
+#define kauth_access_action(access_mode, vn_vtype, file_mode)  \
+       (kauth_mode_to_action(access_mode) |                    \
+       (FS_OBJECT_CAN_EXEC(vn_vtype, file_mode) ? KAUTH_VNODE_IS_EXEC : 0))
 kauth_cred_t kauth_cred_get(void);
 void kauth_proc_fork(struct proc *, struct proc *);

Home | Main Index | Thread Index | Old Index