Index: appfsd.c ================================================================== --- appfsd.c +++ appfsd.c @@ -462,10 +462,30 @@ static int tcl_appfs_simulate_user_fs_leave(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { appfs_simulate_user_fs_leave(); return(TCL_OK); } + +static int tcl_appfs_get_fsuid(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { + uid_t fsuid; + + fsuid = appfs_get_fsuid(); + + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(fsuid)); + + return(TCL_OK); +} + +static int tcl_appfs_get_fsgid(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { + gid_t fsgid; + + fsgid = appfs_get_fsgid(); + + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(fsgid)); + + return(TCL_OK); +} /* * Generate an inode for a given path. The inode should be computed in such * a way that it is unlikely to be duplicated and remains the same for a given * file @@ -716,12 +736,12 @@ stbuf->st_mtime = pathinfo.time; stbuf->st_ctime = pathinfo.time; stbuf->st_atime = pathinfo.time; stbuf->st_ino = pathinfo.inode; stbuf->st_mode = 0; - stbuf->st_uid = appfs_get_fsuid(); - stbuf->st_gid = appfs_get_fsgid(); + stbuf->st_uid = 0; + stbuf->st_gid = 0; switch (pathinfo.type) { case APPFS_PATHTYPE_DIRECTORY: stbuf->st_mode = S_IFDIR | 0555; stbuf->st_nlink = 2 + pathinfo.typeinfo.dir.childcount; @@ -1166,10 +1186,12 @@ return(TCL_ERROR); } #endif Tcl_CreateObjCommand(interp, "appfsd::get_homedir", tcl_appfs_get_homedir, NULL, NULL); + Tcl_CreateObjCommand(interp, "appfsd::get_fsuid", tcl_appfs_get_fsuid, NULL, NULL); + Tcl_CreateObjCommand(interp, "appfsd::get_fsgid", tcl_appfs_get_fsgid, NULL, NULL); Tcl_CreateObjCommand(interp, "appfsd::simulate_user_fs_enter", tcl_appfs_simulate_user_fs_enter, NULL, NULL); Tcl_CreateObjCommand(interp, "appfsd::simulate_user_fs_leave", tcl_appfs_simulate_user_fs_leave, NULL, NULL); Tcl_PkgProvide(interp, "appfsd", "1.0"); Index: appfsd.tcl ================================================================== --- appfsd.tcl +++ appfsd.tcl @@ -4,20 +4,29 @@ package require sqlite3 package require sha1 package require appfsd package require platform package require pki + +# Functions specifically meant for users to replace as a part of configuration +namespace eval ::appfs::user { + # User-replacable function to convert a hostname/hash/method to an URL + proc construct_url {hostname hash method} { + return "http://$hostname/appfs/$method/$hash" + } + + # User-replaceable function get the home directory of the current user + proc get_homedir {} { + return [::appfsd::get_homedir] + } +} namespace eval ::appfs { variable cachedir "/tmp/appfs-cache" variable ttl 3600 variable nttl 60 - # User-replacable function to convert a hostname/hash/method to an URL - proc _construct_url {hostname hash method} { - return "http://$hostname/appfs/$method/$hash" - } proc _hash_sep {hash {seps 4}} { for {set idx 0} {$idx < $seps} {incr idx} { append retval "[string range $hash [expr {$idx * 2}] [expr {($idx * 2) + 1}]]/" } @@ -168,11 +177,11 @@ db eval {CREATE INDEX IF NOT EXISTS packages_index ON packages (hostname, package, version, os, cpuArch);} db eval {CREATE INDEX IF NOT EXISTS files_index ON files (package_sha1, file_name, file_directory);} } proc download {hostname hash {method sha1}} { - set url [_construct_url $hostname $hash $method] + set url [::appfs::user::construct_url $hostname $hash $method] set file [_cachefile $url $hash] if {![file exists $file]} { return -code error "Unable to fetch (file does not exist: $file)" } @@ -354,20 +363,20 @@ } proc _localpath {package hostname file} { set dir "" catch { - set homedir [::appfsd::get_homedir] + set homedir [::appfs::user::get_homedir] set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"] } return $dir } proc _whiteoutpath {package hostname file} { set dir "" catch { - set homedir [::appfsd::get_homedir] + set homedir [::appfs::user::get_homedir] set dir [file join $homedir .appfs "./${package}@${hostname}" ".APPFS.WHITEOUT" "./${file}.APPFS.WHITEOUT"] } return $dir }