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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
		next = obj->_next; \
		ckfree((void *) obj); \
	} \
}

appfs_free_list_type(children, struct appfs_children)

static int appfs_getchildren_cb(void *_head, int columns, char **values, char **names) {
	struct appfs_children **head_p, *obj;

	head_p = _head;

	obj = (void *) ckalloc(sizeof(*obj));

	snprintf(obj->name, sizeof(obj->name), "%s", values[0]);

	if (*head_p == NULL) {
		obj->counter = 0;
	} else {
		obj->counter = (*head_p)->counter + 1;
	}

	obj->_next = *head_p;
	*head_p = obj;

	return(0);
	
}

static uid_t appfs_get_fsuid(void) {
	struct fuse_context *ctx;

	ctx = fuse_get_context();
	if (ctx == NULL) {
		return(1);
	}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







265
266
267
268
269
270
271






















272
273
274
275
276
277
278
		next = obj->_next; \
		ckfree((void *) obj); \
	} \
}

appfs_free_list_type(children, struct appfs_children)























static uid_t appfs_get_fsuid(void) {
	struct fuse_context *ctx;

	ctx = fuse_get_context();
	if (ctx == NULL) {
		return(1);
	}
344
345
346
347
348
349
350
351





































352
353
354
355
356






















357
358
359
360
361
362
363
		return(NULL);
	}

	retval = sqlite3_mprintf("%s", result->pw_dir);

	return(retval);
}






































static struct appfs_children *appfs_getchildren_fs(struct appfs_children *in_children, const char *fspath) {
	APPFS_DEBUG("Searching %s", fspath);

	return(in_children);
}























static struct appfs_children *appfs_getchildren(const char *hostname, const char *package_hash, const char *path, int *children_count_p) {
	struct appfs_children *head = NULL;
	char *sql, *filebuf, *homedir = NULL;
	int sqlite_ret;
	uid_t fsuid;









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
		return(NULL);
	}

	retval = sqlite3_mprintf("%s", result->pw_dir);

	return(retval);
}

static int appfs_getpackage_name_cb(void *_package_name, int columns, char **values, char **names) {
	char **package_name;

	if (columns != 1) {
		return(1);
	}

	package_name = _package_name;

	*package_name = sqlite3_mprintf("%s", values[0]);

	return(0);
}

static char *appfs_getpackage_name(const char *hostname, const char *package_hash) {
	char *sql;
	int sqlite_ret;
	char *package_name = NULL;

	sql = sqlite3_mprintf("SELECT package FROM packages WHERE hostname = %Q AND sha1 = %Q LIMIT 1;", hostname, package_hash);
	if (sql == NULL) {
		APPFS_DEBUG("Call to sqlite3_mprintf failed.");

		return(sqlite3_mprintf("%s", "unknown-package-name"));
	}
	sqlite_ret = sqlite3_exec(globalThread.db, sql, appfs_getpackage_name_cb, &package_name, NULL);
	sqlite3_free(sql);

	if (sqlite_ret != SQLITE_OK) {
		APPFS_DEBUG("Call to sqlite3_exec failed.");

		return(sqlite3_mprintf("%s", "unknown-package-name"));
	}

	return(package_name);
}

static struct appfs_children *appfs_getchildren_fs(struct appfs_children *in_children, const char *fspath) {
	APPFS_DEBUG("Searching %s", fspath);

	return(in_children);
}

static int appfs_getchildren_cb(void *_head, int columns, char **values, char **names) {
	struct appfs_children **head_p, *obj;

	head_p = _head;

	obj = (void *) ckalloc(sizeof(*obj));

	snprintf(obj->name, sizeof(obj->name), "%s", values[0]);

	if (*head_p == NULL) {
		obj->counter = 0;
	} else {
		obj->counter = (*head_p)->counter + 1;
	}

	obj->_next = *head_p;
	*head_p = obj;

	return(0);
	
}

static struct appfs_children *appfs_getchildren(const char *hostname, const char *package_hash, const char *path, int *children_count_p) {
	struct appfs_children *head = NULL;
	char *sql, *filebuf, *homedir = NULL;
	int sqlite_ret;
	uid_t fsuid;

389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420

	if (globalThread.options.writable) {
		/* Determine user of process accessing this file */
		fsuid = appfs_get_fsuid();

		/* Check filesystem paths for updated files */
		/** Check the global directory (/etc) **/
		filebuf = sqlite3_mprintf("/etc/appfs/%s/%s", package_hash, path);
		if (filebuf == NULL) {
			APPFS_DEBUG("Call to sqlite3_mprintf failed.");

			return(NULL);
		}

		head = appfs_getchildren_fs(head, filebuf);

		sqlite3_free(filebuf);

		/** Check the user's directory, if we are not root **/
		if (fsuid != 0) {
			homedir = (char *) appfs_get_homedir(fsuid);
		}

		if (homedir != NULL) {
			filebuf = sqlite3_mprintf("%z/.appfs/%s/%s", homedir, package_hash, path);

			if (filebuf == NULL) {
				APPFS_DEBUG("Call to sqlite3_mprintf failed.");

				return(NULL);
			}








|
















|







426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457

	if (globalThread.options.writable) {
		/* Determine user of process accessing this file */
		fsuid = appfs_get_fsuid();

		/* Check filesystem paths for updated files */
		/** Check the global directory (/etc) **/
		filebuf = sqlite3_mprintf("/etc/appfs/%z@%s/%s", appfs_getpackage_name(hostname, package_hash), hostname, path);
		if (filebuf == NULL) {
			APPFS_DEBUG("Call to sqlite3_mprintf failed.");

			return(NULL);
		}

		head = appfs_getchildren_fs(head, filebuf);

		sqlite3_free(filebuf);

		/** Check the user's directory, if we are not root **/
		if (fsuid != 0) {
			homedir = (char *) appfs_get_homedir(fsuid);
		}

		if (homedir != NULL) {
			filebuf = sqlite3_mprintf("%z/.appfs/%z@%s/%s", homedir, appfs_getpackage_name(hostname, package_hash), hostname, path);

			if (filebuf == NULL) {
				APPFS_DEBUG("Call to sqlite3_mprintf failed.");

				return(NULL);
			}