cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The contents of this file are subject to the terms of the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Common Development and Distribution License (the "License").
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You may not use this file except in compliance with the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * or http://www.opensolaris.org/os/licensing.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * See the License for the specific language governing permissions
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * and limitations under the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * When distributing Covered Code, include this CDDL HEADER in each
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * If applicable, add the following below this CDDL HEADER, with the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * fields enclosed by brackets "[]" replaced with your own identifying
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * information: Portions Copyright [yyyy] [name of copyright owner]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER END
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Use is subject to license terms.
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik * Copyright 2012 Milan Jurik. All rights reserved.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <stdlib.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <locale.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <string.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "cache.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "nscd_door.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "nscd_log.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "nscd_admin.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern nsc_ctx_t *cache_ctx_p[];
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern char *cache_name[];
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic nscd_admin_t admin_c = { 0 };
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic nscd_admin_mod_t admin_mod = { 0 };
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic mutex_t mod_lock = DEFAULTMUTEX;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*ARGSUSED*/
cb5caa98562cf06753163f558cbcfe30b8f4673adjlint
cb5caa98562cf06753163f558cbcfe30b8f4673adjl_nscd_door_getadmin(void *outbuf)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl{
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int i;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int data_size = NSCD_N2N_DOOR_BUF_SIZE(admin_c);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nss_pheader_t *phdr = (nss_pheader_t *)outbuf;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_cache_t cfg_default = NSCD_CFG_CACHE_DEFAULTS;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * if size of buffer is not big enough, tell the caller to
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * increase it to the size returned
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (phdr->pbufsiz < data_size)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (sizeof (admin_c));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSCD_SET_STATUS_SUCCESS(phdr);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl phdr->data_off = sizeof (nss_pheader_t);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl phdr->data_len = sizeof (admin_c);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl for (i = 0; i < CACHE_CTX_COUNT; i++) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (cache_ctx_p[i] != NULL) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) rw_rdlock(&cache_ctx_p[i]->cfg_rwlp);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_c.cache_cfg[i] = cache_ctx_p[i]->cfg;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) rw_unlock(&cache_ctx_p[i]->cfg_rwlp);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) mutex_lock(&cache_ctx_p[i]->stats_mutex);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_c.cache_stats[i] = cache_ctx_p[i]->stats;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) mutex_unlock(&cache_ctx_p[i]->stats_mutex);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl } else {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_c.cache_cfg[i] = cfg_default;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) memset(&admin_c.cache_stats[i], 0,
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik sizeof (admin_c.cache_stats[0]));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) memcpy(((char *)outbuf) + phdr->data_off,
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik &admin_c, sizeof (admin_c));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (0);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlvoid
cb5caa98562cf06753163f558cbcfe30b8f4673adjl_nscd_client_showstats()
cb5caa98562cf06753163f558cbcfe30b8f4673adjl{
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) printf("nscd configuration:\n\n");
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) printf("%10d server debug level\n", admin_c.debug_level);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) printf("\"%s\" is server log file\n", admin_c.logfile);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) nsc_info(NULL, NULL, admin_c.cache_cfg, admin_c.cache_stats);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*ARGSUSED*/
cb5caa98562cf06753163f558cbcfe30b8f4673adjlnscd_rc_t
cb5caa98562cf06753163f558cbcfe30b8f4673adjl_nscd_server_setadmin(nscd_admin_mod_t *set)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl{
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_rc_t rc = NSCD_ADMIN_FAIL_TO_SET;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_handle_t *h;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int i, j;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl char *group = "param-group-cache";
cb5caa98562cf06753163f558cbcfe30b8f4673adjl char *dbname;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_error_t *err = NULL;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl char *me = "_nscd_server_setadmin";
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (set == NULL)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl set = &admin_mod;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* one setadmin at a time */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) mutex_lock(&mod_lock);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG_IF(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_DEBUG) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_logit(me, "total_size = %d\n", set->total_size);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_logit(me, "debug_level_set = %d, debug_level = %d\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik set->debug_level_set, set->debug_level);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_logit(me, "logfile_set = %d, logfile = %s\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik set->logfile_set, *set->logfile == '\0' ?
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik "" : set->logfile);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_logit(me, "cache_cfg_num = %d\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik set->cache_cfg_num);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_logit(me, "cache_flush_num = %d\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik set->cache_flush_num);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * global admin stuff
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (set->debug_level_set == nscd_true) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (_nscd_set_debug_level(set->debug_level)
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik != NSCD_SUCCESS) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "unable to set debug level %d\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik set->debug_level);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl goto err_exit;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_c.debug_level = set->debug_level;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (set->logfile_set == nscd_true) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (_nscd_set_log_file(set->logfile) != NSCD_SUCCESS) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "unable to set log file %s\n", set->logfile);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl goto err_exit;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) strlcpy(admin_c.logfile, set->logfile,
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik NSCD_LOGFILE_LEN);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * For caches to be changed
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (set->cache_cfg_num > CACHE_CTX_COUNT) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "number of caches (%d) to change out of bound %s\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik set->cache_cfg_num);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl goto err_exit;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl for (i = 0; i < set->cache_cfg_num; i++) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_cache_t *new_cfg;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl j = set->cache_cfg_set[i];
cb5caa98562cf06753163f558cbcfe30b8f4673adjl new_cfg = &set->cache_cfg[i];
cb5caa98562cf06753163f558cbcfe30b8f4673adjl dbname = cache_name[j];
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (cache_ctx_p[j] == NULL) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "unable to find cache context for %s\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik dbname);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl rc = _nscd_cfg_get_handle(group, dbname, &h, NULL);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (rc != NSCD_SUCCESS) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "unable to get handle for < %s : %s >\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik dbname, group);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl goto err_exit;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl rc = _nscd_cfg_set(h, new_cfg, &err);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (rc != NSCD_SUCCESS) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "unable to set admin data for < %s : %s >\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik dbname, group);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_cfg_free_handle(h);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl goto err_exit;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_cfg_free_handle(h);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * For caches to be flushed
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (set->cache_flush_num > CACHE_CTX_COUNT) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "number of caches (%d) to flush out of bound %s\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik set->cache_flush_num);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl goto err_exit;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl for (i = 0; i < set->cache_flush_num; i++) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int j;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl j = set->cache_flush_set[i];
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (cache_ctx_p[j] == NULL) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "unable to find cache context for %s\n",
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik dbname);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_invalidate(cache_ctx_p[j], NULL, NULL);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl rc = NSCD_SUCCESS;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl err_exit:
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) mutex_unlock(&mod_lock);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (rc);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*ARGSUSED*/
cb5caa98562cf06753163f558cbcfe30b8f4673adjlvoid
cb5caa98562cf06753163f558cbcfe30b8f4673adjl_nscd_door_setadmin(void *buf)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl{
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_rc_t rc;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nss_pheader_t *phdr = (nss_pheader_t *)buf;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl char *me = "_nscd_door_setadmin";
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl rc = _nscd_server_setadmin(NSCD_N2N_DOOR_DATA(nscd_admin_mod_t, buf));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (rc != NSCD_SUCCESS) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSCD_LOG(NSCD_LOG_ADMIN, NSCD_LOG_LEVEL_ERROR)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "SETADMIN call failed\n");
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik NSCD_SET_N2N_STATUS(phdr, NSS_NSCD_PRIV, 0, rc);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl } else {
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik NSCD_SET_STATUS_SUCCESS(phdr);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * for a database 'dbname', add config value 'val' of option 'opt'
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * to the global admin_mod structure
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlint
cb5caa98562cf06753163f558cbcfe30b8f4673adjl_nscd_add_admin_mod(char *dbname, char opt,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl char *val, char *msg, int msglen) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int i, j;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_cache_t *cfg;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_group_info_t gi = NSCD_CFG_GROUP_INFO_CACHE;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl char dbn[64], *cp;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* set initial admin_mod size; assume no cache config to set */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (admin_mod.total_size == 0)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_mod.total_size = sizeof (admin_mod) -
cb5caa98562cf06753163f558cbcfe30b8f4673adjl sizeof (admin_mod.cache_cfg);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* global admin stuff */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (opt == 'l' || opt == 'd') {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (opt == 'l') {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) strlcpy(admin_mod.logfile,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl val, NSCD_LOGFILE_LEN);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_mod.logfile_set = nscd_true;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl } else {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_mod.debug_level = atoi(val);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_mod.debug_level_set = nscd_true;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (0);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* options to be processed next requires cache name */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) strlcpy(dbn, dbname, sizeof (dbn));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if ((cp = strchr(dbn, ',')) != NULL)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *cp = '\0';
cb5caa98562cf06753163f558cbcfe30b8f4673adjl i = get_cache_idx(dbn);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (i == -1) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) snprintf(msg, msglen,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl gettext("invalid cache name \"%s\""), dbn);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (-1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* flush cache ? */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (opt == 'i') {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_mod.cache_flush_set[admin_mod.cache_flush_num++] = i;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (0);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* options to be processed next requires a param value */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (val == NULL) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) snprintf(msg, msglen,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl gettext("value missing after \"%s\""), dbn);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (-1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* try to use an existing cache_cfg in admin_mod */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl for (j = 0; j < admin_mod.cache_cfg_num; j++) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (admin_mod.cache_cfg_set[j] == i)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl break;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* no existing one, set up another one */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (j == admin_mod.cache_cfg_num) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_mod.cache_cfg_set[j] = i;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_mod.cache_cfg_num++;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl admin_mod.total_size += sizeof (admin_mod.cache_cfg[0]);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg = &admin_mod.cache_cfg[j];
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg->gi.num_param = gi.num_param;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl switch (opt) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl case 'e':
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* enable cache */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_cfg_bitmap_set_nth(cfg->gi.bitmap, 0);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (strcmp(val, "yes") == 0)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg->enable = nscd_true;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl else if (strcmp(val, "no") == 0)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg->enable = nscd_false;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl else {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) snprintf(msg, msglen,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl gettext("\"yes\" or \"no\" not specified after \"%s\""), dbn);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (-1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl break;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl case 'c':
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* check files */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_cfg_bitmap_set_nth(cfg->gi.bitmap, 3);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (strcmp(val, "yes") == 0)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg->check_files = nscd_true;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl else if (strcmp(val, "no") == 0)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg->check_files = nscd_false;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl else {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) snprintf(msg, msglen,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl gettext("\"yes\" or \"no\" not specified after \"%s\""), dbn);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (-1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl break;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl case 'p':
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* positive time to live */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_cfg_bitmap_set_nth(cfg->gi.bitmap, 5);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg->pos_ttl = atoi(val);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl break;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl case 'n':
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* negative time to live */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_cfg_bitmap_set_nth(cfg->gi.bitmap, 6);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg->neg_ttl = atoi(val);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl break;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl case 'h':
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* keep hot count */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _nscd_cfg_bitmap_set_nth(cfg->gi.bitmap, 7);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl cfg->keephot = atoi(val);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl break;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (0);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlint
cb5caa98562cf06753163f558cbcfe30b8f4673adjl_nscd_client_getadmin(char opt)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl{
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int callnum;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nss_pheader_t phdr;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (opt == 'G')
cb5caa98562cf06753163f558cbcfe30b8f4673adjl callnum = NSCD_GETPUADMIN;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl else
cb5caa98562cf06753163f558cbcfe30b8f4673adjl callnum = NSCD_GETADMIN;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) _nscd_doorcall_data(callnum, NULL, sizeof (admin_c),
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik &admin_c, sizeof (admin_c), &phdr);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (NSCD_STATUS_IS_NOT_OK(&phdr)) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (0);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlint
cb5caa98562cf06753163f558cbcfe30b8f4673adjl_nscd_client_setadmin()
cb5caa98562cf06753163f558cbcfe30b8f4673adjl{
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (_nscd_doorcall_data(NSCD_SETADMIN, &admin_mod,
7d7551bcfe5ded1738ddbe3268520996a32023b4Milan Jurik sizeof (admin_mod), NULL, 0, NULL));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}