From 977fe6cdb63ecdeaa067ae9e27c80539b5fefbc5 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 15 Dec 2014 04:01:17 -0500 Subject: add configuring yamldir --- nslcd.conf | 2 ++ nslcd/cfg.c | 23 +++++++++++++++++++++++ nslcd/cfg.h | 2 ++ nslcd/hackers.c | 3 ++- nslcd/hackers.h | 2 +- nslcd/nslcd.c | 2 +- 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/nslcd.conf b/nslcd.conf index 5f1be5f..9ee5853 100644 --- a/nslcd.conf +++ b/nslcd.conf @@ -3,3 +3,5 @@ # between NSS names (see /etc/nsswitch.conf) and LDAP # information in the directory. # See the manual page nslcd.conf(5) for more information. + +yamldir /var/cache/parabola-hackers diff --git a/nslcd/cfg.c b/nslcd/cfg.c index e3f5b9d..086427c 100644 --- a/nslcd/cfg.c +++ b/nslcd/cfg.c @@ -392,6 +392,24 @@ static void handle_validnames(const char *filename, int lnr, free(value); } +static void handle_yamldir( + const char *filename, int lnr, + const char *keyword, char *line, struct nslcd_config *cfg) +{ + char *value; + int l; + /* the rest of the line should be a message */ + value = get_linedup(filename, lnr, keyword, &line); + /* strip quotes if they are present */ + l = strlen(value); + if ((value[0] == '\"') && (value[l - 1] == '\"')) + { + value[l - 1] = '\0'; + value++; + } + cfg->yamldir = value; +} + static void handle_pam_password_prohibit_message( const char *filename, int lnr, const char *keyword, char *line, struct nslcd_config *cfg) @@ -502,6 +520,11 @@ static void cfg_read(const char *filename, struct nslcd_config *cfg) /* get keyword from line and ignore empty lines */ if (get_token(&line, keyword, sizeof(keyword)) == NULL) continue; + /* main options */ + if (strcasecmp(keyword, "yamldir") == 0) + { + handle_yamldir(filename, lnr, keyword, line, cfg); + } /* runtime options */ if (strcasecmp(keyword, "threads") == 0) { diff --git a/nslcd/cfg.h b/nslcd/cfg.h index b7b833c..7e3e6ed 100644 --- a/nslcd/cfg.h +++ b/nslcd/cfg.h @@ -49,6 +49,8 @@ enum nss_map_selector { }; struct nslcd_config { + char *yamldir; + int threads; /* the number of threads to start */ int pagesize; /* set to a greater than 0 to enable handling of paged results with the specified size */ diff --git a/nslcd/hackers.c b/nslcd/hackers.c index 57d4f97..e7b2525 100644 --- a/nslcd/hackers.c +++ b/nslcd/hackers.c @@ -11,12 +11,13 @@ void *hackers_session_worker(void *sess) { return NULL; } -struct session *hackers_session_create(pthread_t *thread) { +struct session *hackers_session_create(pthread_t *thread, const char *yamldir) { struct session *session = malloc(sizeof(struct session)); if (session == NULL) { log_log(LOG_CRIT, "hackers_session_create(): malloc() failed to allocate memory"); exit(EXIT_FAILURE); } + hackers_init(yamldir, session); if (pthread_create(thread, NULL, hackers_session_worker, (void*)session)) { log_log(LOG_ERR, "unable to start hackers worker thread: %s", strerror(errno)); diff --git a/nslcd/hackers.h b/nslcd/hackers.h index e784ec5..24b4488 100644 --- a/nslcd/hackers.h +++ b/nslcd/hackers.h @@ -17,7 +17,7 @@ struct session { }; /*struct session *hackers_session_create(void);*/ /* create */ -struct session *hackers_session_create(pthread_t *); +struct session *hackers_session_create(pthread_t *, const char *); void hackers_session_check(struct session *); /* maintain */ void hackers_session_close(struct session *); /* destroy */ diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c index 1e177b4..9bfcdd2 100644 --- a/nslcd/nslcd.c +++ b/nslcd/nslcd.c @@ -466,7 +466,7 @@ int main(int argc, char *argv[]) log_log(LOG_CRIT, "main(): malloc() failed to allocate memory"); exit(EXIT_FAILURE); } - struct session *session = hackers_session_create(&nslcd_threads[0]); + struct session *session = hackers_session_create(&nslcd_threads[0], nslcd_cfg->yamldir); for (i = 1; i < nslcd_cfg->threads; i++) { if (pthread_create(&nslcd_threads[i], NULL, worker, (void*)session)) -- cgit v1.2.3