diff options
author | Milan Jurik <milan.jurik@xylab.cz> | 2012-04-19 13:45:01 -0500 |
---|---|---|
committer | Richard Lowe <richlowe@richlowe.net> | 2012-04-26 11:57:41 -0400 |
commit | 7d7551bcfe5ded1738ddbe3268520996a32023b4 (patch) | |
tree | 587149ab46b7330321512059c08ef1d6d1287b5e /usr/src | |
parent | f3390f39074f3a68f54318e83a9801b156b0f5d3 (diff) | |
download | illumos-joyent-7d7551bcfe5ded1738ddbe3268520996a32023b4.tar.gz |
2579 nscd contains several bad macros with side effects
Reviewed by: Joshua M. Clulow <josh@sysmgr.org>
Reviewed by: Vitaliy Gusev <gusev.vitaliy@nexenta.com>
Approved by: Garrett D'Amore <garrett@damore.org>
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/nscd/cache.c | 306 | ||||
-rw-r--r-- | usr/src/cmd/nscd/nscd_admin.c | 43 | ||||
-rw-r--r-- | usr/src/cmd/nscd/nscd_door.c | 54 | ||||
-rw-r--r-- | usr/src/cmd/nscd/nscd_door.h | 27 | ||||
-rw-r--r-- | usr/src/cmd/nscd/nscd_frontend.c | 12 | ||||
-rw-r--r-- | usr/src/cmd/nscd/nscd_selfcred.c | 47 | ||||
-rw-r--r-- | usr/src/cmd/nscd/nscd_switch.c | 59 |
7 files changed, 289 insertions, 259 deletions
diff --git a/usr/src/cmd/nscd/cache.c b/usr/src/cmd/nscd/cache.c index a62dfaa890..709611547e 100644 --- a/usr/src/cmd/nscd/cache.c +++ b/usr/src/cmd/nscd/cache.c @@ -20,6 +20,7 @@ */ /* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2012 Milan Jurik. All rights reserved. */ /* @@ -692,11 +693,11 @@ init_cache(int debug_level) { */ nsc_db_t * make_cache(enum db_type dbtype, int dbop, char *name, - int (*compar) (const void *, const void *), - void (*getlogstr)(char *, char *, size_t, nss_XbyY_args_t *), - uint_t (*gethash)(nss_XbyY_key_t *, int), - enum hash_type httype, int htsize) { - + int (*compar) (const void *, const void *), + void (*getlogstr)(char *, char *, size_t, nss_XbyY_args_t *), + uint_t (*gethash)(nss_XbyY_key_t *, int), + enum hash_type httype, int htsize) +{ nsc_db_t *nscdb; char *me = "make_cache"; @@ -728,7 +729,7 @@ make_cache(enum db_type dbtype, int dbop, char *name, /* The cache is an AVL tree */ avl_create(&nscdb->tree, nscdb->compar, sizeof (nsc_entry_t), - offsetof(nsc_entry_t, avl_link)); + offsetof(nsc_entry_t, avl_link)); /* Assign log routine */ if (getlogstr == NULL) { @@ -957,7 +958,7 @@ _nscd_cfg_cache_get_stat( */ void nsc_info(nsc_ctx_t *ctx, char *dbname, nscd_cfg_cache_t cfg[], - nscd_cfg_stat_cache_t stats[]) + nscd_cfg_stat_cache_t stats[]) { int i; char *me = "nsc_info"; @@ -1040,7 +1041,8 @@ ctx_info(nsc_ctx_t *ctx) { * not a daemon. */ int -nsc_dump(char *dbname, int dbop) { +nsc_dump(char *dbname, int dbop) +{ nsc_ctx_t *ctx; nsc_db_t *nscdb; nscd_bool_t enabled; @@ -1091,35 +1093,38 @@ nsc_dump(char *dbname, int dbop) { /* * These macros are for exclusive use of nsc_lookup */ -#define NSC_LOOKUP_RETURN(retcode, loglevel, fmt) \ - (void) mutex_unlock(&nscdb->db_mutex); \ +#define NSC_LOOKUP_LOG(loglevel, fmt) \ _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_##loglevel) \ - (me, fmt, whoami); \ - return (retcode); - -#define NSC_LOOKUP_NO_CACHE(str) \ - _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) \ - (me, "%s: name service lookup (bypassing cache\n", \ - str); \ - nss_psearch(largs->buffer, largs->bufsize); \ - status = NSCD_GET_STATUS(largs->buffer); \ - _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) \ - (me, "%s: name service lookup status = %d\n", \ - str, status); \ - if (status == NSS_SUCCESS) { \ - return (SUCCESS); \ - } else if (status == NSS_NOTFOUND) \ - return (NOTFOUND); \ - else \ + (me, fmt, whoami); + +static int +nsc_lookup_no_cache(nsc_lookup_args_t *largs, const char *str) +{ + char *me = "nsc_lookup_no_cache"; + nss_status_t status; + + _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) + (me, "%s: name service lookup (bypassing cache)\n", str); + nss_psearch(largs->buffer, largs->bufsize); + status = NSCD_GET_STATUS(largs->buffer); + _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) + (me, "%s: name service lookup status = %d\n", str, status); + if (status == NSS_SUCCESS) { + return (SUCCESS); + } else if (status == NSS_NOTFOUND) { + return (NOTFOUND); + } else { return (SERVERERROR); + } +} /* * This function starts the revalidation and reaper threads * for a cache */ static void -start_threads(nsc_ctx_t *ctx) { - +start_threads(nsc_ctx_t *ctx) +{ int errnum; char *me = "start_threads"; @@ -1128,11 +1133,11 @@ start_threads(nsc_ctx_t *ctx) { */ if (ctx->revalidate_on != nscd_true) { if (thr_create(NULL, NULL, (void *(*)(void *))revalidate, - ctx, 0, NULL) != 0) { + ctx, 0, NULL) != 0) { errnum = errno; _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_ERROR) - (me, "thr_create (revalidate thread for %s): %s\n", - ctx->dbname, strerror(errnum)); + (me, "thr_create (revalidate thread for %s): %s\n", + ctx->dbname, strerror(errnum)); exit(1); } ctx->revalidate_on = nscd_true; @@ -1143,11 +1148,11 @@ start_threads(nsc_ctx_t *ctx) { */ if (ctx->reaper_on != nscd_true) { if (thr_create(NULL, NULL, (void *(*)(void *))reaper, - ctx, 0, NULL) != 0) { + ctx, 0, NULL) != 0) { errnum = errno; _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_ERROR) - (me, "thr_create (reaper thread for %s): %s\n", - ctx->dbname, strerror(errnum)); + (me, "thr_create (reaper thread for %s): %s\n", + ctx->dbname, strerror(errnum)); exit(1); } ctx->reaper_on = nscd_true; @@ -1239,11 +1244,10 @@ get_dns_ttl(void *pbuf, char *dbname) static int check_config(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, - char *whoami, int flag) + char *whoami, int flag) { nsc_db_t *nscdb; nsc_ctx_t *ctx; - nss_status_t status; char *me = "check_config"; ctx = largs->ctx; @@ -1267,18 +1271,16 @@ check_config(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, if (UPDATEBIT & flag) return (NOTFOUND); - else { - NSC_LOOKUP_NO_CACHE(whoami); - } + else + return (nsc_lookup_no_cache(largs, whoami)); } /* * if caller requests lookup using his * own nsswitch config, bypass cache */ - if (nsw_config_in_phdr(largs->buffer)) { - NSC_LOOKUP_NO_CACHE(whoami); - } + if (nsw_config_in_phdr(largs->buffer)) + return (nsc_lookup_no_cache(largs, whoami)); /* no need of cache if we are dealing with 0 ttls */ if (cfgp->pos_ttl <= 0 && cfgp->neg_ttl <= 0) { @@ -1286,7 +1288,7 @@ check_config(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, return (NOTFOUND); else if (cfgp->avoid_ns == nscd_true) return (SERVERERROR); - NSC_LOOKUP_NO_CACHE(whoami); + return (nsc_lookup_no_cache(largs, whoami)); } return (CONTINUE); @@ -1298,7 +1300,7 @@ check_config(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, */ static void check_db_file(nsc_ctx_t *ctx, nscd_cfg_cache_t cfg, - char *whoami, time_t now) + char *whoami, time_t now) { struct stat buf; nscd_bool_t file_modified = nscd_false; @@ -1343,8 +1345,8 @@ check_db_file(nsc_ctx_t *ctx, nscd_cfg_cache_t cfg, } static int -lookup_int(nsc_lookup_args_t *largs, int flag) { - +lookup_int(nsc_lookup_args_t *largs, int flag) +{ nsc_ctx_t *ctx; nsc_db_t *nscdb; nscd_cfg_cache_t cfg; @@ -1364,7 +1366,7 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { /* extract dbop, dbname, key and cred */ status = nss_packed_getkey(largs->buffer, largs->bufsize, &dbname, - &dbop, &args); + &dbop, &args); if (status != NSS_SUCCESS) { _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_ERROR) (me, "nss_packed_getkey failure (%d)\n", status); @@ -1379,9 +1381,8 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { if (UPDATEBIT & flag) return (NOTFOUND); - else { - NSC_LOOKUP_NO_CACHE(dbname); - } + else + return (nsc_lookup_no_cache(largs, dbname)); } } ctx = largs->ctx; @@ -1390,13 +1391,12 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { if ((largs->nscdb = nsc_get_db(ctx, dbop)) == NULL) { _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_WARNING) (me, "%s:%d: no cache found\n", - dbname, dbop); + dbname, dbop); if (UPDATEBIT & flag) return (NOTFOUND); - else { - NSC_LOOKUP_NO_CACHE(dbname); - } + else + return (nsc_lookup_no_cache(largs, dbname)); } } @@ -1404,7 +1404,7 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { _NSCD_LOG_IF(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_ALL) { (void) nscdb->getlogstr(nscdb->name, whoami, - sizeof (whoami), &args); + sizeof (whoami), &args); } if (UPDATEBIT & flag) { @@ -1436,7 +1436,7 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { /* Either no entry and avoid name service */ if (rc == NSCD_DB_ENTRY_NOT_FOUND || - rc == NSCD_INVALID_ARGUMENT) + rc == NSCD_INVALID_ARGUMENT) return (NOTFOUND); /* OR memory error */ @@ -1483,10 +1483,10 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { if (cfg.avoid_ns == nscd_true) next_action = _NSC_USECACHED; else if ((flag & UPDATEBIT) || - (this_stats->timestamp < now)) { + (this_stats->timestamp < now)) { _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) (me, "%s: cached entry needs to be updated\n", - whoami); + whoami); next_action = _NSC_NSLOOKUP; } else next_action = _NSC_USECACHED; @@ -1506,8 +1506,10 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG_6) (me, "%s: throttling load\n", whoami); - NSC_LOOKUP_RETURN(NOSERVER, WARNING, - "%s: no clearance to wait\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(WARNING, + "%s: no clearance to wait\n"); + return (NOSERVER); } /* yes can wait */ (void) nscd_wait(ctx, nscdb, this_entry); @@ -1535,13 +1537,15 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { (void) mutex_lock(&ctx->stats_mutex); ctx->stats.drop_count++; (void) mutex_unlock(&ctx->stats_mutex); - NSC_LOOKUP_RETURN(NOSERVER, WARNING, - "%s: no clearance for lookup\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(WARNING, + "%s: no clearance for lookup\n"); + return (NOSERVER); } /* block any threads accessing this entry */ - this_stats->status = (flag & UPDATEBIT)? - ST_UPDATE_PENDING:ST_LOOKUP_PENDING; + this_stats->status = (flag & UPDATEBIT) ? + ST_UPDATE_PENDING : ST_LOOKUP_PENDING; /* release lock and do name service lookup */ (void) mutex_unlock(&nscdb->db_mutex); @@ -1556,7 +1560,7 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) (me, "%s: name service lookup status = %d\n", - whoami, status); + whoami, status); if (status == NSS_SUCCESS) { int ttl; @@ -1568,20 +1572,24 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { status = dup_packed_buffer(largs, this_entry); if (status != NSS_SUCCESS) { delete_entry(nscdb, ctx, this_entry); - NSC_LOOKUP_RETURN(SERVERERROR, ERROR, - "%s: failed to update cache\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(ERROR, + "%s: failed to update cache\n"); + return (SERVERERROR); } /* * store unpacked key in cache */ status = nss_packed_getkey(this_entry->buffer, - this_entry->bufsize, - &dbname, &dbop, &args); + this_entry->bufsize, + &dbname, &dbop, &args); if (status != NSS_SUCCESS) { delete_entry(nscdb, ctx, this_entry); - NSC_LOOKUP_RETURN(SERVERERROR, ERROR, - "%s: failed to extract key\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(ERROR, + "%s: failed to extract key\n"); + return (SERVERERROR); } this_entry->key = args.key; /* struct copy */ @@ -1605,8 +1613,10 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { */ start_threads(ctx); - NSC_LOOKUP_RETURN(SUCCESS, DEBUG, - "%s: cache updated with positive entry\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(DEBUG, + "%s: cache updated with positive entry\n"); + return (SUCCESS); } else if (status == NSS_NOTFOUND) { /* * data not found in name service @@ -1617,25 +1627,32 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { if (NSCD_GET_ERRNO(largs->buffer) == ERANGE) { delete_entry(nscdb, ctx, this_entry); - NSC_LOOKUP_RETURN(NOTFOUND, DEBUG, - "%s: ERANGE, cache not updated with negative entry\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(DEBUG, + "%s: ERANGE, cache not updated " + "with negative entry\n"); + return (NOTFOUND); } status = dup_packed_buffer(largs, this_entry); if (status != NSS_SUCCESS) { delete_entry(nscdb, ctx, this_entry); - NSC_LOOKUP_RETURN(SERVERERROR, ERROR, - "%s: failed to update cache\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(ERROR, + "%s: failed to update cache\n"); + return (SERVERERROR); } /* store unpacked key in cache */ status = nss_packed_getkey(this_entry->buffer, - this_entry->bufsize, - &dbname, &dbop, &args); + this_entry->bufsize, + &dbname, &dbop, &args); if (status != NSS_SUCCESS) { delete_entry(nscdb, ctx, this_entry); - NSC_LOOKUP_RETURN(SERVERERROR, ERROR, - "%s: failed to extract key\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(ERROR, + "%s: failed to extract key\n"); + return (SERVERERROR); } this_entry->key = args.key; /* struct copy */ @@ -1655,8 +1672,10 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { */ start_threads(ctx); - NSC_LOOKUP_RETURN(NOTFOUND, DEBUG, - "%s: cache updated with negative entry\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(DEBUG, + "%s: cache updated with negative entry\n"); + return (NOTFOUND); } else { /* * name service lookup failed @@ -1672,8 +1691,9 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { (void) mutex_unlock(&nscdb->db_mutex); _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_WARNING) - (me, "%s: name service lookup failed (status=%d, errno=%d)\n", - whoami, status, errnum); + (me, "%s: name service lookup failed " + "(status=%d, errno=%d)\n", + whoami, status, errnum); return (SERVERERROR); } @@ -1682,12 +1702,13 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { * found entry in cache */ if (UPDATEBIT & flag) { - NSC_LOOKUP_RETURN(SUCCESS, DEBUG, - "%s: no need to update\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(DEBUG, "%s: no need to update\n"); + return (SUCCESS); } if (NSCD_GET_STATUS((nss_pheader_t *)this_entry->buffer) == - NSS_SUCCESS) { + NSS_SUCCESS) { /* positive hit */ (void) mutex_lock(&ctx->stats_mutex); ctx->stats.pos_hits++; @@ -1695,13 +1716,17 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { /* update response buffer */ if (copy_result(largs->buffer, - this_entry->buffer) != NSS_SUCCESS) { - NSC_LOOKUP_RETURN(SERVERERROR, ERROR, - "%s: response buffer insufficient\n"); + this_entry->buffer) != NSS_SUCCESS) { + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(ERROR, + "%s: response buffer insufficient\n"); + return (SERVERERROR); } - NSC_LOOKUP_RETURN(SUCCESS, DEBUG, - "%s: positive entry in cache\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(DEBUG, + "%s: positive entry in cache\n"); + return (SUCCESS); } else { /* negative hit */ (void) mutex_lock(&ctx->stats_mutex); @@ -1709,18 +1734,21 @@ lookup_int(nsc_lookup_args_t *largs, int flag) { (void) mutex_unlock(&ctx->stats_mutex); NSCD_SET_STATUS((nss_pheader_t *)largs->buffer, - NSCD_GET_STATUS(this_entry->buffer), - NSCD_GET_ERRNO(this_entry->buffer)); + NSCD_GET_STATUS(this_entry->buffer), + NSCD_GET_ERRNO(this_entry->buffer)); NSCD_SET_HERRNO((nss_pheader_t *)largs->buffer, - NSCD_GET_HERRNO(this_entry->buffer)); + NSCD_GET_HERRNO(this_entry->buffer)); - NSC_LOOKUP_RETURN(NOTFOUND, DEBUG, - "%s: negative entry in cache\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(DEBUG, + "%s: negative entry in cache\n"); + return (NOTFOUND); } } - NSC_LOOKUP_RETURN(SERVERERROR, ERROR, - "%s: cache backend failure\n"); + (void) mutex_unlock(&nscdb->db_mutex); + NSC_LOOKUP_LOG(ERROR, "%s: cache backend failure\n"); + return (SERVERERROR); } /* @@ -1741,11 +1769,11 @@ nsc_lookup(nsc_lookup_args_t *largs, int flag) { switch (rc) { case SUCCESS: - NSCD_RETURN_STATUS(phdr, NSS_SUCCESS, 0); + NSCD_SET_STATUS(phdr, NSS_SUCCESS, 0); break; case NOTFOUND: - NSCD_RETURN_STATUS(phdr, NSS_NOTFOUND, -1); + NSCD_SET_STATUS(phdr, NSS_NOTFOUND, -1); break; case SERVERERROR: @@ -1759,7 +1787,7 @@ nsc_lookup(nsc_lookup_args_t *largs, int flag) { break; case NOSERVER: - NSCD_RETURN_STATUS(phdr, NSS_TRYLOCAL, -1); + NSCD_SET_STATUS(phdr, NSS_TRYLOCAL, -1); break; } } @@ -1946,7 +1974,8 @@ do_update(nsc_lookup_args_t *in) { * Invalidate cache */ void -nsc_invalidate(nsc_ctx_t *ctx, char *dbname, nsc_ctx_t **ctxs) { +nsc_invalidate(nsc_ctx_t *ctx, char *dbname, nsc_ctx_t **ctxs) +{ int i; char *me = "nsc_invalidate"; @@ -1957,16 +1986,14 @@ nsc_invalidate(nsc_ctx_t *ctx, char *dbname, nsc_ctx_t **ctxs) { if (dbname) { if ((i = get_cache_idx(dbname)) == -1) { - _NSCD_LOG(NSCD_LOG_CACHE, - NSCD_LOG_LEVEL_WARNING) + _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_WARNING) (me, "%s: invalid cache name\n", dbname); return; } if ((ctx = cache_ctx_p[i]) == NULL) { - _NSCD_LOG(NSCD_LOG_CACHE, - NSCD_LOG_LEVEL_WARNING) + _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_WARNING) (me, "%s: no cache context found\n", - dbname); + dbname); return; } ctx_invalidate(ctx); @@ -1987,7 +2014,8 @@ nsc_invalidate(nsc_ctx_t *ctx, char *dbname, nsc_ctx_t **ctxs) { * Invalidate cache by context */ static void -ctx_invalidate(nsc_ctx_t *ctx) { +ctx_invalidate(nsc_ctx_t *ctx) +{ int i; nsc_entry_t *entry; char *me = "ctx_invalidate"; @@ -2041,8 +2069,8 @@ delete_entry(nsc_db_t *nscdb, nsc_ctx_t *ctx, nsc_entry_t *entry) { static nscd_rc_t lookup_cache(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, - nss_XbyY_args_t *argp, char *whoami, nsc_entry_t **entry) { - + nss_XbyY_args_t *argp, char *whoami, nsc_entry_t **entry) +{ nsc_db_t *nscdb; nsc_ctx_t *ctx; uint_t hash; @@ -2073,8 +2101,8 @@ lookup_cache(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, /* move it to the hash table */ if (nscdb->htable) { if (nscdb->htable[hash] == NULL || - (*entry)->stats.hits >= - nscdb->htable[hash]->stats.hits) { + (*entry)->stats.hits >= + nscdb->htable[hash]->stats.hits) { nscdb->htable[hash] = *entry; } } @@ -2086,18 +2114,16 @@ lookup_cache(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, (me, "%s: cache miss\n", whoami); if (cfgp->avoid_ns == nscd_true) { - _NSCD_LOG(NSCD_LOG_CACHE, - NSCD_LOG_LEVEL_DEBUG) + _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) (me, "%s: avoid name service\n", whoami); return (NSCD_DB_ENTRY_NOT_FOUND); } /* allocate memory for new entry (stub) */ *entry = (nsc_entry_t *)umem_cache_alloc(nsc_entry_cache, - UMEM_DEFAULT); + UMEM_DEFAULT); if (*entry == NULL) { - _NSCD_LOG(NSCD_LOG_CACHE, - NSCD_LOG_LEVEL_ERROR) + _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_ERROR) (me, "%s: memory allocation failure\n", whoami); return (NSCD_NO_MEMORY); } @@ -2132,13 +2158,13 @@ lookup_cache(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, if (cfgp->maxentries > 0 && nentries > cfgp->maxentries) { _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) (me, "%s: maximum entries exceeded -- " - "deleting least recently used entry\n", - whoami); + "deleting least recently used entry\n", + whoami); node = nscdb->qhead; while (node != NULL && node != *entry) { if (node->stats.status == ST_DISCARD || - !(node->stats.status & ST_PENDING)) { + !(node->stats.status & ST_PENDING)) { delete_entry(nscdb, ctx, node); break; } @@ -2156,7 +2182,8 @@ lookup_cache(nsc_lookup_args_t *largs, nscd_cfg_cache_t *cfgp, } static void -reaper(nsc_ctx_t *ctx) { +reaper(nsc_ctx_t *ctx) +{ uint_t ttl, extra_sleep, total_sleep, intervals; uint_t nodes_per_interval, seconds_per_interval; ulong_t nsc_entries; @@ -2207,12 +2234,12 @@ reaper(nsc_ctx_t *ctx) { _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) (me, "%s: total entries = %d, " - "seconds per interval = %d, " - "nodes per interval = %d\n", - ctx->dbname, nsc_entries, seconds_per_interval, - nodes_per_interval); + "seconds per interval = %d, " + "nodes per interval = %d\n", + ctx->dbname, nsc_entries, seconds_per_interval, + nodes_per_interval); total_sleep = reap_cache(ctx, nodes_per_interval, - seconds_per_interval); + seconds_per_interval); extra_sleep = 1 + ttl - total_sleep; if (extra_sleep > 0) (void) sleep(extra_sleep); @@ -2222,7 +2249,8 @@ reaper(nsc_ctx_t *ctx) { static uint_t reap_cache(nsc_ctx_t *ctx, uint_t nodes_per_interval, - uint_t seconds_per_interval) { + uint_t seconds_per_interval) +{ uint_t nodes_togo, total_sleep; time_t now; nsc_entry_t *node, *next_node; @@ -2254,8 +2282,8 @@ reap_cache(nsc_ctx_t *ctx, uint_t nodes_per_interval, if ((node = nscdb->reap_node) == NULL) break; if (node->stats.status == ST_DISCARD || - (!(node->stats.status & ST_PENDING) && - node->stats.timestamp < now)) { + (!(node->stats.status & ST_PENDING) && + node->stats.timestamp < now)) { /* * Delete entry if its discard flag is * set OR if it has expired. Entries @@ -2287,8 +2315,9 @@ reap_cache(nsc_ctx_t *ctx, uint_t nodes_per_interval, */ nentries = avl_numnodes(&nscdb->tree); for (slot = 0, value = _NSC_INIT_HTSIZE_SLOT_VALUE; - slot < _NSC_HTSIZE_NUM_SLOTS && nentries > value; - value = (value << 1) + 1, slot++); + slot < _NSC_HTSIZE_NUM_SLOTS && nentries > value; + value = (value << 1) + 1, slot++) + ; if (nscdb->hash_type == nsc_ht_power2) newhtsize = _NSC_INIT_HTSIZE_POWER2 << slot; else @@ -2302,7 +2331,7 @@ reap_cache(nsc_ctx_t *ctx, uint_t nodes_per_interval, _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_DEBUG) (me, "%s: resizing hash table from %d to %d\n", - nscdb->name, nscdb->htsize, newhtsize); + nscdb->name, nscdb->htsize, newhtsize); /* * Dump old hashes because it would be time @@ -2312,9 +2341,8 @@ reap_cache(nsc_ctx_t *ctx, uint_t nodes_per_interval, nscdb->htable = calloc(newhtsize, sizeof (*(nscdb->htable))); if (nscdb->htable == NULL) { _NSCD_LOG(NSCD_LOG_CACHE, NSCD_LOG_LEVEL_ERROR) - (me, - "%s: memory allocation failure\n", - nscdb->name); + (me, "%s: memory allocation failure\n", + nscdb->name); /* -1 to try later */ nscdb->htsize = -1; } else { @@ -2366,7 +2394,7 @@ reap_cache(nsc_ctx_t *ctx, uint_t nodes_per_interval, node = next_node; next_node = next_node->qprev; if (node->stats.status == ST_DISCARD || - !(node->stats.status & ST_PENDING)) { + !(node->stats.status & ST_PENDING)) { /* Leave nodes with pending updates alone */ delete_entry(nscdb, ctx, node); count++; diff --git a/usr/src/cmd/nscd/nscd_admin.c b/usr/src/cmd/nscd/nscd_admin.c index 5574e88744..8eb9e26203 100644 --- a/usr/src/cmd/nscd/nscd_admin.c +++ b/usr/src/cmd/nscd/nscd_admin.c @@ -21,10 +21,9 @@ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2012 Milan Jurik. All rights reserved. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdlib.h> #include <locale.h> #include <string.h> @@ -72,11 +71,11 @@ _nscd_door_getadmin(void *outbuf) } else { admin_c.cache_cfg[i] = cfg_default; (void) memset(&admin_c.cache_stats[i], 0, - sizeof (admin_c.cache_stats[0])); + sizeof (admin_c.cache_stats[0])); } } (void) memcpy(((char *)outbuf) + phdr->data_off, - &admin_c, sizeof (admin_c)); + &admin_c, sizeof (admin_c)); return (0); } @@ -114,16 +113,16 @@ _nscd_server_setadmin(nscd_admin_mod_t *set) _nscd_logit(me, "total_size = %d\n", set->total_size); _nscd_logit(me, "debug_level_set = %d, debug_level = %d\n", - set->debug_level_set, set->debug_level); + set->debug_level_set, set->debug_level); _nscd_logit(me, "logfile_set = %d, logfile = %s\n", - set->logfile_set, *set->logfile == '\0' ? - "" : set->logfile); + set->logfile_set, *set->logfile == '\0' ? + "" : set->logfile); _nscd_logit(me, "cache_cfg_num = %d\n", - set->cache_cfg_num); + set->cache_cfg_num); _nscd_logit(me, "cache_flush_num = %d\n", - set->cache_flush_num); + set->cache_flush_num); } /* @@ -132,11 +131,11 @@ _nscd_server_setadmin(nscd_admin_mod_t *set) if (set->debug_level_set == nscd_true) { if (_nscd_set_debug_level(set->debug_level) - != NSCD_SUCCESS) { + != NSCD_SUCCESS) { _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR) (me, "unable to set debug level %d\n", - set->debug_level); + set->debug_level); goto err_exit; } @@ -152,7 +151,7 @@ _nscd_server_setadmin(nscd_admin_mod_t *set) goto err_exit; } (void) strlcpy(admin_c.logfile, set->logfile, - NSCD_LOGFILE_LEN); + NSCD_LOGFILE_LEN); } /* @@ -162,7 +161,7 @@ _nscd_server_setadmin(nscd_admin_mod_t *set) _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR) (me, "number of caches (%d) to change out of bound %s\n", - set->cache_cfg_num); + set->cache_cfg_num); goto err_exit; } @@ -177,14 +176,14 @@ _nscd_server_setadmin(nscd_admin_mod_t *set) if (cache_ctx_p[j] == NULL) { _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR) (me, "unable to find cache context for %s\n", - dbname); + dbname); } rc = _nscd_cfg_get_handle(group, dbname, &h, NULL); if (rc != NSCD_SUCCESS) { _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR) (me, "unable to get handle for < %s : %s >\n", - dbname, group); + dbname, group); goto err_exit; } @@ -193,7 +192,7 @@ _nscd_server_setadmin(nscd_admin_mod_t *set) if (rc != NSCD_SUCCESS) { _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR) (me, "unable to set admin data for < %s : %s >\n", - dbname, group); + dbname, group); _nscd_cfg_free_handle(h); @@ -209,7 +208,7 @@ _nscd_server_setadmin(nscd_admin_mod_t *set) _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR) (me, "number of caches (%d) to flush out of bound %s\n", - set->cache_flush_num); + set->cache_flush_num); goto err_exit; } @@ -222,7 +221,7 @@ _nscd_server_setadmin(nscd_admin_mod_t *set) if (cache_ctx_p[j] == NULL) { _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR) (me, "unable to find cache context for %s\n", - dbname); + dbname); } nsc_invalidate(cache_ctx_p[j], NULL, NULL); } @@ -248,9 +247,9 @@ _nscd_door_setadmin(void *buf) _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR) (me, "SETADMIN call failed\n"); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, rc); + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, rc); } else { - NSCD_RETURN_STATUS_SUCCESS(phdr); + NSCD_SET_STATUS_SUCCESS(phdr); } } @@ -393,7 +392,7 @@ _nscd_client_getadmin(char opt) callnum = NSCD_GETADMIN; (void) _nscd_doorcall_data(callnum, NULL, sizeof (admin_c), - &admin_c, sizeof (admin_c), &phdr); + &admin_c, sizeof (admin_c), &phdr); if (NSCD_STATUS_IS_NOT_OK(&phdr)) { return (1); @@ -406,5 +405,5 @@ int _nscd_client_setadmin() { return (_nscd_doorcall_data(NSCD_SETADMIN, &admin_mod, - sizeof (admin_mod), NULL, 0, NULL)); + sizeof (admin_mod), NULL, 0, NULL)); } diff --git a/usr/src/cmd/nscd/nscd_door.c b/usr/src/cmd/nscd/nscd_door.c index dc43c9c92f..9b02c1ea88 100644 --- a/usr/src/cmd/nscd/nscd_door.c +++ b/usr/src/cmd/nscd/nscd_door.c @@ -22,10 +22,9 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2012 Milan Jurik. All rights reserved. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/param.h> #include <string.h> #include <door.h> @@ -48,14 +47,16 @@ initdoor(void *buf, int *doorfd) _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door is %s (fd is %d)\n", NAME_SERVICE_DOOR, - *doorfd); + *doorfd); - if (*doorfd == -1) - NSCD_RETURN_STATUS(phdr, NSS_ERROR, errno); + if (*doorfd == -1) { + NSCD_SET_STATUS(phdr, NSS_ERROR, errno); + return; + } if (door_info(*doorfd, &doori) < 0 || - (doori.di_attributes & DOOR_REVOKED) || - doori.di_data != (uintptr_t)NAME_SERVICE_DOOR_COOKIE) { + (doori.di_attributes & DOOR_REVOKED) || + doori.di_data != (uintptr_t)NAME_SERVICE_DOOR_COOKIE) { /* * we should close doorfd because we just opened it @@ -65,10 +66,11 @@ initdoor(void *buf, int *doorfd) _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door %d not valid\n", *doorfd); - NSCD_RETURN_STATUS(phdr, NSS_ERROR, ECONNREFUSED); + NSCD_SET_STATUS(phdr, NSS_ERROR, ECONNREFUSED); + return; } - NSCD_RETURN_STATUS_SUCCESS(phdr); + NSCD_SET_STATUS_SUCCESS(phdr); } /* general door call functions used by nscd */ @@ -87,15 +89,14 @@ copy_output(void *outdata, int outdlen, (void) memmove(outdata, dp, phdr->data_len); } else { - _NSCD_LOG(NSCD_LOG_FRONT_END, - NSCD_LOG_LEVEL_DEBUG) + _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "output buffer not large enough " - " should be > %d but is %d\n", - phdr->data_len, outdlen); + " should be > %d but is %d\n", + phdr->data_len, outdlen); if (outphdr != NULL) { NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, - 0, NSCD_INVALID_ARGUMENT); + 0, NSCD_INVALID_ARGUMENT); NSCD_COPY_STATUS(outphdr, phdr); } ret = NSS_NSCD_PRIV; @@ -130,7 +131,7 @@ _nscd_doorcall(int callnum) phdr = (nss_pheader_t *)dptr; _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door call (%d) failed (status = %d, error = %s)\n", - callnum, ret, strerror(NSCD_GET_ERRNO(phdr))); + callnum, ret, strerror(NSCD_GET_ERRNO(phdr))); } return (ret); @@ -169,7 +170,7 @@ _nscd_doorcall_data(int callnum, void *indata, int indlen, if (ret != NSS_SUCCESS) { _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door call (%d) failed (status = %d, error = %s)\n", - callnum, ret, strerror(NSCD_GET_ERRNO(phdr_d))); + callnum, ret, strerror(NSCD_GET_ERRNO(phdr_d))); } else { if (phdr != NULL) { NSCD_COPY_STATUS(phdr, phdr_d); @@ -230,7 +231,7 @@ _nscd_doorcall_fd(int fd, int callnum, void *indata, int indlen, _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door call (%d to %d) did not get through (%s)\n", - callnum, fd, strerror(errnum)); + callnum, fd, strerror(errnum)); return (NSS_ERROR); } @@ -250,9 +251,9 @@ _nscd_doorcall_fd(int fd, int callnum, void *indata, int indlen, _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door call (%d to %d) failed: p_status = %d, " - "p_errno = %s, nscd status = %d\n", callnum, fd, - ret, strerror(NSCD_GET_ERRNO(phdr_d)), - NSCD_GET_NSCD_STATUS(phdr_d)); + "p_errno = %s, nscd status = %d\n", callnum, fd, + ret, strerror(NSCD_GET_ERRNO(phdr_d)), + NSCD_GET_NSCD_STATUS(phdr_d)); } else ret = copy_output(outdata, outdlen, phdr_d, phdr); @@ -291,21 +292,20 @@ send_doorfd(void **dptr, size_t *ndata, size_t *adata, _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door call (to fd %d) failed (%s)\n", - doorfd, strerror(errnum)); + doorfd, strerror(errnum)); (void) close(doorfd); - NSCD_RETURN_STATUS(phdr, NSS_ERROR, errnum); + NSCD_SET_STATUS(phdr, NSS_ERROR, errnum); + return; } *adata = param.data_size; *ndata = param.rsize; *dptr = (void *)param.data_ptr; if (*adata == 0 || *dptr == NULL) { - (void) close(doorfd); - _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "no data\n"); - NSCD_RETURN_STATUS(phdr, NSS_ERROR, ENOTCONN); + NSCD_SET_STATUS(phdr, NSS_ERROR, ENOTCONN); } (void) close(doorfd); @@ -348,8 +348,8 @@ _nscd_doorcall_sendfd(int fd, int callnum, void *indata, int indlen, _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door call (%d) failed (status = %d, error = %s)\n", - callnum, NSCD_GET_STATUS(phdr_d), - strerror(NSCD_GET_ERRNO(phdr_d))); + callnum, NSCD_GET_STATUS(phdr_d), + strerror(NSCD_GET_ERRNO(phdr_d))); } return (NSCD_GET_STATUS(phdr_d)); diff --git a/usr/src/cmd/nscd/nscd_door.h b/usr/src/cmd/nscd/nscd_door.h index 3647b59abc..0949e8ed8e 100644 --- a/usr/src/cmd/nscd/nscd_door.h +++ b/usr/src/cmd/nscd/nscd_door.h @@ -22,13 +22,12 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2012 Milan Jurik. All rights reserved. */ #ifndef _NSCD_DOOR_H #define _NSCD_DOOR_H -#pragma ident "%Z%%M% %I% %E% SMI" - /* * Definitions for nscd to nscd door interfaces */ @@ -97,24 +96,10 @@ extern "C" { (ph)->p_herrno = herrno; -#define NSCD_RETURN_STATUS(ph, st, errno) \ - { \ - int e = errno; \ - (ph)->p_status = st; \ - if (e != -1) \ - (ph)->p_errno = e; \ - return; \ - } - #define NSCD_SET_STATUS_SUCCESS(ph) \ (ph)->p_status = NSS_SUCCESS; \ (ph)->p_errno = 0; -#define NSCD_RETURN_STATUS_SUCCESS(ph) \ - (ph)->p_status = NSS_SUCCESS; \ - (ph)->p_errno = 0; \ - return; - #define NSCD_SET_N2N_STATUS(ph, st, errno, n2nst) \ { \ int e = errno; \ @@ -124,16 +109,6 @@ extern "C" { (ph)->nscdpriv = n2nst; \ } -#define NSCD_RETURN_N2N_STATUS(ph, st, errno, n2nst) \ - { \ - int e = errno; \ - (ph)->p_status = st; \ - if (e != -1) \ - (ph)->p_errno = e; \ - (ph)->nscdpriv = n2nst; \ - return; \ - } - #define NSCD_STATUS_IS_OK(ph) \ (((ph)->p_status) == NSS_SUCCESS) diff --git a/usr/src/cmd/nscd/nscd_frontend.c b/usr/src/cmd/nscd/nscd_frontend.c index 70efcb8258..7ed5e71bca 100644 --- a/usr/src/cmd/nscd/nscd_frontend.c +++ b/usr/src/cmd/nscd/nscd_frontend.c @@ -21,6 +21,7 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2012 Milan Jurik. All rights reserved. */ #include <stdlib.h> @@ -389,7 +390,8 @@ N2N_check_priv( _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) (me, "door_ucred: %s\n", strerror(errno)); - NSCD_RETURN_STATUS(phdr, NSS_ERROR, errnum); + NSCD_SET_STATUS(phdr, NSS_ERROR, errnum); + return; } eset = ucred_getprivset(uc, PRIV_EFFECTIVE); @@ -405,7 +407,8 @@ N2N_check_priv( ucred_getruid(uc), ucred_geteuid(uc), zoneid); ucred_free(uc); - NSCD_RETURN_STATUS(phdr, NSS_ERROR, EACCES); + NSCD_SET_STATUS(phdr, NSS_ERROR, EACCES); + return; } _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_DEBUG) @@ -415,7 +418,7 @@ N2N_check_priv( ucred_free(uc); - NSCD_RETURN_STATUS_SUCCESS(phdr); + NSCD_SET_STATUS_SUCCESS(phdr); } void @@ -439,7 +442,8 @@ _nscd_APP_check_cred( _NSCD_LOG(log_comp, NSCD_LOG_LEVEL_ERROR) (me, "door_ucred: %s\n", strerror(errno)); - NSCD_RETURN_STATUS(phdr, NSS_ERROR, errnum); + NSCD_SET_STATUS(phdr, NSS_ERROR, errnum); + return; } NSCD_SET_STATUS_SUCCESS(phdr); diff --git a/usr/src/cmd/nscd/nscd_selfcred.c b/usr/src/cmd/nscd/nscd_selfcred.c index fb3f877b5b..df4d2a2c5b 100644 --- a/usr/src/cmd/nscd/nscd_selfcred.c +++ b/usr/src/cmd/nscd/nscd_selfcred.c @@ -520,8 +520,9 @@ _nscd_proc_iamhere( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "door_ucred failed: %s\n", strerror(errnum)); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, errnum, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, errnum, NSCD_DOOR_UCRED_ERROR); + return; } uid = ucred_geteuid(uc); @@ -716,8 +717,9 @@ _nscd_proc_pulse( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "MAIN IMPOSTER CAUGHT! i am %d not NSCD_MAIN\n", iam); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, NSCD_SELF_CRED_MAIN_IMPOSTER); + return; } /* forker doesn't return stats, it just pauses */ @@ -725,11 +727,8 @@ _nscd_proc_pulse( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "forker ready to pause ...\n"); - /*CONSTCOND*/ - while (1) + for (;;) (void) pause(); - - NSCD_RETURN_STATUS_SUCCESS(phdr); } /* remember the current activity sequence number */ @@ -784,8 +783,9 @@ _nscd_proc_fork( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "MAIN IMPOSTER CAUGHT! i am %d not NSCD_MAIN\n", iam); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, NSCD_SELF_CRED_MAIN_IMPOSTER); + return; } /* only forker handles fork requests */ @@ -793,8 +793,9 @@ _nscd_proc_fork( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "MAIN IMPOSTER CAUGHT! I AM NOT FORKER!\n"); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, NSCD_SELF_CRED_WRONG_NSCD); + return; } /* fork a child for the slot assigned by the main nscd */ @@ -809,8 +810,9 @@ _nscd_proc_fork( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "bas slot number\n"); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, NSCD_SELF_CRED_INVALID_SLOT_NUMBER); + return; } _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) @@ -854,7 +856,8 @@ _nscd_proc_fork( NSCD_IMHERE | (NSCD_CHILD & NSCD_WHOAMI), &ih, sizeof (ih), NULL); - NSCD_RETURN_STATUS_SUCCESS(phdr); + NSCD_SET_STATUS_SUCCESS(phdr); + return; } if (cid == (pid_t)-1) { _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "forker unable to fork ...\n"); @@ -953,8 +956,9 @@ _nscd_proc_alt_get( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_ERROR) (me, "no door to talk to the forker\n"); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, NSCD_SELF_CRED_NO_FORKER); + return; } /* get door client's credential information */ @@ -963,8 +967,9 @@ _nscd_proc_alt_get( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "door_ucred failed: %s\n", strerror(errnum)); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, errnum, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, errnum, NSCD_DOOR_UCRED_ERROR); + return; } /* get door client's effective uid and effective gid */ @@ -983,8 +988,9 @@ _nscd_proc_alt_get( (me, "no child slot available (child array = %p, slot = %d)\n", child, ch->child_slot); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, NSCD_SELF_CRED_NO_CHILD_SLOT); + return; } /* create the per user nscd if necessary */ @@ -1036,8 +1042,9 @@ _nscd_proc_alt_get( if (ch->child_state != CHILD_STATE_PIDKNOWN) { - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, NSCD_SELF_CRED_INVALID_SLOT_STATE); + return; } *door = ch->child_door; @@ -1046,7 +1053,7 @@ _nscd_proc_alt_get( (me, "returning door %d for slot %d, uid %d, gid = %d\n", *door, ch->child_slot, set2uid, set2gid); - NSCD_RETURN_STATUS(phdr, NSS_ALTRETRY, 0); + NSCD_SET_STATUS(phdr, NSS_ALTRETRY, 0); } static char ** @@ -1260,8 +1267,9 @@ _nscd_peruser_getadmin( _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_DEBUG) (me, "door_ucred failed: %s\n", strerror(errnum)); - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, errnum, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, errnum, NSCD_DOOR_UCRED_ERROR); + return; } /* get door client's effective uid */ @@ -1275,8 +1283,9 @@ _nscd_peruser_getadmin( /* is the per-user nscd running ? if not, no one to serve */ ch = get_cslot(uid, 1); if (ch == NULL) { - NSCD_RETURN_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, + NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, NSCD_SELF_CRED_NO_CHILD_SLOT); + return; } ret = _nscd_doorcall_fd(ch->child_door, NSCD_GETADMIN, @@ -1457,8 +1466,7 @@ check_user_process(void *arg) int found; char *me = "check_user_process"; - /*CONSTCOND*/ - while (1) { + for (;;) { (void) sleep(60); found = 0; @@ -1492,7 +1500,6 @@ check_user_process(void *arg) } (void) closedir(dp); } - /* NOTREACHED */ /*LINTED E_FUNC_HAS_NO_RETURN_STMT*/ } diff --git a/usr/src/cmd/nscd/nscd_switch.c b/usr/src/cmd/nscd/nscd_switch.c index 386d25e542..44a02b2427 100644 --- a/usr/src/cmd/nscd/nscd_switch.c +++ b/usr/src/cmd/nscd/nscd_switch.c @@ -22,6 +22,7 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2012 Milan Jurik. All rights reserved. */ #include <stdlib.h> /* getenv() */ @@ -1352,13 +1353,15 @@ nss_psearch(void *buffer, size_t length) char *me = "nss_psearch"; if (buffer == NULL || length == 0) { - NSCD_RETURN_STATUS(pbuf, NSS_ERROR, EFAULT); + NSCD_SET_STATUS(pbuf, NSS_ERROR, EFAULT); + return; } status = nss_packed_arg_init(buffer, length, NULL, &initf, &dbop, &arg); if (status != NSS_SUCCESS) { - NSCD_RETURN_STATUS(pbuf, status, -1); + NSCD_SET_STATUS(pbuf, status, -1); + return; } /* @@ -1376,7 +1379,8 @@ nss_psearch(void *buffer, size_t length) */ rc = set_initf_key(pbuf); if (rc != 0) { - NSCD_RETURN_STATUS(pbuf, NSS_UNAVAIL, EINVAL); + NSCD_SET_STATUS(pbuf, NSS_UNAVAIL, EINVAL); + return; } initf = nscd_initf; @@ -1443,7 +1447,8 @@ nscd_map_contextp(void *buffer, nss_getent_t *contextp, nscd_getent_p1_cookie_t *cookie; if (buffer == NULL) { - NSCD_RETURN_STATUS(pbuf, NSS_ERROR, EFAULT); + NSCD_SET_STATUS(pbuf, NSS_ERROR, EFAULT); + return; } off = pbuf->key_off; @@ -1464,7 +1469,8 @@ nscd_map_contextp(void *buffer, nss_getent_t *contextp, if (cookie_num_p != NULL) *cookie_num_p = &cookie->p1_cookie_num; if (setent == 1 && cookie->p1_cookie_num == NSCD_NEW_COOKIE) { - NSCD_RETURN_STATUS_SUCCESS(pbuf); + NSCD_SET_STATUS_SUCCESS(pbuf); + return; } /* @@ -1475,8 +1481,10 @@ nscd_map_contextp(void *buffer, nss_getent_t *contextp, if (cookie->p1_seqnum == NSCD_P0_COOKIE_SEQNUM) { nscd_getent_p0_cookie_t *p0c = (nscd_getent_p0_cookie_t *)cookie; - if (p0c->p0_time == _nscd_get_start_time()) - NSCD_RETURN_STATUS_SUCCESS(pbuf); + if (p0c->p0_time == _nscd_get_start_time()) { + NSCD_SET_STATUS_SUCCESS(pbuf); + return; + } } _NSCD_LOG(NSCD_LOG_SWITCH_ENGINE, NSCD_LOG_LEVEL_DEBUG) @@ -1490,7 +1498,8 @@ nscd_map_contextp(void *buffer, nss_getent_t *contextp, (me, "No matching context found (cookie number: %lld)\n", cookie->p1_cookie_num); - NSCD_RETURN_STATUS(pbuf, NSS_ERROR, EFAULT); + NSCD_SET_STATUS(pbuf, NSS_ERROR, EFAULT); + return; } /* if not called by nss_psetent, verify sequence number */ @@ -1500,12 +1509,13 @@ nscd_map_contextp(void *buffer, nss_getent_t *contextp, (me, "invalid sequence # (%lld)\n", cookie->p1_seqnum); _nscd_free_ctx_if_aborted(ctx); - NSCD_RETURN_STATUS(pbuf, NSS_ERROR, EFAULT); + NSCD_SET_STATUS(pbuf, NSS_ERROR, EFAULT); + return; } contextp->ctx = (struct nss_getent_context *)ctx; - NSCD_RETURN_STATUS_SUCCESS(pbuf); + NSCD_SET_STATUS_SUCCESS(pbuf); } void @@ -1520,7 +1530,8 @@ nss_psetent(void *buffer, size_t length, pid_t pid) char *me = "nss_psetent"; if (buffer == NULL || length == 0) { - NSCD_RETURN_STATUS(pbuf, NSS_ERROR, EFAULT); + NSCD_SET_STATUS(pbuf, NSS_ERROR, EFAULT); + return; } /* @@ -1542,7 +1553,8 @@ nss_psetent(void *buffer, size_t length, pid_t pid) _NSCD_LOG(NSCD_LOG_SWITCH_ENGINE, NSCD_LOG_LEVEL_DEBUG) (me, "NSS_TRYLOCAL: fallback to caller process\n"); - NSCD_RETURN_STATUS(pbuf, NSS_TRYLOCAL, 0); + NSCD_SET_STATUS(pbuf, NSS_TRYLOCAL, 0); + return; } } } @@ -1590,7 +1602,7 @@ nss_psetent(void *buffer, size_t length, pid_t pid) (me, "returning a p0 cookie: pid = %ld, time = %ld, seq #= %llx\n", p0c->p0_pid, p0c->p0_time, p0c->p0_seqnum); - NSCD_RETURN_STATUS(pbuf, NSS_SUCCESS, 0); + NSCD_SET_STATUS(pbuf, NSS_SUCCESS, 0); } static void @@ -1639,14 +1651,15 @@ delayed_setent(nss_pheader_t *pbuf, nss_db_initf_t initf, _NSCD_LOG(NSCD_LOG_SWITCH_ENGINE, NSCD_LOG_LEVEL_DEBUG) (me, "NSS_TRYLOCAL: cookie # = %lld, sequence # = %lld\n", *cookie_num_p, *seqnum_p); - NSCD_RETURN_STATUS(pbuf, NSS_TRYLOCAL, 0); + NSCD_SET_STATUS(pbuf, NSS_TRYLOCAL, 0); + return; } _NSCD_LOG(NSCD_LOG_SWITCH_ENGINE, NSCD_LOG_LEVEL_DEBUG) (me, "NSS_SUCCESS: cookie # = %lld, sequence # = %lld\n", ctx->cookie_num, ctx->seq_num); - NSCD_RETURN_STATUS(pbuf, NSS_SUCCESS, 0); + NSCD_SET_STATUS(pbuf, NSS_SUCCESS, 0); } void @@ -1666,7 +1679,8 @@ nss_pgetent(void *buffer, size_t length) char *me = "nss_pgetent"; if (buffer == NULL || length == 0) { - NSCD_RETURN_STATUS(pbuf, NSS_ERROR, EFAULT); + NSCD_SET_STATUS(pbuf, NSS_ERROR, EFAULT); + return; } /* verify the cookie passed in */ @@ -1680,7 +1694,8 @@ nss_pgetent(void *buffer, size_t length) */ rc = set_initf_key(pbuf); if (rc != 0) { - NSCD_RETURN_STATUS(pbuf, NSS_UNAVAIL, EINVAL); + NSCD_SET_STATUS(pbuf, NSS_UNAVAIL, EINVAL); + return; } initf = nscd_initf; @@ -1703,7 +1718,8 @@ nss_pgetent(void *buffer, size_t length) clear_initf_key(); _nscd_free_ctx_if_aborted( (nscd_getent_context_t *)contextp->ctx); - NSCD_RETURN_STATUS(pbuf, status, -1); + NSCD_SET_STATUS(pbuf, status, -1); + return; } /* Perform local search and pack results into return buffer */ @@ -1751,7 +1767,8 @@ nss_pendent(void *buffer, size_t length) char *me = "nss_pendent"; if (buffer == NULL || length == 0) { - NSCD_RETURN_STATUS(pbuf, NSS_ERROR, EFAULT); + NSCD_SET_STATUS(pbuf, NSS_ERROR, EFAULT); + return; } /* map the contextp from the cookie information */ @@ -1769,7 +1786,7 @@ nss_pendent(void *buffer, size_t length) /* Perform local endent and reset context */ nss_endent(NULL, NULL, contextp); - NSCD_RETURN_STATUS(pbuf, NSS_SUCCESS, 0); + NSCD_SET_STATUS(pbuf, NSS_SUCCESS, 0); } /*ARGSUSED*/ @@ -1779,5 +1796,5 @@ nss_pdelete(void *buffer, size_t length) nss_pheader_t *pbuf = (nss_pheader_t *)buffer; /* unnecessary, kept for completeness */ - NSCD_RETURN_STATUS_SUCCESS(pbuf); + NSCD_SET_STATUS_SUCCESS(pbuf); } |