From f13bf0cac65ff06347c007363fc8cb97929f9633 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Mon, 2 Nov 2015 14:55:30 -0500 Subject: [PATCH] Use main_config.name everywhere. So we see less hard-coded "radiusd". --- src/include/radiusd.h | 1 - src/main/listen.c | 6 ++-- src/main/mainconfig.c | 42 ++++++++++++---------- src/main/radiusd.c | 19 +++++----- src/main/radmin.c | 2 +- src/main/radwho.c | 2 +- src/main/tls.c | 2 +- src/main/unittest.c | 14 ++++---- src/modules/rlm_eap/radeapclient.c | 2 +- .../rlm_sql_postgresql/rlm_sql_postgresql.c | 2 +- 10 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/include/radiusd.h b/src/include/radiusd.h index bdbf0c6..47edc17 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -344,7 +344,6 @@ typedef enum request_fail { * * We really shouldn't have this many. */ -extern char const *progname; extern log_lvl_t rad_debug_lvl; extern char const *radacct_dir; extern char const *radlog_dir; diff --git a/src/main/listen.c b/src/main/listen.c index 8ddc811..4abd9fa 100644 --- a/src/main/listen.c +++ b/src/main/listen.c @@ -3127,7 +3127,7 @@ int listen_init(CONF_SECTION *config, rad_listen_t **head, bool spawn_flag) override = true; #ifdef WITH_VMPS - if (strcmp(progname, "vmpsd") == 0) { + if (strcmp(main_config.name, "vmpsd") == 0) { this = listen_alloc(config, RAD_LISTEN_VQP); if (!auth_port) auth_port = 1589; } else @@ -3167,7 +3167,7 @@ int listen_init(CONF_SECTION *config, rad_listen_t **head, bool spawn_flag) /* * No acct for vmpsd */ - if (strcmp(progname, "vmpsd") == 0) goto add_sockets; + if (strcmp(main_config.name, "vmpsd") == 0) goto add_sockets; #endif #ifdef WITH_ACCOUNTING @@ -3305,7 +3305,7 @@ add_sockets: if (!check_config && !spawn_flag && this->tls) { cf_log_err_cs(this->cs, "Threading must be enabled for TLS sockets to function properly"); cf_log_err_cs(this->cs, "You probably need to do '%s -fxx -l stdout' for debugging", - progname); + main_config.name); return -1; } #endif diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index fca7221..8f22d37 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -499,7 +499,7 @@ static int switch_users(CONF_SECTION *cs) * initialized. */ if (fr_set_dumpable_init() < 0) { - fr_perror("radiusd"); + fr_perror("%s", main_config.name); return 0; } @@ -510,7 +510,8 @@ static int switch_users(CONF_SECTION *cs) if (rad_debug_lvl && (getuid() != 0)) return 1; if (cf_section_parse(cs, NULL, bootstrap_config) < 0) { - fprintf(stderr, "radiusd: Error: Failed to parse user/group information.\n"); + fprintf(stderr, "%s: Error: Failed to parse user/group information.\n", + main_config.name); return 0; } @@ -526,7 +527,7 @@ static int switch_users(CONF_SECTION *cs) gr = getgrnam(gid_name); if (!gr) { fprintf(stderr, "%s: Cannot get ID for group %s: %s\n", - progname, gid_name, fr_syserror(errno)); + main_config.name, gid_name, fr_syserror(errno)); return 0; } @@ -547,7 +548,7 @@ static int switch_users(CONF_SECTION *cs) if (rad_getpwnam(cs, &user, uid_name) < 0) { fprintf(stderr, "%s: Cannot get passwd entry for user %s: %s\n", - progname, uid_name, fr_strerror()); + main_config.name, uid_name, fr_strerror()); return 0; } @@ -560,7 +561,7 @@ static int switch_users(CONF_SECTION *cs) #ifdef HAVE_INITGROUPS if (initgroups(uid_name, server_gid) < 0) { fprintf(stderr, "%s: Cannot initialize supplementary group list for user %s: %s\n", - progname, uid_name, fr_syserror(errno)); + main_config.name, uid_name, fr_syserror(errno)); talloc_free(user); return 0; } @@ -576,7 +577,7 @@ static int switch_users(CONF_SECTION *cs) if (chroot_dir) { if (chroot(chroot_dir) < 0) { fprintf(stderr, "%s: Failed to perform chroot %s: %s", - progname, chroot_dir, fr_syserror(errno)); + main_config.name, chroot_dir, fr_syserror(errno)); return 0; } @@ -604,7 +605,7 @@ static int switch_users(CONF_SECTION *cs) if (do_sgid) { if (setgid(server_gid) < 0){ fprintf(stderr, "%s: Failed setting group to %s: %s", - progname, gid_name, fr_syserror(errno)); + main_config.name, gid_name, fr_syserror(errno)); return 0; } } @@ -660,7 +661,8 @@ static int switch_users(CONF_SECTION *cs) default_log.fd = open(main_config.log_file, O_WRONLY | O_APPEND | O_CREAT, 0640); if (default_log.fd < 0) { - fprintf(stderr, "radiusd: Failed to open log file %s: %s\n", main_config.log_file, fr_syserror(errno)); + fprintf(stderr, "%s: Failed to open log file %s: %s\n", + main_config.name, main_config.log_file, fr_syserror(errno)); return 0; } } @@ -677,7 +679,7 @@ static int switch_users(CONF_SECTION *cs) (default_log.dst == L_DST_FILES)) { if (fchown(default_log.fd, server_uid, server_gid) < 0) { fprintf(stderr, "%s: Cannot change ownership of log file %s: %s\n", - progname, main_config.log_file, fr_syserror(errno)); + main_config.name, main_config.log_file, fr_syserror(errno)); return 0; } } @@ -865,13 +867,15 @@ do {\ */ if (default_log.dst == L_DST_NULL) { if (cf_section_parse(cs, NULL, startup_server_config) < 0) { - fprintf(stderr, "radiusd: Error: Failed to parse log{} section.\n"); + fprintf(stderr, "%s: Error: Failed to parse log{} section.\n", + main_config.name); cf_file_free(cs); return -1; } if (!radlog_dest) { - fprintf(stderr, "radiusd: Error: No log destination specified.\n"); + fprintf(stderr, "%s: Error: No log destination specified.\n", + main_config.name); cf_file_free(cs); return -1; } @@ -879,8 +883,8 @@ do {\ default_log.dst = fr_str2int(log_str2dst, radlog_dest, L_DST_NUM_DEST); if (default_log.dst == L_DST_NUM_DEST) { - fprintf(stderr, "radiusd: Error: Unknown log_destination %s\n", - radlog_dest); + fprintf(stderr, "%s: Error: Unknown log_destination %s\n", + main_config.name, radlog_dest); cf_file_free(cs); return -1; } @@ -891,14 +895,15 @@ do {\ * before using it */ if (!syslog_facility) { - fprintf(stderr, "radiusd: Error: Syslog chosen but no facility was specified\n"); + fprintf(stderr, "%s: Error: Syslog chosen but no facility was specified\n", + main_config.name); cf_file_free(cs); return -1; } main_config.syslog_facility = fr_str2int(syslog_facility_table, syslog_facility, -1); if (main_config.syslog_facility < 0) { - fprintf(stderr, "radiusd: Error: Unknown syslog_facility %s\n", - syslog_facility); + fprintf(stderr, "%s: Error: Unknown syslog_facility %s\n", + main_config.name, syslog_facility); cf_file_free(cs); return -1; } @@ -908,12 +913,13 @@ do {\ * Call openlog only once, when the * program starts. */ - openlog(progname, LOG_PID, main_config.syslog_facility); + openlog(main_config.name, LOG_PID, main_config.syslog_facility); #endif } else if (default_log.dst == L_DST_FILES) { if (!main_config.log_file) { - fprintf(stderr, "radiusd: Error: Specified \"files\" as a log destination, but no log filename was given!\n"); + fprintf(stderr, "%s: Error: Specified \"files\" as a log destination, but no log filename was given!\n", + main_config.name); cf_file_free(cs); return -1; } diff --git a/src/main/radiusd.c b/src/main/radiusd.c index fc29e28..e3a3de9 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -54,7 +54,6 @@ RCSID("$Id$") /* * Global variables. */ -char const *progname = NULL; char const *radacct_dir = NULL; char const *radlog_dir = NULL; @@ -94,6 +93,7 @@ int main(int argc, char *argv[]) bool display_version = false; int flag = 0; int from_child[2] = {-1, -1}; + char *p; fr_state_t *state = NULL; /* @@ -107,16 +107,19 @@ int main(int argc, char *argv[]) set_auth_parameters(argc, argv); #endif - if ((progname = strrchr(argv[0], FR_DIR_SEP)) == NULL) - progname = argv[0]; - else - progname++; + p = strrchr(argv[0], FR_DIR_SEP); + if (!p) { + main_config.name = argv[0]; + } else { + main_config.name = p + 1; + } #ifdef WIN32 { WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 0), &wsaData)) { - fprintf(stderr, "%s: Unable to initialize socket library.\n", progname); + fprintf(stderr, "%s: Unable to initialize socket library.\n", + main_config.name); exit(EXIT_FAILURE); } } @@ -309,7 +312,7 @@ int main(int argc, char *argv[]) default_log.dst = L_DST_STDOUT; default_log.fd = STDOUT_FILENO; - INFO("%s: %s", progname, radiusd_version); + INFO("%s: %s", main_config.name, radiusd_version); version_print(); exit(EXIT_SUCCESS); } @@ -661,7 +664,7 @@ static void NEVER_RETURNS usage(int status) { FILE *output = status?stderr:stdout; - fprintf(output, "Usage: %s [options]\n", progname); + fprintf(output, "Usage: %s [options]\n", main_config.name); fprintf(output, "Options:\n"); fprintf(output, " -C Check configuration and exit.\n"); fprintf(stderr, " -d Set configuration directory (defaults to " RADDBDIR ").\n"); diff --git a/src/main/radmin.c b/src/main/radmin.c index 5834078..b43dc05 100644 --- a/src/main/radmin.c +++ b/src/main/radmin.c @@ -64,7 +64,7 @@ RCSID("$Id$") /* * For configuration file stuff. */ -char const *progname = "radmin"; +static char const *progname = "radmin"; static char const *radmin_version = "radmin version " RADIUSD_VERSION_STRING #ifdef RADIUSD_VERSION_COMMIT " (git #" STRINGIFY(RADIUSD_VERSION_COMMIT) ")" diff --git a/src/main/radwho.c b/src/main/radwho.c index 3cfff29..e169a47 100644 --- a/src/main/radwho.c +++ b/src/main/radwho.c @@ -45,7 +45,7 @@ static char const *eol = "\n"; static int showname = -1; static int showptype = 0; static int showcid = 0; -char const *progname = "radwho"; +static char const *progname = "radwho"; char const *radlog_dir = NULL; static char const *radutmp_file = NULL; diff --git a/src/main/tls.c b/src/main/tls.c index 77628d9..33c2bd9 100644 --- a/src/main/tls.c +++ b/src/main/tls.c @@ -2076,7 +2076,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx) FILE *fp; snprintf(filename, sizeof(filename), "%s/%s.client.XXXXXXXX", - conf->verify_tmp_dir, progname); + conf->verify_tmp_dir, main_config.name); fd = mkstemp(filename); if (fd < 0) { RDEBUG("Failed creating file in %s: %s", diff --git a/src/main/unittest.c b/src/main/unittest.c index e0a301b..6e2a1a1 100644 --- a/src/main/unittest.c +++ b/src/main/unittest.c @@ -37,7 +37,6 @@ RCSID("$Id$") /* * Global variables. */ -char const *progname = NULL; char const *radacct_dir = NULL; char const *radlog_dir = NULL; bool log_stripped_names = false; @@ -629,6 +628,7 @@ int main(int argc, char *argv[]) VALUE_PAIR *vp; VALUE_PAIR *filter_vps = NULL; bool xlat_only = false; + char *p; fr_state_t *state = NULL; fr_talloc_fault_setup(); @@ -644,10 +644,12 @@ int main(int argc, char *argv[]) } #endif - if ((progname = strrchr(argv[0], FR_DIR_SEP)) == NULL) - progname = argv[0]; - else - progname++; + p = strrchr(argv[0], FR_DIR_SEP); + if (!p) { + main_config.name = argv[0]; + } else { + main_config.name = p + 1; + } rad_debug_lvl = 0; set_radius_dir(NULL, RADIUS_DIR); @@ -941,7 +943,7 @@ static void NEVER_RETURNS usage(int status) { FILE *output = status?stderr:stdout; - fprintf(output, "Usage: %s [options]\n", progname); + fprintf(output, "Usage: %s [options]\n", main_config.name); fprintf(output, "Options:\n"); fprintf(output, " -d raddb_dir Configuration files are in \"raddb_dir/*\".\n"); fprintf(output, " -D dict_dir Dictionary files are in \"dict_dir/*\".\n"); diff --git a/src/modules/rlm_eap/radeapclient.c b/src/modules/rlm_eap/radeapclient.c index 5cc5fa5..020d252 100644 --- a/src/modules/rlm_eap/radeapclient.c +++ b/src/modules/rlm_eap/radeapclient.c @@ -55,7 +55,7 @@ static int totalapp = 0; static int totaldeny = 0; static char filesecret[256]; static char const *radius_dir = NULL; -char const *progname = "radeapclient"; +static char const *progname = "radeapclient"; /* fr_randctx randctx; */ main_config_t main_config; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c index 1c2034e..eb348df 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c @@ -113,7 +113,7 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config) if (!name) name = cf_section_name1(cs); snprintf(application_name, sizeof(application_name), - "FreeRADIUS " RADIUSD_VERSION_STRING " - %s (%s)", progname, name); + "FreeRADIUS " RADIUSD_VERSION_STRING " - %s (%s)", main_config.name, name); } /* -- 2.1.4