From 4c1571bfce4532687ca3ea245a7423e3dee2c66e Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Tue, 12 Mar 2019 20:22:29 +0100 Subject: [PATCH] subu-mk-0 and subu-rm-0 working --- src/2_bin/subudb | Bin 0 -> 12288 bytes src/2_doc/to_do.txt | 10 +++++++ src/subu.lib.c | 68 ++++++++++++++++++++++++-------------------- 3 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 src/2_bin/subudb diff --git a/src/2_bin/subudb b/src/2_bin/subudb new file mode 100644 index 0000000000000000000000000000000000000000..23c3c4490656ab00cd8c2637995be790aa2b31f3 GIT binary patch literal 12288 zcmeI#F-yZh6u|MjM95-^i*ynWO2J}r@e5cbgV0K~8Qel5CkkFGmmGBM>Q{C16L<$k zBG$pJ$p6SC@A4jb;kUiT&Gf0!>S1L~*{CydAfy!MN(mtnzhl4K75QMVJ@}{W#J`1! zI33S>J{zS&k-qvH3jqWWKmY**5I_I{1Q0*~fn622kCOgiAUD0Hte*9(tQ&1zF)P=d zFuuIaCV8gv$;C8Noy4*EtY4N!t312Q$I6uJqIQ)lmd;e#s;ldK)X1bi9Lmkfwb%7 literal 0 HcmV?d00001 diff --git a/src/2_doc/to_do.txt b/src/2_doc/to_do.txt index eebf52a..61e81be 100644 --- a/src/2_doc/to_do.txt +++ b/src/2_doc/to_do.txt @@ -16,4 +16,14 @@ want to add subu-type to masteru_subu(), I imagine there will be static, permanent, and temporary subu types. +2019-03-12T18:35:06Z + the masteru subu relation should contain the uid of the masteru as + well as the backup type for the subu: git, rdiff, rsync, none. + and the persisitance fo the subu: indefinite, session. + seems that operations need to be logged, in case the db is lost + the transcript can be played back. It should also be possible + to co-opt an existing user as a subu, though, would require + sudo privs. + + diff --git a/src/subu.lib.c b/src/subu.lib.c index d456c53..a9bc330 100644 --- a/src/subu.lib.c +++ b/src/subu.lib.c @@ -100,7 +100,7 @@ char *userdel_mess(int err){ #define SUBU_ERR_BUG_SSS 10 #define SUBU_ERR_FAILED_USERADD 11 #define SUBU_ERR_FAILED_USERDEL 12 -#define SUBU_ERR_CONFIG_SUBU_NOT_FOUND 13 +#define SUBU_ERR_SUBU_NOT_FOUND 13 #define SUBU_ERR_N 14 #endif @@ -211,7 +211,7 @@ static int masteru_rmdir_subuhome(void *arg){ static int mk_subu_user(char **mess, sqlite3 *db, char *masteru_name, int n, char **subu_username){ size_t len = 0; FILE* name_stream = open_memstream(subu_username, &len); - fprintf(name_stream, "s%x", n); + fprintf(name_stream, "s%d", n); fclose(name_stream); return 0; } @@ -434,17 +434,14 @@ int subu_rm_0(char **mess, sqlite3 *db, char *subuname){ if(mess)*mess = 0; //-------------------------------------------------------------------------------- - #ifdef DEBUG - dbprintf("Check that subuname is well formed and find its length\n"); - #endif size_t subuname_len; rc = allowed_subuname(mess, subuname, &subuname_len); if(rc) return rc; - - //-------------------------------------------------------------------------------- #ifdef DEBUG - dbprintf("Check that we are running from a user and are setuid root.\n"); + dbprintf("subuname is well formed\n"); #endif + + //-------------------------------------------------------------------------------- uid_t masteru_uid; gid_t masteru_gid; uid_t set_euid; @@ -462,10 +459,6 @@ int subu_rm_0(char **mess, sqlite3 *db, char *subuname){ //-------------------------------------------------------------------------------- // various strings that we will need - #ifdef DEBUG - dbprintf("building strings.\n"); - #endif - char *subu_username = 0; char *masteru_name = 0; char *masteru_home = 0; char *subuland = 0; @@ -478,37 +471,50 @@ int subu_rm_0(char **mess, sqlite3 *db, char *subuname){ mk_subuhome(subuland, subuname, &subuhome) ; if(rc) RETURN(rc); - #ifdef DEBUG - dbprintf("looking up subu_username given masteru_name/subuname\n"); + dbprintf("masteru_home, subuhome: \"%s\", \"%s\"\n", masteru_home, subuhome); #endif - { - int sgret = subudb_Masteru_Subu_get(db, masteru_name, subuname, &subu_username); - if( sgret != SQLITE_DONE ){ - if(mess) *mess = strdup("subu requested for removal not found under this masteru in db file"); - rc = SUBU_ERR_CONFIG_SUBU_NOT_FOUND; - RETURN(rc); - } + + //-------------------------------------------------------------------------------- + // removal from db + + db_begin(db); + + char *subu_username = 0; + rc = subudb_Masteru_Subu_get(db, masteru_name, subuname, &subu_username); + if( rc != SQLITE_OK ){ + if(mess) *mess = strdup("subu requested for removal not found under this masteru in db file"); + rc = SUBU_ERR_SUBU_NOT_FOUND; + db_rollback(); + RETURN(rc); } #ifdef DEBUG - printf("subu_username: %s\n", subu_username); + printf("subu_username: \"%s\"\n", subu_username); #endif - //-------------------------------------------------------------------------------- + rc = subudb_Masteru_Subu_rm(db, masteru_name, subuname, subu_username); + if( rc != SQLITE_OK ){ + if(mess)*mess = strdup("removal of masteru subu relation failed"); + db_rollback(); + RETURN(SUBU_ERR_DB_FILE); + } #ifdef DEBUG - dbprintf("remove the masteru_name, subuname, subu_username relation\n"); + dbprintf("removed the masteru_name, subuname, subu_username relation\n"); #endif - { - int rc = subudb_Masteru_Subu_rm(db, masteru_name, subuname, subu_username); - if( rc != SQLITE_DONE ){ - if(mess)*mess = strdup("removal of masteru subu relation failed"); - RETURN(SUBU_ERR_DB_FILE); - } + + rc = db_commit(db); + if( rc != SQLITE_OK ){ + if(mess)*mess = strdup("removal of masteru subu relation in unknown state, exiting"); + RETURN(SUBU_ERR_DB_FILE); } + + // even after removing the last masteru subu relation, we still do not remove + // the max subu count. Hence, a masteru will keep such for a life time. + //-------------------------------------------------------------------------------- // Only masteru can remove directories from masteru/subuland, so we switch to - // masteru's uid for performing the rmdir. + // masteru's uid to perform the rmdir. // { #ifdef DEBUG -- 2.20.1