diff options
author | Stefan Siegl <stesie@brokenpipe.de> | 2006-08-04 00:39:36 +0000 |
---|---|---|
committer | Stefan Siegl <stesie@brokenpipe.de> | 2006-08-04 00:39:36 +0000 |
commit | ea03092a6c07eaeeb456a1ed845ebf62d81ec314 (patch) | |
tree | 89114a56df4fe9d14f1777eb468bb8bf8608a97d | |
parent | f7f3136a35212fa7a346bf65867639bfbfd5eaec (diff) |
added support for fuse contexts, including fuse_get_context function
-rw-r--r-- | src/fuse_i.h | 8 | ||||
-rw-r--r-- | src/main.c | 16 | ||||
-rw-r--r-- | src/netfs.c | 59 |
3 files changed, 75 insertions, 8 deletions
diff --git a/src/fuse_i.h b/src/fuse_i.h index 81d46d405..85e320b1a 100644 --- a/src/fuse_i.h +++ b/src/fuse_i.h @@ -1,7 +1,7 @@ /********************************************************** * fuse_i.h * - * Copyright (C) 2004, 2005 by Stefan Siegl <ssiegl@gmx.de>, Germany + * Copyright (C) 2004, 2005, 2006 by Stefan Siegl <ssiegl@gmx.de>, Germany * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU General Publice License, @@ -131,6 +131,12 @@ struct _libfuse_params { extern struct _libfuse_params libfuse_params; +/* the private data pointer returned from init() callback */ +extern void *fsys_privdata; + +/* magic number, passed from fuse_mount to fuse_new */ +#define FUSE_MAGIC ((int) 0x66757365) + /***************************************************************************** diff --git a/src/main.c b/src/main.c index ed61db41e..cbb54832f 100644 --- a/src/main.c +++ b/src/main.c @@ -39,9 +39,8 @@ const struct fuse_operations_compat2 *fuse_ops_compat2 = NULL; /* the port where to write out debug messages to, NULL to omit these */ FILE *debug_port = NULL; -/* magic number, passed from fuse_mount to fuse_new */ -#define FUSE_MAGIC ((int) 0x66757365) - +/* the private data pointer returned from init() callback */ +void *fsys_privdata = NULL; /* Interpret a __single__ mount option @@ -322,6 +321,9 @@ fuse_new_compat22(int fd, const char *opts, fuse_ops_compat22 = op; + if(op->init) + fsys_privdata = op->init(); + return (void *) FUSE_MAGIC; /* we don't have a fuse structure, sorry. */ } @@ -529,3 +531,11 @@ fuse_exited(struct fuse *f) */ return 0; } + + +struct fuse_context * +fuse_get_context(void) +{ + struct fuse_context *ctx = cthread_data(cthread_self()); + return ctx; +} diff --git a/src/netfs.c b/src/netfs.c index dfca2e817..083ebe534 100644 --- a/src/netfs.c +++ b/src/netfs.c @@ -1,7 +1,7 @@ /********************************************************** * netfs.c * - * Copyright(C) 2004, 2005 by Stefan Siegl <ssiegl@gmx.de>, Germany + * Copyright(C) 2004,2005,2006 by Stefan Siegl <stesie@brokenpipe.de>, Germany * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU General Publice License, @@ -50,6 +50,48 @@ struct fuse_dirhandle { char *filename; }; + +static inline void +refresh_context_struct(struct iouser *cred) +{ + FUNC_PROLOGUE("refresh_context_struct"); + struct fuse_context *ctx = cthread_data(cthread_self()); + + if(! ctx) + { + ctx = malloc(sizeof(struct fuse_context)); + if(! ctx) + { + perror(PACKAGE_NAME); + return; + } + + cthread_set_data(cthread_self(), ctx); + + ctx->fuse = (void *) FUSE_MAGIC; + ctx->private_data = fsys_privdata; + + /* FIXME, how to figure out the pid of the program asking for the + * filesystem operation? */ + ctx->pid = 0; + } + + if(cred) + { + ctx->uid = cred->uids->num ? cred->uids->ids[0] : + (libfuse_params.force_uid ? libfuse_params.uid : geteuid()); + ctx->gid = cred->gids->num ? cred->gids->ids[0] : + (libfuse_params.force_gid ? libfuse_params.gid : getegid()); + } + else + { + ctx->uid = libfuse_params.force_uid ? libfuse_params.uid : geteuid(); + ctx->gid = libfuse_params.force_gid ? libfuse_params.gid : getegid(); + } + + FUNC_EPILOGUE_NORET(); +} + /* Check whether to allow access to a node, testing the allow_root and * allow_other flag. This does not check whether default permissions * are okay to allow access. @@ -105,7 +147,10 @@ netfs_validate_stat (struct node *node, struct iouser *cred) FUNC_RETURN(EPERM); if(FUSE_OP_HAVE(getattr)) - err = -FUSE_OP_CALL(getattr, node->nn->path, &node->nn_stat); + { + refresh_context_struct(cred); + err = -FUSE_OP_CALL(getattr, node->nn->path, &node->nn_stat); + } if(! err) { @@ -267,7 +312,10 @@ netfs_attempt_statfs (struct iouser *cred, struct node *node, err = EPERM; else if(FUSE_OP_HAVE(statfs)) - err = -FUSE_OP_CALL(statfs, node->nn->path, st); + { + refresh_context_struct(cred); + err = -FUSE_OP_CALL(statfs, node->nn->path, st); + } else err = EOPNOTSUPP; @@ -482,7 +530,10 @@ error_t netfs_attempt_syncfs (struct iouser *cred, int wait) if(test_allow_root_or_other(cred)) err = EPERM; else - err = fuse_sync_filesystem(); + { + refresh_context_struct(cred); + err = fuse_sync_filesystem(); + } FUNC_EPILOGUE(err); } |