static char Conf_HelpFile[FNAME_LEN];
static char Conf_IncludeDir[FNAME_LEN];
-static void Set_Defaults PARAMS(( bool InitServers ));
-static bool Read_Config PARAMS(( bool TestOnly, bool IsStarting ));
+static void Set_Defaults PARAMS(( bool InitServers, const char *ServerName,
+ const char *MotdPhrase ));
+static bool Read_Config PARAMS(( bool TestOnly, bool IsStarting,
+ const char *ServerName,
+ const char *MotdPhrase ));
static void Read_Config_File PARAMS(( const char *File, FILE *fd ));
static bool Validate_Config PARAMS(( bool TestOnly, bool Rehash ));
/**
* Initialize configuration module.
+ *
+ * @param ServerName Name of the server (when available) or NULL.
+ * @param MotdPhrase MOTD phrase (when available) or NULL.
*/
GLOBAL void
-Conf_Init( void )
+Conf_Init(const char *ServerName, const char *MotdPhrase)
{
- Read_Config(false, true);
+ Read_Config(false, true, ServerName, MotdPhrase);
Validate_Config(false, false);
}
GLOBAL bool
Conf_Rehash( void )
{
- if (!Read_Config(false, false))
+ if (!Read_Config(false, false, NULL, NULL))
return false;
Validate_Config(false, true);
* This function waits for a keypress of the user when stdin/stdout are valid
* tty's ("you can read our nice message and we can read in your keypress").
*
+ * @param ServerName Name of the server (when available) or NULL.
+ * @param MotdPhrase MOTD phrase (when available) or NULL.
+
* @return 0 on success, 1 on failure(s); therefore the result code can
* directly be used by exit() when running "ngircd --configtest".
*/
GLOBAL int
-Conf_Test( void )
+Conf_Test(const char *ServerName, const char *MotdPhrase)
{
struct passwd *pwd;
struct group *grp;
Use_Log = false;
- if (!Read_Config(true, true))
+ if (!Read_Config(true, true, ServerName, MotdPhrase))
return 1;
config_valid = Validate_Config(true, false);
/**
* Initialize configuration settings with their default values.
+ *
+ * @param InirServers Initialize the server structure?
+ * @param ServerName Name of the server (when available) or NULL.
+ * @param MotdPhrase MOTD phrase (when available) or NULL.
*/
static void
-Set_Defaults(bool InitServers)
+Set_Defaults(bool InitServers, const char *ServerName, const char *MotdPhrase)
{
int i;
char random[RANDOM_SALT_LEN + 1];
/* Global */
- strcpy(Conf_ServerName, "");
+ strlcpy(Conf_ServerName, ServerName ? ServerName : "",
+ sizeof(Conf_ServerName));
strcpy(Conf_ServerAdmin1, "");
strcpy(Conf_ServerAdmin2, "");
strcpy(Conf_ServerAdminMail, "");
Conf_ListenAddress = NULL;
array_free(&Conf_ListenPorts);
array_free(&Conf_Motd);
+ if (MotdPhrase) {
+ array_copyb(&Conf_Motd, MotdPhrase, strlen(MotdPhrase) + 1);
+ Using_MotdFile = false;
+ }
array_free(&Conf_Helptext);
strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
* can result in ngIRCd terminating!
*
* @param IsStarting Flag indicating if ngIRCd is starting or not.
+ * @param ServerName Name of the server (when available) or NULL.
+ * @param MotdPhrase MOTD phrase (when available) or NULL.
* @returns true when the configuration file has been read
* successfully; false otherwise.
*/
static bool
-Read_Config(bool TestOnly, bool IsStarting)
+Read_Config(bool TestOnly, bool IsStarting, const char *ServerName,
+ const char *MotdPhrase)
{
const UINT16 defaultport = 6667;
char *ptr, file[FNAME_LEN];
}
opers_free();
- Set_Defaults(IsStarting);
+ Set_Defaults(IsStarting, ServerName, MotdPhrase);
if (TestOnly)
Config_Error(LOG_INFO,
assert(Arg != NULL);
if (strcasecmp(Var, "Name") == 0) {
+ if (Conf_ServerName[0]) {
+ Config_Error(LOG_WARNING,
+ "%s, line %d: Server name already set, \"%s\" ignored!",
+ File, Line, Var);
+ return;
+ }
len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
if (len >= sizeof(Conf_ServerName))
Config_Error_TooLong(File, Line, Var);
/* No server name configured! */
config_valid = false;
Config_Error(LOG_ALERT,
- "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
+ "No (valid) server name configured in \"%s\" or on the command line!",
NGIRCd_ConfFile);
if (!Configtest && !Rehash) {
Config_Error(LOG_ALERT,
GLOBAL int
main(int argc, const char *argv[])
{
+ const char *name_ptr = NULL, *motd_ptr = NULL;
bool ok, configtest = false;
bool NGIRCd_NoDaemon = false;
int i;
/* long option */
if (strcmp(argv[i], "--config") == 0) {
if (i + 1 < argc) {
- /* Ok, there's an parameter left */
+ /* Ok, there's a parameter left */
strlcpy(NGIRCd_ConfFile, argv[i+1],
sizeof(NGIRCd_ConfFile));
/* next parameter */
puts(""); Show_Help( ); puts( "" );
exit(0);
}
+ if (strcmp(argv[i], "--motd") == 0) {
+ if (i + 1 < argc) {
+ /* Next parameter is MOTD phrase */
+ motd_ptr = argv[i +1];
+ i++; ok = true;
+ }
+ }
+ if (strcmp(argv[i], "--name") == 0) {
+ if (i + 1 < argc) {
+ /* Next parameter is server name */
+ name_ptr = argv[i +1];
+ i++; ok = true;
+ }
+ }
if (strcmp(argv[i], "--nodaemon") == 0) {
NGIRCd_NoDaemon = true;
ok = true;
exit(1);
}
+ if (argv[i][n] == 'i') {
+ if (!argv[i][n+1] && i+1 < argc) {
+ name_ptr = argv[i +1];
+ i++; n = strlen(argv[i]);
+ ok = true;
+ }
+ }
+
+ if (argv[i][n] == 'm') {
+ if (!argv[i][n+1] && i+1 < argc) {
+ motd_ptr = argv[i +1];
+ i++; n = strlen(argv[i]);
+ ok = true;
+ }
+ }
+
if (argv[i][n] == 'n') {
NGIRCd_NoDaemon = true;
ok = true;
}
+
if (argv[i][n] == 'p') {
NGIRCd_Passive = true;
ok = true;
if (configtest) {
Show_Version(); puts("");
- exit(Conf_Test());
+ exit(Conf_Test(name_ptr, motd_ptr));
}
while (!NGIRCd_SignalQuit) {
Log_Init(!NGIRCd_NoDaemon);
Random_Init();
- Conf_Init();
+ Conf_Init(name_ptr, motd_ptr);
Log_ReInit();
/* Initialize the "main program":
puts( " -d, --debug log extra debug messages" );
#endif
puts( " -f, --config <f> use file <f> as configuration file" );
+ puts( " -i, --name <id> set the server ID (\"name\") to <id>" );
+ puts( " -m, --motd <txt> set the MOTD phrase to <txt>");
puts( " -n, --nodaemon don't fork and don't detach from controlling terminal" );
puts( " -p, --passive disable automatic connections to other servers" );
#ifdef SNIFFER