--- /dev/null
+
+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
--- /dev/null
+
+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.
/* \aThis file was automatically generated. Do not edit! */
#undef INTERFACE
+extern char config_file[];
typedef unsigned int uint;
#define INTERFACE 0
#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
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);
/* \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);
#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);
/* \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);
#if INTERFACE
typedef unsigned int uint;
#endif
+
+// char *config_file = "/etc/subu.db";
+char config_file[] = "subu.db";
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
@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;\
#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);
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;"
"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;
}
#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)
#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);
#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
/*
-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;