00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 #include <stdio.h>
00035 #include <string.h>
00036 #include <libgen.h>
00037 #include <assert.h>
00038
00039 #ifdef HAVE_LIBXML2
00040 #include <libxml/tree.h>
00041 #include <libxml/xpath.h>
00042 #include <libxml/xmlstring.h>
00043 #endif
00044
00045 #include <eurephia_nullsafe.h>
00046 #include <eurephia_context.h>
00047 #include <eurephiadb.h>
00048 #include <eurephiadb_driver.h>
00049 #include <eurephia_values.h>
00050 #include <eurephia_xml.h>
00051
00052 #define MODULE "eurephia_init"
00053 #include <client_context.h>
00054 #include <argparser.h>
00055 #include <get_console_input.h>
00056
00057
00058
00059 int benchmark(int *min, int *max, int thr_min, int thr_max);
00060
00061
00069 char *print_version(char *fprg) {
00070 char *prg = basename(fprg);
00071
00072 fprintf(stdout, "%s (v%s) - eurephia initialisation utility\n"
00073 "Copyright (C) 2009-2010 David Sommerseth <dazo@users.sourceforge.net>\n",
00074 prg, EUREPHIAVERSION);
00075 return prg;
00076 }
00077
00078
00084 void print_help(char *fprg) {
00085 print_version(fprg);
00086
00087 printf("\n This utility is only supposed to be used when installing eurephia. The\n"
00088 " purpose is to initialise the database eurephia will use, by setting up\n"
00089 " some standard configuration values and create an administrator account\n\n");
00090
00091 printf(" Valid arguments:\n"
00092 " -V | --version : Show version information\n"
00093 " -h | --help : This help screen\n"
00094 " -l | --log <filename> : Log file for debugging\n"
00095 " -L | --log-level <log level> : Sets the log level\n"
00096 " -N | --hash-threshold-min <ms> : Benchmarking parameter, see below. Default 95ms\n"
00097 " -M | --hash-threshold-max <ms> : Benchmarking parameter, see below. Default 200ms\n"
00098 " -D | --database-driver <path> : Full path to the database driver\n"
00099 " -d | --database-args <args> : Required database arguments for the driver\n\n");
00100
00101 printf("* Benchmarking\n"
00102 " During the initialisation this utility will benchmark the CPU power by doing\n"
00103 " multiple SHA512 hash calculations. This is to determinate the optimal rounds\n"
00104 " the password hashes should use on the current computer. To make it more difficult\n"
00105 " to brute force passwords, eurephia implements dynamic password hash rounds, based\n"
00106 " on a random number within in a given range. This benchmark will suggest an optimal\n"
00107 " range. To do this, two limits are defined, the shortest time and the longest time\n"
00108 " to be used for calculating a hash. The default values are 95ms and 200ms.\n"
00109 "\n"
00110 " If you want to modify those thresholds, you can do so with the --hash-threshold-min\n"
00111 " and --hash-threshold-max options. By increasing these numbers, you will allow the\n"
00112 " number of rounds to be increased.\n\n");
00113 }
00114
00123 int eurephia_ConnectDB(eurephiaCTX *ctx, eurephiaVALUES *cfg) {
00124 char *delims = " ";
00125 char *cp = NULL;
00126 const char *dbargv[MAX_ARGUMENTS];
00127 int dbargc = 0;
00128 char *argstr = NULL;
00129
00130 argstr = eGet_value(cfg, "database_params");
00131 if( (argstr == NULL) || (strlen(argstr) < 1) ) {
00132 eurephia_log(ctx, LOG_FATAL, 0, "No database connection string given");
00133 return 0;
00134 }
00135
00136
00137 cp = strdup(argstr);
00138 assert(cp != NULL);
00139
00140 dbargc = 0;
00141 dbargv[dbargc] = strtok(cp, delims);
00142 while( (dbargv[dbargc] != NULL) && (dbargc <= MAX_ARGUMENTS) ) {
00143 dbargv[++dbargc] = strtok(NULL, delims);
00144 }
00145
00146 if( !eDBconnect(ctx, dbargc, dbargv) ) {
00147 eurephia_log(ctx, LOG_PANIC, 0, "Could not connect to the database");
00148 eDBlink_close(ctx);
00149 return 0;
00150 }
00151 free_nullsafe(ctx, cp);
00152
00153 return 1;
00154 }
00155
00156
00166 static int config_set(eurephiaCTX *ctx, const char *key, const char *val) {
00167 xmlDoc *cfgxml = NULL, *resxml = NULL;
00168 xmlNode *cfg_n = NULL;
00169 eurephiaRESULT *res = NULL;
00170 int ret = 0;
00171
00172 eurephiaXML_CreateDoc(ctx, 1, "configuration", &cfgxml, &cfg_n);
00173 assert( (cfgxml != NULL) && (cfg_n != NULL) );
00174
00175 cfg_n = xmlNewChild(cfg_n, NULL, (xmlChar *) "set", (xmlChar *) val);
00176 xmlNewProp(cfg_n, (xmlChar *) "key", (xmlChar *) key);
00177 resxml = eDBadminConfiguration(ctx, cfgxml);
00178 xmlFreeDoc(cfgxml);
00179 if( resxml == NULL ) {
00180 fprintf(stderr, "%s: Error updating the configuration.\n", MODULE);
00181 return 0;
00182 }
00183
00184 res = eurephiaXML_ParseResultMsg(ctx, resxml);
00185 if( res == NULL ) {
00186 fprintf(stderr, "%s: Error updating the configuration. No results returned.\n",
00187 MODULE);
00188 xmlFreeDoc(resxml);
00189 return 0;
00190 }
00191
00192 if( res->resultType == exmlERROR ) {
00193 fprintf(stderr, "%s: %s\n", MODULE, res->message);
00194 ret = 0;
00195 } else {
00196 ret = 1;
00197 }
00198 free_nullsafe(ctx, res);
00199 xmlFreeDoc(resxml);
00200 return ret;
00201 }
00202
00210 int setup_admin_account(eurephiaCTX *ctx) {
00211 xmlDoc *xmldoc = NULL, *resxml = NULL;
00212 xmlNode *node = NULL, *node2 = NULL;
00213 int uid = 0, i;
00214 char uname[66], pwd1[66], pwd2[66];
00215
00216 printf("------------------------------------------------------------------------------\n");
00217 printf(" eurephia :: ADMINISTRATOR ACCOUNT\n");
00218 printf("------------------------------------------------------------------------------\n\n");
00219 printf("Checking database for user accounts ... ");
00220
00221 eurephiaXML_CreateDoc(ctx, 1, "UserAccount", &xmldoc, &node);
00222 assert( (xmldoc != NULL) && (node != NULL) );
00223 xmlNewProp(node, (xmlChar *) "mode", (xmlChar *) "view");
00224
00225 node = xmlNewChild(node, NULL, (xmlChar *) "fieldMapping", NULL);
00226 assert( node != NULL );
00227 xmlNewProp(node, (xmlChar *) "table", (xmlChar *) "users");
00228
00229 resxml = eDBadminUserAccount(ctx, xmldoc);
00230 node = eurephiaXML_getRoot(ctx, resxml, "UserAccount", 1);
00231 if( node == NULL ) {
00232 fprintf(stderr, "Could not retrieve valid data\n");
00233 xmlFreeDoc(xmldoc);
00234 xmlFreeDoc(resxml);
00235 return 0;
00236 }
00237
00238 node = xmlFindNode(node, "Account");
00239 if( (node != NULL) ) {
00240 printf("User accounts found, aborting. eurephia is already initialised\n");
00241 xmlFreeDoc(xmldoc);
00242 xmlFreeDoc(resxml);
00243 return 0;
00244 }
00245 xmlFreeDoc(xmldoc); xmldoc = NULL;
00246 xmlFreeDoc(resxml); resxml = NULL;
00247 printf("None found. Good!\n");
00248
00249 get_console_input(uname, 64, "Admin username: ", 0);
00250 if( strlen_nullsafe(uname) < 4 ) {
00251 fprintf(stderr, "Username is too short. Minimum 4 characters\n");
00252 return 0;
00253 }
00254 get_console_input(pwd1, 64, "Password: ", 1);
00255 if( strlen_nullsafe(pwd1) < 5 ) {
00256 fprintf(stderr, "Password is too short\n");
00257 return 0;
00258 }
00259 get_console_input(pwd2, 64, "Confirm password: ", 1);
00260 if( strcmp(pwd1, pwd2) != 0 ) {
00261 fprintf(stderr, "Passwords do not match\n");
00262 return 0;
00263 }
00264 memset(pwd2, 0, 66);
00265
00266 eurephiaXML_CreateDoc(ctx, 1, "UserAccount", &xmldoc, &node);
00267 xmlNewProp(node, (xmlChar *) "mode", (xmlChar *) "add");
00268 node = xmlNewChild(node, NULL, (xmlChar *) "fieldMapping", NULL);
00269 xmlNewProp(node, (xmlChar *) "table", (xmlChar *) "users");
00270
00271 xmlNewChild(node, NULL, (xmlChar *) "username", (xmlChar *) uname);
00272 node2 = xmlNewChild(node, NULL, (xmlChar *) "password", (xmlChar *) pwd1);
00273 xmlNewProp(node2, (xmlChar *) "pwhash", (xmlChar *) "none");
00274
00275
00276 resxml = eDBadminUserAccount(ctx, xmldoc);
00277 memset(pwd1, 0, 66);
00278 xmlFreeDoc(xmldoc);
00279
00280 if( !eurephiaXML_IsResultMsg(ctx, resxml) ) {
00281 fprintf(stderr, "Failed to register user\n");
00282 if( resxml ) {
00283 xmlFreeDoc(resxml);
00284 }
00285 return 0;
00286 } else {
00287 eurephiaRESULT *res = NULL;
00288
00289 res = eurephiaXML_ParseResultMsg(ctx, resxml);
00290 switch( res->resultType ) {
00291 case exmlERROR:
00292 fprintf(stderr, "** ERROR ** %s\n", res->message);
00293 uid = 0;
00294 break;
00295
00296 case exmlRESULT:
00297 fprintf(stdout, "%s\n", res->message);
00298 node = xmlFindNode(res->details, "UserAccount");
00299 uid = atoi_nullsafe(xmlGetAttrValue(node->properties, "uid"));
00300 break;
00301 }
00302 xmlFreeDoc(resxml);
00303 free_nullsafe(ctx, res);
00304
00305 if( uid < 1 ) {
00306 fprintf(stderr, "Failed to register user\n");
00307 return 0;
00308 }
00309 }
00310
00311
00312 static char *grants[] = { "config", "useradmin", "certadmin", "fwprofiles",
00313 "attempts", "blacklist", NULL };
00314
00315 printf("Granting access to user account:");
00316
00317 eurephiaXML_CreateDoc(ctx, 1, "admin_access", &xmldoc, &node);
00318 xmlNewProp(node, (xmlChar *) "mode", (xmlChar *) "grant");
00319
00320 node = xmlNewChild(node, NULL, (xmlChar *) "fieldMapping", NULL);
00321 xmlNewProp(node, (xmlChar *) "table", (xmlChar *) "eurephia_adminaccess");
00322
00323 snprintf(uname, 64, "%i", uid);
00324 xmlNewChild(node, NULL, (xmlChar *) "uid", (xmlChar *) uname);
00325 xmlNewChild(node, NULL, (xmlChar *) "interface", (xmlChar *) "C");
00326 node2 = xmlNewChild(node, NULL, (xmlChar *) "accesslevel", (xmlChar *)"");
00327
00328 for( i = 0; grants[i] != NULL; i++ ) {
00329 xmlNode *new_n = NULL;
00330
00331 new_n = xmlNewChild(node, NULL, (xmlChar *) "accesslevel", (xmlChar *)grants[i]);
00332 xmlReplaceNode(node2, new_n);
00333 node2 = new_n;
00334 printf(" %s", grants[i]);
00335 if( !eDBadminAccessLevel(ctx, xmldoc) ) {
00336 fprintf(stderr, "\n** ERROR: Could not grant %s access. Initialisation failed\n",
00337 grants[i]);
00338 xmlFreeDoc(xmldoc);
00339 return 0;
00340 }
00341 }
00342 xmlFreeDoc(xmldoc);
00343 node = NULL; node2 = NULL;
00344 printf("\n");
00345
00346
00347
00348 printf("Activating the user account ... ");
00349 eurephiaXML_CreateDoc(ctx, 1, "UserAccount", &xmldoc, &node);
00350 xmlNewProp(node, (xmlChar *) "mode", (xmlChar *) "update");
00351 xmlNewProp(node, (xmlChar *) "uid", (xmlChar *) uname);
00352
00353
00354 node2 = xmlNewChild(node, NULL, (xmlChar *) "fieldMapping", NULL);
00355 xmlNewProp(node2, (xmlChar *) "table", (xmlChar *) "users");
00356 xmlNewChild(node2, NULL, (xmlChar *) "activated", (xmlChar *) "CURRENT_TIMESTAMP");
00357
00358 resxml = eDBadminUserAccount(ctx, xmldoc);
00359 if( !eurephiaXML_IsResultMsg(ctx, resxml) ) {
00360 printf("FAILED\n");
00361 xmlFreeDoc(xmldoc);
00362 xmlFreeDoc(resxml);
00363 return 0;
00364 } else {
00365 eurephiaRESULT *res = NULL;
00366
00367 res = eurephiaXML_ParseResultMsg(ctx, resxml);
00368 switch( res->resultType ) {
00369 case exmlERROR:
00370 fprintf(stderr, "** ERROR ** %s\n", res->message);
00371 break;
00372
00373 case exmlRESULT:
00374 break;
00375 }
00376 xmlFreeDoc(resxml);
00377 free_nullsafe(ctx, res);
00378 }
00379
00380
00381
00382 printf("Done");
00383 xmlFreeDoc(xmldoc);
00384
00385 printf("\n==============================================================================\n\n");
00386 return 1;
00387 }
00388
00389
00400 int setup_password_params(eurephiaCTX *ctx, const int hash_thr_min, const int hash_thr_max) {
00401 int rounds_min = 0, rounds_max = 0;
00402 char buffer[22], prompt[80], value[22];
00403
00404 memset(&buffer, 0, 22);
00405
00406 printf("------------------------------------------------------------------------------\n");
00407 printf(" eurephia :: PASSWORD PARAMETERS\n");
00408 printf("------------------------------------------------------------------------------\n\n");
00409
00410 get_console_input(buffer, 10, "Salt length for password hashes [32] ", 0);
00411 memset(&value, 0, 22);
00412 snprintf(value, 20, "%i", (atoi_nullsafe(buffer) > 0 ? atoi_nullsafe(buffer) : 32));
00413 if( !config_set(ctx, "passwordhash_salt_length", value) ) {
00414 fprintf(stderr, "Failed to set configuration settings in database\n");
00415 return 0;
00416 }
00417
00418 printf("\n** Preparing for SHA512 performance benchmark.\n");
00419 printf("Aiming for minimum hashing calculation time: %ims\n", hash_thr_min);
00420 printf("Aiming for maximum hashing calculation time: %ims\n", hash_thr_max);
00421 if( !benchmark(&rounds_min, &rounds_max, hash_thr_min, hash_thr_max) ) {
00422 fprintf(stderr, "Failed to meassure SHA512 hash performance\n");
00423 return 0;
00424 }
00425 printf("\n");
00426 snprintf(prompt, 78, "Minimum hashing rounds: [%i] ", rounds_min);
00427 get_console_input(buffer, 20, prompt, 0);
00428 memset(&value, 0, 22);
00429 snprintf(value, 20, "%i", (atoi_nullsafe(buffer) > 1 ? atoi_nullsafe(buffer) : rounds_min));
00430 if( !config_set(ctx, "passwordhash_rounds_min", value) ) {
00431 fprintf(stderr, "Failed to set configuration settings in database\n");
00432 return 0;
00433 }
00434
00435 snprintf(prompt, 78, "Maximum hashing rounds: [%i] ", rounds_max);
00436 get_console_input(buffer, 20, prompt, 0);
00437 memset(&value, 0, 22);
00438 snprintf(value, 20, "%i", (atoi_nullsafe(buffer) > 1 ? atoi_nullsafe(buffer) : rounds_max));
00439 if( !config_set(ctx, "passwordhash_rounds_max", value) ) {
00440 fprintf(stderr, "Failed to set configuration settings in database\n");
00441 return 0;
00442 }
00443
00444 printf("\n==============================================================================\n\n");
00445
00446 return 1;
00447 }
00448
00449
00457 int setup_attempt_limits(eurephiaCTX *ctx) {
00458 char buffer[22], value[22];
00459 memset(&buffer, 0, 22);
00460
00461 printf("------------------------------------------------------------------------------\n");
00462 printf(" eurephia :: ATTEMPTS LIMITS\n");
00463 printf("------------------------------------------------------------------------------\n\n");
00464 printf("These parameters here will decide when eurephia should block access, based on\n"
00465 "how many registered failed attempts. Normally, you should be strict regarding\n"
00466 "number of attempts on usernames, less strict on certificates and even less on\n"
00467 "IP addresses. Remember that the user might connect via a proxy or a firewall\n"
00468 "with NAT enabled.\n\n");
00469
00470 get_console_input(buffer, 10, "How many failed attempts will you allow per user name? [3]", 0);
00471 memset(&value, 0, 22);
00472 snprintf(value, 20, "%i", (atoi_nullsafe(buffer) > 0 ? atoi_nullsafe(buffer) : 3));
00473 if( !config_set(ctx, "allow_username_attempts", value) ) {
00474 fprintf(stderr, "Failed to set configuration settings in database\n");
00475 return 0;
00476 }
00477
00478 get_console_input(buffer, 10, "How many failed attempts will you allow per certificate? [5]", 0);
00479 memset(&value, 0, 22);
00480 snprintf(value, 20, "%i", (atoi_nullsafe(buffer) > 0 ? atoi_nullsafe(buffer) : 5));
00481 if( !config_set(ctx, "allow_cert_attempts", value) ) {
00482 fprintf(stderr, "Failed to set configuration settings in database\n");
00483 return 0;
00484 }
00485
00486 get_console_input(buffer, 10, "How many failed attempts will you allow per IP address? [10]", 0);
00487 memset(&value, 0, 22);
00488 snprintf(value, 20, "%i", (atoi_nullsafe(buffer) > 0 ? atoi_nullsafe(buffer) : 10));
00489 if( !config_set(ctx, "allow_ipaddr_attempts", value) ) {
00490 fprintf(stderr, "Failed to set configuration settings in database\n");
00491 return 0;
00492 }
00493 printf("\n==============================================================================\n\n");
00494 return 1;
00495 }
00496
00497
00505 int setup_session_params(eurephiaCTX *ctx) {
00506 char buffer[22], value[22];
00507 memset(&buffer, 0, 22);
00508
00509 printf("------------------------------------------------------------------------------\n");
00510 printf(" eurephia :: SESSION PARAMETERS\n");
00511 printf("------------------------------------------------------------------------------\n\n");
00512
00513 get_console_input(buffer, 10,
00514 "eurephiadmin: How many minutes before a session is auto logged out: [10]", 0);
00515 memset(&value, 0, 22);
00516 snprintf(value, 20, "%i", (atoi_nullsafe(buffer) > 0 ? atoi_nullsafe(buffer) : 10));
00517 if( !config_set(ctx, "eurephiadmin_autologout", value) ) {
00518 fprintf(stderr, "Failed to set configuration settings in database\n");
00519 return 0;
00520 }
00521 printf("\n==============================================================================\n\n");
00522
00523 return 1;
00524 }
00525
00526
00527 #ifdef FW_IPTABLES
00528
00535 int setup_iptables(eurephiaCTX *ctx) {
00536 char buffer[1026], value[1026], prompt[180];
00537 memset(&buffer, 0, 1026);
00538 memset(&value, 0, 1026);
00539
00540 printf("------------------------------------------------------------------------------\n");
00541 printf(" eurephia :: FIREWALL SUPPORT - iptables\n");
00542 printf("------------------------------------------------------------------------------\n\n");
00543
00544 get_console_input(buffer, 8, "Do you want to load the iptables module? [No]", 0);
00545 if( (strlen_nullsafe(buffer) > 0) && ((buffer[0] != 'y') && (buffer[0] != 'Y')) ) {
00546 printf("\niptables firewall support is not configured\n");
00547 goto ipt_done;
00548 }
00549
00550 snprintf(value, 1024, "%s/efw-iptables.so", PLUGINDIR);
00551 snprintf(prompt, 178, "\nFull path to the efw-iptables.so library:\n[%s]", value);
00552 get_console_input(buffer, 1024, prompt, 0);
00553 if( !config_set(ctx, "firewall_interface", (strlen_nullsafe(buffer) > 1 ? buffer : value)) ) {
00554 fprintf(stderr, "Failed to set configuration settings in database\n");
00555 return 0;
00556 }
00557
00558 snprintf(value, 1024, "/sbin/iptables");
00559 snprintf(prompt, 78, "\nFull path to the iptables command: [%s]", value);
00560 get_console_input(buffer, 1024, prompt, 0);
00561 if( !config_set(ctx, "firewall_command", (strlen_nullsafe(buffer) > 1 ? buffer : value)) ) {
00562 fprintf(stderr, "Failed to set configuration settings in database\n");
00563 return 0;
00564 }
00565
00566 snprintf(value, 1024, "vpn_users");
00567 snprintf(prompt, 78, "\nWhich iptables chain should eurephia use? [%s]", value);
00568 get_console_input(buffer, 1024, prompt, 0);
00569 if( !config_set(ctx, "firewall_destination", (strlen_nullsafe(buffer) > 1 ? buffer : value)) ) {
00570 fprintf(stderr, "Failed to set configuration settings in database\n");
00571 return 0;
00572 }
00573
00574 get_console_input(buffer, 8, "\nDo you want you eurephia to block blacklisted IP addresses\n"
00575 "in iptables too? [No]", 0);
00576 if( (strlen_nullsafe(buffer) < 1) || (buffer[0] == 'y') || (buffer[0] == 'Y') ) {
00577 snprintf(value, 1024, "vpn_blacklist");
00578 snprintf(prompt, 178, "\nWhich iptables chain should eurephia use for"
00579 "\nblacklisted IP addresses? [%s]", value);
00580 get_console_input(buffer, 1024, prompt, 0);
00581 if( !config_set(ctx, "firewall_blacklist_destination",
00582 (strlen_nullsafe(buffer) > 1 ? buffer : value)) ) {
00583 fprintf(stderr, "Failed to set configuration settings in database\n");
00584 return 0;
00585 }
00586
00587 memset(&value, 0, 1024);
00588 snprintf(prompt, 178, "\nWhich iptables chain should eurephia send blacklisted"
00589 "\nIP addresses to (iptables '-j' argument) ? [DROP]");
00590 get_console_input(buffer, 1024, prompt, 0);
00591 if( (strlen_nullsafe(buffer) > 1)
00592 && !config_set(ctx, "firewall_blacklist_send_to", buffer) ) {
00593 fprintf(stderr, "Failed to set configuration settings in database\n");
00594 return 0;
00595 }
00596 }
00597 ipt_done:
00598 printf("\n==============================================================================\n\n");
00599
00600 return 1;
00601 }
00602 #endif
00603
00604
00613 int main(int argc, char **argv) {
00614
00615 int hash_thr_min = 95;
00616 int hash_thr_max = 200;
00617 int argi = 0;
00618 eurephiaVALUES *cfg = NULL;
00619 eurephiaCTX *ctx = NULL;
00620 int rc = 0;
00621
00622 static e_options argopts[] = {
00623 {"--version", "-V", 0},
00624 {"--help", "-h", 0},
00625 {"--log", "-l", 1},
00626 {"--log-level", "-L", 1},
00627 {"--hash-threshold-min", "-N", 1},
00628 {"--hash-threshold-max", "-M", 1},
00629 {"--database-driver", "-D", 1},
00630 {"--database-args", "-d", 1},
00631 {NULL, NULL, 0}
00632 };
00633
00634
00635 cfg = eCreate_value_space(NULL, 30);
00636 for( argi = 1; argi < argc; argi++ ) {
00637 switch( eurephia_getopt(&argi, argc, argv, argopts) ) {
00638 case 'V':
00639 print_version(argv[0]);
00640 rc = 0;
00641 goto exit;
00642
00643 case 'h':
00644 print_help(argv[0]);
00645 rc = 0;
00646 goto exit;
00647
00648 case 'l':
00649 eAdd_value(NULL, cfg, "log", optargs[0]);
00650 break;
00651
00652 case 'L':
00653 eAdd_value(NULL, cfg, "log_level", optargs[0]);
00654 break;
00655
00656 case 'D':
00657 eAdd_value(NULL, cfg, "database_driver", optargs[0]);
00658 break;
00659
00660 case 'd':
00661 eAdd_value(NULL, cfg, "database_params", optargs[0]);
00662 break;
00663
00664 case 'N':
00665 hash_thr_min = atoi_nullsafe(optargs[0]);
00666 break;
00667
00668 case 'M':
00669 hash_thr_max = atoi_nullsafe(optargs[0]);
00670 break;
00671
00672 default:
00673 rc = 1;
00674 goto exit;
00675 }
00676 }
00677
00678 if( eGet_value(cfg, "database_driver") == NULL ) {
00679 fprintf(stderr, "Missing required database driver (--database-driver)\n");
00680 rc = 2;
00681 goto exit;
00682
00683 }
00684
00685 if( eGet_value(cfg, "database_params") == NULL ) {
00686 fprintf(stderr, "Missing required database driver parameters (--database-args)\n");
00687 rc = 2;
00688 goto exit;
00689
00690 }
00691
00692 ctx = eurephiaCTX_init("eurephia_init", NULL, 0, cfg);
00693 if( ctx == NULL ) {
00694 fprintf(stderr, "Failed to initialise an eurephia context.\n");
00695 rc = 3;
00696 goto exit;
00697 }
00698
00699 if( !eurephia_ConnectDB(ctx, cfg) ) {
00700 fprintf(stderr, "Failed to access the database.\n");
00701 rc = 4;
00702 goto exit;
00703 }
00704
00705 if( !setup_password_params(ctx, hash_thr_min, hash_thr_max) ) {
00706 rc = 11;
00707 goto exit;
00708 }
00709
00710 if( !setup_admin_account(ctx) ) {
00711 rc = 12;
00712 goto exit;
00713 }
00714
00715 if( !setup_session_params(ctx) ) {
00716 rc = 13;
00717 goto exit;
00718 }
00719
00720 if( !setup_attempt_limits(ctx) ) {
00721 rc = 14;
00722 goto exit;
00723 }
00724
00725 #ifdef FW_IPTABLES
00726 if( !setup_iptables(ctx) ){
00727 rc = 15;
00728 goto exit;
00729 }
00730 #endif
00731
00732 printf("\neurephia is now configured. For further changes, please use the eurephiadm utility.\n\n");
00733 exit:
00734 eFree_values(ctx, cfg);
00735 eurephiaCTX_destroy(ctx);
00736 return 0;
00737 }