summaryrefslogtreecommitdiff
path: root/nslcd/nslcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'nslcd/nslcd.c')
-rw-r--r--nslcd/nslcd.c60
1 files changed, 8 insertions, 52 deletions
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++)
{