/* \aThis file was automatically generated. Do not edit! */
#undef INTERFACE
typedef unsigned int uint;
+extern uint first_max_subu_number;
extern uint subuhome_perms;
extern char config_file[];
#define BUG_SSS_CACHE_RUID 1
int subu_number_get(sqlite3 *db,char **nsp,char **errmsg);
typedef unsigned int uint;
int schema(sqlite3 *db,uint max_subu_number);
-#define ERR_CONFIG_FILE -1
+#define ERR_CONFIG_FILE 1
#define INTERFACE 0
/* \aThis file was automatically generated. Do not edit! */
#undef INTERFACE
-#include <sqlite3.h>
-#define ERR_CONFIG_FILE -1
typedef unsigned int uint;
+extern uint first_max_subu_number;
+#include <sqlite3.h>
int schema(sqlite3 *db,uint max_subu_number);
+#define ERR_CONFIG_FILE 1
extern char config_file[];
char *aux;
uint err;
};
-#define ERR_SUBU_MK_0_FAILED_USERADD 9
-#define ERR_SUBU_MK_0_BUG_SSS 8
-#define ERR_SUBU_MK_0_SUBUHOME_EXISTS 7
-#define ERR_SUBU_MK_0_CONFIG_FILE 6
-#define ERR_SUBU_MK_0_MALLOC 5
-#define ERR_SUBU_MK_0_MASTERU_HOMELESS 4
-#define ERR_SUBU_MK_0_SETUID_ROOT 3
-#define ERR_SUBU_MK_0_SUBUNAME_MALFORMED 2
+#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
#undef INTERFACE
#include <sqlite3.h>
int subu_number_get(sqlite3 *db,char **nsp,char **errmsg);
-#define ERR_CONFIG_FILE -1
+#define ERR_CONFIG_FILE 1
extern char config_file[];
#undef INTERFACE
#include <sqlite3.h>
int subu_put_masteru_subu(sqlite3 *db,char *masteru_name,char *subuname,char *subu_username);
-#define ERR_CONFIG_FILE -1
+#define ERR_CONFIG_FILE 1
extern char config_file[];
// char *config_file = "/etc/subu.db";
char config_file[] = "subu.db";
uint subuhome_perms = 0700;
+uint first_max_subu_number = 114;
#if INTERFACE
#include <sqlite3.h>
-#define ERR_CONFIG_FILE -1
+#define ERR_CONFIG_FILE 1
#endif
#include <stdio.h>
int main(){
sqlite3 *db;
- if(
- sqlite3_open(config_file, &db)
- ||
- schema(db, 10)
- ){
- fprintf(stderr, "error exit, could not build schema\n");
+ if( sqlite3_open_v2(config_file, &db, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK ){
+ fprintf(stderr, "error exit, could not open configuration file\n");
return ERR_CONFIG_FILE;
}
- if( sqlite3_close(db) ){
- fprintf(stderr, "error exit, strange, we could not close the db\n");
+ if( schema(db, first_max_subu_number) != SQLITE_OK ){
+ fprintf(stderr, "error exit, opened config file but could not build scheme\n");
+ return ERR_CONFIG_FILE;
+ }
+ if( sqlite3_close(db) != SQLITE_OK ){
+ fprintf(stderr, "error exit, could not close the db\n");
return ERR_CONFIG_FILE;
}
return 0;
//
#if INTERFACE
#define ERR_SUBU_MK_0_MKDIR_SUBUHOME 1
-#define ERR_SUBU_MK_0_SUBUNAME_MALFORMED 2
-#define ERR_SUBU_MK_0_SETUID_ROOT 3
-#define ERR_SUBU_MK_0_MASTERU_HOMELESS 4
-#define ERR_SUBU_MK_0_MALLOC 5
-#define ERR_SUBU_MK_0_CONFIG_FILE 6
-#define ERR_SUBU_MK_0_SUBUHOME_EXISTS 7
-#define ERR_SUBU_MK_0_BUG_SSS 8
-#define ERR_SUBU_MK_0_FAILED_USERADD 9
+#define ERR_SUBU_MK_0_RMDIR_SUBUHOME 2
+#define ERR_SUBU_MK_0_SUBUNAME_MALFORMED 3
+#define ERR_SUBU_MK_0_SETUID_ROOT 4
+#define ERR_SUBU_MK_0_MASTERU_HOMELESS 5
+#define ERR_SUBU_MK_0_MALLOC 6
+#define ERR_SUBU_MK_0_CONFIG_FILE 7
+#define ERR_SUBU_MK_0_SUBUHOME_EXISTS 8
+#define ERR_SUBU_MK_0_BUG_SSS 9
+#define ERR_SUBU_MK_0_FAILED_USERADD 10
struct subu_mk_0_ctx{
char *name;
// dispatched functions
//
// the making of subuhome is dispatched to its own process so as to give it its own uid/gid
-static int masteru_makes_subuhome(void *arg){
+static int masteru_mkdir_subuhome(void *arg){
char *subuhome = (char *) arg;
if( mkdir( subuhome, subuhome_perms ) == -1 ){ // find subuhome perms in common
- perror("masteru_makes_subuhome");
+ perror("masteru_mkdir_subuhome");
return ERR_SUBU_MK_0_MKDIR_SUBUHOME;
}
return 0;
}
+static int masteru_rmdir_subuhome(void *arg){
+ char *subuhome = (char *) arg;
+ if( rmdir( subuhome ) == -1 ){ // find subuhome perms in common
+ perror("masteru_rmdir_subuhome");
+ return ERR_SUBU_MK_0_RMDIR_SUBUHOME;
+ }
+ return 0;
+}
//--------------------------------------------------------------------------------
// the public call point
}
dispatch_ctx *dfr = dispatch_f_euid_egid
(
- "masteru_makes_subuhome",
- masteru_makes_subuhome,
+ "masteru_mkdir_subuhome",
+ masteru_mkdir_subuhome,
(void *)ctxp->subuhome,
masteru_uid,
masteru_gid
envp[0] = (char *) NULL;
dispatch_ctx *dfr = dispatch_exec(argv, envp);
if( dfr->err != 0 ){
- #ifdef DEBUG
+ #ifdef DEBUG
if( dfr->err <= ERR_DISPATCH )
dispatch_f_mess(dfr);
else
perror("useradd");
#endif
+ // go back and remove the directory we made in subuland
+ dispatch_ctx *dfr = dispatch_f_euid_egid
+ (
+ "masteru_rmdir_subuhome",
+ masteru_rmdir_subuhome,
+ (void *)ctxp->subuhome,
+ masteru_uid,
+ masteru_gid
+ );
+ #ifdef DEBUG
+ if( dfr->err <= ERR_DISPATCH || dfr->err == ERR_SUBU_MK_0_RMDIR_SUBUHOME )
+ if( dfr->err == ERR_SUBU_MK_0_RMDIR_SUBUHOME )
+ perror("rmdir");
+ else
+ dispatch_f_mess(dfr);
+ #endif
ctxp->err = ERR_SUBU_MK_0_FAILED_USERADD;
return ctxp;
}