From: Thomas Walker Lynch Date: Mon, 25 Feb 2019 15:16:28 +0000 (+0100) Subject: first version subu-number working X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.css?a=commitdiff_plain;h=0530ef9b54282817051d1442e8b166551dcb5ebe;p=subu first version subu-number working --- diff --git a/doc/subu.txt b/doc/subu.txt new file mode 100644 index 0000000..d422784 --- /dev/null +++ b/doc/subu.txt @@ -0,0 +1,68 @@ + +subu is short for subservient user. + +A subu is much like any other user. It has an entry in /etc/passwd, and a home +directory. As for other users this home directory is most likely under /home. +Direct login to the subu might be barred, though that is not necessarly the case. + +Each subu has two names. One is its 'subu_username'. The other is its +'subuname'. The subu_username is autogenerated. When using our tools, one +never needs to know the subu_username. However, the entry in /etc/passwd will be +the generated name, and the home directory will have the generated name. The +command 'subu-username subuname' will print the subu_username. + +Each subu belongs to a master user, known as masteru. A given masteru may have many +subus. The masteru is a different user than any of the subu's that are +subservient to it. + +Each masteru has a top level subdirectory called 'subuland'. In this sub +directory the masteru will find all of its subu home directories. The masteru +will then see all subu owned files in the subuland through the illusion that the +masteru owns them rather than the corresponding subu. Thus the master may move +files around using a regular file navigator. + +Actually the subus will not appear in subuland until masteru runs the command +'subu-mount'. This is normally done when masteru logs in. + +The masteru may create and delete subus at will. The masteru may set default +nice values, renice, or kill subu processes. The masteru may set limits for a +subu. In fact, the masteru is a bit like root relative to its subus. + +There is a control panel that masteru may use. It has a matrix of rectangles, +where in each rectangle, there is information about each subu's processes and +disk usage. + +The masteru may set the subu for each launched process. + +--- +subu-username + +prints the username +returns an error code + +--- +subu-number + +prints a new maximums subu number. +returns an error code + +These numbers are used in synthesizing usernames. Used for testing, should not +appear in any scripts. + +--- +subu-mount + +mounts all of the subus for the given masteru +returns an error code + +--- +subu-mk-0 + +primitve makes a new subu +returns an error code + +--- +subu-rm-0 + +primitive removes a subu +returns an error code diff --git a/src/3_documents/sqlite.txt b/src/3_documents/sqlite.txt new file mode 100644 index 0000000..b7f8cbb --- /dev/null +++ b/src/3_documents/sqlite.txt @@ -0,0 +1,15 @@ + +1. + This sql: + + char *sql = + "BEGIN TRANSACTION;" + "UPDATE Key_Int SET value = value + 1 WHERE key = 'max_subu_number';" + "SELECT value FROM Key_Int WHERE key = 'max_subu_number';" + "COMMIT;" + ; + + with sqlite_exec, the call back is called with the data from the select. + + with sqlite_prepare_v2, sqlite_step just returns SQLITE_DONE, and we never + get to see our data from the select. diff --git a/src/5_scratch/common.lib.h b/src/5_scratch/common.lib.h index 6b7f7c9..f3c3c8f 100644 --- a/src/5_scratch/common.lib.h +++ b/src/5_scratch/common.lib.h @@ -1,4 +1,5 @@ /* This file was automatically generated. Do not edit! */ #undef INTERFACE +extern char config_file[]; typedef unsigned int uint; #define INTERFACE 0 diff --git a/src/5_scratch/subu-config.lib.h b/src/5_scratch/subu-config.lib.h index a63786d..bed36a7 100644 --- a/src/5_scratch/subu-config.lib.h +++ b/src/5_scratch/subu-config.lib.h @@ -2,9 +2,7 @@ #undef INTERFACE #include typedef unsigned int uint; -int subu_number(sqlite3 *db,uint *subu_number); +int subu_number_get(sqlite3 *db,uint *subu_number); int schema(sqlite3 *db,uint max_subu_number); -extern char config_file[]; -extern char config_file[]; #define ERR_CONFIG_FILE -1 #define INTERFACE 0 diff --git a/src/5_scratch/subu-init.cli.h b/src/5_scratch/subu-init.cli.h index eff6c3f..d0dcddd 100644 --- a/src/5_scratch/subu-init.cli.h +++ b/src/5_scratch/subu-init.cli.h @@ -5,7 +5,3 @@ typedef unsigned int uint; int schema(sqlite3 *db,uint max_subu_number); extern char config_file[]; -extern char config_file[]; -int main(int argc,char **argv,char **envp); -int main(int argc,char **argv,char **envp); -int main(int argc,char **argv,char **envp); diff --git a/src/5_scratch/subu-mk-0.cli.h b/src/5_scratch/subu-mk-0.cli.h index 9c73c68..6aaecca 100644 --- a/src/5_scratch/subu-mk-0.cli.h +++ b/src/5_scratch/subu-mk-0.cli.h @@ -1,10 +1,6 @@ /* This file was automatically generated. Do not edit! */ #undef INTERFACE -#include -extern char config_file[]; extern char config_file[]; +#include int subu_mk_0(char *subuname,char *config_file); #define ERR_SUBU_MK_0_ARG_CNT 1 -int main(int argc,char **argv,char **envp); -int main(int argc,char **argv,char **envp); -int main(int argc,char **argv,char **envp); diff --git a/src/5_scratch/subu-mk-0.lib.h b/src/5_scratch/subu-mk-0.lib.h index 76a337a..bcc2b2c 100644 --- a/src/5_scratch/subu-mk-0.lib.h +++ b/src/5_scratch/subu-mk-0.lib.h @@ -13,9 +13,8 @@ struct dispatch_useradd_ret_t dispatch_useradd(char **argv,char **envp); #include int dispatch_f_euid_egid(char *fname,int(*f)(void *arg),void *f_arg,uid_t euid,gid_t egid); int dbprintf(const char *format,...); -#include -extern char config_file[]; extern char config_file[]; +#include int subu_mk_0(char *subuname,char *config_file); int masteru_makes_subuhome(void *arg); int allowed_subuname(char *subuname); diff --git a/src/5_scratch/subu-number.cli.h b/src/5_scratch/subu-number.cli.h index 91145ce..9844291 100644 --- a/src/5_scratch/subu-number.cli.h +++ b/src/5_scratch/subu-number.cli.h @@ -1,11 +1,8 @@ /* This file was automatically generated. Do not edit! */ #undef INTERFACE #include -typedef unsigned int uint; -int subu_number(sqlite3 *db,uint *subu_number); #define ERR_CONFIG_FILE -1 extern char config_file[]; -extern char config_file[]; -int main(int argc,char **argv,char **envp); -int main(int argc,char **argv,char **envp); -int main(int argc,char **argv,char **envp); +typedef unsigned int uint; +int subu_number_get(sqlite3 *db,uint *subu_number); +int print_subu_number(sqlite3 *db); diff --git a/src/common.lib.c b/src/common.lib.c index d998b3b..1384e73 100644 --- a/src/common.lib.c +++ b/src/common.lib.c @@ -3,3 +3,6 @@ #if INTERFACE typedef unsigned int uint; #endif + +// char *config_file = "/etc/subu.db"; +char config_file[] = "subu.db"; diff --git a/src/makefile b/src/makefile index 030a9f7..0db3c22 100755 --- a/src/makefile +++ b/src/makefile @@ -16,7 +16,8 @@ ECHO= echo SHELL=/bin/bash SCRATCHDIR= 5_scratch # clean and others put things here CC=gcc -CFLAGS=-std=c11 -fPIC -I. -ggdb -DDEBUG -Werror +#CFLAGS=-std=c11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB +CFLAGS=-std=c11 -fPIC -I. -Werror LIB="libsubu.a" LINKFLAGS=-L. -lsubu -lsqlite3 @@ -66,6 +67,7 @@ deps: @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' makeheaders $(SOURCES) $(HFILES) + sed -i '/^ *int *main *(.*)/d' *.h $(CC) $(CFLAGS) -MM $(SOURCES) 1> 2_makefile_deps for i in $(EXECS) ; do\ $(ECHO) >> 2_makefile_deps;\ diff --git a/src/subu-config.lib.c b/src/subu-config.lib.c index 525e195..0f02110 100644 --- a/src/subu-config.lib.c +++ b/src/subu-config.lib.c @@ -21,9 +21,6 @@ currently a unit converted to base 10 will always fit in a 21 bit buffer. #include #include -//char config_file[] = "/etc/subu.db"; -char config_file[] = "subu.db"; - int schema(sqlite3 *db, uint max_subu_number){ char max_subu_number_string[32]; uint max_subu_number_string_len = snprintf(max_subu_number_string, 32, "%u", max_subu_number); @@ -50,19 +47,14 @@ int schema(sqlite3 *db, uint max_subu_number){ return sqlite3_exec(db, sql, NULL, NULL, NULL); } -static uint count = 0; - -static int callback(void *NotUsed, int argc, char **argv, char **col_name){ - int i; - printf("count: %u\n", count++); - for(i=0; i= 1){ + sscanf(colvals[0], "%u", n); return 0; } - -int subu_number(sqlite3 *db, uint *subu_number){ + return -1; +} +int subu_number_get(sqlite3 *db, uint *subu_number){ *subu_number = 0; char *sql = "BEGIN TRANSACTION;" @@ -71,9 +63,10 @@ int subu_number(sqlite3 *db, uint *subu_number){ "COMMIT;"; int ret; char *errmsg; - ret = sqlite3_exec(db, sql, callback, NULL, &errmsg); + ret = sqlite3_exec(db, sql, subu_number_extract, subu_number, &errmsg); if( errmsg ){ - printf("exec failed: %s\n", errmsg); + printf("exec failed when accessing max_subu_number: %s\n", errmsg); sqlite3_free(errmsg); } + return ret; } diff --git a/src/subu-init.cli.c b/src/subu-init.cli.c index bf59be1..4ef7527 100644 --- a/src/subu-init.cli.c +++ b/src/subu-init.cli.c @@ -5,7 +5,7 @@ This command initializes the configuration file. #include "subu-init.cli.h" #include -int main(int argc, char **argv, char **envp){ +int main(){ sqlite3 *db; if( sqlite3_open(config_file, &db) diff --git a/src/subu-mk-0.cli.c b/src/subu-mk-0.cli.c index 6ed3bed..ffa8122 100644 --- a/src/subu-mk-0.cli.c +++ b/src/subu-mk-0.cli.c @@ -5,10 +5,7 @@ #include "subu-mk-0.lib.h" #include -// char *config_file = "/etc/subu.db"; -char config_file[] = "subu.db"; - -int main(int argc, char **argv, char **envp){ +int main(int argc, char **argv){ char *command = argv[0]; if( argc != 2 ){ fprintf(stderr, "usage: %s subu", command); diff --git a/src/subu-mk-0.lib.c b/src/subu-mk-0.lib.c index 657dc80..e03399f 100644 --- a/src/subu-mk-0.lib.c +++ b/src/subu-mk-0.lib.c @@ -33,6 +33,7 @@ #include #if INTERFACE +#include #define ERR_SUBU_MK_0_ARG_CNT 1 #define ERR_SUBU_MK_0_CONFIG_FILE 2 #define ERR_SUBU_MK_0_SETUID_ROOT 3 diff --git a/src/subu-number.cli.c b/src/subu-number.cli.c index 586115c..68758a1 100644 --- a/src/subu-number.cli.c +++ b/src/subu-number.cli.c @@ -1,24 +1,32 @@ /* -This command optionally sets the subu number in the config file, and prints its value. - -Currently it doesn't do the setting part. +Set or get a new maximum subu number. Currently doesn't do the setting part. */ #include "subu-number.cli.h" #include -int main(int argc, char **argv, char **envp){ + +int print_subu_number(sqlite3 *db){ + uint msn; + int ret = subu_number_get(db, &msn); + if( ret == 0 ) printf("%u\n", msn); + return ret; +} + +int main(){ int ret; sqlite3 *db; - ret = sqlite3_open(config_file, &db); + ret = sqlite3_open_v2(config_file, &db, SQLITE_OPEN_READWRITE, NULL); if( ret != SQLITE_OK ){ - fprintf(stderr, "error exit, could not build schema\n"); + fprintf(stderr, "error exit, could not open configuration file\n"); + return ERR_CONFIG_FILE; + } + if( print_subu_number(db) == -1 ){ + fprintf(stderr, "error exit, could not read access maximum subunumber\n"); return ERR_CONFIG_FILE; } - uint msn; - ret = subu_number(db, &msn); if( sqlite3_close(db) != SQLITE_OK ){ - fprintf(stderr, "error exit, strange, we could not close the db\n"); + fprintf(stderr, "error exit, strange, we could not close the configuration file\n"); return ERR_CONFIG_FILE; } return 0;