@@ -145,15 +145,29 @@ Tcl_DeleteInterp(interp); return(NULL); } - Tcl_HideCommand(interp, "glob", "glob"); - Tcl_HideCommand(interp, "exec", "exec"); - Tcl_HideCommand(interp, "pid", "pid"); Tcl_HideCommand(interp, "auto_load_index", "auto_load_index"); Tcl_HideCommand(interp, "unknown", "unknown"); + + return(interp); +} + +static Tcl_Interp *appfs_TclInterp(void) { + Tcl_Interp *interp; + + interp = pthread_getspecific(interpKey); + if (interp == NULL) { + interp = appfs_create_TclInterp(); + + if (interp == NULL) { + return(NULL); + } + + pthread_setspecific(interpKey, interp); + } return(interp); } static int appfs_Tcl_Eval(Tcl_Interp *interp, int objc, const char *cmd, ...) { @@ -198,19 +212,13 @@ Tcl_Interp *interp; int tcl_ret; APPFS_DEBUG("Enter: hostname = %s", hostname); - interp = pthread_getspecific(interpKey); - if (interp == NULL) { - interp = appfs_create_TclInterp(); - - if (interp == NULL) { - return; - } - - pthread_setspecific(interpKey, interp); + interp = appfs_TclInterp(); + if (interp == NULL) { + return; } tcl_ret = appfs_Tcl_Eval(interp, 2, "::appfs::getindex", hostname); if (tcl_ret != TCL_OK) { APPFS_DEBUG("Call to ::appfs::getindex failed: %s", Tcl_GetStringResult(interp)); @@ -224,19 +232,13 @@ static const char *appfs_getfile(const char *hostname, const char *sha1) { Tcl_Interp *interp; char *retval; int tcl_ret; - interp = pthread_getspecific(interpKey); - if (interp == NULL) { - interp = appfs_create_TclInterp(); - - if (interp == NULL) { - return(NULL); - } - - pthread_setspecific(interpKey, interp); + interp = appfs_TclInterp(); + if (interp == NULL) { + return(NULL); } tcl_ret = appfs_Tcl_Eval(interp, 3, "::appfs::download", hostname, sha1); if (tcl_ret != TCL_OK) { APPFS_DEBUG("Call to ::appfs::download failed: %s", Tcl_GetStringResult(interp)); @@ -251,19 +253,13 @@ static void appfs_update_manifest(const char *hostname, const char *sha1) { Tcl_Interp *interp; int tcl_ret; - interp = pthread_getspecific(interpKey); - if (interp == NULL) { - interp = appfs_create_TclInterp(); - - if (interp == NULL) { - return; - } - - pthread_setspecific(interpKey, interp); + interp = appfs_TclInterp(); + if (interp == NULL) { + return; } tcl_ret = appfs_Tcl_Eval(interp, 3, "::appfs::getpkgmanifest", hostname, sha1); if (tcl_ret != TCL_OK) { APPFS_DEBUG("Call to ::appfs::getpkgmanifest failed: %s", Tcl_GetStringResult(interp)); @@ -277,10 +273,12 @@ static uid_t appfs_get_fsuid(void) { struct fuse_context *ctx; ctx = fuse_get_context(); if (ctx == NULL) { + /* Unable to lookup user for some reason */ + /* Return an unprivileged user ID */ return(1); } return(ctx->uid); } @@ -351,19 +349,10 @@ free(homedir); return(TCL_OK); } -static struct appfs_children *appfs_getchildren(const char *hostname, const char *package_hash, const char *path, int *children_count_p) { -} - -static char *appfs_lookup_package_hash(const char *hostname, const char *package, const char *os, const char *cpuArch, const char *version) { -} - -static int appfs_getfileinfo(const char *hostname, const char *package_hash, const char *_path, struct appfs_pathinfo *pathinfo) { -} - /* Generate an inode for a given path */ static long long appfs_get_path_inode(const char *path) { long long retval; const char *p; @@ -577,11 +566,41 @@ fprintf(stderr, "[error] %s\n", sql_ret); return(1); } - printf("%s\n", sql_ret); + if (sql_ret && sql_ret[0] != '\0') { + printf("%s\n", sql_ret); + } + + return(0); +} + +static int appfs_tcl(const char *tcl) { + Tcl_Interp *interp; + const char *tcl_result; + int tcl_ret; + + interp = appfs_create_TclInterp(); + if (interp == NULL) { + fprintf(stderr, "Unable to create a Tcl interpreter. Aborting.\n"); + + return(1); + } + + tcl_ret = Tcl_Eval(interp, tcl); + tcl_result = Tcl_GetStringResult(interp); + + if (tcl_ret != TCL_OK) { + fprintf(stderr, "[error] %s\n", tcl_result); + + return(1); + } + + if (tcl_result && tcl_result[0] != '\0') { + printf("%s\n", tcl_result); + } return(0); } static int Appfsd_Init(Tcl_Interp *interp) { @@ -626,9 +645,13 @@ } if (argc == 3 && strcmp(argv[1], "-sqlite3") == 0) { return(appfs_sqlite3(argv[2])); } + + if (argc == 3 && strcmp(argv[1], "-tcl") == 0) { + return(appfs_tcl(argv[2])); + } return(fuse_main(argc, argv, &appfs_oper, NULL)); }