/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <locale.h>
#include <limits.h>
#include <fcntl.h>
#include <synch.h>
#include <thread.h>
#include <string.h>
#include <unistd.h>
#include "nscd_log.h"
#include "nscd_config.h"
#include "nscd_switch.h"
#include "cache.h"
/*
* old nscd debug levels
*/
#define DBG_OFF 0
/* max. chars in a nscd log entry */
/* configuration for the nscd log component */
/* statistics data */
/* if no log file specified, log entry goes to stderr */
/* close old log file and open a new one */
static nscd_rc_t
char *lf)
{
int newlogfd;
/*
*/
/* ignore empty log file specs */
return (NSCD_SUCCESS);
if (_logfd >= 0)
_logfd = -1;
return (NSCD_SUCCESS);
_logfd = 2;
return (NSCD_SUCCESS);
} else {
/*
* In order to open this file securely, we'll try a few tricks
*/
/*
* File already exists... now we need to get cute
* since opening a file in a world-writeable directory
* safely is hard = it could be a hard link or a
* symbolic link to a system file.
*/
if (_nscd_debug == NSCD_DEBUG_NONE)
"logfile \"%s\": %sn",
return (NSCD_CFG_FILE_OPEN_ERROR);
}
if ((newlogfd =
if (_nscd_debug == NSCD_DEBUG_NONE)
"Cannot open new "\
"logfile \"%s\": %s\n", lf,
return (NSCD_CFG_FILE_OPEN_ERROR);
}
} else {
if (_nscd_debug == NSCD_DEBUG_NONE)
"logfile \"%s\": "\
"owned by root\n", lf);
return (NSCD_CFG_FILE_OPEN_ERROR);
}
}
if (_nscd_debug == NSCD_DEBUG_NONE)
}
return (NSCD_SUCCESS);
}
/* log an entry to the configured nscd log file */
void
char *funcname,
char *format,
...)
{
if (_logfd < 0)
return;
if (_nscd_debug == NSCD_DEBUG_OPEN) {
(void) mutex_lock(&loglock);
if (_nscd_debug == NSCD_DEBUG_OPEN &&
*_nscd_logfile_d != '\0' &&
(void) strlcpy(_nscd_logfile_s,
(void) _nscd_set_lf(_nscd_logfile_d);
}
(void) mutex_unlock(&loglock);
} else if (_nscd_debug == NSCD_DEBUG_CLOSE) {
(void) mutex_lock(&loglock);
if (_nscd_debug == NSCD_DEBUG_CLOSE)
(void) _nscd_set_lf(_nscd_logfile_s);
(void) mutex_unlock(&loglock);
}
"<time conversion failed>\t");
} else {
/*
* ctime_r() includes some stuff we don't want;
* adjust length to overwrite " YYYY\n" and
* include tid string length.
*/
safechars, ".%.4ld%s%s\t%s:\n\t\t",
funcname);
}
/*LINTED: E_SEC_PRINTF_VAR_FMT*/
safechars) {
}
(void) mutex_lock(&loglock);
(void) mutex_unlock(&loglock);
}
/*
* Map old nscd debug level (0 -10) to log level:
* -- >= 6: DBG_ALL --> NSCD_LOG_LEVEL_ALL
* -- >= 4: DBG_DBG_NETLOOKUPS --> NSCD_LOG_LEVEL_CANT_FIND
* -- >= 2: DBG_CANT_FIND --> NSCD_LOG_LEVEL_CANT_FIND
* -- >= 0: DBG_OFF --> NSCD_LOG_LEVEL_NONE
*/
static int
int level)
{
return (NSCD_LOG_LEVEL_ALL);
else if (level >= DBG_NETLOOKUPS)
return (NSCD_LOG_LEVEL_CANT_FIND);
else if (level >= DBG_CANT_FIND)
return (NSCD_LOG_LEVEL_CANT_FIND);
return (NSCD_LOG_LEVEL_NONE);
}
return (level);
}
/* ARGSUSED */
void *data,
struct nscd_cfg_param_desc *pdesc,
void *cookie)
{
int off;
/*
* At init time, the whole group of config params are received.
* At update time, group or individual parameter value could
* be received.
*/
/*
* logcfg->logfile should have been opened
* by _nscd_cfg_log_verify()
*/
return (NSCD_SUCCESS);
}
/*
* individual config parameter
*/
return (NSCD_SUCCESS);
}
/*
* logcfg->logfile should have been opened
* by _nscd_cfg_log_verify()
*/
return (NSCD_SUCCESS);
}
/* ARGSUSED */
void *data,
struct nscd_cfg_param_desc *pdesc,
void **cookie)
{
int off;
/*
* There is no switch db specific config params
* for the nscd log component. It is a bug if
* the input param description is global.
*/
return (NSCD_CFG_PARAM_DESC_ERROR);
/*
* At init time, the whole group of config params are received.
* At update time, group or individual parameter value could
* be received.
*/
NSCD_LOG_ALL) == 0)
return (NSCD_CFG_SYNTAX_ERROR);
NSCD_LOG_LEVEL_ALL) == 0)
return (NSCD_CFG_SYNTAX_ERROR);
return (NSCD_SUCCESS);
}
/*
* individual config parameter
*/
return (NSCD_CFG_SYNTAX_ERROR);
return (NSCD_SUCCESS);
}
return (NSCD_CFG_SYNTAX_ERROR);
return (NSCD_SUCCESS);
}
return (_nscd_set_lf((char *)data));
else
return (NSCD_SUCCESS);
}
return (NSCD_CFG_PARAM_DESC_ERROR);
}
/* ARGSUSED */
void **stat,
struct nscd_cfg_stat_desc *sdesc,
{
/* indicate the statistics are static, i.e., do not free */
return (NSCD_SUCCESS);
}
/*
* set the name of the current log file and make it current.
*/
char *name)
{
if (rc != NSCD_SUCCESS)
return (rc);
if (rc != NSCD_SUCCESS)
return (NSCD_SUCCESS);
}
/* Set debug level to the new one and make it current */
int level)
{
int l = 0;
int c = -1;
/* old nscd debug level is 1 to 10, map it to log_level and log_comp */
l = debug_to_log_level(level);
c = NSCD_LOG_CACHE;
} else
l = level;
if (level < 0)
if (c != -1) {
if (rc != NSCD_SUCCESS)
return (rc);
if (rc != NSCD_SUCCESS)
}
if (rc != NSCD_SUCCESS)
return (rc);
if (level < 0)
if (rc != NSCD_SUCCESS)
return (NSCD_SUCCESS);
}
void
char *level,
int llen,
char *file,
int flen)
{
if (_nscd_log_level != 0)
if (*_nscd_logfile != '\0')
}