Overview
Comment: | Added start of writability |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
5c1bbda2c6d3e179b5c159056e9caa2e |
User & Date: | rkeene on 2014-10-12 02:54:43 |
Other Links: | manifest | tags |
Context
2014-10-28
| ||
19:08 | Updated to allow individual flags to be replaced check-in: ca67f3d740 user: rkeene tags: trunk | |
2014-10-12
| ||
02:54 | Added start of writability check-in: 5c1bbda2c6 user: rkeene tags: trunk | |
2014-09-18
| ||
17:49 | Added SQLite indexes to tables for faster lookup check-in: 222e571ce8 user: rkeene tags: trunk | |
Changes
Modified Makefile from [be705a2fe3] to [a8370ad444].
1 2 | CC = gcc PKG_CONFIG = pkg-config | | | 1 2 3 4 5 6 7 8 9 10 | CC = gcc PKG_CONFIG = pkg-config CFLAGS = -Wall $(shell $(PKG_CONFIG) --cflags fuse) $(shell $(PKG_CONFIG) --cflags sqlite3) $(TCL_CFLAGS) -DDEBUG=1 LDFLAGS = $(TCL_LDFLAGS) LIBS = $(shell $(PKG_CONFIG) --libs fuse) $(shell $(PKG_CONFIG) --libs sqlite3) $(TCL_LIBS) PREFIX = /usr/local prefix = $(PREFIX) bindir = $(prefix)/bin sbindir = $(prefix)/sbin |
︙ | ︙ |
Modified appfsd.c from [4990aac269] to [5ba05dc7d6].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #define FUSE_USE_VERSION 26 #include <sys/types.h> #include <sqlite3.h> #include <pthread.h> #include <string.h> #include <stdarg.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <fuse.h> #include <tcl.h> #ifndef APPFS_CACHEDIR #define APPFS_CACHEDIR "/var/cache/appfs" #endif #ifdef DEBUG #define APPFS_DEBUG(x...) { fprintf(stderr, "[debug] %s:%i:%s: ", __FILE__, __LINE__, __func__); fprintf(stderr, x); fprintf(stderr, "\n"); } #else #define APPFS_DEBUG(x...) /**/ #endif static pthread_key_t interpKey; struct appfs_thread_data { sqlite3 *db; const char *cachedir; time_t boottime; const char *platform; }; struct appfs_thread_data globalThread; typedef enum { APPFS_PATHTYPE_INVALID, APPFS_PATHTYPE_FILE, | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #define FUSE_USE_VERSION 26 #include <sys/types.h> #include <sqlite3.h> #include <pthread.h> #include <string.h> #include <stdarg.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <fuse.h> #include <pwd.h> #include <tcl.h> #ifndef APPFS_CACHEDIR #define APPFS_CACHEDIR "/var/cache/appfs" #endif #ifdef DEBUG #define APPFS_DEBUG(x...) { fprintf(stderr, "[debug] %s:%i:%s: ", __FILE__, __LINE__, __func__); fprintf(stderr, x); fprintf(stderr, "\n"); } #else #define APPFS_DEBUG(x...) /**/ #endif static pthread_key_t interpKey; struct appfs_thread_data { sqlite3 *db; const char *cachedir; time_t boottime; const char *platform; struct { int writable; } options; }; struct appfs_thread_data globalThread; typedef enum { APPFS_PATHTYPE_INVALID, APPFS_PATHTYPE_FILE, |
︙ | ︙ | |||
249 250 251 252 253 254 255 256 257 258 | 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; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | 253 254 255 256 257 258 259 260 261 262 263 264 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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | 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); } return(ctx->uid); } static const char *appfs_get_homedir(uid_t fsuid) { struct passwd entry, *result; struct stat stbuf; char buf[1024], *retval; int gpu_ret, stat_ret; gpu_ret = getpwuid_r(fsuid, &entry, buf, sizeof(buf), &result); if (gpu_ret != 0) { APPFS_DEBUG("getpwuid_r(%llu, ...) returned in failure", (unsigned long long) fsuid); return(NULL); } if (result == NULL) { APPFS_DEBUG("getpwuid_r(%llu, ...) returned NULL result", (unsigned long long) fsuid); return(NULL); } if (result->pw_dir == NULL) { APPFS_DEBUG("getpwuid_r(%llu, ...) returned NULL home directory", (unsigned long long) fsuid); return(NULL); } stat_ret = stat(result->pw_dir, &stbuf); if (stat_ret != 0) { APPFS_DEBUG("stat(%s) returned in failure", result->pw_dir); return(NULL); } if (stbuf.st_uid != fsuid) { APPFS_DEBUG("UID mis-match on user %llu's home directory (%s). It's owned by %llu.", (unsigned long long) fsuid, result->pw_dir, (unsigned long long) stbuf.st_uid ); 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; if (children_count_p == NULL) { return(NULL); } appfs_update_index(hostname); appfs_update_manifest(hostname, package_hash); |
︙ | ︙ | |||
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | if (sqlite_ret != SQLITE_OK) { APPFS_DEBUG("Call to sqlite3_exec failed."); appfs_free_list_children(head); return(NULL); } if (head != NULL) { *children_count_p = head->counter + 1; } return(head); } static int appfs_sqlite3_query_cb(void *_cb_handle, int columns, char **values, char **names) { struct appfs_sqlite3_query_cb_handle *cb_handle; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 401 402 403 404 | if (sqlite_ret != SQLITE_OK) { APPFS_DEBUG("Call to sqlite3_exec failed."); appfs_free_list_children(head); return(NULL); } 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); } head = appfs_getchildren_fs(head, filebuf); sqlite3_free(filebuf); } } if (head != NULL) { *children_count_p = head->counter + 1; } else { *children_count_p = 0; } return(head); } static int appfs_sqlite3_query_cb(void *_cb_handle, int columns, char **values, char **names) { struct appfs_sqlite3_query_cb_handle *cb_handle; |
︙ | ︙ | |||
825 826 827 828 829 830 831 832 833 834 835 836 837 838 | memset(stbuf, 0, sizeof(struct stat)); stbuf->st_mtime = pathinfo.time; stbuf->st_ctime = pathinfo.time; stbuf->st_atime = pathinfo.time; stbuf->st_ino = pathinfo.inode; switch (pathinfo.type) { case APPFS_PATHTYPE_DIRECTORY: stbuf->st_mode = S_IFDIR | 0555; stbuf->st_nlink = 2 + pathinfo.typeinfo.dir.childcount; break; case APPFS_PATHTYPE_FILE: | > | 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 | memset(stbuf, 0, sizeof(struct stat)); stbuf->st_mtime = pathinfo.time; stbuf->st_ctime = pathinfo.time; stbuf->st_atime = pathinfo.time; stbuf->st_ino = pathinfo.inode; stbuf->st_mode = 0; switch (pathinfo.type) { case APPFS_PATHTYPE_DIRECTORY: stbuf->st_mode = S_IFDIR | 0555; stbuf->st_nlink = 2 + pathinfo.typeinfo.dir.childcount; break; case APPFS_PATHTYPE_FILE: |
︙ | ︙ | |||
851 852 853 854 855 856 857 858 859 860 861 862 863 864 | stbuf->st_size = pathinfo.typeinfo.symlink.size; break; case APPFS_PATHTYPE_INVALID: res = -EIO; break; } return res; } static int appfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { struct appfs_pathinfo pathinfo; struct appfs_children *children, *child; | > > > > | 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | stbuf->st_size = pathinfo.typeinfo.symlink.size; break; case APPFS_PATHTYPE_INVALID: res = -EIO; break; } if (globalThread.options.writable) { stbuf->st_mode |= 0222; } return res; } static int appfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { struct appfs_pathinfo pathinfo; struct appfs_children *children, *child; |
︙ | ︙ | |||
960 961 962 963 964 965 966 967 968 969 970 971 972 973 | const char *cachedir = APPFS_CACHEDIR; char dbfilename[1024]; int pthread_ret, snprintf_ret, sqlite_ret; globalThread.cachedir = cachedir; globalThread.boottime = time(NULL); globalThread.platform = "linux-x86_64"; pthread_ret = pthread_key_create(&interpKey, NULL); if (pthread_ret != 0) { fprintf(stderr, "Unable to create TSD key for Tcl. Aborting.\n"); return(1); } | > | 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 | const char *cachedir = APPFS_CACHEDIR; char dbfilename[1024]; int pthread_ret, snprintf_ret, sqlite_ret; globalThread.cachedir = cachedir; globalThread.boottime = time(NULL); globalThread.platform = "linux-x86_64"; globalThread.options.writable = 1; pthread_ret = pthread_key_create(&interpKey, NULL); if (pthread_ret != 0) { fprintf(stderr, "Unable to create TSD key for Tcl. Aborting.\n"); return(1); } |
︙ | ︙ |