}
-static int
-switch_to_real_user(void)
-{
- int ret;
- uid_t uid = fuse_get_context()->uid;
- struct group_list gl;
- TDB_DATA data = {NULL,0};
-
- pthread_mutex_lock(&groups_db_mutex);
-
- gl.num_groups = MAX_GROUPS;
-
- /* make sure we have a group mapping database */
- if (groups_db == NULL) {
- DEBUG(DEBUG_INFO,("Initializing group mapping cache database\n"));
- groups_db = tdb_open("groups", 10000, TDB_INTERNAL, O_RDWR|O_CREAT, 0);
- if (groups_db == NULL) {
- DEBUG(DEBUG_ERR,("Failed to initialize group mapping database.\n"));
- }
- }
-
- if (groups_db) {
- TDB_DATA key, newdata;
- struct passwd *pw;
-
- key.dptr = (uint8_t *)&uid;
- key.dsize= sizeof(uid);
-
- tdb_chainlock(groups_db, key);
- data = tdb_fetch(groups_db, key);
-
- /* we already have a record for thus uid, check if it is still
- valid
-5B */
- if (data.dptr != NULL) {
- if (data.dsize != sizeof(gl)) {
- DEBUG(DEBUG_ERR,("Wrong size of gl structure was:%d expected:%d\n", (int)data.dsize, (int)sizeof(gl)));
- free(data.dptr);
- data.dptr = NULL;
- tdb_chainunlock(groups_db, key);
- goto finished_groups;
- }
-
- memcpy(&gl, data.dptr, sizeof(gl));
- free(data.dptr);
- data.dptr = NULL;
-
- if (gl.num_groups >= MAX_GROUPS) {
- gl.num_groups = MAX_GROUPS;
- DEBUG(DEBUG_ERR,("Invalid number of groups in gl structure (%d)\n", gl.num_groups));
- }
-
- if (gl.ts > time(NULL)-36000) {
- tdb_chainunlock(groups_db, key);
- goto finished_groups;
- }
- }
-
- /* we need to re-read the list of groups from the system and
- store it in the cache
- */
- pw = getpwuid(uid);
- if (pw == NULL) {
- tdb_chainunlock(groups_db, key);
- goto finished_groups;
- }
-
- getgrouplist(pw->pw_name, pw->pw_gid, gl.groups, &gl.num_groups);
- gl.ts = time(NULL);
-
- newdata.dptr = (uint8_t *)≷
- newdata.dsize = sizeof(gl);
- if (tdb_store(groups_db, key, newdata, TDB_REPLACE)) {
- DEBUG(DEBUG_ERR,("Failed to write gl structure to cahce tdb\n"));
- tdb_chainunlock(groups_db, key);
- goto finished_groups;
- }
-
- tdb_chainunlock(groups_db, key);
- }
-finished_groups:
-
- ret = setgid(fuse_get_context()->gid);
- if (ret != 0) {
- DEBUG(DEBUG_ERR, (__location__ " failed to setegid\n"));
- ret = -EACCES;
- goto finished;
- }
-
- if (gl.num_groups != MAX_GROUPS) {
- ret = setgroups(gl.num_groups, gl.groups);
- if (ret != 0) {
- DEBUG(DEBUG_ERR, (__location__ " failed to setgroups\n"));
- ret = -EACCES;
- goto finished;
- }
- }
-
- ret = seteuid(uid);
- if (ret != 0) {
- DEBUG(DEBUG_ERR, (__location__ " failed to seteuid\n"));
- ret = -EACCES;
- goto finished;
- }
-
-finished:
- pthread_mutex_unlock(&groups_db_mutex);
- return ret;
-}
-
-static int
-switch_back_to_root(void )
-{
- /* switch back to root */
- seteuid(0);
- setgid(0);
-
- return 0;
-}
-
#define MAX_NAME_LEN 255
struct cached_dir_entry {