Check-in [98449bcf3e]
Overview
Comment:Updated to use package name instead of hash for looking up extra files
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:98449bcf3ecf50f7d99e9ee341a07da1413f75b9
User & Date: rkeene on 2014-11-06 03:05:47
Other Links: manifest | tags
Context
2014-11-10
05:57
Moved to tcl-ops branch check-in: 0effed3239 user: rkeene tags: trunk
2014-11-06
16:19
Create new branch named "tcl-ops" check-in: a80b5fa283 user: rkeene tags: tcl-ops
03:05
Updated to use package name instead of hash for looking up extra files check-in: 98449bcf3e user: rkeene tags: trunk
02:49
Updated to indicate only that packaged files are writable check-in: 97e72202db user: rkeene tags: trunk
Changes

Modified appfsd.c from [430cff4a7a] to [251c8531b4].

   265    265   		next = obj->_next; \
   266    266   		ckfree((void *) obj); \
   267    267   	} \
   268    268   }
   269    269   
   270    270   appfs_free_list_type(children, struct appfs_children)
   271    271   
   272         -static int appfs_getchildren_cb(void *_head, int columns, char **values, char **names) {
   273         -	struct appfs_children **head_p, *obj;
   274         -
   275         -	head_p = _head;
   276         -
   277         -	obj = (void *) ckalloc(sizeof(*obj));
   278         -
   279         -	snprintf(obj->name, sizeof(obj->name), "%s", values[0]);
   280         -
   281         -	if (*head_p == NULL) {
   282         -		obj->counter = 0;
   283         -	} else {
   284         -		obj->counter = (*head_p)->counter + 1;
   285         -	}
   286         -
   287         -	obj->_next = *head_p;
   288         -	*head_p = obj;
   289         -
   290         -	return(0);
   291         -	
   292         -}
   293         -
   294    272   static uid_t appfs_get_fsuid(void) {
   295    273   	struct fuse_context *ctx;
   296    274   
   297    275   	ctx = fuse_get_context();
   298    276   	if (ctx == NULL) {
   299    277   		return(1);
   300    278   	}
................................................................................
   344    322   		return(NULL);
   345    323   	}
   346    324   
   347    325   	retval = sqlite3_mprintf("%s", result->pw_dir);
   348    326   
   349    327   	return(retval);
   350    328   }
          329  +
          330  +static int appfs_getpackage_name_cb(void *_package_name, int columns, char **values, char **names) {
          331  +	char **package_name;
          332  +
          333  +	if (columns != 1) {
          334  +		return(1);
          335  +	}
          336  +
          337  +	package_name = _package_name;
          338  +
          339  +	*package_name = sqlite3_mprintf("%s", values[0]);
          340  +
          341  +	return(0);
          342  +}
          343  +
          344  +static char *appfs_getpackage_name(const char *hostname, const char *package_hash) {
          345  +	char *sql;
          346  +	int sqlite_ret;
          347  +	char *package_name = NULL;
          348  +
          349  +	sql = sqlite3_mprintf("SELECT package FROM packages WHERE hostname = %Q AND sha1 = %Q LIMIT 1;", hostname, package_hash);
          350  +	if (sql == NULL) {
          351  +		APPFS_DEBUG("Call to sqlite3_mprintf failed.");
          352  +
          353  +		return(sqlite3_mprintf("%s", "unknown-package-name"));
          354  +	}
          355  +	sqlite_ret = sqlite3_exec(globalThread.db, sql, appfs_getpackage_name_cb, &package_name, NULL);
          356  +	sqlite3_free(sql);
          357  +
          358  +	if (sqlite_ret != SQLITE_OK) {
          359  +		APPFS_DEBUG("Call to sqlite3_exec failed.");
          360  +
          361  +		return(sqlite3_mprintf("%s", "unknown-package-name"));
          362  +	}
          363  +
          364  +	return(package_name);
          365  +}
   351    366   
   352    367   static struct appfs_children *appfs_getchildren_fs(struct appfs_children *in_children, const char *fspath) {
   353    368   	APPFS_DEBUG("Searching %s", fspath);
   354    369   
   355    370   	return(in_children);
   356    371   }
          372  +
          373  +static int appfs_getchildren_cb(void *_head, int columns, char **values, char **names) {
          374  +	struct appfs_children **head_p, *obj;
          375  +
          376  +	head_p = _head;
          377  +
          378  +	obj = (void *) ckalloc(sizeof(*obj));
          379  +
          380  +	snprintf(obj->name, sizeof(obj->name), "%s", values[0]);
          381  +
          382  +	if (*head_p == NULL) {
          383  +		obj->counter = 0;
          384  +	} else {
          385  +		obj->counter = (*head_p)->counter + 1;
          386  +	}
          387  +
          388  +	obj->_next = *head_p;
          389  +	*head_p = obj;
          390  +
          391  +	return(0);
          392  +	
          393  +}
   357    394   
   358    395   static struct appfs_children *appfs_getchildren(const char *hostname, const char *package_hash, const char *path, int *children_count_p) {
   359    396   	struct appfs_children *head = NULL;
   360    397   	char *sql, *filebuf, *homedir = NULL;
   361    398   	int sqlite_ret;
   362    399   	uid_t fsuid;
   363    400   
................................................................................
   389    426   
   390    427   	if (globalThread.options.writable) {
   391    428   		/* Determine user of process accessing this file */
   392    429   		fsuid = appfs_get_fsuid();
   393    430   
   394    431   		/* Check filesystem paths for updated files */
   395    432   		/** Check the global directory (/etc) **/
   396         -		filebuf = sqlite3_mprintf("/etc/appfs/%s/%s", package_hash, path);
          433  +		filebuf = sqlite3_mprintf("/etc/appfs/%z@%s/%s", appfs_getpackage_name(hostname, package_hash), hostname, path);
   397    434   		if (filebuf == NULL) {
   398    435   			APPFS_DEBUG("Call to sqlite3_mprintf failed.");
   399    436   
   400    437   			return(NULL);
   401    438   		}
   402    439   
   403    440   		head = appfs_getchildren_fs(head, filebuf);
................................................................................
   406    443   
   407    444   		/** Check the user's directory, if we are not root **/
   408    445   		if (fsuid != 0) {
   409    446   			homedir = (char *) appfs_get_homedir(fsuid);
   410    447   		}
   411    448   
   412    449   		if (homedir != NULL) {
   413         -			filebuf = sqlite3_mprintf("%z/.appfs/%s/%s", homedir, package_hash, path);
          450  +			filebuf = sqlite3_mprintf("%z/.appfs/%z@%s/%s", homedir, appfs_getpackage_name(hostname, package_hash), hostname, path);
   414    451   
   415    452   			if (filebuf == NULL) {
   416    453   				APPFS_DEBUG("Call to sqlite3_mprintf failed.");
   417    454   
   418    455   				return(NULL);
   419    456   			}
   420    457