first version subu-number working
authorThomas Walker Lynch <thomas.lynch@reasoningtechnology.com>
Mon, 25 Feb 2019 15:16:28 +0000 (16:16 +0100)
committerThomas Walker Lynch <thomas.lynch@reasoningtechnology.com>
Mon, 25 Feb 2019 15:16:28 +0000 (16:16 +0100)
15 files changed:
doc/subu.txt [new file with mode: 0644]
src/3_documents/sqlite.txt [new file with mode: 0644]
src/5_scratch/common.lib.h
src/5_scratch/subu-config.lib.h
src/5_scratch/subu-init.cli.h
src/5_scratch/subu-mk-0.cli.h
src/5_scratch/subu-mk-0.lib.h
src/5_scratch/subu-number.cli.h
src/common.lib.c
src/makefile
src/subu-config.lib.c
src/subu-init.cli.c
src/subu-mk-0.cli.c
src/subu-mk-0.lib.c
src/subu-number.cli.c

diff --git a/doc/subu.txt b/doc/subu.txt
new file mode 100644 (file)
index 0000000..d422784
--- /dev/null
@@ -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 <subuname> 
+
+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 <subuname>
+
+primitve makes a new subu
+returns an error code
+
+---
+subu-rm-0 <subuname>
+
+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 (file)
index 0000000..b7f8cbb
--- /dev/null
@@ -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.
index 6b7f7c9..f3c3c8f 100644 (file)
@@ -1,4 +1,5 @@
 /* \aThis file was automatically generated.  Do not edit! */
 #undef INTERFACE
+extern char config_file[];
 typedef unsigned int uint;
 #define INTERFACE 0
index a63786d..bed36a7 100644 (file)
@@ -2,9 +2,7 @@
 #undef INTERFACE
 #include <sqlite3.h>
 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
index eff6c3f..d0dcddd 100644 (file)
@@ -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);
index 9c73c68..6aaecca 100644 (file)
@@ -1,10 +1,6 @@
 /* \aThis file was automatically generated.  Do not edit! */
 #undef INTERFACE
-#include <sqlite3.h>
-extern char config_file[];
 extern char config_file[];
+#include <sqlite3.h>
 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);
index 76a337a..bcc2b2c 100644 (file)
@@ -13,9 +13,8 @@ struct dispatch_useradd_ret_t dispatch_useradd(char **argv,char **envp);
 #include <unistd.h>
 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 <sqlite3.h>
-extern char config_file[];
 extern char config_file[];
+#include <sqlite3.h>
 int subu_mk_0(char *subuname,char *config_file);
 int masteru_makes_subuhome(void *arg);
 int allowed_subuname(char *subuname);
index 91145ce..9844291 100644 (file)
@@ -1,11 +1,8 @@
 /* \aThis file was automatically generated.  Do not edit! */
 #undef INTERFACE
 #include <sqlite3.h>
-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);
index d998b3b..1384e73 100644 (file)
@@ -3,3 +3,6 @@
 #if INTERFACE
 typedef unsigned int uint;
 #endif
+
+//  char *config_file = "/etc/subu.db";
+char config_file[] = "subu.db";
index 030a9f7..0db3c22 100755 (executable)
@@ -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;\
index 525e195..0f02110 100644 (file)
@@ -21,9 +21,6 @@ currently a unit converted to base 10 will always fit in a 21 bit buffer.
 #include <string.h>
 #include <stdlib.h>
 
-//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<argc; i++){
-      printf("%s = %s\n", col_name[i], argv[i] ? argv[i] : "NULL");
-    }
-    printf("\n");
+static int subu_number_extract(void *n, int colcnt, char **colvals, char **colnames){
+  if(colcnt >= 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;
 }
index bf59be1..4ef7527 100644 (file)
@@ -5,7 +5,7 @@ This command initializes the configuration file.
 #include "subu-init.cli.h"
 #include <stdio.h>
 
-int main(int argc, char **argv, char **envp){
+int main(){
   sqlite3 *db;
   if(
      sqlite3_open(config_file, &db)
index 6ed3bed..ffa8122 100644 (file)
@@ -5,10 +5,7 @@
 #include "subu-mk-0.lib.h"
 #include <stdio.h>
 
-//  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);
index 657dc80..e03399f 100644 (file)
@@ -33,6 +33,7 @@
 #include <stdbool.h>
 
 #if INTERFACE
+#include <sqlite3.h>
 #define ERR_SUBU_MK_0_ARG_CNT 1
 #define ERR_SUBU_MK_0_CONFIG_FILE 2
 #define ERR_SUBU_MK_0_SETUID_ROOT 3
index 586115c..68758a1 100644 (file)
@@ -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 <stdio.h>
 
-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;