/* $OpenBSD: conf.c,v 1.55 2003/06/03 14:28:16 ho Exp $ */
/* $EOM: conf.c,v 1.48 2000/12/04 02:04:29 angelos Exp $ */
/*
* Copyright (c) 1998, 1999, 2000, 2001 Niklas Hallqvist. All rights reserved.
* Copyright (c) 2000, 2001, 2002 H�kan Olsson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This code was written under funding by Ericsson Radio Systems.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/param.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <err.h>
#include <syslog.h>
#include <libgen.h>
#include <sys/file.h>
#include <time.h>
#include "conffile.h"
#include "xlog.h"
#pragma GCC visibility push(hidden)
static void conf_load_defaults(void);
static char * conf_readfile(const char *path);
static int conf_set(int , const char *, const char *, const char *,
const char *, int , int );
static void conf_parse(int trans, char *buf,
char **section, char **subsection, const char *filename);
struct conf_trans {
TAILQ_ENTRY (conf_trans) link;
int trans;
enum conf_op { CONF_SET, CONF_REMOVE, CONF_REMOVE_SECTION } op;
char *section;
char *arg;
char *tag;
char *value;
int override;
int is_default;
};
TAILQ_HEAD (conf_trans_head, conf_trans) conf_trans_queue;
/*
* Radix-64 Encoding.
*/
static const uint8_t asc2bin[] =
{
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 62, 255, 255, 255, 63,
52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 255, 255, 255, 255, 255, 255,
255, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 255, 255, 255, 255, 255,
255, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 255, 255, 255, 255, 255
};
struct conf_binding {
LIST_ENTRY (conf_binding) link;
char *section;
char *arg;
char *tag;
char *value;
int is_default;
};
LIST_HEAD (conf_bindings, conf_binding) conf_bindings[256];
const char *modified_by = NULL;
static __inline__ uint8_t
conf_hash(const char *s)
{
uint8_t hash = 0;
while (*s) {
hash = ((hash << 1) | (hash >> 7)) ^ tolower (*s);
s++;
}
return hash;
}
/*
* Insert a tag-value combination from LINE (the equal sign is at POS)
*/
static int
conf_remove_now(const char *section, const char *tag)
{
struct conf_binding *cb, *next;
cb = LIST_FIRST(&conf_bindings[conf_hash (section)]);
for (; cb; cb = next) {
next = LIST_NEXT(cb, link);
if (strcasecmp(cb->section, section) == 0
&& strcasecmp(cb->tag, tag) == 0) {
LIST_REMOVE(cb, link);
xlog(LOG_INFO,"[%s]:%s->%s removed", section, tag, cb->value);
free(cb->section);
free(cb->arg);
free(cb->tag);
free(cb->value);
free(cb);
return 0;
}
}
return 1;
}
static int
conf_remove_section_now(const char *section)
{
struct conf_binding *cb, *next;
int unseen = 1;
cb = LIST_FIRST(&conf_bindings[conf_hash (section)]);
for (; cb; cb = next) {
next = LIST_NEXT(cb, link);
if (strcasecmp(cb->section, section) == 0) {
unseen = 0;
LIST_REMOVE(cb, link);
xlog(LOG_INFO, "[%s]:%s->%s removed", section, cb->tag, cb->value);
free(cb->section);
free(cb->arg);
free(cb->tag);
free(cb->value);
free(cb);
}
}
return unseen;
}
/*
* Insert a tag-value combination from LINE (the equal sign is at POS)
* into SECTION of our configuration database.
*/
static int
conf_set_now(const char *section, const char *arg, const char *tag,
const char *value, int override, int is_default)
{
struct conf_binding *node = 0;
if (override)
conf_remove_now(section, tag);
else if (conf_get_section(section, arg, tag)) {
if (!is_default) {
xlog(LOG_INFO, "conf_set: duplicate tag [%s]:%s, ignoring...",
section, tag);
}
return 1;
}
node = calloc(1, sizeof *node);
if (!node) {
xlog_warn("conf_set: calloc (1, %lu) failed", (unsigned long)sizeof *node);
return 1;
}
node->section = strdup(section);
if (arg)
node->arg = strdup(arg);
node->tag = strdup(tag);
node->value = strdup(value);
node->is_default = is_default;
LIST_INSERT_HEAD(&conf_bindings[conf_hash (section)], node, link);
return 0;
}
/* Attempt to construct a relative path to the new file */
static char *
relative_path(const char *oldfile, const char *newfile)
{
char *tmpcopy = NULL;
char *dir = NULL;
char *relpath = NULL;
size_t pathlen;
if (!newfile)
return strdup(oldfile);
if (newfile[0] == '/')
return strdup(newfile);
tmpcopy = strdup(oldfile);
if (!tmpcopy)
goto mem_err;
dir = dirname(tmpcopy);
pathlen = strlen(dir) + strlen(newfile) + 2;
relpath = calloc(1, pathlen);
if (!relpath)
goto mem_err;
snprintf(relpath, pathlen, "%s/%s", dir, newfile);
free(tmpcopy);
return relpath;
mem_err:
if (tmpcopy)
free(tmpcopy);
return NULL;
}
/*
* Parse the line LINE of SZ bytes. Skip Comments, recognize section
* headers and feed tag-value pairs into our configuration database.
*/
static void
conf_parse_line(int trans, char *line, const char *filename, int lineno, char **section, char **subsection)
{
char *val, *ptr;
char *inc_section = NULL, *inc_subsection = NULL;
char *relpath, *subconf;
/* Strip off any leading blanks */
while (isspace(*line))
line++;
/* Ignore blank lines */
if (*line == '\0')
return;
/* Lines starting with '#' or ';' are comments. */
if (*line == '#' || *line == ';')
return;
/* '[section]' parsing... */
if (*line == '[') {
line++;
if (*section) {
free(*section);
*section = NULL;
}
if (*subsection) {
free(*subsection);
*subsection = NULL;
}
/* Strip off any blanks after '[' */
while (isblank(*line))
line++;
/* find the closing ] */
ptr = strchr(line, ']');
if (ptr == NULL) {
xlog_warn("config error at %s:%d: "
"non-matched ']', ignoring until next section",
filename, lineno);
return;
}
/* just ignore everything after the closing ] */
*(ptr--) = '\0';
/* Strip off any blanks before ']' */
while (ptr >= line && isblank(*ptr))
*(ptr--)='\0';
/* look for an arg to split from the section name */
val = strchr(line, '"');
if (val != NULL) {
ptr = val - 1;
*(val++) = '\0';
/* trim away any whitespace before the " */
while (ptr > line && isblank(*ptr))
*(ptr--)='\0';
}
/* copy the section name */
*section = strdup(line);
if (!*section) {
没有合适的资源?快使用搜索试试~ 我知道了~
nfs-utils-2.4.3.tar.gz
需积分: 46 45 下载量 78 浏览量
2020-03-18
12:18:18
上传
评论 1
收藏 1.24MB GZ 举报
温馨提示
共420个文件
c:136个
h:77个
in:44个
nfs-utils2.4.3用于NFS在ARM LINUX系统的移植,具体请参考移植的文章描述,实际测试可用
资源推荐
资源详情
资源评论
收起资源包目录
nfs-utils-2.4.3.tar.gz (420个子文件)
rpcgen.1 10KB
nfs4_uid_to_name.3 5KB
idmapd.conf.5 9KB
configure.ac 21KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 514B
Makefile.am 504B
Makefile.am 479B
Makefile.am 448B
Makefile.am 437B
Makefile.am 432B
Makefile.am 383B
Makefile.am 383B
Makefile.am 377B
Makefile.am 365B
Makefile.am 318B
Makefile.am 309B
Makefile.am 306B
Makefile.am 306B
Makefile.am 304B
Makefile.am 284B
Makefile.am 254B
Makefile.am 250B
Makefile.am 245B
Makefile.am 230B
Makefile.am 202B
Makefile.am 159B
Makefile.am 135B
Makefile.am 123B
Makefile.am 121B
Makefile.am 119B
Makefile.am 108B
AUTHORS 41B
conffile.c 47KB
network.c 45KB
nfs.c 41KB
umich_ldap.c 41KB
krb5_util.c 39KB
cache.c 37KB
rpc_main.c 36KB
sqlite.c 35KB
stropts.c 31KB
getport.c 31KB
nfsstat.c 30KB
rpc_svcout.c 30KB
file.c 25KB
gssd.c 25KB
idmapd.c 23KB
nfsmount.c 23KB
gssd_proc.c 23KB
mountd.c 22KB
exports.c 21KB
nfsdcld.c 20KB
sm-notify.c 19KB
rpc_cout.c 19KB
gums.c 18KB
client.c 17KB
exportfs.c 17KB
libnfsidmap.c 17KB
rpc_parse.c 16KB
fstab.c 16KB
mount.c 15KB
sqlite.c 15KB
svc_create.c 14KB
nfsdcltrack.c 14KB
rpc_socket.c 14KB
rpc.c 14KB
rpc_hout.c 13KB
parse_opt.c 13KB
device-discovery.c 13KB
svcgssd_proc.c 13KB
statd.c 13KB
junction.c 12KB
nfs4mount.c 12KB
dm-device.c 12KB
nss.c 11KB
nsm_client.c 11KB
mount_libmount.c 11KB
monitor.c 11KB
rpc_scan.c 10KB
configfile.c 10KB
nfssvc.c 10KB
nfsd.c 10KB
xml.c 10KB
device-process.c 10KB
rpc_util.c 10KB
nfsidmap.c 9KB
共 420 条
- 1
- 2
- 3
- 4
- 5
资源评论
木子衿L
- 粉丝: 6
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功