expose the single-key validation

This commit is contained in:
Ron Pedde 2006-05-16 06:39:09 +00:00
parent c99e0c23dc
commit 1003812ee9
3 changed files with 39 additions and 22 deletions

View File

@ -87,6 +87,7 @@ static int _conf_existdir(char *path);
static int _conf_split(char *s, char *delimiters, char ***argvp); static int _conf_split(char *s, char *delimiters, char ***argvp);
static void _conf_dispose_split(char **argv); static void _conf_dispose_split(char **argv);
static int _conf_xml_dump(XMLSTRUCT *pxml,LL *pll,int sublevel,char *parent); static int _conf_xml_dump(XMLSTRUCT *pxml,LL *pll,int sublevel,char *parent);
static int _conf_verify_element(char *section, char *key, char *value);
static CONF_ELEMENTS conf_elements[] = { static CONF_ELEMENTS conf_elements[] = {
{ 1, 0, CONF_T_STRING,"general","runas" }, { 1, 0, CONF_T_STRING,"general","runas" },
@ -303,7 +304,7 @@ int _conf_verify_element(char *section, char *key, char *value) {
return CONF_E_BADELEMENT; return CONF_E_BADELEMENT;
} }
switch(pce->conf_elements) { switch(pce->type) {
case CONF_T_MULTICOMMA: /* can't really check these */ case CONF_T_MULTICOMMA: /* can't really check these */
case CONF_T_STRING: case CONF_T_STRING:
return CONF_E_SUCCESS; return CONF_E_SUCCESS;
@ -857,11 +858,11 @@ char *conf_alloc_string(char *section, char *key, char *dflt) {
* @param value value to set it to * @param value value to set it to
* @returns E_CONF_SUCCESS on success, error code otherwise * @returns E_CONF_SUCCESS on success, error code otherwise
*/ */
int conf_set_int(char *section, char *key, int value) { int conf_set_int(char *section, char *key, int value, int verify) {
char buffer[40]; /* ?? */ char buffer[40]; /* ?? */
snprintf(buffer,sizeof(buffer),"%d",value); snprintf(buffer,sizeof(buffer),"%d",value);
return conf_set_string(section, key, buffer); return conf_set_string(section, key, buffer, verify);
} }
/** /**
@ -872,7 +873,7 @@ int conf_set_int(char *section, char *key, int value) {
* @param value value to set it to * @param value value to set it to
* @returns E_CONF_SUCCESS on success, error code otherwise * @returns E_CONF_SUCCESS on success, error code otherwise
*/ */
int conf_set_string(char *section, char *key, char *value) { int conf_set_string(char *section, char *key, char *value, int verify) {
LL_ITEM *pitem; LL_ITEM *pitem;
LL_ITEM *psection; LL_ITEM *psection;
LL *section_ll; LL *section_ll;
@ -886,6 +887,16 @@ int conf_set_string(char *section, char *key, char *value) {
_conf_lock(); _conf_lock();
/* verify the item */ /* verify the item */
err=_conf_verify_element(section,key,value);
if(err != CONF_E_SUCCESS) {
_conf_unlock();
return err;
}
if(verify) {
_conf_unlock();
return CONF_E_SUCCESS;
}
pce = _conf_get_keyinfo(section,key); pce = _conf_get_keyinfo(section,key);
if(pce) if(pce)

View File

@ -1,4 +1,4 @@
o/* /*
* $Id$ * $Id$
* Functions for reading and writing the config file * Functions for reading and writing the config file
* *
@ -19,19 +19,19 @@ o/*
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _CONFIG_H_ #ifndef _CONF_H_
#define _CONFIG_H_ #define _CONF_H_
#define CONF_E_SUCCESS 0 #define CONF_E_SUCCESS 0
#define CONF_E_FOPEN 1 #define CONF_E_FOPEN 1
#define CONF_E_UNKNOWN 2 #define CONF_E_UNKNOWN 2
#define CONF_E_BADHEADER 3 #define CONF_E_BADHEADER 3
#define CONF_E_PARSE 4 #define CONF_E_PARSE 4
#define CONF_E_OVERFLOW 5 /** <Buffer passed too small */ #define CONF_E_OVERFLOW 5 /** <Buffer passed too small */
#define CONF_E_NOCONF 6 /** <No open config file */ #define CONF_E_NOCONF 6 /** <No open config file */
#define CONF_E_NOTFOUND 7 #define CONF_E_NOTFOUND 7
#define CONF_E_NOTWRITABLE 8 #define CONF_E_NOTWRITABLE 8
#define CONF_E_BADELEMENT 9 #define CONF_E_BADELEMENT 9
#define CONF_E_PATHEXPECTED 10 #define CONF_E_PATHEXPECTED 10
#define CONF_E_INTEXPECTED 11 #define CONF_E_INTEXPECTED 11
@ -42,8 +42,8 @@ extern int conf_get_int(char *section, char *key, int dflt);
extern int conf_get_string(char *section, char *key, char *dflt, extern int conf_get_string(char *section, char *key, char *dflt,
char *out, int *size); char *out, int *size);
extern char *conf_alloc_string(char *section, char *key, char *dflt); extern char *conf_alloc_string(char *section, char *key, char *dflt);
extern int conf_set_int(char *section, char *key, int value); extern int conf_set_int(char *section, char *key, int value, int verify);
extern int conf_set_string(char *section, char *key, char *value); extern int conf_set_string(char *section, char *key, char *value, int verify);
extern int conf_isset(char *section, char *key); extern int conf_isset(char *section, char *key);
extern int conf_iswritable(void); extern int conf_iswritable(void);
@ -58,6 +58,5 @@ extern char *conf_get_filename(void);
/* FIXME: get enum functions and move to xml-rpc */ /* FIXME: get enum functions and move to xml-rpc */
#include "webserver.h" #include "webserver.h"
extern int conf_xml_dump(WS_CONNINFO *pwsc); extern int conf_xml_dump(WS_CONNINFO *pwsc);
extern int conf_verify_element(char *section, char *key, char *value);
#endif /* _CONFIG_H_ */ #endif /* _CONF_H_ */

View File

@ -114,18 +114,25 @@ void xml_set_config(WS_CONNINFO *pwsc) {
char *section; char *section;
char *key; char *key;
char *value; char *value;
int verify_only;
int err; int err;
section = ws_getvar(pwsc,"section"); section = ws_getvar(pwsc,"section");
key = ws_getvar(pwsc,"key"); key = ws_getvar(pwsc,"key");
value = ws_getvar(pwsc,"value"); value = ws_getvar(pwsc,"value");
verify_only=0;
if(ws_getvar(pwsc,"verify_only")) {
verify_only = 1;
}
if((!section) || (!key) || (!value)) { if((!section) || (!key) || (!value)) {
xml_return_error(pwsc,500,"Missing section, key, or value"); xml_return_error(pwsc,500,"Missing section, key, or value");
return; return;
} }
if((err=conf_set_string(section,key,value) != CONF_E_SUCCESS)) { if((err=conf_set_string(section,key,value,verify_only)!=CONF_E_SUCCESS)) {
/* should return text error from conf_ */ /* should return text error from conf_ */
xml_return_error(pwsc,500,"conf_set_string: error"); xml_return_error(pwsc,500,"conf_set_string: error");
return; return;