From 2fcc98aa0294a4d6d1a986be0c15c767172b4aa0 Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Mon, 18 Mar 2019 17:32:25 +0100 Subject: [PATCH] adds subu-bind-all; rearranges src tree --- 7_makefile => makefile | 10 +- src/{7_makefile => 0_makefile} | 141 +++++++++-------- .../dispatch_exec.lib.c | 0 .../dispatch_f.lib.c | 0 .../dispatch_useradd.lib.c | 0 .../subu-rm-0.lib.c | 0 .../subudb-number-next.cli.c | 0 src/{2_doc => 1_doc}/README.txt | 0 src/{2_doc => 1_doc}/makefile.txt | 0 src/{2_doc => 1_doc}/makeheaders.txt | 0 src/{2_doc => 1_doc}/sqlite.txt | 0 src/{2_doc => 1_doc}/to_do.txt | 0 src/1_tmp/da.lib.h | 23 +++ src/{5_scratch => 1_tmp}/dbprintf.lib.h | 0 src/{5_scratch => 1_tmp}/dispatch.lib.h | 0 .../subu-bind-all.cli.h} | 4 +- src/{5_scratch => 1_tmp}/subu-bind.cli.h | 0 src/{5_scratch => 1_tmp}/subu-common.lib.h | 0 src/{5_scratch => 1_tmp}/subu-mk-0.cli.h | 0 src/{5_scratch => 1_tmp}/subu-rm-0.cli.h | 0 src/{5_scratch => 1_tmp}/subu.lib.h | 23 ++- src/{5_scratch => 1_tmp}/subudb-init.cli.h | 0 src/{5_scratch => 1_tmp}/subudb-number.cli.h | 0 src/{5_scratch => 1_tmp}/subudb-rel-get.cli.h | 0 src/{5_scratch => 1_tmp}/subudb-rel-put.cli.h | 0 src/{5_scratch => 1_tmp}/subudb-rel-rm.cli.h | 0 src/{5_scratch => 1_tmp}/subudb-subus.cli.h | 0 src/{5_scratch => 1_tmp}/subudb.lib.h | 5 + src/5_scratch/common.lib.h | 9 -- src/5_scratch/dispatch_exec.lib.h | 4 - src/5_scratch/dispatch_f.lib.h | 22 --- src/5_scratch/dispatch_useradd.lib.h | 16 -- ...~ceea6e7d697546c47f7736b72e7fb60b15c104de~ | 147 ------------------ src/5_scratch/subu-config.lib.h | 13 -- src/5_scratch/subu-get.cli.h | 6 - src/5_scratch/subu-init.cli.h | 8 - src/5_scratch/subu-mk-0.lib.h | 49 ------ src/5_scratch/subu-number.cli.h | 11 -- src/5_scratch/subu-put.cli.h | 6 - src/5_scratch/subu-rel-get.cli.h | 9 -- src/5_scratch/subu-rel-put.cli.h | 8 - src/5_scratch/subu-rel-rm.cli.h | 8 - src/5_scratch/subu-rm-0.lib.h | 2 - src/5_scratch/subu-rm.cli.h | 6 - src/da.lib.c | 95 +++++++++++ src/darray.c | 45 ------ src/subu-bind-all.cli.c | 31 ++++ src/subu.lib.c | 81 ++++++---- src/subudb.lib.c | 5 +- tools/bin/make | 11 +- 50 files changed, 325 insertions(+), 473 deletions(-) rename 7_makefile => makefile (71%) rename src/{7_makefile => 0_makefile} (60%) rename src/{5_deprecated => 1_deprecated}/dispatch_exec.lib.c (100%) rename src/{5_deprecated => 1_deprecated}/dispatch_f.lib.c (100%) rename src/{5_deprecated => 1_deprecated}/dispatch_useradd.lib.c (100%) rename src/{5_deprecated => 1_deprecated}/subu-rm-0.lib.c (100%) rename src/{5_deprecated => 1_deprecated}/subudb-number-next.cli.c (100%) rename src/{2_doc => 1_doc}/README.txt (100%) rename src/{2_doc => 1_doc}/makefile.txt (100%) rename src/{2_doc => 1_doc}/makeheaders.txt (100%) rename src/{2_doc => 1_doc}/sqlite.txt (100%) rename src/{2_doc => 1_doc}/to_do.txt (100%) create mode 100644 src/1_tmp/da.lib.h rename src/{5_scratch => 1_tmp}/dbprintf.lib.h (100%) rename src/{5_scratch => 1_tmp}/dispatch.lib.h (100%) rename src/{5_scratch/subudb-number-next.cli.h => 1_tmp/subu-bind-all.cli.h} (74%) rename src/{5_scratch => 1_tmp}/subu-bind.cli.h (100%) rename src/{5_scratch => 1_tmp}/subu-common.lib.h (100%) rename src/{5_scratch => 1_tmp}/subu-mk-0.cli.h (100%) rename src/{5_scratch => 1_tmp}/subu-rm-0.cli.h (100%) rename src/{5_scratch => 1_tmp}/subu.lib.h (73%) rename src/{5_scratch => 1_tmp}/subudb-init.cli.h (100%) rename src/{5_scratch => 1_tmp}/subudb-number.cli.h (100%) rename src/{5_scratch => 1_tmp}/subudb-rel-get.cli.h (100%) rename src/{5_scratch => 1_tmp}/subudb-rel-put.cli.h (100%) rename src/{5_scratch => 1_tmp}/subudb-rel-rm.cli.h (100%) rename src/{5_scratch => 1_tmp}/subudb-subus.cli.h (100%) rename src/{5_scratch => 1_tmp}/subudb.lib.h (84%) delete mode 100644 src/5_scratch/common.lib.h delete mode 100644 src/5_scratch/dispatch_exec.lib.h delete mode 100644 src/5_scratch/dispatch_f.lib.h delete mode 100644 src/5_scratch/dispatch_useradd.lib.h delete mode 100644 src/5_scratch/subu-config.lib.c.~ceea6e7d697546c47f7736b72e7fb60b15c104de~ delete mode 100644 src/5_scratch/subu-config.lib.h delete mode 100644 src/5_scratch/subu-get.cli.h delete mode 100644 src/5_scratch/subu-init.cli.h delete mode 100644 src/5_scratch/subu-mk-0.lib.h delete mode 100644 src/5_scratch/subu-number.cli.h delete mode 100644 src/5_scratch/subu-put.cli.h delete mode 100644 src/5_scratch/subu-rel-get.cli.h delete mode 100644 src/5_scratch/subu-rel-put.cli.h delete mode 100644 src/5_scratch/subu-rel-rm.cli.h delete mode 100644 src/5_scratch/subu-rm-0.lib.h delete mode 100644 src/5_scratch/subu-rm.cli.h create mode 100644 src/da.lib.c delete mode 100644 src/darray.c create mode 100644 src/subu-bind-all.cli.c diff --git a/7_makefile b/makefile similarity index 71% rename from 7_makefile rename to makefile index f170e23..98808e5 100755 --- a/7_makefile +++ b/makefile @@ -11,16 +11,14 @@ all : clean : $(foreach dir, $(subdirectories), \ - if [ -f ./$(dir)/7_makefile ]; then \ - make -C $(dir) clean; \ - fi;\ + cd $(dir);\ + make clean;\ ) dist-clean : $(foreach dir, $(subdirectories), \ - if [ -f ./$(dir)/7_makefile ]; then \ - make -C $(dir) dist-clean; \ - fi;\ + cd $(dir);\ + make dist-clean;\ ) diff --git a/src/7_makefile b/src/0_makefile similarity index 60% rename from src/7_makefile rename to src/0_makefile index 5ab5990..528caae 100755 --- a/src/7_makefile +++ b/src/0_makefile @@ -1,118 +1,135 @@ -# a single space literal, for example if you wanted to subsitute commas to -# spaces: $(subst $(space),;,$(string)) we ran into this out of a need to send -# multiple separate command arguments to a shell script from one variable value -blank := -space :=$(blank) $(blank) +SHELL=/bin/bash # some versions of Linux need a -e option others complain if there is a -e .. and it isn't the binary for echo .. ECHO= echo #ECHO= echo -e -SHELL=/bin/bash -SCRATCHDIR= 5_scratch # clean and others put things here +# directories used by this makefile, these could all be set to dot for +# the simplest source directory structure + +#$(PWD) is the directory that make was called from, this is already build in +TMPDIR=1_tmp +EXECSDIR=1_execs +HDIR=1_headers +LIBDIR=1_lib +TOOLSDIR=$(realpath ../tools) + +# some important files +DEPS_FILE=$(TMPDIR)/makefile_deps +LIB_FILE=$(LIBDIR)/libsubu.a + +# external tools called out in this makefile +SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh + +# compiler and flags CC=gcc CFLAGS=-std=gnu11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB #CFLAGS=-std=gnu11 -fPIC -I. -Werror -LIBDIR=2_lib/ -LIB=$(LIBDIR)libsubu.a -LINKFLAGS=-L2_lib -lsubu -lsqlite3 +LINKFLAGS=-L1_lib -lsubu -lsqlite3 -#these are the source files that exist +### end of user defined variables +###-------------------------------------------------------------------------------- + +# a single space literal, for example if you wanted to subsitute commas to +# spaces: $(subst $(space),;,$(string)) we ran into this out of a need to send +# multiple separate command arguments to a shell script from one variable value +blank := +space :=$(blank) $(blank) + +# files used by the compiler SOURCES_LIB= $(wildcard *.lib.c) SOURCES_CLI= $(wildcard *.cli.c) SOURCES= $(SOURCES_LIB) $(SOURCES_CLI) -#these are the object files to be made +HFILES = $(wildcard *.lib.h) $(wildcard *.cli.h) + OBJECTS_LIB= $(patsubst %.c, %.o, $(SOURCES_LIB)) OBJECTS_CLI= $(patsubst %.c, %.o, $(SOURCES_CLI)) OBJECTS= $(OBJECTS_LIB) $(OBJECTS_CLI) -#these are the header files that exist, makeheaders will want to see them -HFILES = $(wildcard *.lib.h) $(wildcard *.cli.h) - -# sort causes compiles to go in lexical order by file name, this is used to order the tests e.g. EXECS= $(sort $(patsubst %.cli.c, %, $(wildcard *.cli.c))) -SUID=$(realpath ../tools/bin/setuid_root.sh) - - all: version deps lib execs +version: + @echo '---- make $@:------------------------------------------------------------' + @echo makefile version 3.0 + @echo "PWD: " $(PWD) + @echo "MAKEFILE_LIST: " $(MAKEFILE_LIST) + @echo "TMPDIR: " $(TMPDIR) + @echo "EXECSDIR: " $(EXECSDIR) + @echo "HDIR: " $(HDIR) + @echo "LIBDIR: " $(LIBDIR) + @echo "DEPS_FILE: " $(DEPS_FILE) + @echo "LIB_FILE: " $(LIB_FILE) + @echo "CC: " $(CC) + @echo "CFLAGS: " $(CFLAGS) + @echo "LINKFLAGS: " $(LINKFLAGS) + @echo "SUID_TOOL: " $(SUID_TOOL) + @echo '______end make $@_____' + lists: @echo '---- make $@:------------------------------------------------------------' @echo "SOURCES_LIB: " $(SOURCES_LIB) @echo "SOURCES_CLI: " $(SOURCES_CLI) @echo "SOURCES: " $(SOURCES) + @echo "HFILES: " $(HFILES) @echo "OBJECTS_LIB: " $(OBJECTS_LIB) @echo "OBJECTS_CLI: " $(OBJECTS_CLI) @echo "OBJECTS: " $(OBJECTS) - @echo "HFILES: " $(HFILES) @echo "EXECS: " $(EXECS) @echo '______end make $@_____' -version: - @echo '---- make $@:------------------------------------------------------------' - @echo `pwd`'>' - @echo makefile version 2.0 - @echo "CC: " $(CC) - @echo "CFLAGS: " $(CFLAGS) - @echo "LINKFLAGS: " $(LINKFLAGS) - @echo "LIB: " $(LIB) - @echo "SUID: " $(SUID) - @echo '______end make $@_____' - -# safe to run this in an already setup or partially setup directory +# should be safe to run this in an already setup or partially setup directory setup: @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' - if [ ! -e $(SCRATCHDIR) ]; then mkdir $(SCRATCHDIR); fi + if [ ! -e $(TMPDIR) ]; then mkdir $(TMPDIR); fi + if [ ! -e 1_deprecated ]; then mkdir 1_deprecated; fi + if [ ! -e 1_doc ]; then mkdir 1_doc; fi + if [ ! -e 1_execs ]; then mkdir 1_execs; fi + if [ ! -e 1_headers ]; then mkdir 1_headers; fi + if [ ! -e 1_lib ]; then mkdir 1_lib; fi if [ ! -e 1_tests ]; then mkdir 1_tests; fi if [ ! -e 1_try ]; then mkdir 1_try; fi - if [ ! -e 2_bin ]; then mkdir 2_bin; fi - if [ ! -e 2_lib ]; then mkdir 2_lib; fi - if [ ! -e 2_doc ]; then mkdir 2_doc; fi - if [ ! -e 2_include ]; then mkdir 2_include; fi - if [ ! -e 5_deprecated ]; then mkdir 5_deprecated; fi - if [ ! -e 5_scratch ]; then mkdir 5_scratch; fi @echo '______end make $@_____' - deps: @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' makeheaders $(SOURCES) $(HFILES) sed -i '/^ *int *main *(.*)/d' *.h - $(CC) $(CFLAGS) -MM $(SOURCES) 1> 7_makefile_deps + $(CC) $(CFLAGS) -MM $(SOURCES) 1> $(DEPS_FILE) for i in $(EXECS) ; do\ - $(ECHO) >> 7_makefile_deps;\ - $(ECHO) "2_bin/$$i : $$i.cli.o $(LIB)" >> 7_makefile_deps;\ - $(ECHO) " $(CC) -o 2_bin/$$i $$i.cli.o $(LINKFLAGS)" >> 7_makefile_deps;\ + $(ECHO) >> $(DEPS_FILE);\ + $(ECHO) "$(EXECSDIR)/$$i : $$i.cli.o $(LIB_FILE)" >> $(DEPS_FILE);\ + $(ECHO) " $(CC) -o $(EXECSDIR)/$$i $$i.cli.o $(LINKFLAGS)" >> $(DEPS_FILE);\ done @echo '______end make $@_____' lib: @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' - if [ ! -e 7_makefile_deps ]; then make deps; fi + if [ ! -e $(DEPS_FILE) ]; then make deps; fi make sub_lib @echo '______end make $@_____' -sub_lib: $(LIB) +sub_lib: $(LIB_FILE) -execs: $(LIB) +execs: $(LIB_FILE) @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' - if [ ! -e 7_makefile_deps ]; then make deps; fi + if [ ! -e $(DEPS_FILE) ]; then make deps; fi make sub_execs - @echo "-> $(SUID) 2_bin/subu-mk-0 2_bin/subu-rm-0" - cat $(SUID) + @echo "-> $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all" + cat $(SUID_TOOL) @echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} == y ] - sudo $(SUID) 2_bin/subu-mk-0 2_bin/subu-rm-0 + sudo $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all @echo '______end make $@_____' -sub_execs: $(patsubst %, 2_bin/%, $(EXECS)) +sub_execs: $(patsubst %, $(EXECSDIR)/%, $(EXECS)) #not ready yet install: all @@ -120,8 +137,8 @@ install: all @echo `pwd`'>' @if[ ! -e 1_tests_passed ]; then echo "can't install as tests have not passed"; fi @test -e test_passed - for i in $(BIN); do cp $$i $(RT_BASE)/bin; done - cp $(LIB) $(RT_BASE)/lib + for i in $(EXECSDIR); do cp $$i $(RT_BASE)/bin; done + cp $(LIB_FILE) $(RT_BASE)/lib cp $(APPLICATION).h $(RT_BASE)/include if [ -d $(APPLICATION) ]; then cp $(APPLICATION)/*.h $(RT_BASE)/include/$(APPLICATION); fi @echo '______end make $@_____' @@ -134,12 +151,12 @@ clean: @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' if [ -f subudb ]; then rm subudb; fi - for i in $(wildcard *~); do mv $$i $(SCRATCHDIR); done + for i in $(wildcard *~); do mv $$i $(TMPDIR); done for i in $(wildcard *.lib.o) $(wildcard *.cli.o); do rm $$i; done - for i in $(HFILES); do mv $$i 5_scratch; done # just in case someone wrote a header file - for i in $(EXECS); do if [ -e 2_bin/$$i ]; then rm 2_bin/$$i; fi; done - if [ -f $(LIB) ]; then rm $(LIB); fi - if [ -f 7_makefile_deps ]; then rm 7_makefile_deps; fi + for i in $(HFILES); do mv $$i $(TMPDIR); done # just in case someone wrote a header file + for i in $(EXECS); do if [ -e $(EXECSDIR)/$$i ]; then rm $(EXECSDIR)/$$i; fi; done + if [ -f $(LIB_FILE) ]; then rm $(LIB_FILE); fi + if [ -f $(DEPS_FILE) ]; then rm $(DEPS_FILE); fi @echo '______end make $@_____' @@ -157,10 +174,10 @@ dist-clean: @echo '______end make $@_____' # -$(LIB) : $(OBJECTS_LIB) - ar rcs $(LIB) $(OBJECTS_LIB) +$(LIB_FILE) : $(OBJECTS_LIB) + ar rcs $(LIB_FILE) $(OBJECTS_LIB) --include 7_makefile_deps +-include $(DEPS_FILE) # recipe for making object files: # diff --git a/src/5_deprecated/dispatch_exec.lib.c b/src/1_deprecated/dispatch_exec.lib.c similarity index 100% rename from src/5_deprecated/dispatch_exec.lib.c rename to src/1_deprecated/dispatch_exec.lib.c diff --git a/src/5_deprecated/dispatch_f.lib.c b/src/1_deprecated/dispatch_f.lib.c similarity index 100% rename from src/5_deprecated/dispatch_f.lib.c rename to src/1_deprecated/dispatch_f.lib.c diff --git a/src/5_deprecated/dispatch_useradd.lib.c b/src/1_deprecated/dispatch_useradd.lib.c similarity index 100% rename from src/5_deprecated/dispatch_useradd.lib.c rename to src/1_deprecated/dispatch_useradd.lib.c diff --git a/src/5_deprecated/subu-rm-0.lib.c b/src/1_deprecated/subu-rm-0.lib.c similarity index 100% rename from src/5_deprecated/subu-rm-0.lib.c rename to src/1_deprecated/subu-rm-0.lib.c diff --git a/src/5_deprecated/subudb-number-next.cli.c b/src/1_deprecated/subudb-number-next.cli.c similarity index 100% rename from src/5_deprecated/subudb-number-next.cli.c rename to src/1_deprecated/subudb-number-next.cli.c diff --git a/src/2_doc/README.txt b/src/1_doc/README.txt similarity index 100% rename from src/2_doc/README.txt rename to src/1_doc/README.txt diff --git a/src/2_doc/makefile.txt b/src/1_doc/makefile.txt similarity index 100% rename from src/2_doc/makefile.txt rename to src/1_doc/makefile.txt diff --git a/src/2_doc/makeheaders.txt b/src/1_doc/makeheaders.txt similarity index 100% rename from src/2_doc/makeheaders.txt rename to src/1_doc/makeheaders.txt diff --git a/src/2_doc/sqlite.txt b/src/1_doc/sqlite.txt similarity index 100% rename from src/2_doc/sqlite.txt rename to src/1_doc/sqlite.txt diff --git a/src/2_doc/to_do.txt b/src/1_doc/to_do.txt similarity index 100% rename from src/2_doc/to_do.txt rename to src/1_doc/to_do.txt diff --git a/src/1_tmp/da.lib.h b/src/1_tmp/da.lib.h new file mode 100644 index 0000000..0f5bb47 --- /dev/null +++ b/src/1_tmp/da.lib.h @@ -0,0 +1,23 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +#include +#include +void daps_map(char **base,char **end_pt,void f(void *)); +#define RETURN(rc) \ + { daps_map(mrs, mrs_end, free); return rc; } +void daps_alloc(char **base,size_t *s); +#define MK_MRS \ + char **mrs; \ + char **mrs_end; \ + size_t mrs_size; \ + daps_alloc(mrs, &mrs_size);\ + mrs_end = mrs; +void daps_push(char **base,char **pt,size_t *s,char *item); +bool daps_bound(char **base,char **pt,size_t s); +void daps_expand(char **base,char **pt,size_t *s); +void da_map(void *base,void *end_pt,void f(void *),size_t item_size); +void da_push(void **base,void **pt,size_t *s,void *item,size_t item_size); +bool da_bound(void *base,void *pt,size_t s); +void da_expand(void **base,void **pt,size_t *s); +void da_alloc(void **base,size_t *s,size_t item_size); +#define INTERFACE 0 diff --git a/src/5_scratch/dbprintf.lib.h b/src/1_tmp/dbprintf.lib.h similarity index 100% rename from src/5_scratch/dbprintf.lib.h rename to src/1_tmp/dbprintf.lib.h diff --git a/src/5_scratch/dispatch.lib.h b/src/1_tmp/dispatch.lib.h similarity index 100% rename from src/5_scratch/dispatch.lib.h rename to src/1_tmp/dispatch.lib.h diff --git a/src/5_scratch/subudb-number-next.cli.h b/src/1_tmp/subu-bind-all.cli.h similarity index 74% rename from src/5_scratch/subudb-number-next.cli.h rename to src/1_tmp/subu-bind-all.cli.h index 2c295dc..7e52675 100644 --- a/src/5_scratch/subudb-number-next.cli.h +++ b/src/1_tmp/subu-bind-all.cli.h @@ -1,9 +1,9 @@ /* This file was automatically generated. Do not edit! */ #undef INTERFACE -#include -int subudb_number_next(sqlite3 *db,char *masteru_name,int *n,char **mess); #include #include +#include +int subu_bind_all(char **mess,sqlite3 *db); #define SUBU_ERR_DB_FILE 8 extern char DB_File[]; #define SUBU_ERR_ARG_CNT 1 diff --git a/src/5_scratch/subu-bind.cli.h b/src/1_tmp/subu-bind.cli.h similarity index 100% rename from src/5_scratch/subu-bind.cli.h rename to src/1_tmp/subu-bind.cli.h diff --git a/src/5_scratch/subu-common.lib.h b/src/1_tmp/subu-common.lib.h similarity index 100% rename from src/5_scratch/subu-common.lib.h rename to src/1_tmp/subu-common.lib.h diff --git a/src/5_scratch/subu-mk-0.cli.h b/src/1_tmp/subu-mk-0.cli.h similarity index 100% rename from src/5_scratch/subu-mk-0.cli.h rename to src/1_tmp/subu-mk-0.cli.h diff --git a/src/5_scratch/subu-rm-0.cli.h b/src/1_tmp/subu-rm-0.cli.h similarity index 100% rename from src/5_scratch/subu-rm-0.cli.h rename to src/1_tmp/subu-rm-0.cli.h diff --git a/src/5_scratch/subu.lib.h b/src/1_tmp/subu.lib.h similarity index 73% rename from src/5_scratch/subu.lib.h rename to src/1_tmp/subu.lib.h index da9b468..5d072e7 100644 --- a/src/5_scratch/subu.lib.h +++ b/src/1_tmp/subu.lib.h @@ -1,8 +1,16 @@ /* This file was automatically generated. Do not edit! */ #undef INTERFACE +typedef unsigned int uint; +#include +typedef struct subudb_subu_element subudb_subu_element; +int subudb_Masteru_Subu_get_subus(sqlite3 *db,char *masteru_name,subudb_subu_element **sa_pt,subudb_subu_element **sa_end_pt); +struct subudb_subu_element { + char *subuname; + char *subu_username; +}; #include #include -#include +int subu_bind_all(char **mess,sqlite3 *db); int subu_bind(char **mess,char *masteru_name,char *subu_username,char *subuhome); int subudb_Masteru_Subu_rm(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); int subudb_Masteru_Subu_get_subu_username(sqlite3 *db,char *masteru_name,char *subuname,char **subu_username); @@ -15,7 +23,19 @@ int dispatch_exec(char **argv,char **envp); void dispatch_f_mess(char *fname,int err,char *dispatchee); #define ERR_DISPATCH -1024 int dispatch_f_euid_egid(char *fname,int(*f)(void *arg),void *f_arg,uid_t euid,gid_t egid); +#include +void daps_map(char **base,char **end_pt,void f(void *)); +#define RETURN(rc) \ + { daps_map(mrs, mrs_end, free); return rc; } +void daps_push(char **base,char **pt,size_t *s,char *item); int dbprintf(const char *format,...); +void daps_alloc(char **base,size_t *s); +#define MK_MRS \ + char **mrs; \ + char **mrs_end; \ + size_t mrs_size; \ + daps_alloc(mrs, &mrs_size);\ + mrs_end = mrs; int subu_mk_0(char **mess,sqlite3 *db,char *subuname); extern char Subuland_Extension[]; int db_commit(sqlite3 *db); @@ -23,7 +43,6 @@ int db_rollback(sqlite3 *db); int subudb_number_set(sqlite3 *db,int n); int subudb_number_get(sqlite3 *db,int *n); int db_begin(sqlite3 *db); -typedef unsigned int uint; extern uint Subuhome_Perms; extern char DB_File[]; void subu_err(char *fname,int err,char *mess); diff --git a/src/5_scratch/subudb-init.cli.h b/src/1_tmp/subudb-init.cli.h similarity index 100% rename from src/5_scratch/subudb-init.cli.h rename to src/1_tmp/subudb-init.cli.h diff --git a/src/5_scratch/subudb-number.cli.h b/src/1_tmp/subudb-number.cli.h similarity index 100% rename from src/5_scratch/subudb-number.cli.h rename to src/1_tmp/subudb-number.cli.h diff --git a/src/5_scratch/subudb-rel-get.cli.h b/src/1_tmp/subudb-rel-get.cli.h similarity index 100% rename from src/5_scratch/subudb-rel-get.cli.h rename to src/1_tmp/subudb-rel-get.cli.h diff --git a/src/5_scratch/subudb-rel-put.cli.h b/src/1_tmp/subudb-rel-put.cli.h similarity index 100% rename from src/5_scratch/subudb-rel-put.cli.h rename to src/1_tmp/subudb-rel-put.cli.h diff --git a/src/5_scratch/subudb-rel-rm.cli.h b/src/1_tmp/subudb-rel-rm.cli.h similarity index 100% rename from src/5_scratch/subudb-rel-rm.cli.h rename to src/1_tmp/subudb-rel-rm.cli.h diff --git a/src/5_scratch/subudb-subus.cli.h b/src/1_tmp/subudb-subus.cli.h similarity index 100% rename from src/5_scratch/subudb-subus.cli.h rename to src/1_tmp/subudb-subus.cli.h diff --git a/src/5_scratch/subudb.lib.h b/src/1_tmp/subudb.lib.h similarity index 84% rename from src/5_scratch/subudb.lib.h rename to src/1_tmp/subudb.lib.h index 2a9e9b7..be73823 100644 --- a/src/5_scratch/subudb.lib.h +++ b/src/1_tmp/subudb.lib.h @@ -2,9 +2,14 @@ #undef INTERFACE #include int subudb_Masteru_Subu_rm(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); +#include +#include +void da_expand(void **base,void **pt,size_t *s); +bool da_bound(void *base,void *pt,size_t s); typedef struct subudb_subu_element subudb_subu_element; int subudb_Masteru_Subu_get_subus(sqlite3 *db,char *masteru_name,subudb_subu_element **sa_pt,subudb_subu_element **sa_end_pt); void subu_element_free(subudb_subu_element *base,subudb_subu_element *end_pt); +void da_alloc(void **base,size_t *s,size_t item_size); struct subudb_subu_element { char *subuname; char *subu_username; diff --git a/src/5_scratch/common.lib.h b/src/5_scratch/common.lib.h deleted file mode 100644 index cfdc520..0000000 --- a/src/5_scratch/common.lib.h +++ /dev/null @@ -1,9 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -extern char Subuland_Extension[]; -typedef unsigned int uint; -extern uint First_Max_Subunumber; -extern uint Subuhome_Perms; -extern char DB_File[]; -#define BUG_SSS_CACHE_RUID 1 -#define INTERFACE 0 diff --git a/src/5_scratch/dispatch_exec.lib.h b/src/5_scratch/dispatch_exec.lib.h deleted file mode 100644 index 877a38e..0000000 --- a/src/5_scratch/dispatch_exec.lib.h +++ /dev/null @@ -1,4 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -int dbprintf(const char *format,...); -int dispatch_exec(char **argv,char **envp); diff --git a/src/5_scratch/dispatch_f.lib.h b/src/5_scratch/dispatch_f.lib.h deleted file mode 100644 index 6b3653f..0000000 --- a/src/5_scratch/dispatch_f.lib.h +++ /dev/null @@ -1,22 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -#include -typedef struct dispatch_f_ctx dispatch_f_ctx; -dispatch_f_ctx *dispatch_f_euid_egid(char *fname,int(*f)(void *arg),void *f_arg,uid_t euid,gid_t egid); -int dbprintf(const char *format,...); -dispatch_f_ctx *dispatch_f(char *fname,int(*f)(void *arg),void *f_arg); -void dispatch_f_mess(struct dispatch_f_ctx *ctxp); -void dispatch_f_ctx_free(dispatch_f_ctx *ctxp); -dispatch_f_ctx *dispatch_f_ctx_mk(char *name,char *fname); -struct dispatch_f_ctx { - char *dispatcher; // name of the dispatch function (currently "dispatch_f" or "dispatch_f_euid_egid") - char *dispatchee; // name of the function being dispatched - int err; - int status; // return value from the function -}; -#define ERR_DISPATCH_F_SETEGID -4 -#define ERR_DISPATCH_F_SETEUID -3 -#define ERR_DISPATCH_F_FORK -2 -#define ERR_NEGATIVE_RETURN_STATUS -1 -#define INTERFACE 0 diff --git a/src/5_scratch/dispatch_useradd.lib.h b/src/5_scratch/dispatch_useradd.lib.h deleted file mode 100644 index 0ce7e9d..0000000 --- a/src/5_scratch/dispatch_useradd.lib.h +++ /dev/null @@ -1,16 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -int dispatch_exec(char **argv,char **envp); -#include -#include -typedef struct dispatch_useradd_ret_t dispatch_useradd_ret_t; -typedef unsigned int uint; -struct dispatch_useradd_ret_t { - uint error; - struct passwd *pw_record; -}; -struct dispatch_useradd_ret_t dispatch_useradd(char **argv,char **envp); -#define ERR_DISPATCH_USERADD_PWREC 3 -#define ERR_DISPATCH_USERADD_DISPATCH 2 -#define ERR_DISPATCH_USERADD_ARGC 1 -#define INTERFACE 0 diff --git a/src/5_scratch/subu-config.lib.c.~ceea6e7d697546c47f7736b72e7fb60b15c104de~ b/src/5_scratch/subu-config.lib.c.~ceea6e7d697546c47f7736b72e7fb60b15c104de~ deleted file mode 100644 index de7bcbb..0000000 --- a/src/5_scratch/subu-config.lib.c.~ceea6e7d697546c47f7736b72e7fb60b15c104de~ +++ /dev/null @@ -1,147 +0,0 @@ -/* -The config file is maintained in SQLite - -Because user names of are of limited length, subu user names are always named _s. -A separate table translates the numbers into the subu names. - -The first argument is the biggest subu number in the system, or one minus an -starting point for subu numbering. - -currently a unit converted to base 10 will always fit in a 21 bit buffer. - -*/ -#include "subu-config.lib.h" - -#if INTERFACE -#include -#define ERR_CONFIG_FILE 1 -#endif - -#include -#include -#include - -//-------------------------------------------------------------------------------- -int subudb_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); - if( max_subu_number_string_len >= 32 ){ - fprintf(stderr, "error exit, max_subu_number too big to deal with\n"); - return ERR_CONFIG_FILE; - } - char sql1[] = "CREATE TABLE Masteru_Subu(masteru_name TEXT, subuname TEXT, subu_username TEXT); "; - char sql2[] = "CREATE TABLE Key_Int(key TEXT, value INT); "; - - char sql3_1[] = "INSERT INTO Key_Int VALUES( 'max_subu_number', "; - char sql3_2[] = " ); "; - char sql3_len = strlen(sql3_1) + max_subu_number_string_len + strlen(sql3_2) + 1; - char sql3[sql3_len]; - strcpy(sql3, sql3_1); - strcpy(sql3 + strlen(sql3_1), max_subu_number_string); - strcpy(sql3 + strlen(sql3_1) + max_subu_number_string_len, sql3_2); - - char sql[strlen(sql1) + strlen(sql2) + strlen(sql3) + 1]; - strcpy(sql, sql1); - strcpy(sql + strlen(sql1), sql2); - strcpy(sql + strlen(sql1) + strlen(sql2), sql3); - - return sqlite3_exec(db, sql, NULL, NULL, NULL); -} - -//-------------------------------------------------------------------------------- - -// the call back for subu_number_next, note also 3_doc/sqlite3.txt -static int subu_number_extract(void *nsp, int colcnt, char **colvals, char **colnames){ - if(colcnt >= 1){ - *(char **)nsp = strdup( colvals[0] ); - return 0; - } - return -1; -} -int subu_number_next(sqlite3 *db, char **nsp, char **mess){ - 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;"; - int rc = sqlite3_exec(db, sql, subu_number_extract, (void *)nsp, mess); - return rc; -} -int subu_number_get(sqlite3 *db, int *n){ - char *sql = "SELECT value FROM Key_Int WHERE key = 'max_subu_number';"; - sqlite3_stmt *stmt; - sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); - int rc = sqlite3_step(stmt); - if( rc == SQLITE_ROW ){ - *n = sqlite3_column_int(stmt,0); - }else{ - sqlite3_finalize(stmt); - return rc; // woops this needs to return an error!, be sure it is not SQLITE_DONE - } - rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - return rc; -} -int subu_number_set(sqlite3 *db, int n){ - char *sql = "UPDATE Key_Int SET value = ?1 WHERE key = 'max_subu_number';"; - sqlite3_stmt *stmt; - sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); - sqlite3_bind_int(stmt, 1, n); - int rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - return rc; -} - - -//-------------------------------------------------------------------------------- -// put relation into Masteru_Subu table -int subu_Masteru_Subu_put(sqlite3 *db, char *masteru_name, char *subuname, char *subu_username){ - char *sql = "INSERT INTO Masteru_Subu VALUES (?1, ?2, ?3);"; - sqlite3_stmt *stmt; - sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); - sqlite3_bind_text(stmt, 1, masteru_name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, subuname, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 3, subu_username, -1, SQLITE_STATIC); - int rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - return rc; -} - -//-------------------------------------------------------------------------------- -int subu_Masteru_Subu_get(sqlite3 *db, char *masteru_name, char *subuname, char **subu_username){ - char *sql = "SELECT subu_username FROM Masteru_Subu WHERE masteru_name = ?1 AND subuname = ?2;"; - size_t sql_len = strlen(sql); - sqlite3_stmt *stmt; - int rc; - rc = sqlite3_prepare_v2(db, sql, sql_len, &stmt, NULL); - if( rc != SQLITE_OK ) return rc; - sqlite3_bind_text(stmt, 1, masteru_name, strlen(masteru_name), SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, subuname, strlen(subuname), SQLITE_STATIC); - rc = sqlite3_step(stmt); - if( rc == SQLITE_ROW ){ - const char *username = sqlite3_column_text(stmt, 0); - *subu_username = strdup(username); - }else{ - sqlite3_finalize(stmt); - return rc; // woops this needs to return an error!, be sure it is not SQLITE_DONE - } - rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - return rc; -} - -//-------------------------------------------------------------------------------- -int subu_Masteru_Subu_rm(sqlite3 *db, char *masteru_name, char *subuname, char *subu_username){ - char *sql = "DELETE FROM Masteru_Subu WHERE masteru_name = ?1 AND subuname = ?2 AND subu_username = ?3;"; - size_t sql_len = strlen(sql); - sqlite3_stmt *stmt; - int rc; - rc = sqlite3_prepare_v2(db, sql, sql_len, &stmt, NULL); - if( rc != SQLITE_OK ) return rc; - sqlite3_bind_text(stmt, 1, masteru_name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, subuname, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 3, subu_username, -1, SQLITE_STATIC); - rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - return rc; -} diff --git a/src/5_scratch/subu-config.lib.h b/src/5_scratch/subu-config.lib.h deleted file mode 100644 index 482d289..0000000 --- a/src/5_scratch/subu-config.lib.h +++ /dev/null @@ -1,13 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_rm_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); -int subu_get_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char **subu_username); -int subu_put_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); -int subu_number_set(sqlite3 *db,int n); -int subu_number_get(sqlite3 *db,int *n); -int subu_number_next(sqlite3 *db,char **nsp,char **mess); -typedef unsigned int uint; -int schema(sqlite3 *db,uint max_subu_number); -#define ERR_CONFIG_FILE 1 -#define INTERFACE 0 diff --git a/src/5_scratch/subu-get.cli.h b/src/5_scratch/subu-get.cli.h deleted file mode 100644 index 163709f..0000000 --- a/src/5_scratch/subu-get.cli.h +++ /dev/null @@ -1,6 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_put_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); -#define ERR_CONFIG_FILE 1 -extern char Config_File[]; diff --git a/src/5_scratch/subu-init.cli.h b/src/5_scratch/subu-init.cli.h deleted file mode 100644 index 22281b6..0000000 --- a/src/5_scratch/subu-init.cli.h +++ /dev/null @@ -1,8 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -typedef unsigned int uint; -extern uint First_Max_Subu_number; -#include -int schema(sqlite3 *db,uint max_subu_number); -#define ERR_CONFIG_FILE 1 -extern char Config_File[]; diff --git a/src/5_scratch/subu-mk-0.lib.h b/src/5_scratch/subu-mk-0.lib.h deleted file mode 100644 index 28954ba..0000000 --- a/src/5_scratch/subu-mk-0.lib.h +++ /dev/null @@ -1,49 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_put_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); -#include -#include -typedef struct dispatch_ctx dispatch_ctx; -dispatch_ctx *dispatch_exec(char **argv,char **envp); -#define BUG_SSS_CACHE_RUID 1 -void dispatch_f_mess(struct dispatch_ctx *ctxp); -#define ERR_DISPATCH -1024 -dispatch_ctx *dispatch_f_euid_egid(char *fname,int(*f)(void *arg),void *f_arg,uid_t euid,gid_t egid); -struct dispatch_ctx { - char *dispatcher; // name of the dispatch function ("dispatch_f", "dispatch_f_euid_egid", etc.) - char *dispatchee; // name of the function being dispatched - int err; // error code as listed below, or status returned from dispatchee -}; -int subu_number_get(sqlite3 *db,char **nsp,char **errmsg); -extern char subuland_extension[]; -int dbprintf(const char *format,...); -#include -#include -typedef struct subu_mk_0_ctx subu_mk_0_ctx; -struct subu_mk_0_ctx *subu_mk_0(sqlite3 *db,char *subuname); -typedef unsigned int uint; -extern uint subuhome_perms; -void subu_mk_0_mess(struct subu_mk_0_ctx *ctxp); -void subu_mk_0_ctx_free(struct subu_mk_0_ctx *ctxp); -struct subu_mk_0_ctx *subu_mk_0_ctx_mk(); -struct subu_mk_0_ctx { - char *name; - char *subuland; - char *subuhome; - char *subu_username; - bool free_aux; - char *aux; - uint err; -}; -#define ERR_SUBU_MK_0_FAILED_USERADD 10 -#define ERR_SUBU_MK_0_BUG_SSS 9 -#define ERR_SUBU_MK_0_SUBUHOME_EXISTS 8 -#define ERR_SUBU_MK_0_CONFIG_FILE 7 -#define ERR_SUBU_MK_0_MALLOC 6 -#define ERR_SUBU_MK_0_MASTERU_HOMELESS 5 -#define ERR_SUBU_MK_0_SETUID_ROOT 4 -#define ERR_SUBU_MK_0_SUBUNAME_MALFORMED 3 -#define ERR_SUBU_MK_0_RMDIR_SUBUHOME 2 -#define ERR_SUBU_MK_0_MKDIR_SUBUHOME 1 -#define INTERFACE 0 diff --git a/src/5_scratch/subu-number.cli.h b/src/5_scratch/subu-number.cli.h deleted file mode 100644 index ac69056..0000000 --- a/src/5_scratch/subu-number.cli.h +++ /dev/null @@ -1,11 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_number_get(sqlite3 *db,int *n); -int subu_number_set(sqlite3 *db,int n); -#include -#include -#define SUBU_ERR_N 14 -#define SUBU_ERR_CONFIG_FILE 8 -extern char Config_File[]; -#define SUBU_ERR_ARG_CNT 1 diff --git a/src/5_scratch/subu-put.cli.h b/src/5_scratch/subu-put.cli.h deleted file mode 100644 index 163709f..0000000 --- a/src/5_scratch/subu-put.cli.h +++ /dev/null @@ -1,6 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_put_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); -#define ERR_CONFIG_FILE 1 -extern char Config_File[]; diff --git a/src/5_scratch/subu-rel-get.cli.h b/src/5_scratch/subu-rel-get.cli.h deleted file mode 100644 index 8b51ff3..0000000 --- a/src/5_scratch/subu-rel-get.cli.h +++ /dev/null @@ -1,9 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_get_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char **subu_username); -#include -#include -#define SUBU_ERR_CONFIG_FILE 8 -extern char Config_File[]; -#define SUBU_ERR_ARG_CNT 1 diff --git a/src/5_scratch/subu-rel-put.cli.h b/src/5_scratch/subu-rel-put.cli.h deleted file mode 100644 index 6ce971b..0000000 --- a/src/5_scratch/subu-rel-put.cli.h +++ /dev/null @@ -1,8 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_put_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); -#include -#include -#define SUBU_ERR_CONFIG_FILE 8 -extern char Config_File[]; diff --git a/src/5_scratch/subu-rel-rm.cli.h b/src/5_scratch/subu-rel-rm.cli.h deleted file mode 100644 index 5973cbe..0000000 --- a/src/5_scratch/subu-rel-rm.cli.h +++ /dev/null @@ -1,8 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_rm_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); -#include -#include -#define SUBU_ERR_CONFIG_FILE 8 -extern char Config_File[]; diff --git a/src/5_scratch/subu-rm-0.lib.h b/src/5_scratch/subu-rm-0.lib.h deleted file mode 100644 index f63f1db..0000000 --- a/src/5_scratch/subu-rm-0.lib.h +++ /dev/null @@ -1,2 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE diff --git a/src/5_scratch/subu-rm.cli.h b/src/5_scratch/subu-rm.cli.h deleted file mode 100644 index 163709f..0000000 --- a/src/5_scratch/subu-rm.cli.h +++ /dev/null @@ -1,6 +0,0 @@ -/* This file was automatically generated. Do not edit! */ -#undef INTERFACE -#include -int subu_put_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username); -#define ERR_CONFIG_FILE 1 -extern char Config_File[]; diff --git a/src/da.lib.c b/src/da.lib.c new file mode 100644 index 0000000..f2cabcb --- /dev/null +++ b/src/da.lib.c @@ -0,0 +1,95 @@ +/* +Dynamic Array + +*/ + +#include "da.lib.h" + +#if INTERFACE +#include +#include +#endif +#include + +//-------------------------------------------------------------------------------- +// generic + +// s is the size of the array in bytes +void da_alloc(void **base, size_t *s, size_t item_size){ + *s = 4 * item_size; + *base = malloc(*s); +} + +// doubles size of an array +void da_expand(void **base, void **pt, size_t *s){ + size_t offset = ((unsigned char *)*pt - (unsigned char *)*base); + size_t new_s = *s << 1; + void *new_base = malloc( new_s ); + memcpy( new_base, *base, offset + 1); + free(base); + *base = new_base; + *pt = new_base + offset; + *s = new_s; +} + +// true when pt has run off the end of the area currently allocated for the array +bool da_bound(void *base, void *pt, size_t s){ + return pt >= base + s; +} + +void da_push(void **base, void **pt, size_t *s, void *item, size_t item_size){ + while( *pt + item_size >= *base + *s ){ + da_expand(base, pt, s); + } + memcpy(*pt, item, item_size); + *pt += item_size; +} + +void da_map(void *base, void *end_pt, void f(void *), size_t item_size){ + void *pt = base; + while( pt != end_pt ){ + f(pt); + pt += item_size; + } +} + +//-------------------------------------------------------------------------------- +// dynamic array of pointers to strings + +// s is still the length of the array in bytes +void daps_alloc(char **base, size_t *s){ + da_alloc((void **)base, s, sizeof(char *)); +} + +void daps_expand(char **base, char **pt, size_t *s){ + da_expand((void **)base, (void **)pt, s); +} + +bool daps_bound(char **base, char **pt, size_t s){ + return da_bound( (void *) base, (void *)pt, s); +} + +void daps_push(char **base, char **pt, size_t *s, char *item){ + da_push((void **)base, (void **)pt, s, (void *)item, sizeof(char *)); +} + +void daps_map(char **base, char **end_pt, void f(void *)){ + da_map((void *)base, (void *)end_pt, f, sizeof(char *)); +} + +// one use for an array of string pointers is to keep list of +// strings that must be freed. I.e. 'managed' strings +#if INTERFACE + +#define MK_MRS \ + char **mrs; \ + char **mrs_end; \ + size_t mrs_size; \ + daps_alloc(mrs, &mrs_size);\ + mrs_end = mrs; + +#define RETURN(rc) \ + { daps_map(mrs, mrs_end, free); return rc; } + +#endif + diff --git a/src/darray.c b/src/darray.c deleted file mode 100644 index 02f5704..0000000 --- a/src/darray.c +++ /dev/null @@ -1,45 +0,0 @@ -/* -Dynamic Array - -*/ - -void d_alloc(subudb_subu_element **base, size_t *s, size_t item_size){ - *s = 4 * item_size; - *base = malloc(*s); -} - -// doubles size of an array -void d_expand(void **base, void **pt, size_t *s){ - size_t offset = ((unsigned char *)*pt - (unsigned char *)*base); - size_t new_s = *s << 1; - void *new_base = malloc( new_s ); - memcpy( new_base, *base, offset + 1); - free(base); - *base = new_base; - *pt = new_base + offset; - *s = new_s; -} - -// true when pt has run off the end of the area currently allocated for the array -bool d_bounds(void *base, void *pt, size_t s){ - return pt >= base + s; -} - -void d_push(void **base, void **pt, size_t *s, void *item, size_t item_size){ - while( *pt + item_size >= *base + *s ){ - expand(base, pt, s); - } - memcpy(*pt, item, item_size); - *pt += item_size; -} - -// special case when the dynamic array is holding pointers to items on the heap -void d_map(void *base, void *end_pt){ - void *pt = base; - while( pt != end_pt ){ - free(pt->subuname); - free(pt->subu_username); - pt++; - } - free(base); -} diff --git a/src/subu-bind-all.cli.c b/src/subu-bind-all.cli.c new file mode 100644 index 0000000..4754d55 --- /dev/null +++ b/src/subu-bind-all.cli.c @@ -0,0 +1,31 @@ +/* +mount all the subu user directories into master's subuland +uses unmount to undo this + +*/ +#include "subu-bind-all.cli.h" +#include +#include + +int main(int argc, char **argv){ + if( argc != 2){ + fprintf(stderr, "%s does not take arguments\n",argv[0]); + return SUBU_ERR_ARG_CNT; + } + + int rc; + sqlite3 *db; + rc = sqlite3_open_v2(DB_File, &db, SQLITE_OPEN_READWRITE, NULL); + if( rc != SQLITE_OK ){ + fprintf(stderr, "could not open db file \"%s\"\n", DB_File); + return SUBU_ERR_DB_FILE; + } + + char *mess; + rc = subu_bind_all(&mess, db); + if(rc != 0){ + fprintf(stderr, "subu-bind: %s\n", mess); + return rc; + } + return 0; +} diff --git a/src/subu.lib.c b/src/subu.lib.c index 9950380..d0d68a0 100644 --- a/src/subu.lib.c +++ b/src/subu.lib.c @@ -268,21 +268,14 @@ static int mk_subuhome(char *subuland, char *subuname, char **subuhome){ return 0; } -#define RETURN(err)\ - {\ - free(subu_username);\ - free(masteru_name);\ - free(masteru_home);\ - free(subuland);\ - free(subuhome);\ - return err;\ - } + //=============================================================================== int subu_mk_0(char **mess, sqlite3 *db, char *subuname){ int rc; if(mess)*mess = 0; + MK_MRS; //-------------------------------------------------------------------------------- size_t subuname_len; @@ -314,6 +307,11 @@ int subu_mk_0(char **mess, sqlite3 *db, char *subuname){ char *subu_username = 0; char *subuland = 0; char *subuhome = 0; // the name of the directory to put in subuland, not subu_user home dir + daps_push(mrs, mrs_end, &mrs_size, masteru_name); + daps_push(mrs, mrs_end, &mrs_size, masteru_home); + daps_push(mrs, mrs_end, &mrs_size, subu_username); + daps_push(mrs, mrs_end, &mrs_size, subuland); + daps_push(mrs, mrs_end, &mrs_size, subuhome); rc = uid_to_name_and_home(masteru_uid, &masteru_name, &masteru_home) || @@ -423,6 +421,7 @@ int subu_rm_0(char **mess, sqlite3 *db, char *subuname){ int rc; if(mess)*mess = 0; + MK_MRS; //-------------------------------------------------------------------------------- size_t subuname_len; @@ -454,7 +453,10 @@ int subu_rm_0(char **mess, sqlite3 *db, char *subuname){ char *masteru_home = 0; char *subuland = 0; char *subuhome = 0; // the name of the directory to put in subuland, not subu_user home dir - char *subu_username = 0; + daps_push(mrs, mrs_end, &mrs_size, masteru_name); + daps_push(mrs, mrs_end, &mrs_size, masteru_home); + daps_push(mrs, mrs_end, &mrs_size, subuland); + daps_push(mrs, mrs_end, &mrs_size, subuhome); rc = uid_to_name_and_home(masteru_uid, &masteru_name, &masteru_home) || @@ -469,6 +471,8 @@ int subu_rm_0(char **mess, sqlite3 *db, char *subuname){ //-------------------------------------------------------------------------------- // removal from db + char *subu_username = 0; + daps_push(mrs, mrs_end, &mrs_size, subu_username); db_begin(db); @@ -539,8 +543,7 @@ int subu_rm_0(char **mess, sqlite3 *db, char *subuname){ dbprintf("setting inherited real uid to 0 to accomodate SSS_CACHE UID BUG\n"); #endif if( setuid(0) == -1 ){ - rc = SUBU_ERR_BUG_SSS; - RETURN(rc); + RETURN(SUBU_ERR_BUG_SSS); } #endif char *command = "/usr/sbin/userdel"; @@ -575,16 +578,22 @@ int subu_rm_0(char **mess, sqlite3 *db, char *subuname){ // in subuland. int subu_bind(char **mess, char *masteru_name, char *subu_username, char *subuhome){ - char *subu_user_home; int rc; + if(mess)*mess = 0; + MK_MRS; + + // lookup the subu_user_home + char *subu_user_home = 0; + daps_push(mrs, mrs_end, &mrs_size, subu_user_home); rc = username_to_home(subu_username, &subu_user_home); if( rc ){ if(mess) *mess = strdup("in subu_bind, subu user home directory lookup in /etc/passwd failed."); - return rc; + RETURN(rc); } size_t len = 0; - char *map; + char *map = 0; + daps_push(mrs, mrs_end, &mrs_size, map); FILE* map_stream = open_memstream(&map, &len); fprintf(map_stream, "--map=%s/%s:@%s/@%s", subu_username, masteru_name, subu_username, masteru_name); fclose(map_stream); @@ -599,25 +608,24 @@ int subu_bind(char **mess, char *masteru_name, char *subu_username, char *subuho char *envp[1]; envp[0] = (char *) NULL; int dispatch_err = dispatch_exec(argv, envp); - free(map); if( dispatch_err != 0 ){ #ifdef DEBUG dispatch_f_mess(command, dispatch_err, "dispatch_exec"); #endif if(mess)*mess = strdup("bind failed"); - return SUBU_ERR_BIND; + RETURN(SUBU_ERR_BIND); } #ifdef DEBUG dbprintf("mapped \"%s\" as \"%s\"\n", subu_user_home, subuhome); #endif - return 0; + RETURN(0); } int subu_bind_all(char **mess, sqlite3 *db){ int rc; if(mess)*mess = 0; - char **free_list; + MK_MRS; //-------------------------------------------------------------------------------- uid_t masteru_uid; @@ -640,19 +648,25 @@ int subu_bind_all(char **mess, sqlite3 *db){ char *masteru_name = 0; char *masteru_home = 0; char *subuland = 0; - char *subuhome = 0; // the name of the directory to put in subuland, not subu_user home dir + daps_push(mrs, mrs_end, &mrs_size, masteru_name); + daps_push(mrs, mrs_end, &mrs_size, masteru_home); + daps_push(mrs, mrs_end, &mrs_size, subuland); rc = uid_to_name_and_home(masteru_uid, &masteru_name, &masteru_home) || mk_subuland(masteru_home, &subuland) ; - if(rc){ - free(masteru_name); - free(masteru_home); - free(subuland); - } + if(rc) RETURN(rc); #ifdef DEBUG - dbprintf("masteru_home, subuhome: \"%s\", \"%s\"\n", masteru_home, subuhome); + if(masteru_name) + dbprintf("masteru_name: \"%s\"", masteru_name); + else + dbprintf("masteru_name unknown"); + if(subuland) + dbprintf("subuland: \"%s\"", subuland); + else + dbprintf("subuland unknown"); + dbprintf("\n"); #endif //-------------------------------------------------------------------------------- @@ -667,20 +681,29 @@ int subu_bind_all(char **mess, sqlite3 *db){ // a limitation of our error reporting approach is that we can only // return one error, but here is a loop that might generate many + char *subuhome = 0; // the name of the directory to put in subuland, not subu_user home dir uint rc_count = 0; subudb_subu_element *pt = sa; while( pt != sa_end ){ rc = mk_subuhome(subuland, pt->subuname, &subuhome); + #ifdef DEBUG + if(subuhome) + dbprintf("subuhome: \"%s\"\n", subuhome); + else + dbprintf("subuhome unknown \n"); + #endif if(!rc) rc = subu_bind(NULL, masteru_name, pt->subu_username, subuhome); if(rc) rc_count++; + free(subuhome); + subuhome=0; pt++; } if(rc_count==1){ - return rc; + RETURN(rc); } if(rc_count > 1){ - mess = strdup("multiple errors occured while binding subus"); + *mess = strdup("multiple errors occured while binding subus"); RETURN(SUBU_ERR_BIND); } - return RETURN(0); + RETURN(0); } diff --git a/src/subudb.lib.c b/src/subudb.lib.c index 5a1d279..cce9661 100644 --- a/src/subudb.lib.c +++ b/src/subudb.lib.c @@ -140,7 +140,7 @@ struct subudb_subu_element{ }; #endif static void subu_element_alloc(subudb_subu_element **base, size_t *s){ - dalloc((void *)base, s, sizeof(subudb_subu_element)); + da_alloc((void *)base, s, sizeof(subudb_subu_element)); } void subu_element_free(subudb_subu_element *base, subudb_subu_element *end_pt){ subudb_subu_element *pt = base; @@ -175,7 +175,8 @@ int subudb_Masteru_Subu_get_subus subudb_subu_element *pt = subu_element; rc = sqlite3_step(stmt); while( rc == SQLITE_ROW ){ - if( off_alloc(subu_element, pt, subu_element_size) ) expand((void **)&subu_element, (void **)&pt, &subu_element_size); + if( da_bound(subu_element, pt, subu_element_size) ) + da_expand((void **)&subu_element, (void **)&pt, &subu_element_size); pt->subuname = strdup(sqlite3_column_text(stmt, 0)); pt->subu_username = strdup(sqlite3_column_text(stmt, 1)); rc = sqlite3_step(stmt); diff --git a/tools/bin/make b/tools/bin/make index 3312575..d51fcb8 100755 --- a/tools/bin/make +++ b/tools/bin/make @@ -1,2 +1,11 @@ #!/bin/bash -/usr/bin/make -f 7_makefile "$@" + +mf=( ?_makefile ) +if [ -f "$mf" ]; then + /usr/bin/make -f ?_makefile "$@" +else + /usr/bin/make "$@" +fi + + + -- 2.20.1