From b89fc0fcd219d47e2bdec3066e1eff58cf7e3303 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 14 Dec 2014 23:12:15 -0500 Subject: cleanup: - Remove a bunch of unused stuff from common. - Rename some ldap-named stuff - Don't bother messing with UIDs/GIDs, let systemd do it --- nslcd/cfg.c | 114 ++++++---------------------------------------------- nslcd/cfg.h | 13 ++---- nslcd/common.c | 77 ----------------------------------- nslcd/common.h | 105 +---------------------------------------------- nslcd/db_pam.c | 12 +++--- nslcd/invalidator.c | 6 +-- nslcd/nslcd.c | 60 ++++----------------------- 7 files changed, 33 insertions(+), 354 deletions(-) diff --git a/nslcd/cfg.c b/nslcd/cfg.c index d9a800f..e3f5b9d 100644 --- a/nslcd/cfg.c +++ b/nslcd/cfg.c @@ -58,7 +58,7 @@ #include "cfg.h" #include "common/expr.h" -struct ldap_config *nslcd_cfg = NULL; +struct nslcd_config *nslcd_cfg = NULL; /* the maximum line length in the configuration file */ #define MAX_LINE_LENGTH 4096 @@ -193,75 +193,6 @@ static const char *print_boolean(int bool) else return "no"; } -static void handle_uid(const char *filename, int lnr, - const char *keyword, char *line, - struct ldap_config *cfg) -{ - char token[32]; - struct passwd *pwent; - char *tmp; - check_argumentcount(filename, lnr, keyword, - get_token(&line, token, sizeof(token)) != NULL); - get_eol(filename, lnr, keyword, &line); - /* check if it is a valid numerical uid */ - errno = 0; - cfg->uid = strtouid(token, &tmp, 10); - if ((*token != '\0') && (*tmp == '\0') && (errno == 0) && (strchr(token, '-') == NULL)) - { - /* get the name and gid from the passwd database */ - pwent = getpwuid(cfg->uid); - if (pwent != NULL) - { - if (cfg->gid == NOGID) - cfg->gid = pwent->pw_gid; - cfg->uidname = strdup(pwent->pw_name); - return; - } - } - /* find by name */ - pwent = getpwnam(token); - if (pwent != NULL) - { - cfg->uid = pwent->pw_uid; - if (cfg->gid == NOGID) - cfg->gid = pwent->pw_gid; - cfg->uidname = strdup(token); - return; - } - /* log an error */ - log_log(LOG_ERR, "%s:%d: %s: not a valid uid: '%s'", - filename, lnr, keyword, token); - exit(EXIT_FAILURE); -} - -static void handle_gid(const char *filename, int lnr, - const char *keyword, char *line, - gid_t *gid) -{ - char token[32]; - struct group *grent; - char *tmp; - check_argumentcount(filename, lnr, keyword, - get_token(&line, token, sizeof(token)) != NULL); - get_eol(filename, lnr, keyword, &line); - /* check if it is a valid numerical gid */ - errno = 0; - *gid = strtogid(token, &tmp, 10); - if ((*token != '\0') && (*tmp == '\0') && (errno == 0) && (strchr(token, '-') == NULL)) - return; - /* find by name */ - grent = getgrnam(token); - if (grent != NULL) - { - *gid = grent->gr_gid; - return; - } - /* log an error */ - log_log(LOG_ERR, "%s:%d: %s: not a valid gid: '%s'", - filename, lnr, keyword, token); - exit(EXIT_FAILURE); -} - static int parse_loglevel(const char *filename, int lnr, const char *value) { if (strcasecmp(value, "crit") == 0) @@ -309,7 +240,7 @@ static void handle_log(const char *filename, int lnr, } } -static enum ldap_map_selector parse_map(const char *value) +static enum nss_map_selector parse_map(const char *value) { if ((strcasecmp(value, "alias") == 0) || (strcasecmp(value, "aliases") == 0)) return LM_ALIASES; @@ -339,7 +270,7 @@ static enum ldap_map_selector parse_map(const char *value) return LM_NONE; } -static const char *print_map(enum ldap_map_selector map) +static const char *print_map(enum nss_map_selector map) { switch (map) { @@ -363,7 +294,7 @@ static const char *print_map(enum ldap_map_selector map) /* this function modifies the line argument passed */ static void handle_nss_initgroups_ignoreusers( const char *filename, int lnr, - const char *keyword, char *line, struct ldap_config *cfg) + const char *keyword, char *line, struct nslcd_config *cfg) { char token[MAX_LINE_LENGTH]; char *username, *next; @@ -408,7 +339,7 @@ static void handle_nss_initgroups_ignoreusers( static void handle_validnames(const char *filename, int lnr, const char *keyword, char *line, - struct ldap_config *cfg) + struct nslcd_config *cfg) { char *value; int i, l; @@ -463,7 +394,7 @@ static void handle_validnames(const char *filename, int lnr, static void handle_pam_password_prohibit_message( const char *filename, int lnr, - const char *keyword, char *line, struct ldap_config *cfg) + const char *keyword, char *line, struct nslcd_config *cfg) { char *value; int l; @@ -481,11 +412,11 @@ static void handle_pam_password_prohibit_message( static void handle_reconnect_invalidate( const char *filename, int lnr, - const char *keyword, char *line, struct ldap_config *cfg) + const char *keyword, char *line, struct nslcd_config *cfg) { char token[MAX_LINE_LENGTH]; char *name, *next; - enum ldap_map_selector map; + enum nss_map_selector map; check_argumentcount(filename, lnr, keyword, (line != NULL) && (*line != '\0')); while (get_token(&line, token, sizeof(token)) != NULL) { @@ -514,14 +445,11 @@ static void handle_reconnect_invalidate( } /* set the configuration information to the defaults */ -static void cfg_defaults(struct ldap_config *cfg) +static void cfg_defaults(struct nslcd_config *cfg) { int i; - memset(cfg, 0, sizeof(struct ldap_config)); + memset(cfg, 0, sizeof(struct nslcd_config)); cfg->threads = 5; - cfg->uidname = NULL; - cfg->uid = NOUID; - cfg->gid = NOGID; cfg->pagesize = 0; cfg->nss_initgroups_ignoreusers = NULL; cfg->nss_min_uid = 0; @@ -536,7 +464,7 @@ static void cfg_defaults(struct ldap_config *cfg) cfg->reconnect_invalidate[i] = 0; } -static void cfg_read(const char *filename, struct ldap_config *cfg) +static void cfg_read(const char *filename, struct nslcd_config *cfg) { FILE *fp; int lnr = 0; @@ -580,14 +508,6 @@ static void cfg_read(const char *filename, struct ldap_config *cfg) cfg->threads = get_int(filename, lnr, keyword, &line); get_eol(filename, lnr, keyword, &line); } - else if (strcasecmp(keyword, "uid") == 0) - { - handle_uid(filename, lnr, keyword, line, cfg); - } - else if (strcasecmp(keyword, "gid") == 0) - { - handle_gid(filename, lnr, keyword, line, &cfg->gid); - } else if (strcasecmp(keyword, "log") == 0) { handle_log(filename, lnr, keyword, line); @@ -650,16 +570,6 @@ static void cfg_dump(void) const char **strp; char buffer[1024]; log_log(LOG_DEBUG, "CFG: threads %d", nslcd_cfg->threads); - if (nslcd_cfg->uidname != NULL) - log_log(LOG_DEBUG, "CFG: uid %s", nslcd_cfg->uidname); - else if (nslcd_cfg->uid != NOUID) - log_log(LOG_DEBUG, "CFG: uid %d", (int)nslcd_cfg->uid); - else - log_log(LOG_DEBUG, "CFG: # uid not set"); - if (nslcd_cfg->gid != NOGID) - log_log(LOG_DEBUG, "CFG: gid %d", (int)nslcd_cfg->gid); - else - log_log(LOG_DEBUG, "CFG: # gid not set"); log_log_config(); log_log(LOG_DEBUG, "CFG: pagesize %d", nslcd_cfg->pagesize); @@ -713,7 +623,7 @@ void cfg_init(const char *fname) exit(EXIT_FAILURE); } /* allocate the memory (this memory is not freed anywhere) */ - nslcd_cfg = (struct ldap_config *)malloc(sizeof(struct ldap_config)); + nslcd_cfg = (struct nslcd_config *)malloc(sizeof(struct nslcd_config)); if (nslcd_cfg == NULL) { log_log(LOG_CRIT, "malloc() failed to allocate memory"); diff --git a/nslcd/cfg.h b/nslcd/cfg.h index 890974c..73f9139 100644 --- a/nslcd/cfg.h +++ b/nslcd/cfg.h @@ -31,12 +31,8 @@ #include "compat/attrs.h" #include "common/set.h" -/* values for uid and gid */ -#define NOUID ((gid_t)-1) -#define NOGID ((gid_t)-1) - /* selectors for different maps */ -enum ldap_map_selector { +enum nss_map_selector { LM_ALIASES, LM_ETHERS, LM_GROUP, @@ -52,11 +48,8 @@ enum ldap_map_selector { LM_NONE }; -struct ldap_config { +struct nslcd_config { int threads; /* the number of threads to start */ - char *uidname; /* the user name specified in the uid option */ - uid_t uid; /* the user id nslcd should be run as */ - gid_t gid; /* the group id nslcd should be run as */ int pagesize; /* set to a greater than 0 to enable handling of paged results with the specified size */ SET *nss_initgroups_ignoreusers; /* the users for which no initgroups() searches should be done */ @@ -71,7 +64,7 @@ struct ldap_config { /* this is a pointer to the global configuration, it should be available and populated after cfg_init() is called */ -extern struct ldap_config *nslcd_cfg; +extern struct nslcd_config *nslcd_cfg; /* Initialize the configuration in nslcd_cfg. This method will read the default configuration file and call exit() if an error occurs. */ diff --git a/nslcd/common.c b/nslcd/common.c index da508f6..d4966bb 100644 --- a/nslcd/common.c +++ b/nslcd/common.c @@ -118,80 +118,3 @@ int isvalidname(const char *name) { return regexec(&nslcd_cfg->validnames, name, 0, NULL, 0) == 0; } - -/* convert the provided string representation of a sid - (e.g. S-1-5-21-1936905831-823966427-12391542-23578) - to a format that can be used to search the objectSid property with */ -char *sid2search(const char *sid) -{ - const char *tmpsid = sid; - char *res, *tmp; - int i = 0; - long int l; - /* check the beginning of the string */ - if (strncasecmp(sid, "S-", 2) != 0) - { - log_log(LOG_ERR, "error in SID %s", sid); - exit(EXIT_FAILURE); - } - /* count the number of dashes in the sid */ - while (tmpsid != NULL) - { - i++; - tmpsid = strchr(tmpsid + 1, '-'); - } - i -= 2; /* number of security ids plus one because we add the uid later */ - /* allocate memory */ - res = malloc(3 + 3 + 6 * 3 + i * 4 * 3 + 1); - if (res == NULL) - { - log_log(LOG_CRIT, "malloc() failed to allocate memory"); - exit(1); - } - /* build the first part */ - l = strtol(sid + 2, &tmp, 10); - sprintf(res, "\\%02x\\%02x", (int)l & 0xff, (int)i); - /* build authority part (we only handle 32 of the 48 bits) */ - l = strtol(tmp + 1, &tmp, 10); - sprintf(res + strlen(res), "\\00\\00\\%02x\\%02x\\%02x\\%02x", - (int)((l >> 24) & 0xff), (int)((l >> 16) & 0xff), - (int)((l >> 8) & 0xff), (int)(l & 0xff)); - /* go over the rest of the bits */ - while (*tmp != '\0') - { - l = strtol(tmp + 1, &tmp, 10); - sprintf(res + strlen(res), "\\%02x\\%02x\\%02x\\%02x", - (int)(l & 0xff), (int)((l >> 8) & 0xff), (int)((l >> 16) & 0xff), - (int)((l >> 24) & 0xff)); - } - return res; -} - -/* return the last security identifier of the binary sid */ -long int binsid2id(const char *binsid) -{ - int i; - /* find the position of the last security id */ - i = 2 + 6 + ((((int)binsid[1]) & 0xff) - 1) * 4; - return (((long int)binsid[i]) & 0xff) | - ((((long int)binsid[i + 1]) & 0xff) << 8) | - ((((long int)binsid[i + 2]) & 0xff) << 16) | - ((((long int)binsid[i + 3]) & 0xff) << 24); -} - -#ifdef WANT_STRTOUI -/* provide a strtoui() implementation, similar to strtoul() but returning - an range-checked unsigned int instead */ -unsigned int strtoui(const char *nptr, char **endptr, int base) -{ - unsigned long val; - val = strtoul(nptr, endptr, base); - if (val > UINT_MAX) - { - errno = ERANGE; - return UINT_MAX; - } - /* If errno was set by strtoul, we'll pass it back as-is */ - return (unsigned int)val; -} -#endif /* WANT_STRTOUI */ diff --git a/nslcd/common.h b/nslcd/common.h index 7951588..e75585e 100644 --- a/nslcd/common.h +++ b/nslcd/common.h @@ -77,53 +77,9 @@ int mysnprintf(char *buffer, size_t buflen, const char *format, ...) /* get a name of a signal with a given signal number */ const char *signame(int signum); -/* This tries to get the user password attribute from the entry. - It will try to return an encrypted password as it is used in /etc/passwd, - /etc/group or /etc/shadow depending upon what is in the directory. - This function will return NULL if no passwd is found and will return the - literal value in the directory if conversion is not possible. */ -const char *get_userpassword(MYLDAP_ENTRY *entry, const char *attr, - char *buffer, size_t buflen); - -/* convert the provided string representation of a sid - (e.g. S-1-5-21-1936905831-823966427-12391542-23578) - to a format that can be used to search the objectSid property with */ -MUST_USE char *sid2search(const char *sid); - -/* return the last security identifier of the binary sid */ -MUST_USE long int binsid2id(const char *binsid); - /* checks to see if the specified string is a valid user or group name */ MUST_USE int isvalidname(const char *name); -/* Perform an LDAP lookup to translate the DN into a uid. - This function either returns NULL or a strdup()ed string. */ -MUST_USE char *lookup_dn2uid(MYLDAP_SESSION *session, const char *dn, - int *rcp, char *buf, size_t buflen); - -/* transforms the DN info a uid doing an LDAP lookup if needed */ -MUST_USE char *dn2uid(MYLDAP_SESSION *session, const char *dn, char *buf, - size_t buflen); - -/* use the user id to lookup an LDAP entry */ -MYLDAP_ENTRY *uid2entry(MYLDAP_SESSION *session, const char *uid, int *rcp); - -/* transforms the uid into a DN by doing an LDAP lookup */ -MUST_USE char *uid2dn(MYLDAP_SESSION *session, const char *uid, char *buf, - size_t buflen); - -/* use the user id to lookup an LDAP entry with the shadow attributes - requested */ -MYLDAP_ENTRY *shadow_uid2entry(MYLDAP_SESSION *session, const char *username, - int *rcp); - -/* return shadow information */ -void get_shadow_properties(MYLDAP_ENTRY *entry, long *lastchangedate, - long *mindays, long *maxdays, long *warndays, - long *inactdays, long *expiredate, - unsigned long *flag); - - /* check whether the nsswitch file should be reloaded */ void nsswitch_check_reload(void); @@ -135,72 +91,13 @@ int nsswitch_shadow_uses_ldap(void); int invalidator_start(void); /* signal invalidator to invalidate the selected external cache */ -void invalidator_do(enum ldap_map_selector map); - -/* fallback definition of HOST_NAME_MAX */ -#ifndef HOST_NAME_MAX -#ifdef _POSIX_HOST_NAME_MAX -#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX -#else -#define HOST_NAME_MAX 255 -#endif /* _POSIX_HOST_NAME_MAX */ -#endif /* not HOST_NAME_MAX */ +void invalidator_do(enum nss_map_selector map); /* common buffer lengths */ #define BUFLEN_NAME 256 /* user, group names and such */ -#define BUFLEN_SAFENAME 300 /* escaped name */ #define BUFLEN_PASSWORD 128 /* passwords */ -#define BUFLEN_PASSWORDHASH 256 /* passwords hashes */ -#define BUFLEN_DN 512 /* distinguished names */ -#define BUFLEN_SAFEDN 600 /* escapedd dn */ -#define BUFLEN_HOSTNAME (HOST_NAME_MAX + 1) /* host names (+ escaped) */ #define BUFLEN_MESSAGE 1024 /* message strings */ -/* provide strtouid() function alias */ -#if SIZEOF_UID_T == SIZEOF_UNSIGNED_LONG_INT -#define strtouid (uid_t)strtoul -#elif SIZEOF_UID_T == SIZEOF_UNSIGNED_LONG_LONG_INT -#define strtouid (uid_t)strtoull -#elif SIZEOF_UID_T == SIZEOF_UNSIGNED_INT -#define WANT_STRTOUI 1 -#define strtouid (uid_t)strtoui -#else -#error unable to find implementation for strtouid() -#endif - -/* provide strtogid() function alias */ -#if SIZEOF_GID_T == SIZEOF_UNSIGNED_LONG_INT -#define strtogid (gid_t)strtoul -#elif SIZEOF_GID_T == SIZEOF_UNSIGNED_LONG_LONG_INT -#define strtogid (gid_t)strtoull -#elif SIZEOF_GID_T == SIZEOF_UNSIGNED_INT -#ifndef WANT_STRTOUI -#define WANT_STRTOUI 1 -#endif -#define strtogid (gid_t)strtoui -#else -#error unable to find implementation for strtogid() -#endif - -#ifdef WANT_STRTOUI -/* provide a strtoui() if it is needed */ -unsigned int strtoui(const char *nptr, char **endptr, int base); -#endif /* WANT_STRTOUI */ - -/* these are the functions for initialising the database specific - modules */ -void alias_init(void); -void ether_init(void); -void group_init(void); -void host_init(void); -void netgroup_init(void); -void network_init(void); -void passwd_init(void); -void protocol_init(void); -void rpc_init(void); -void service_init(void); -void shadow_init(void); - /* these are the different functions that handle the database specific actions, see nslcd.h for the action descriptions */ #include "dispatch.h" diff --git a/nslcd/db_pam.c b/nslcd/db_pam.c index 08a9a4a..045962c 100644 --- a/nslcd/db_pam.c +++ b/nslcd/db_pam.c @@ -74,7 +74,7 @@ NSLCD_HANDLE_UID(PAM, AUTHC char username[BUFLEN_NAME]; char service[BUFLEN_NAME]; char ruser[BUFLEN_NAME]; - char rhost[BUFLEN_HOSTNAME]; + char rhost[HOST_NAME_MAX+1]; char tty[64]; char password[BUFLEN_PASSWORD]; struct authc _entry; @@ -102,7 +102,7 @@ NSLCD_HANDLE_UID(PAM, AUTHC for (; i < session->cnt; i++) { - if (strcmp(username, session->users[i].pw_name)==0) { + if (STR_CMP(username, session->users[i].pw_name)==0) { *rcp = 0; i = session->cnt; user = &(session->users[i]); @@ -142,7 +142,7 @@ NSLCD_HANDLE(PAM, AUTHZ char username[BUFLEN_NAME]; char service[BUFLEN_NAME]; char ruser[BUFLEN_NAME]; - char rhost[BUFLEN_HOSTNAME]; + char rhost[HOST_NAME_MAX+1]; char tty[64]; struct authz _entry; ,/* read */ @@ -163,7 +163,7 @@ NSLCD_HANDLE(PAM, AUTHZ for (size_t i = 0; i < session->cnt; i++) { - if (strcmp(username, session->users[i].pw_name)==0) { + if (STR_CMP(username, session->users[i].pw_name)==0) { *rcp = 0; i = session->cnt; user = &(session->users[i]); @@ -201,7 +201,7 @@ NSLCD_HANDLE(PAM, SESS_O char username[BUFLEN_NAME]; char service[BUFLEN_NAME]; char ruser[BUFLEN_NAME]; - char rhost[BUFLEN_HOSTNAME]; + char rhost[HOST_NAME_MAX+1]; char tty[64]; char sessionid[25]; static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -246,7 +246,7 @@ NSLCD_HANDLE(PAM, SESS_C char username[BUFLEN_NAME]; char service[BUFLEN_NAME]; char ruser[BUFLEN_NAME]; - char rhost[BUFLEN_HOSTNAME]; + char rhost[HOST_NAME_MAX+1]; char tty[64]; char sessionid[64]; ,/* read */ diff --git a/nslcd/invalidator.c b/nslcd/invalidator.c index 7b9520b..11ffa5c 100644 --- a/nslcd/invalidator.c +++ b/nslcd/invalidator.c @@ -41,7 +41,7 @@ static int signalfd = -1; /* we have our own implementation because nscd could use different names */ -static const char *map2name(enum ldap_map_selector map) +static const char *map2name(enum nss_map_selector map) { switch (map) { @@ -183,7 +183,7 @@ static void handle_requests(int fd) } else { - db = map2name((enum ldap_map_selector)c); + db = map2name((enum nss_map_selector)c); if (db == NULL) log_log(LOG_ERR, "invalidator: invalid db received"); else @@ -245,7 +245,7 @@ int invalidator_start(void) } /* signal invalidator to invalidate the selected external cache */ -void invalidator_do(enum ldap_map_selector map) +void invalidator_do(enum nss_map_selector map) { uint8_t c; int rc; diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c index 3c61bfb..4a005d9 100644 --- a/nslcd/nslcd.c +++ b/nslcd/nslcd.c @@ -419,9 +419,6 @@ int main(int argc, char *argv[]) { int i; sigset_t signalmask, oldmask; -#ifdef HAVE_PTHREAD_TIMEDJOIN_NP - struct timespec ts; -#endif /* HAVE_PTHREAD_TIMEDJOIN_NP */ /* parse the command line */ parse_cmdline(argc, argv); @@ -453,52 +450,7 @@ int main(int argc, char *argv[]) break; if (i < LM_NONE) invalidator_start(); - /* change nslcd group and supplemental groups */ - if ((nslcd_cfg->gid != NOGID) && (nslcd_cfg->uidname != NULL)) - { -#ifdef HAVE_INITGROUPS - /* load supplementary groups */ - if (initgroups(nslcd_cfg->uidname, nslcd_cfg->gid) < 0) - log_log(LOG_WARNING, "cannot initgroups(\"%s\",%d) (ignored): %s", - nslcd_cfg->uidname, (int)nslcd_cfg->gid, strerror(errno)); - else - log_log(LOG_DEBUG, "initgroups(\"%s\",%d) done", - nslcd_cfg->uidname, (int)nslcd_cfg->gid); -#else /* not HAVE_INITGROUPS */ -#ifdef HAVE_SETGROUPS - /* just drop all supplemental groups */ - if (setgroups(0, NULL) < 0) - log_log(LOG_WARNING, "cannot setgroups(0,NULL) (ignored): %s", - strerror(errno)); - else - log_log(LOG_DEBUG, "setgroups(0,NULL) done"); -#else /* not HAVE_SETGROUPS */ - log_log(LOG_DEBUG, "neither initgroups() or setgroups() available"); -#endif /* not HAVE_SETGROUPS */ -#endif /* not HAVE_INITGROUPS */ - } - /* change to nslcd gid */ - if (nslcd_cfg->gid != NOGID) - { - if (setgid(nslcd_cfg->gid) != 0) - { - log_log(LOG_ERR, "cannot setgid(%d): %s", - (int)nslcd_cfg->gid, strerror(errno)); - exit(EXIT_FAILURE); - } - log_log(LOG_DEBUG, "setgid(%d) done", (int)nslcd_cfg->gid); - } - /* change to nslcd uid */ - if (nslcd_cfg->uid != NOUID) - { - if (setuid(nslcd_cfg->uid) != 0) - { - log_log(LOG_ERR, "cannot setuid(%d): %s", - (int)nslcd_cfg->uid, strerror(errno)); - exit(EXIT_FAILURE); - } - log_log(LOG_DEBUG, "setuid(%d) done", (int)nslcd_cfg->uid); - } + /* block all these signals so our worker threads won't handle them */ sigemptyset(&signalmask); sigaddset(&signalmask, SIGHUP); @@ -512,7 +464,7 @@ int main(int argc, char *argv[]) pthread_sigmask(SIG_BLOCK, &signalmask, &oldmask); /* start worker threads */ log_log(LOG_INFO, "accepting connections"); - nslcd_threads = (pthread_t *)malloc(nslcd_cfg->threads * sizeof(pthread_t)); + nslcd_threads = malloc(nslcd_cfg->threads * sizeof(pthread_t)); if (nslcd_threads == NULL) { log_log(LOG_CRIT, "main(): malloc() failed to allocate memory"); @@ -537,6 +489,7 @@ int main(int argc, char *argv[]) install_sighandler(SIGTERM, sig_handler); install_sighandler(SIGUSR1, sig_handler); install_sighandler(SIGUSR2, SIG_IGN); + /* wait until we received a signal */ while ((nslcd_receivedsignal == 0) || (nslcd_receivedsignal == SIGUSR1)) { @@ -549,6 +502,7 @@ int main(int argc, char *argv[]) nslcd_receivedsignal = 0; } } + /* print something about received signal */ log_log(LOG_INFO, "caught signal %s (%d), shutting down", signame(nslcd_receivedsignal), nslcd_receivedsignal); @@ -562,8 +516,10 @@ int main(int argc, char *argv[]) nslcd_serversocket = -1; /* if we can, wait a few seconds for the threads to finish */ #ifdef HAVE_PTHREAD_TIMEDJOIN_NP - ts.tv_sec = time(NULL) + 3; - ts.tv_nsec = 0; + struct timespec ts = { + .tv_sec = time(NULL) + 3, + .tv_nsec = 0, + }; #endif /* HAVE_PTHREAD_TIMEDJOIN_NP */ for (i = 0; i < nslcd_cfg->threads; i++) { -- cgit v1.2.3