From: Thomas Walker Lynch Date: Sat, 23 Feb 2019 23:05:50 +0000 (+0100) Subject: moved from automake to rtmake and makeheaders X-Git-Url: https://git.reasoningtechnology.com/style/rt_dark_doc.css?a=commitdiff_plain;h=0aed55494aebabe1416b764a4cf92de80ded817e;p=subu moved from automake to rtmake and makeheaders --- diff --git a/doc/makeheaders.txt b/doc/makeheaders.txt deleted file mode 100644 index 5aebda9..0000000 --- a/doc/makeheaders.txt +++ /dev/null @@ -1,16 +0,0 @@ - -This worked to force the include to be part of the interface: - -#if INTERFACE -#include -#endif - -But this did not: - -#if INTERFACE - #include -#endif - -makeheaders looks to be sensitive to indentation - - diff --git a/doc/todo.txt b/doc/todo.txt index 52d1998..139597f 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,23 +1,2 @@ -2019-02-05T23:14:40Z morpheus@manorhouse§~/src/subu§ - error can cause subu-mk-0 to leave the creating of a subu - in an intermediate state. Rather than bailing on some - of the errors we need to clean up instead. Perhaps the - yet to be written subu-rm program will be resilent enough - to do more general cleanup. - -2019-02-21T22:02:15Z morpheus@manorhouse§~/src/subu§ - subu-mk-0 only gives x privs via setfacl to subu on masteru home and on - subuland. Hence a subu can not run subu-mk-0 and be guaranteed access to the - subu's newly made subu. I.e. cd might not work for recurisve subu. - - The easy fix would be to use perms instead of facls, and give all home - directories other 'x' privs. Another fix would be to take apart the subu - home path, and make sure that all sub paths have 'x'. - - For now, I'm just leaving it to one layer. - -2019-02-23T18:56:31Z morpheus@manorhouse§~/subu_land/subu/src§ - need to modify subu-init to take a configuration file name argument - might want to add arguments to other subu commands also diff --git a/makefile b/makefile index 6e5ff7d..f5487c9 100755 --- a/makefile +++ b/makefile @@ -1,4 +1,5 @@ -subdirectories=$(shell /usr/bin/find . -maxdepth 1 -printf "%f " | sed y/\./\ /) +#subdirectories=$(shell /usr/bin/find . -maxdepth 1 -printf "%f " | sed y/\./\ /) +subdirectories=src all : $(foreach dir, $(subdirectories), \ diff --git a/rtmake b/rtmake deleted file mode 100755 index 6fac2ab..0000000 --- a/rtmake +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -make --no-print-directory -f $RT_BASE/bin/source_local_makefile $@ - diff --git a/src/2_makefile_deps b/src/2_makefile_deps new file mode 100644 index 0000000..8bf3e2d --- /dev/null +++ b/src/2_makefile_deps @@ -0,0 +1,19 @@ +common.lib.o: common.lib.c +dispatch_useradd.lib.o: dispatch_useradd.lib.c dispatch_useradd.lib.h +subu-mk-0.lib.o: subu-mk-0.lib.c subu-mk-0.lib.h +subu-config.lib.o: subu-config.lib.c subu-config.lib.h +dispatch_exec.lib.o: dispatch_exec.lib.c dispatch_exec.lib.h +dbprintf.lib.o: dbprintf.lib.c dbprintf.lib.h +dispatch_f.lib.o: dispatch_f.lib.c dispatch_f.lib.h +subu-number.cli.o: subu-number.cli.c subu-number.cli.h +subu-mk-0.cli.o: subu-mk-0.cli.c subu-mk-0.lib.h +subu-init.cli.o: subu-init.cli.c subu-init.cli.h + +subu-init : subu-init.cli.o . /libsubu.a + g++ -o subu-init subu-init.cli.o -L. -lsubu + +subu-mk-0 : subu-mk-0.cli.o . /libsubu.a + g++ -o subu-mk-0 subu-mk-0.cli.o -L. -lsubu + +subu-number : subu-number.cli.o . /libsubu.a + g++ -o subu-number subu-number.cli.o -L. -lsubu diff --git a/src/3_documents/makefile.txt b/src/3_documents/makefile.txt new file mode 100644 index 0000000..722de84 --- /dev/null +++ b/src/3_documents/makefile.txt @@ -0,0 +1,91 @@ +these are the comments from my RT makefile: + +# +# 2010 11 20 TWL Created +# 2011 05 26 TWL Modified to generalize +# 2012 02 23 NLS Add ECHO variable to use on different environnement +# corrected setup macro --> add include directory in the path to copy +# corrected install macro --> change the name of installed library : lib$(LIB)$(LIBSUFFIX) +# changed DOC_DIR directory name to 5_documents +# 2012 02 23 TWL removed LIB variable which is now set from the command line so +# so that all source dirs can use the same makefile +# 2012 02 23 TWL added target make dist_clean which also deletes the 2_makefile_deps file +# 2012 04 11 AWW added creation of temporary disk before each test is run +# 2012 06 05 TWL moved tests and try .cc files to directories. caused rtmake tests to +# dist_clean and make deps +# +# +#---------------------------------------------------------------------------- +# use this makefile to compile and test the code: +# +# for a first time run, or for regression use the following: +# +# $ make setup # makes the directories, though should already exist +# $ make regress +# +# the usual development workflow makes use of these: +# +# $ make deps # only when needed, for example if headers includes change or new files introduced +# $ cd tests; make deps # only when needed +# $ make lib # this makes the local library +# $ make tests # this updates tests and compiles +# $ make clean # deletes the .o files and library to force a recompile +# $ cd 1_tests; make clean +# +# for a release of a component +# +# $ make regress +# $ make install # this will only work if all the tests in 1_tests are passing +# +# before a checkin +# +# $ make dist_clean # will also clean the tests and try directories +# +# .lib.cc c++ files taken as source of object files for local build library +# .exl.cc c++ files taken to have main calls and are linked against local build libary +# .ex.cc c++ files taken to have main calls and are not linked against the local build library +# there are no rules for other files in this makefile +# +# about dependencies +# The makefile has no way of knowing if an edit changed the dependencies. Often they do not +# and it would be unwieldy to make the deps every time. Hence *the programmer* must delete +# the deps file if he has made any changes that change the dependencies. +# +# The makefile will make the 2_makefile_deps if the file is missing. +# +# +# about testing +# +# the name of the directory you run make in is taken to also be: the name of the library, +# the name of the main include file (with a .h added), and the name of the include directory +# where the individual headers are found. It is called LIB +# +# test programs are kept in a subdirectory called 1_tests, and are either .exl.cc, ex.cc, +# .sh files. When 'make tests' target is invoked they are all run. Test executables return 0 +# if the test fails, non-zero otherwise. +# +# to remove a test from the pool move it into the subdirectory in 1_tests, 9_broken, +# 5_more_tests of 5_scratch. broken tests are things that are known but must be fixed +# before a release. 5_more_tests are tests being worked on. 5_scratch is stuff that is +# probably going to be deleted. if there is a 5_deprecated, that is for good stuff but it +# is no longer used for some reason or other. +# +# There is a standard source code template and a +# messaging convention. Also, the names, by convention,are test_xxxx_ where xxx is a +# hexadecimal series nummber. If all the test executables pass the file 1_TESTS_PASSED is +# left in the directory. Otherwise the file 1_TESTS_FAILED is left in the directory. +# +# about release directory +# +# this is set in the ApplicationBase variable by rt_init +# +# after the tests pass stuff might be copied to the release directory using +# +# make install +# +# the release directory must have these subdirectories: +# +# bin documents include src +# +# +# diff --git a/src/3_documents/makeheaders.txt b/src/3_documents/makeheaders.txt new file mode 100644 index 0000000..5aebda9 --- /dev/null +++ b/src/3_documents/makeheaders.txt @@ -0,0 +1,16 @@ + +This worked to force the include to be part of the interface: + +#if INTERFACE +#include +#endif + +But this did not: + +#if INTERFACE + #include +#endif + +makeheaders looks to be sensitive to indentation + + diff --git a/src/3_to_do.txt b/src/3_to_do.txt new file mode 100644 index 0000000..d5f0e34 --- /dev/null +++ b/src/3_to_do.txt @@ -0,0 +1,10 @@ +2019-02-05T23:14:40Z morpheus@manorhouse§~/src/subu§ + error can cause subu-mk-0 to leave the creating of a subu in an intermediate + state. Rather than bailing on some of the errors we need to clean up instead. + Perhaps the yet to be written subu-rm program will be resilent enough to do + more general cleanup. + +2019-02-23T18:56:31Z morpheus@manorhouse§~/subu_land/subu/src§ + need to modify subu-init to take a configuration file name argument instead of + using a global variabel value. might want to add arguments to other subu + commands also diff --git a/src/5_scratch/common.lib.h b/src/5_scratch/common.lib.h new file mode 100644 index 0000000..6b7f7c9 --- /dev/null +++ b/src/5_scratch/common.lib.h @@ -0,0 +1,4 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +typedef unsigned int uint; +#define INTERFACE 0 diff --git a/src/5_scratch/dbprintf.lib.h b/src/5_scratch/dbprintf.lib.h new file mode 100644 index 0000000..3056cf6 --- /dev/null +++ b/src/5_scratch/dbprintf.lib.h @@ -0,0 +1,3 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +int dbprintf(const char *format,...); diff --git a/src/5_scratch/dispatch_exec.lib.h b/src/5_scratch/dispatch_exec.lib.h new file mode 100644 index 0000000..877a38e --- /dev/null +++ b/src/5_scratch/dispatch_exec.lib.h @@ -0,0 +1,4 @@ +/* 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 new file mode 100644 index 0000000..994592d --- /dev/null +++ b/src/5_scratch/dispatch_f.lib.h @@ -0,0 +1,5 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +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,...); +int dispatch_f(char *fname,int(*f)(void *arg),void *f_arg); diff --git a/src/5_scratch/dispatch_useradd.lib.h b/src/5_scratch/dispatch_useradd.lib.h new file mode 100644 index 0000000..ce62797 --- /dev/null +++ b/src/5_scratch/dispatch_useradd.lib.h @@ -0,0 +1,5 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +typedef unsigned int uint; +int dispatch_exec(char **argv,char **envp); +struct dispatch_useradd_ret_t dispatch_useradd(char **argv,char **envp); diff --git a/src/5_scratch/makefile b/src/5_scratch/makefile new file mode 100755 index 0000000..268cf34 --- /dev/null +++ b/src/5_scratch/makefile @@ -0,0 +1,148 @@ + +# 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) + +# 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 +CC=gcc +CFLAGS="-std=c11 -fPIC -I. -ggdb -DDEBUG" +LIB="libsubu.a" +LIBPATH="." #no trailing slash +LINKFLAGS="-L. -lsubu" + +SOURCES_LIB= $(wildcard *.lib.c) +SOURCES_CLI= $(wildcard *.cli.c) +SOURCES= $(SOURCES_LIB) $(SOURCES_CLI) + +OBJECTS_LIB= $(patsubst %.c, %.o, $(SOURCES_LIB)) +OBJECTS_CLI= $(patsubst %.c, %.o, $(SOURCES_CLI)) +OBJECTS= $(OBJECTS_LIB) $(OBJECTS_CLI) + +# 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))) + +version: + @echo '---- make $@:------------------------------------------------------------' + @echo `pwd`'>' + @echo makefile version 2.0 + @echo "CC: " $(CC) + @echo "CFLAGS: " $(CFLAGS) + @echo "LIB: " $(LIB) + @echo "LIBPATH: " $(LIBPATH) + @echo "LINKFLAGS: " $(LINKFLAGS) + @echo '______end make $@_____' + +# 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 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 3_documents ]; then mkdir 3_documents; fi + if [ ! -e 3_to_do.txt ]; then touch 3_to_do.txt; fi + if [ ! -e 5_deprecated ]; then mkdir 5_deprecated; fi + @echo '______end make $@_____' + + +deps: + @echo '---- make $@:------------------------------------------------------------' + @echo `pwd`'>' + $(CC) $(CFLAGS) -MM $(SOURCES) 1> 2_makefile_deps + for i in $(EXECS) ; do\ + echo >> 2_makefile_deps;\ + $(ECHO) "$$i : $$i.cli.o" >> 2_makefile_deps;\ + $(ECHO) " $(CC) -o $$i $$i.cli.o" >> 2_makefile_deps;\ + done + @echo '______end make $@_____' + +lib: clear_test_flags + @echo '---- make $@:------------------------------------------------------------' + @echo `pwd`'>' + if [ ! -e 2_makefile_deps ]; then make deps; fi # the user must delete 2_makefile_deps if deps change! + make sub_lib + @echo '______end make $@_____' + +sub_lib: $(LIB) + + +$(LIBPATH)/$(LIB): + @if [ "$(LIBPATH)" != "$(APPLICATION_BASE)" ]; then \ + echo "LIBPATH: " "$(LIBPATH)";\ + echo "$APPLICATION_BASE: " "$(APPLICATION_BASE)";\ + echo "The library path is not the same as the application base so don't know how to make it.";\ + fi + [ "$(LIBPATH)" == "$(APPLICATION_BASE)" ] + cd $(APPLICATION_BASE); make lib + +execs: $(LIBPATH)/$(LIB) + @echo '---- make $@:------------------------------------------------------------' + @echo `pwd`'>' + if [ ! -e 2_makefile_deps ]; then make deps; fi + make sub_execs + # for i in $(EXEC_OBJECTS); do rm $$i; done + @echo '______end make $@_____' + +sub_execs: $(EXECS) + +install: all + @echo '---- make $@:------------------------------------------------------------' + @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 + cp $(APPLICATION).h $(RT_BASE)/include + if [ -d $(APPLICATION) ]; then cp $(APPLICATION)/*.h $(RT_BASE)/include/$(APPLICATION); fi + @echo '______end make $@_____' + +# "make lib" "make execs" now cleans up the .o files afterward, so clean should not be needed often +# clean works on the current working directory, dist_clean also descends into 1_tests and 1_try +# +clean: + @echo '---- make $@:------------------------------------------------------------' + @echo `pwd`'>' + for i in $(wildcard *~); do mv $$i $(SCRATCHDIR); done + for i in $(wildcard *.lib.o) $(wildcard *.exl.o) $(wildcard *.ex.o); do rm $$i; done + if [ -f 2_makefile_deps ]; then rm 2_makefile_deps; fi + if [ -f $(LIB) ]; then mv $(LIB) 5_scratch; fi + for i in $(EXEC_WL) $(EXEC); do if [ -e $$i ]; then rm $$i; fi; done + @echo '______end make $@_____' + + +# dist_clean is used to clean thing up before doing a checkin, hg add should be safe after a dist_clean +# dist_clean will recurse into the include directory = $(APPLICATION), tests, and try if they are present +# +dist_clean: + @echo '---- make $@:------------------------------------------------------------' + @echo `pwd`'>' + make clean + if [ -d $(APPLICATION) ]; then cd $(APPLICATION); make clean; fi + if [ -d 1_tests ]; then cd 1_tests; make clean; fi + if [ -d 1_try ] ; then cd 1_try; make clean; fi + @echo '______end make $@_____' + + +-include 2_makefile_deps + +# recipe for making object files: +# +%.o : %.cc + $(CC) $(CFLAGS) -c $< + + +# +$(LIB) : $(LIB_OBJECTS) + ar rcs $(LIB) $(LIB_OBJECTS) +# for i in $(LIB_OBJECTS); do rm $$i; done + + + diff --git a/src/5_scratch/subu-config.lib.h b/src/5_scratch/subu-config.lib.h new file mode 100644 index 0000000..d2b1f97 --- /dev/null +++ b/src/5_scratch/subu-config.lib.h @@ -0,0 +1,9 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +#include +typedef unsigned int uint; +int subu_number(sqlite3 *db,uint&subu_number); +int schema(sqlite3 *db,uint max_subu_number); +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 new file mode 100644 index 0000000..46bfd20 --- /dev/null +++ b/src/5_scratch/subu-init.cli.h @@ -0,0 +1,10 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +#include +#define ERR_CONFIG_FILE -1 +typedef unsigned int uint; +int schema(sqlite3 *db,uint max_subu_number); +extern char config_file[]; +int main(); +int main(); +int main(int argc,char **argv,char **env); diff --git a/src/5_scratch/subu-mk-0.cli.h b/src/5_scratch/subu-mk-0.cli.h new file mode 100644 index 0000000..075b350 --- /dev/null +++ b/src/5_scratch/subu-mk-0.cli.h @@ -0,0 +1,8 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +#include +extern char config_file[]; +int subu_mk_0(char *subuname,char *config_file); +int main(); +int main(); +int main(int argc,char **argv,char **env); diff --git a/src/5_scratch/subu-mk-0.lib.h b/src/5_scratch/subu-mk-0.lib.h new file mode 100644 index 0000000..8f6969c --- /dev/null +++ b/src/5_scratch/subu-mk-0.lib.h @@ -0,0 +1,13 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +int dispatch_exec(char **argv,char **envp); +struct dispatch_useradd_ret_t dispatch_useradd(char **argv,char **envp); +int dispatch_f_euid_egid(char *fname,int(*f)(void *arg),void *f_arg,uid_t euid,gid_t egid); +#include +#define ERR_CONFIG_FILE -1 +int dbprintf(const char *format,...); +extern char config_file[]; +int subu_mk_0(char *subuname,char *config_file); +int masteru_makes_subuhome(void *arg); +int allowed_subuname(char *subuname); +typedef unsigned int uint; diff --git a/src/5_scratch/subu-number.cli.h b/src/5_scratch/subu-number.cli.h new file mode 100644 index 0000000..7605c8e --- /dev/null +++ b/src/5_scratch/subu-number.cli.h @@ -0,0 +1,10 @@ +/* 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[]; +int main(); +int main(); +int main(int argc,char **argv,char **env); diff --git a/src/common.lib.c b/src/common.lib.c new file mode 100644 index 0000000..d998b3b --- /dev/null +++ b/src/common.lib.c @@ -0,0 +1,5 @@ + + +#if INTERFACE +typedef unsigned int uint; +#endif diff --git a/src/common.lib.h b/src/common.lib.h new file mode 100644 index 0000000..6b7f7c9 --- /dev/null +++ b/src/common.lib.h @@ -0,0 +1,4 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +typedef unsigned int uint; +#define INTERFACE 0 diff --git a/src/common.lib.o b/src/common.lib.o new file mode 100644 index 0000000..88e4513 Binary files /dev/null and b/src/common.lib.o differ diff --git a/src/dbprintf.lib.c b/src/dbprintf.lib.c index edea747..d9d236b 100644 --- a/src/dbprintf.lib.c +++ b/src/dbprintf.lib.c @@ -1,7 +1,8 @@ +#include "dbprintf.lib.h" + #include #include -#include "dbprintf.aux.h" int dbprintf(const char *format, ...){ va_list args; diff --git a/src/dbprintf.lib.h b/src/dbprintf.lib.h new file mode 100644 index 0000000..3056cf6 --- /dev/null +++ b/src/dbprintf.lib.h @@ -0,0 +1,3 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +int dbprintf(const char *format,...); diff --git a/src/dispatch_exec.lib.c b/src/dispatch_exec.lib.c index 1c3b4ae..024bff8 100644 --- a/src/dispatch_exec.lib.c +++ b/src/dispatch_exec.lib.c @@ -10,18 +10,19 @@ command passed in, and wants better behavior, he or she can spin a special version of dispatch for that command. */ +#include "dispatch_exec.lib.h" // without this #define execvpe is undefined #define _GNU_SOURCE + #include #include - #include #include #include #include -#include "local_common.h" -#include "dispatch_exec.lib.h" + + int dispatch_exec(char **argv, char **envp){ if( !argv || !argv[0] ){ diff --git a/src/dispatch_exec.lib.h b/src/dispatch_exec.lib.h new file mode 100644 index 0000000..877a38e --- /dev/null +++ b/src/dispatch_exec.lib.h @@ -0,0 +1,4 @@ +/* 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/dispatch_f.lib.c b/src/dispatch_f.lib.c index 1548124..cfa75a8 100644 --- a/src/dispatch_f.lib.c +++ b/src/dispatch_f.lib.c @@ -11,18 +11,17 @@ version of dispatch for that command. */ +#include "dispatch_f.lib.h" + // without this #define execvpe is undefined #define _GNU_SOURCE #include #include - #include #include #include #include -#include "local_common.h" -#include "dispatch_f.lib.h" int dispatch_f(char *fname, int (*f)(void *arg), void *f_arg){ char *perror_src = "dispatch_f_as"; diff --git a/src/dispatch_f.lib.h b/src/dispatch_f.lib.h new file mode 100644 index 0000000..994592d --- /dev/null +++ b/src/dispatch_f.lib.h @@ -0,0 +1,5 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +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,...); +int dispatch_f(char *fname,int(*f)(void *arg),void *f_arg); diff --git a/src/dispatch_useradd.lib.c b/src/dispatch_useradd.lib.c index e94ee88..7b75291 100644 --- a/src/dispatch_useradd.lib.c +++ b/src/dispatch_useradd.lib.c @@ -1,17 +1,28 @@ /* -There is no C library interface to useradd(8), but if there were, these functions +There is no C library interface to useradd(8), but if there were, this function would be found there instead. */ +#include "dispatch_useradd.lib.h" #include #include #include #include #include -#include "local_common.h" -#include "dispatch_exec.lib.h" -#include "dispatch_useradd.lib.h" + +#if INTERFACE +#include +#include +#define ERR_DISPATCH_USERADD_ARGC 1 +#define ERR_DISPATCH_USERADD_DISPATCH 2 +#define ERR_DISPATCH_USERADD_PWREC 3 +struct dispatch_useradd_ret_t{ + uint error; + struct passwd *pw_record; +}; +#endif + // we have a contract with the caller that argv[1] is always the subuname struct dispatch_useradd_ret_t dispatch_useradd(char **argv, char **envp){ @@ -19,7 +30,7 @@ struct dispatch_useradd_ret_t dispatch_useradd(char **argv, char **envp){ { if( !argv || !argv[0] || !argv[1]){ fprintf(stderr,"useradd() needs a first argument as the name of the user to be made"); - ret.error = DISPATCH_USERADD_ERR_ARGC; + ret.error = ERR_DISPATCH_USERADD_ARGC; ret.pw_record = NULL; return ret; } @@ -29,7 +40,7 @@ struct dispatch_useradd_ret_t dispatch_useradd(char **argv, char **envp){ subu_name = argv[1]; if( dispatch_exec(argv, envp) == -1 ){ fprintf(stderr,"%s failed\n", argv[0]); - ret.error = DISPATCH_USERADD_ERR_DISPATCH; + ret.error = ERR_DISPATCH_USERADD_DISPATCH; ret.pw_record = NULL; return ret; }} @@ -46,7 +57,7 @@ struct dispatch_useradd_ret_t dispatch_useradd(char **argv, char **envp){ count++; } if( !pw_record ){ - ret.error = DISPATCH_USERADD_ERR_PWREC; + ret.error = ERR_DISPATCH_USERADD_PWREC; ret.pw_record = NULL; return ret; } diff --git a/src/dispatch_useradd.lib.h b/src/dispatch_useradd.lib.h new file mode 100644 index 0000000..0ce7e9d --- /dev/null +++ b/src/dispatch_useradd.lib.h @@ -0,0 +1,16 @@ +/* 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/dispatch_useradd.lib.o b/src/dispatch_useradd.lib.o new file mode 100644 index 0000000..079dd04 Binary files /dev/null and b/src/dispatch_useradd.lib.o differ diff --git a/src/duck/local_common.h b/src/duck/local_common.h deleted file mode 100644 index bb60b59..0000000 --- a/src/duck/local_common.h +++ /dev/null @@ -1,4 +0,0 @@ - - -typedef unsigned int uint; - diff --git a/src/local_common.h b/src/local_common.h deleted file mode 100644 index bb60b59..0000000 --- a/src/local_common.h +++ /dev/null @@ -1,4 +0,0 @@ - - -typedef unsigned int uint; - diff --git a/src/makefile b/src/makefile index 85e94a5..ddfcfdd 100755 --- a/src/makefile +++ b/src/makefile @@ -1,260 +1,103 @@ # Copyright 2011 (C) Reasoning Technology Ltd. All Rights Reserved # # 2010 11 20 TWL Created -# 2011 05 26 TWL Modified to generalize -# 2012 02 23 NLS Add ECHO variable to use on different environnement -# corrected setup macro --> add include directory in the path to copy -# corrected install macro --> change the name of installed library : lib$(LIB)$(LIBSUFFIX) -# changed DOC_DIR directory name to 5_documents -# 2012 02 23 TWL removed LIB variable which is now set from the command line so -# so that all source dirs can use the same makefile -# 2012 02 23 TWL added target make dist_clean which also deletes the 2_makefile_deps file -# 2012 04 11 AWW added creation of temporary disk before each test is run -# 2012 06 05 TWL moved tests and try .cc files to directories. caused rtmake tests to -# dist_clean and make deps -# -# -#---------------------------------------------------------------------------- -# use this makefile to compile and test the code: -# -# for a first time run, or for regression use the following: -# -# $ make setup # makes the directories, though should already exist -# $ make regress -# -# the usual development workflow makes use of these: -# -# $ make deps # only when needed, for example if headers includes change or new files introduced -# $ cd tests; make deps # only when needed -# $ make lib # this makes the local library -# $ make tests # this updates tests and compiles -# $ make clean # deletes the .o files and library to force a recompile -# $ cd 1_tests; make clean -# -# for a release of a component -# -# $ make regress -# $ make install # this will only work if all the tests in 1_tests are passing -# -# before a checkin -# -# $ make dist_clean # will also clean the tests and try directories -# -# .lib.cc c++ files taken as source of object files for local build library -# .exl.cc c++ files taken to have main calls and are linked against local build libary -# .ex.cc c++ files taken to have main calls and are not linked against the local build library -# there are no rules for other files in this makefile -# -# about dependencies -# The makefile has no way of knowing if an edit changed the dependencies. Often they do not -# and it would be unwieldy to make the deps every time. Hence *the programmer* must delete -# the deps file if he has made any changes that change the dependencies. -# -# The makefile will make the 2_makefile_deps if the file is missing. -# -# -# about testing -# -# the name of the directory you run make in is taken to also be: the name of the library, -# the name of the main include file (with a .h added), and the name of the include directory -# where the individual headers are found. It is called LIB -# -# test programs are kept in a subdirectory called 1_tests, and are either .exl.cc, ex.cc, -# .sh files. When 'make tests' target is invoked they are all run. Test executables return 0 -# if the test fails, non-zero otherwise. -# -# to remove a test from the pool move it into the subdirectory in 1_tests, 9_broken, -# 5_more_tests of 5_scratch. broken tests are things that are known but must be fixed -# before a release. 5_more_tests are tests being worked on. 5_scratch is stuff that is -# probably going to be deleted. if there is a 5_deprecated, that is for good stuff but it -# is no longer used for some reason or other. -# -# There is a standard source code template and a -# messaging convention. Also, the names, by convention,are test_xxxx_ where xxx is a -# hexadecimal series nummber. If all the test executables pass the file 1_TESTS_PASSED is -# left in the directory. Otherwise the file 1_TESTS_FAILED is left in the directory. -# -# about release directory -# -# this is set in the ApplicationBase variable by rt_init -# -# after the tests pass stuff might be copied to the release directory using -# -# make install -# -# the release directory must have these subdirectories: -# -# bin documents include src -# -# -# - -# set the shell to use -SHELL=/bin/bash +# 2019 02 24 TWL modified for subu project and placed under MIT license -# the LIB variable is now passed in to us as a parameter to make, see 'rtmake' -# LIB= +# 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) # 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 -# 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 SCRATCHDIR= 5_scratch # clean and others put things here +CC=gcc +CFLAGS=-std=c11 -fPIC -I. -ggdb -DDEBUG +LIB="libsubu.a" +LIBPATH="." #no trailing slash +LINKFLAGS="-L. -lsubu" +#these are the source files that exist +SOURCES_LIB= $(wildcard *.lib.c) +SOURCES_CLI= $(wildcard *.cli.c) +SOURCES= $(SOURCES_LIB) $(SOURCES_CLI) -# see 2_bin/local_build for the compile and link flags -SOURCES= $(wildcard *.lib.cc) $(wildcard *.exl.cc) $(wildcard *.ex.cc) +#these are the object files to be made +OBJECTS_LIB= $(patsubst %.c, %.o, $(SOURCES_LIB)) +OBJECTS_CLI= $(patsubst %.c, %.o, $(SOURCES_CLI)) +OBJECTS= $(OBJECTS_LIB) $(OBJECTS_CLI) -OBJECTS= $(patsubst %.cc, %.o, $(SOURCES)) -LIB_OBJECTS= $(patsubst %.cc, %.o, $(wildcard *.lib.cc)) -EXEC_OBJECTS= $(patsubst %.cc, %.o, $(wildcard *.ex.cc) $(wildcard *.exl.cc) ) +#these are the header files that exist, makeheaders will want to see them +HFILES = $(wildcard *.lib.h) $(wildcard *.cli.h) -# the sort causes compiles to go in lexical order by file name, this is used to order the tests e.g. -EXEC= $(sort $(patsubst %.ex.cc, %, $(wildcard *.ex.cc))) -EXEC_WL= $(sort $(patsubst %.exl.cc, %, $(wildcard *.exl.cc))) -EXECS= $(sort $(EXEC_WL) $(EXEC)) +# 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))) + +all: version deps lib execs version: - @echo '---- rtmake $@:------------------------------------------------------------' - @echo `pwd`'>' - @echo source_local_makefile version 4.0 - @echo "RT_BASE: " $(RT_BASE) - @echo "APPLICATION_BASE: " $(APPLICATION_BASE) - @echo "APPLICATION: " $(APPLICATION) - @echo "CXX: " $(CXX) - @echo "CXXFLAGS: " $(CXXFLAGS) + @echo '---- make $@:------------------------------------------------------------' + @echo `pwd`'>' + @echo makefile version 2.0 + @echo "CC: " $(CC) + @echo "CFLAGS: " $(CFLAGS) @echo "LIB: " $(LIB) @echo "LIBPATH: " $(LIBPATH) @echo "LINKFLAGS: " $(LINKFLAGS) - @echo "note, the rt bin directory, and the application 2_bin directory must be in the path for rtmake to work:" - @echo "PATH: " $(PATH) - @echo '______end rtmake $@_____' - - -# chances are if you got to this makefile that rt_init has been run, but we can catch application_init here -# -init: - @if [ "$(RT_BASE)" == "" ]; then echo "init_rt has not been sourced"; exit 1; fi - @if [ "$(APPLICATION_BASE)" == "" ]; then echo "init_application has not been sourced"; exit 1; fi - - - -all: regress + @echo '______end make $@_____' # safe to run this in an already setup or partially setup directory setup: - @echo '---- rtmake $@:------------------------------------------------------------' + @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' if [ ! -e $(SCRATCHDIR) ]; then mkdir $(SCRATCHDIR); fi - if [ ! -e $(RT_BASE)/include/$(APPLICATION) ]; then mkdir $(RT_BASE)/include/$(APPLICATION); fi # a place to put the individual header files - if [ ! -e 0_Copyright_Notice.txt ]; then cp $(RT_BASE)/documents/0_Copyright_Notice.txt .; 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 3_documents ]; then mkdir 3_documents; fi if [ ! -e 3_to_do.txt ]; then touch 3_to_do.txt; fi if [ ! -e 5_deprecated ]; then mkdir 5_deprecated; fi - @echo '______end rtmake $@_____' + @echo '______end make $@_____' -deps: init - @echo '---- rtmake $@:------------------------------------------------------------' +deps: + @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' - $(CXX) $(CXXFLAGS) -MM $(SOURCES) 1> 2_makefile_deps - for i in $(EXEC_WL) ; do\ - $(ECHO) >> 2_makefile_deps;\ - $(ECHO) "$$i : $$i.exl.o $(LIBPATH)/$(LIB)" >> 2_makefile_deps;\ - $(ECHO) " $(CXX) -o $$i $$i.exl.o $(LINKFLAGS)" >> 2_makefile_deps;\ - done - for i in $(EXEC) ; do\ - echo >> 2_makefile_deps;\ - $(ECHO) "$$i : $$i.ex.o" >> 2_makefile_deps;\ - $(ECHO) " $(CXX) -o $$i $$i.ex.o" >> 2_makefile_deps;\ - done - @echo '______end rtmake $@_____' - -lib: init clear_test_flags - @echo '---- rtmake $@:------------------------------------------------------------' + makeheaders $(SOURCES) $(HFILES) + $(CC) $(CFLAGS) -MM $(SOURCES) 1> 2_makefile_deps + for i in $(EXECS) ; do\ + $(ECHO) >> 2_makefile_deps;\ + $(ECHO) "$$i : $$i.cli.o $(LIBPATH)/$(LIB)" >> 2_makefile_deps;\ + $(ECHO) " $(CXX) -o $$i $$i.cli.o $(LINKFLAGS)" >> 2_makefile_deps;\ + done + @echo '______end make $@_____' + +lib: + @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' - if [ ! -e 2_makefile_deps ]; then rtmake deps; fi # the user must delete 2_makefile_deps if deps change! - rtmake sub_lib - @echo '______end rtmake $@_____' + if [ ! -e 2_makefile_deps ]; then make deps; fi # the user must delete 2_makefile_deps if deps change! + make sub_lib + @echo '______end make $@_____' sub_lib: $(LIB) -$(LIBPATH)/$(LIB): - @if [ "$(LIBPATH)" != "$(APPLICATION_BASE)" ]; then \ - echo "LIBPATH: " "$(LIBPATH)";\ - echo "$APPLICATION_BASE: " "$(APPLICATION_BASE)";\ - echo "The library path is not the same as the application base so don't know how to make it.";\ - fi - [ "$(LIBPATH)" == "$(APPLICATION_BASE)" ] - cd $(APPLICATION_BASE); rtmake lib - -execs: init $(LIBPATH)/$(LIB) - @echo '---- rtmake $@:------------------------------------------------------------' +execs: $(LIBPATH)/$(LIB) + @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' - if [ ! -e 2_makefile_deps ]; then rtmake deps; fi - rtmake sub_execs - # for i in $(EXEC_OBJECTS); do rm $$i; done - @echo '______end rtmake $@_____' + if [ ! -e 2_makefile_deps ]; then make deps; fi + make sub_execs + @echo '______end make $@_____' sub_execs: $(EXECS) - -clear_test_flags: - @if [ ! -d 1_tests ]; then echo "can only rtmake tests when there is a 1_tests directory, did you mean: rtmake execs ?"; fi - @ test -d 1_tests # we only need to clear tests flags when there is a tests dir - @echo '---- rtmake $@:------------------------------------------------------------' - @echo `pwd`'>' - echo `date_stamp` $(APPLICATION) > 1_tests_log - if [ -f 1_tests_passed ]; then \ - if [ `repo_tracks 1_tests_passed` == "y" ]; then hg rm 1_tests_passed; else rm 1_tests_passed; fi; \ - fi - if [ -f 1_tests_failed ]; then \ - if [ `repo_tracks 1_tests_failed` == "y" ]; then hg rm 1_tests_failed; else rm 1_tests_failed; fi; \ - fi - echo "tests have not been run" > 1_tests_log - @echo '______end rtmake $@_____' - -tests: clear_test_flags - @echo '---- rtmake $@:------------------------------------------------------------' - @echo `pwd`'>' - echo `date_stamp` $(APPLICATION) > 1_tests_log - cd 1_tests; rtmake sub_test; - @echo '______end rtmake $@_____' - -sub_test: - rtmake execs - for i in $(EXECS); do \ - echo >> ../1_tests_log; \ - echo ">$$i launching .." | tee -a ../1_tests_log;\ - if ./$$i 2>> ../1_tests_log; then echo ">$$i passed" | tee -a ../1_tests_log; else echo "#>$$i failed" | tee -a ../1_tests_log; touch ../1_tests_failed; fi;\ - done - if [ -e ../1_tests_failed ]; then echo "test set FAIL" | tee -a ../1_tests_log; \ - else echo "test set PASS" | tee -a ../1_tests_log; touch ../1_tests_passed; fi #if none failed, then they passed - -regress: init - @if [ ! -d 1_tests ]; then echo "can only do regression when there is a 1_tests directory"; fi - @test -d 1_tests - @echo '---- rtmake $@:------------------------------------------------------------' - @echo `pwd`'>' - rtmake dist_clean - rtmake deps - rtmake lib - rtmake tests - @echo '______end rtmake $@_____' - +#not ready yet install: all - @echo '---- rtmake $@:------------------------------------------------------------' + @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' @if[ ! -e 1_tests_passed ]; then echo "can't install as tests have not passed"; fi @test -e test_passed @@ -262,47 +105,42 @@ install: all cp $(LIB) $(RT_BASE)/lib cp $(APPLICATION).h $(RT_BASE)/include if [ -d $(APPLICATION) ]; then cp $(APPLICATION)/*.h $(RT_BASE)/include/$(APPLICATION); fi - @echo '______end rtmake $@_____' + @echo '______end make $@_____' -# "rtmake lib" "rtmake execs" now cleans up the .o files afterward, so clean should not be needed often -# clean works on the current working directory, dist_clean also descends into 1_tests and 1_try -# -clean: init - @echo '---- rtmake $@:------------------------------------------------------------' +clean: + @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' for i in $(wildcard *~); do mv $$i $(SCRATCHDIR); done - for i in $(wildcard *.lib.o) $(wildcard *.exl.o) $(wildcard *.ex.o); do rm $$i; 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 if [ -f 2_makefile_deps ]; then rm 2_makefile_deps; fi - if [ -f $(LIB) ]; then mv $(LIB) 5_scratch; fi - for i in $(EXEC_WL) $(EXEC); do if [ -e $$i ]; then rm $$i; fi; done - @echo '______end rtmake $@_____' + if [ -f $(LIB) ]; then rm $(LIB); fi + for i in $(EXECS); do if [ -e $$i ]; then rm $$i; fi; done + @echo '______end make $@_____' +# not ready ... # dist_clean is used to clean thing up before doing a checkin, hg add should be safe after a dist_clean # dist_clean will recurse into the include directory = $(APPLICATION), tests, and try if they are present # -dist_clean: init - @echo '---- rtmake $@:------------------------------------------------------------' +dist_clean: + @echo '---- make $@:------------------------------------------------------------' @echo `pwd`'>' - rtmake clean - if [ -d $(APPLICATION) ]; then cd $(APPLICATION); rtmake clean; fi - if [ -d 1_tests ]; then cd 1_tests; rtmake clean; fi - if [ -d 1_try ] ; then cd 1_try; rtmake clean; fi - @echo '______end rtmake $@_____' + make clean + if [ -d $(APPLICATION) ]; then cd $(APPLICATION); make clean; fi + if [ -d 1_tests ]; then cd 1_tests; make clean; fi + if [ -d 1_try ] ; then cd 1_try; make clean; fi + @echo '______end make $@_____' -include 2_makefile_deps # recipe for making object files: # -%.o : %.cc - $(CXX) $(CXXFLAGS) -c $< +%.o : %.c + $(CC) $(CFLAGS) -c $< # -$(LIB) : $(LIB_OBJECTS) - ar rcs $(LIB) $(LIB_OBJECTS) -# for i in $(LIB_OBJECTS); do rm $$i; done - - - +$(LIB) : $(OBJECTS_LIB) + ar rcs $(LIB) $(OBJECTS_LIB) diff --git a/src/subu-config.lib.c b/src/subu-config.lib.c index 7577d30..8706aaf 100644 --- a/src/subu-config.lib.c +++ b/src/subu-config.lib.c @@ -10,14 +10,16 @@ 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 "subu-config.lib.h" +#include //char config_file[] = "/etc/subu.db"; char config_file[] = "subu.db"; @@ -48,8 +50,8 @@ int schema(sqlite3 *db, uint max_subu_number){ return sqlite3_exec(db, sql, NULL, NULL, NULL); } -int subu_number(sqlite3 *db, uint &subu_number){ - subu_number = 0; +int subu_number(sqlite3 *db, uint **subu_number){ + *subu_number = 0; char *sql = "BEGIN TRANSACTION;" "UPDATE Key_Int SET value = value + 1 WHERE key = 'max_subu_number';" @@ -60,9 +62,6 @@ int subu_number(sqlite3 *db, uint &subu_number){ sqlite3_stmt *stmt; ret = sqlite3_prepare_v2(db, sql, sql_len, &stmt, NULL); if( ret != SQLITE_OK ){ - free(subuland); - free(subuhome); - sqlite3_close(db); return ERR_CONFIG_FILE; } sqlite3_stmt *res; diff --git a/src/subu-config.lib.h b/src/subu-config.lib.h index d2b1f97..c359b52 100644 --- a/src/subu-config.lib.h +++ b/src/subu-config.lib.h @@ -2,7 +2,7 @@ #undef INTERFACE #include typedef unsigned int uint; -int subu_number(sqlite3 *db,uint&subu_number); +int subu_number(sqlite3 *db,uint **subu_number); int schema(sqlite3 *db,uint max_subu_number); extern char config_file[]; #define ERR_CONFIG_FILE -1 diff --git a/src/subu-config.lib.o b/src/subu-config.lib.o deleted file mode 100644 index ff24969..0000000 Binary files a/src/subu-config.lib.o and /dev/null differ diff --git a/src/subu-init.cli.h b/src/subu-init.cli.h index d4418ca..46bfd20 100644 --- a/src/subu-init.cli.h +++ b/src/subu-init.cli.h @@ -6,3 +6,5 @@ typedef unsigned int uint; int schema(sqlite3 *db,uint max_subu_number); extern char config_file[]; int main(); +int main(); +int main(int argc,char **argv,char **env); diff --git a/src/subu-init.cli.o b/src/subu-init.cli.o deleted file mode 100644 index ca91858..0000000 Binary files a/src/subu-init.cli.o and /dev/null differ diff --git a/src/subu-mk-0.cli.h b/src/subu-mk-0.cli.h new file mode 100644 index 0000000..075b350 --- /dev/null +++ b/src/subu-mk-0.cli.h @@ -0,0 +1,8 @@ +/* This file was automatically generated. Do not edit! */ +#undef INTERFACE +#include +extern char config_file[]; +int subu_mk_0(char *subuname,char *config_file); +int main(); +int main(); +int main(int argc,char **argv,char **env); diff --git a/src/subu-mk-0.lib.c b/src/subu-mk-0.lib.c index 7c3836c..5c1bc88 100644 --- a/src/subu-mk-0.lib.c +++ b/src/subu-mk-0.lib.c @@ -16,6 +16,7 @@ */ +#include "subu-mk-0.lib.h" // without this #define we get the warning: implicit declaration of function ‘seteuid’/‘setegid’ #define _GNU_SOURCE @@ -30,12 +31,19 @@ #include #include #include -#include "dispatch_f.lib.h" -#include "dispatch_exec.lib.h" -#include "dispatch_useradd.lib.h" -#include "subu-mk-0.lib.h" -typedef unsigned int uint; +#if INTERFACE +#define ERR_SUBU_MK_0_CONFIG_FILE 1 +#define ERR_SUBU_MK_0_SETUID_ROOT 2 +#define ERR_SUBU_MK_0_BAD_MASTERU_HOME 3 +#define ERR_SUBU_MK_0_MALLOC 4 +#define ERR_SUBU_MK_0_MK_SUBUHOME 5 +#define ERR_SUBU_MK_0_FAILED_MKDIR_SUBU 6 +#define ERR_SUBU_MK_0_BUG_SSS 7 +#define ERR_SUBU_MK_0_FAILED_USERADD 8 +#define ERR_SUBU_MK_0_SETFACL 9 +#endif + /* Fedora 29's sss_cache is checking the inherited uid instead of the effective @@ -50,30 +58,30 @@ static uint max_subuname_len = 128; // a well formed subuname // returns the length of the subuname, or -1 int allowed_subuname(char *subuname){ - char *ch = token; + char *ch = subuname; uint i = 0; while( *ch && i < max_subuname_len && - ( ch >= 'a' && ch <= 'z' + ( *ch >= 'a' && *ch <= 'z' || - ch >= 'A' && ch <= 'Z' + *ch >= 'A' && *ch <= 'Z' || - ch >= '0' && ch <= '9' + *ch >= '0' && *ch <= '9' || - ch == '_' + *ch == '_' || - ch == '.' + *ch == '.' || - ch == ' ' + *ch == ' ' ) ){ ch++; i++; } - if( !*ch && i < max_len; ) + if( !*ch && i < max_subuname_len ) return i; else return -1; @@ -100,8 +108,8 @@ int subu_mk_0(char *subuname, char *config_file){ sqlite3 *db; { if( sqlite3_open(config_file, &db) ){ - fprintf(stderr, "error exit, could not open config file, \"%s\"\n", file); - return ERR_CONFIG_FILE; + fprintf(stderr, "error exit, could not open config file, \"%s\"\n", config_file); + return ERR_SUBU_MK_0_CONFIG_FILE; } } @@ -124,7 +132,7 @@ int subu_mk_0(char *subuname, char *config_file){ if( masteru_uid == 0 || set_euid != 0 ){ fprintf(stderr, "error exit, this program must be run setuid root from a user account\n"); sqlite3_close(db); - return ERR_SETUID_ROOT; + return ERR_SUBU_MK_0_SETUID_ROOT; } } @@ -141,7 +149,7 @@ int subu_mk_0(char *subuname, char *config_file){ if( subuname_len == -1 ){ fprintf(stderr, "error exit, subuname is not in [ _.a-zA-Z0-9]* less than %u characters", max_subuname_len); sqlite3_close(db); - return ERR_CONFIG_FILE; + return ERR_SUBU_MK_0_CONFIG_FILE; } } @@ -159,7 +167,7 @@ int subu_mk_0(char *subuname, char *config_file){ char *subuhome; size_t subuhome_len; { - masteru_pw_record_pt = getpwuid(masteru_uid); // reading /etc/passwd + struct passwd *masteru_pw_record_pt = getpwuid(masteru_uid); // reading /etc/passwd masteru_name = masteru_pw_record_pt->pw_name; #ifdef DEBUG dbprintf("masteru_name \"%s\"\n", masteru_name); @@ -171,7 +179,7 @@ int subu_mk_0(char *subuname, char *config_file){ if( masteru_name_len == -1 ){ fprintf(stderr, "error exit, masteru_name is not in [ _.a-zA-Z0-9]* less than %u characters", max_subuname_len); sqlite3_close(db); - return ERR_CONFIG_FILE; + return ERR_SUBU_MK_0_CONFIG_FILE; } masteru_home = masteru_pw_record_pt->pw_dir; #ifdef DEBUG @@ -181,7 +189,7 @@ int subu_mk_0(char *subuname, char *config_file){ if( masteru_home_len == 0 || masteru_home[0] == '(' ){ fprintf(stderr,"error exit, %s has no home directory\n", masteru_name); sqlite3_close(db); - return ERR_BAD_MASTERU_HOME; + return ERR_SUBU_MK_0_BAD_MASTERU_HOME; } char *subuland_extension = "/subuland/"; size_t subuland_extension_len = strlen(subuland_extension); @@ -198,7 +206,7 @@ int subu_mk_0(char *subuname, char *config_file){ perror(perror_src); free(subuland); sqlite3_close(db); - return ERR_MALLOC; + return ERR_SUBU_MK_0_MALLOC; } strcpy (subuhome, subuland); strcpy (subuhome + subuland_len, subuname); @@ -220,7 +228,7 @@ int subu_mk_0(char *subuname, char *config_file){ free(subuland); free(subuhome); sqlite3_close(db); - return ERR_MK_SUBUHOME; + return ERR_SUBU_MK_0_MK_SUBUHOME; } int ret = dispatch_f_euid_egid ( @@ -235,7 +243,7 @@ int subu_mk_0(char *subuname, char *config_file){ free(subuland); free(subuhome); sqlite3_close(db); - return ERR_FAILED_MKDIR_SUBU; + return ERR_SUBU_MK_0_FAILED_MKDIR_SUBU; } } #ifdef DEBUG @@ -267,7 +275,7 @@ int subu_mk_0(char *subuname, char *config_file){ free(subuland); free(subuhome); sqlite3_close(db); - return ERR_BUG_SSS; + return ERR_SUBU_MK_0_BUG_SSS; } #endif char *command = "/usr/sbin/useradd"; @@ -287,7 +295,7 @@ int subu_mk_0(char *subuname, char *config_file){ free(subuland); free(subuhome); sqlite3_close(db); - return ERR_FAILED_USERADD; + return ERR_SUBU_MK_0_FAILED_USERADD; } #ifdef DEBUG dbprintf("useradd finished\n"); @@ -344,7 +352,7 @@ int subu_mk_0(char *subuname, char *config_file){ free(subuland); free(subuhome); sqlite3_close(db); - return ERR_SETFACL; + return ERR_SUBU_MK_0_SETFACL; } // 2.1 x acls on subuland // setfacl -m u:subuname:x subuland @@ -357,7 +365,7 @@ int subu_mk_0(char *subuname, char *config_file){ free(subuland); free(subuhome); sqlite3_close(db); - return ERR_SETFACL; + return ERR_SUBU_MK_0_SETFACL; } // 2.2 x acls on masteru_home // setfacl -m u:subuname:x masteru_home @@ -367,7 +375,7 @@ int subu_mk_0(char *subuname, char *config_file){ free(subuland); free(subuhome); sqlite3_close(db); - return ERR_SETFACL; + return ERR_SUBU_MK_0_SETFACL; } // 3. give subu ownership of subuhome @@ -406,7 +414,7 @@ int subu_mk_0(char *subuname, char *config_file){ free(subuland); free(subuhome); sqlite3_close(db); - return ERR_SETFACL; + return ERR_SUBU_MK_0_SETFACL; } #ifdef DEBUG dbprintf("masteru now has default access\n"); diff --git a/src/subu-mk-0.lib.h b/src/subu-mk-0.lib.h new file mode 100644 index 0000000..82c7e14 --- /dev/null +++ b/src/subu-mk-0.lib.h @@ -0,0 +1,29 @@ +/* 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); +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[]; +int subu_mk_0(char *subuname,char *config_file); +int masteru_makes_subuhome(void *arg); +int allowed_subuname(char *subuname); +#define ERR_SUBU_MK_0_SETFACL 9 +#define ERR_SUBU_MK_0_FAILED_USERADD 8 +#define ERR_SUBU_MK_0_BUG_SSS 7 +#define ERR_SUBU_MK_0_FAILED_MKDIR_SUBU 6 +#define ERR_SUBU_MK_0_MK_SUBUHOME 5 +#define ERR_SUBU_MK_0_MALLOC 4 +#define ERR_SUBU_MK_0_BAD_MASTERU_HOME 3 +#define ERR_SUBU_MK_0_SETUID_ROOT 2 +#define ERR_SUBU_MK_0_CONFIG_FILE 1 +#define INTERFACE 0 diff --git a/src/subu-mk-0.lib.o b/src/subu-mk-0.lib.o new file mode 100644 index 0000000..0322536 Binary files /dev/null and b/src/subu-mk-0.lib.o differ diff --git a/src/subu-number.cli.h b/src/subu-number.cli.h new file mode 100644 index 0000000..759d808 --- /dev/null +++ b/src/subu-number.cli.h @@ -0,0 +1,10 @@ +/* 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[]; +int main(); +int main(); +int main(int argc,char **argv,char **env);