preparations for cred checking in fs
authorMiklos Szeredi <miklos@szeredi.hu>
Thu, 20 Dec 2001 12:17:25 +0000 (12:17 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Thu, 20 Dec 2001 12:17:25 +0000 (12:17 +0000)
include/fuse.h
lib/fuse.c
lib/fuse_i.h
lib/helper.c

index 700569c7e353736fa21378e88db1ae052ed3fd26..bafa1827dbbc269f96dbd8eb2180696734ad601b 100644 (file)
@@ -83,6 +83,12 @@ struct fuse_operations {
     int (*write)    (const char *, const char *, size_t, off_t);
 };
 
+/** Extra context that may be needed by some filesystems */
+struct fuse_context {
+    uid_t uid;
+    gid_t gid;
+};
+
 /* FUSE flags: */
 
 /** Enable debuging output */
@@ -97,20 +103,10 @@ extern "C" {
  *
  * @param fd the control file descriptor
  * @param flags any combination of the FUSE flags defined above, or 0
- * @return the created FUSE handle
- */
-struct fuse *fuse_new(int fd, int flags);
-
-/**
- * Set the filesystem operations. 
- * 
- * Operations which are initialised to NULL will return ENOSYS to the
- * calling process.
- * 
- * @param f the FUSE handle
  * @param op the operations
+ * @return the created FUSE handle
  */
-void fuse_set_operations(struct fuse *f, const struct fuse_operations *op);
+struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op);
 
 /**
  * FUSE event loop.
@@ -146,6 +142,17 @@ void fuse_loop_mt(struct fuse *f);
  */
 void fuse_destroy(struct fuse *f);
 
+/**
+ * Get the current context
+ * 
+ * The context is only valid for the duration of a filesystem
+ * operation, and thus must not be stored and used later.
+ *
+ * @param f the FUSE handle
+ * @return the context 
+ */
+struct fuse_context *fuse_get_context(struct fuse *f);
+
 /* ----------------------------------------------------------- *
  * Miscellaneous helper fuctions                               *
  * ----------------------------------------------------------- */
index 03f814c478139d8565cf1a6d442179f284229f26..0a0b40a521860c513c431610d039d934f70558e2 100644 (file)
@@ -290,7 +290,6 @@ static void rename_node(struct fuse *f, fino_t olddir, const char *oldname,
     pthread_mutex_unlock(&f->lock);
 }
 
-
 static void convert_stat(struct stat *stbuf, struct fuse_attr *attr)
 {
     attr->mode    = stbuf->st_mode;
@@ -442,7 +441,7 @@ static int do_chmod(struct fuse *f, const char *path, struct fuse_attr *attr)
 }        
 
 static int do_chown(struct fuse *f, const char *path, struct fuse_attr *attr,
-             int valid)
+                    int valid)
 {
     int res;
     uid_t uid = (valid & FATTR_UID) ? attr->uid : (uid_t) -1;
@@ -912,7 +911,15 @@ void fuse_loop(struct fuse *f)
     }
 }
 
-struct fuse *fuse_new(int fd, int flags)
+struct fuse_context *fuse_get_context(struct fuse *f)
+{
+    if(f->getcontext)
+        return f->getcontext(f);
+    else
+        return &f->context;
+}
+
+struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op)
 {
     struct fuse *f;
     struct node *root;
@@ -943,6 +950,10 @@ struct fuse *fuse_new(int fd, int flags)
     pthread_mutex_init(&f->lock, NULL);
     f->numworker = 0;
     f->numavail = 0;
+    f->op = *op;
+    f->getcontext = NULL;
+    f->context.uid = 0;
+    f->context.gid = 0;
 
     root = (struct node *) calloc(1, sizeof(struct node));
     root->mode = 0;
@@ -954,11 +965,6 @@ struct fuse *fuse_new(int fd, int flags)
     return f;
 }
 
-void fuse_set_operations(struct fuse *f, const struct fuse_operations *op)
-{
-    f->op = *op;
-}
-
 void fuse_destroy(struct fuse *f)
 {
     size_t i;
index 6e1453e72190a0e7e99134c9e1248af2fb90527b..604c297c999b9ae9a24d5df9175cca3c24ee19ae 100644 (file)
@@ -35,6 +35,8 @@ struct fuse {
     pthread_mutex_t lock;
     int numworker;
     int numavail;
+    struct fuse_context *(*getcontext)(struct fuse *);
+    struct fuse_context context;
 };
 
 struct fuse_dirhandle {
index f4a8a16b9694f7f40daa57dae318969d192386d3..556a1c1f3a19672485543427cd7914ab2572f7e4 100644 (file)
@@ -143,8 +143,7 @@ void fuse_main(int argc, char *argv[], const struct fuse_operations *op)
         exit(1);
     }
 
-    fuse = fuse_new(fd, flags);
-    fuse_set_operations(fuse, op);
+    fuse = fuse_new(fd, flags, op);
 
     if(multithreaded)
         fuse_loop_mt(fuse);