Check-in [dde1c0a38d]
Overview
Comment:Made home directory part user-servicable via config file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:dde1c0a38da539410c69c892aa6a3e005cc24db7
User & Date: rkeene on 2014-11-10 06:47:31
Other Links: manifest | tags
Context
2014-11-10
07:11
Updated ownership/group and disabled all caching so that things are consistent (and slow!) check-in: 6e3b24c68c user: rkeene tags: trunk
06:47
Made home directory part user-servicable via config file check-in: dde1c0a38d user: rkeene tags: trunk
06:19
Updated to deal with having no home directory gracefully and fixed bug introduced with childcount patch check-in: c0f54be8fb user: rkeene tags: trunk
Changes

Modified appfsd.c from [1dcdd9bb28] to [126129663c].

   460    460   }
   461    461   
   462    462   static int tcl_appfs_simulate_user_fs_leave(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
   463    463   	appfs_simulate_user_fs_leave();
   464    464   
   465    465   	return(TCL_OK);
   466    466   }
          467  +
          468  +static int tcl_appfs_get_fsuid(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
          469  +	uid_t fsuid;
          470  +
          471  +	fsuid = appfs_get_fsuid();
          472  +
          473  +       	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(fsuid));
          474  +
          475  +	return(TCL_OK);
          476  +}
          477  +
          478  +static int tcl_appfs_get_fsgid(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
          479  +	gid_t fsgid;
          480  +
          481  +	fsgid = appfs_get_fsgid();
          482  +
          483  +       	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(fsgid));
          484  +
          485  +	return(TCL_OK);
          486  +}
   467    487   
   468    488   /*
   469    489    * Generate an inode for a given path.  The inode should be computed in such
   470    490    * a way that it is unlikely to be duplicated and remains the same for a given
   471    491    * file
   472    492    */
   473    493   static long long appfs_get_path_inode(const char *path) {
................................................................................
   714    734   	memset(stbuf, 0, sizeof(struct stat));
   715    735   
   716    736   	stbuf->st_mtime = pathinfo.time;
   717    737   	stbuf->st_ctime = pathinfo.time;
   718    738   	stbuf->st_atime = pathinfo.time;
   719    739   	stbuf->st_ino   = pathinfo.inode;
   720    740   	stbuf->st_mode  = 0;
   721         -	stbuf->st_uid   = appfs_get_fsuid();
   722         -	stbuf->st_gid   = appfs_get_fsgid();
          741  +	stbuf->st_uid   = 0;
          742  +	stbuf->st_gid   = 0;
   723    743   
   724    744   	switch (pathinfo.type) {
   725    745   		case APPFS_PATHTYPE_DIRECTORY:
   726    746   			stbuf->st_mode = S_IFDIR | 0555;
   727    747   			stbuf->st_nlink = 2 + pathinfo.typeinfo.dir.childcount;
   728    748   			break;
   729    749   		case APPFS_PATHTYPE_FILE:
................................................................................
  1164   1184   #ifdef USE_TCL_STUBS
  1165   1185   	if (Tcl_InitStubs(interp, TCL_VERSION, 0) == 0L) {
  1166   1186   		return(TCL_ERROR);
  1167   1187   	}
  1168   1188   #endif
  1169   1189   
  1170   1190   	Tcl_CreateObjCommand(interp, "appfsd::get_homedir", tcl_appfs_get_homedir, NULL, NULL);
         1191  +	Tcl_CreateObjCommand(interp, "appfsd::get_fsuid", tcl_appfs_get_fsuid, NULL, NULL);
         1192  +	Tcl_CreateObjCommand(interp, "appfsd::get_fsgid", tcl_appfs_get_fsgid, NULL, NULL);
  1171   1193   	Tcl_CreateObjCommand(interp, "appfsd::simulate_user_fs_enter", tcl_appfs_simulate_user_fs_enter, NULL, NULL);
  1172   1194   	Tcl_CreateObjCommand(interp, "appfsd::simulate_user_fs_leave", tcl_appfs_simulate_user_fs_leave, NULL, NULL);
  1173   1195   
  1174   1196   	Tcl_PkgProvide(interp, "appfsd", "1.0");
  1175   1197   
  1176   1198   	return(TCL_OK);
  1177   1199   }

Modified appfsd.tcl from [9561940a42] to [2a6db15ed4].

     2      2   
     3      3   package require http 2.7
     4      4   package require sqlite3
     5      5   package require sha1
     6      6   package require appfsd
     7      7   package require platform
     8      8   package require pki
            9  +
           10  +# Functions specifically meant for users to replace as a part of configuration
           11  +namespace eval ::appfs::user {
           12  +	# User-replacable function to convert a hostname/hash/method to an URL
           13  +	proc construct_url {hostname hash method} {
           14  +		return "http://$hostname/appfs/$method/$hash"
           15  +	}
           16  +
           17  +	# User-replaceable function get the home directory of the current user
           18  +	proc get_homedir {} {
           19  +		return [::appfsd::get_homedir]
           20  +	}
           21  +}
     9     22   
    10     23   namespace eval ::appfs {
    11     24   	variable cachedir "/tmp/appfs-cache"
    12     25   	variable ttl 3600
    13     26   	variable nttl 60
    14     27   
    15         -	# User-replacable function to convert a hostname/hash/method to an URL
    16         -	proc _construct_url {hostname hash method} {
    17         -		return "http://$hostname/appfs/$method/$hash"
    18         -	}
    19     28   
    20     29   	proc _hash_sep {hash {seps 4}} {
    21     30   		for {set idx 0} {$idx < $seps} {incr idx} {
    22     31   			append retval "[string range $hash [expr {$idx * 2}] [expr {($idx * 2) + 1}]]/"
    23     32   		}
    24     33   		append retval "[string range $hash [expr {$idx * 2}] end]"
    25     34   
................................................................................
   166    175   		# Create indexes
   167    176   		db eval {CREATE INDEX IF NOT EXISTS sites_index ON sites (hostname);}
   168    177   		db eval {CREATE INDEX IF NOT EXISTS packages_index ON packages (hostname, package, version, os, cpuArch);}
   169    178   		db eval {CREATE INDEX IF NOT EXISTS files_index ON files (package_sha1, file_name, file_directory);}
   170    179   	}
   171    180   
   172    181   	proc download {hostname hash {method sha1}} {
   173         -		set url [_construct_url $hostname $hash $method]
          182  +		set url [::appfs::user::construct_url $hostname $hash $method]
   174    183   		set file [_cachefile $url $hash]
   175    184   
   176    185   		if {![file exists $file]} {
   177    186   			return -code error "Unable to fetch (file does not exist: $file)"
   178    187   		}
   179    188   
   180    189   		return $file
................................................................................
   352    361   
   353    362   		return COMPLETE
   354    363   	}
   355    364   
   356    365   	proc _localpath {package hostname file} {
   357    366   		set dir ""
   358    367   		catch {
   359         -			set homedir [::appfsd::get_homedir]
          368  +			set homedir [::appfs::user::get_homedir]
   360    369   			set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"]
   361    370   		}
   362    371   		return $dir
   363    372   	}
   364    373   
   365    374   	proc _whiteoutpath {package hostname file} {
   366    375   		set dir ""
   367    376   		catch {
   368         -			set homedir [::appfsd::get_homedir]
          377  +			set homedir [::appfs::user::get_homedir]
   369    378   			set dir [file join $homedir .appfs "./${package}@${hostname}" ".APPFS.WHITEOUT" "./${file}.APPFS.WHITEOUT"]
   370    379   		}
   371    380   		return $dir
   372    381   	}
   373    382   
   374    383   	proc _parsepath {path} {
   375    384   		set path [string trim $path "/"]