X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/8a3ddcfc8179233d007a4ee88f22c17d28e8ea4e..11ef77b76aa0837851bc1c808921c5bacaa3d464:/loadparm.c diff --git a/loadparm.c b/loadparm.c index 4b3741f9..b3197a8c 100644 --- a/loadparm.c +++ b/loadparm.c @@ -17,7 +17,7 @@ * and Karl Auer. Some of the changes are: * * Copyright (C) 2001, 2002 Martin Pool - * Copyright (C) 2003-2008 Wayne Davison + * Copyright (C) 2003-2009 Wayne Davison */ /* Load parameters. @@ -44,12 +44,12 @@ */ #include "rsync.h" -#include "ifuncs.h" -#define PTR_DIFF(p1, p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2))) +#include "itypes.h" + +extern item_list dparam_list; + #define strequal(a, b) (strcasecmp(a, b)==0) #define BOOLSTR(b) ((b) ? "Yes" : "No") -typedef char pstring[1024]; -#define pstrcpy(a, b) strlcpy((a), (b), sizeof (pstring)) #ifndef LOG_DAEMON #define LOG_DAEMON 0 @@ -60,12 +60,12 @@ typedef char pstring[1024]; /* the following are used by loadparm for option lists */ typedef enum { - P_BOOL, P_BOOLREV, P_CHAR, P_INTEGER, P_OCTAL, - P_PATH, P_STRING, P_GSTRING, P_ENUM, P_SEP + P_BOOL, P_BOOLREV, P_CHAR, P_INTEGER, + P_OCTAL, P_PATH, P_STRING, P_ENUM } parm_type; typedef enum { - P_LOCAL, P_GLOBAL, P_SEPARATOR, P_NONE + P_LOCAL, P_GLOBAL, P_NONE } parm_class; struct enum_list { @@ -89,6 +89,7 @@ struct parm_struct { /* some helpful bits */ #define iSECTION(i) ((section*)section_list.items)[i] #define LP_SNUM_OK(i) ((i) >= 0 && (i) < (int)section_list.count) +#define SECTION_PTR(s, p) (((char*)(s)) + (ptrdiff_t)(((char *)(p)) - (char *)&sDefault)) /* * This structure describes global (ie., server-wide) parameters. @@ -148,6 +149,7 @@ typedef struct { BOOL munge_symlinks; BOOL numeric_ids; BOOL read_only; + BOOL reverse_lookup; BOOL strict_modes; BOOL transfer_logging; BOOL use_chroot; @@ -202,6 +204,7 @@ static section sDefault = { /* munge_symlinks; */ (BOOL)-1, /* numeric_ids; */ (BOOL)-1, /* read_only; */ True, + /* reverse_lookup; */ True, /* strict_modes; */ True, /* transfer_logging; */ False, /* use_chroot; */ True, @@ -326,6 +329,7 @@ static struct parm_struct parm_table[] = #endif {"read only", P_BOOL, P_LOCAL, &sDefault.read_only, NULL,0}, {"refuse options", P_STRING, P_LOCAL, &sDefault.refuse_options, NULL,0}, + {"reverse lookup", P_BOOL, P_LOCAL, &sDefault.reverse_lookup, NULL,0}, {"secrets file", P_STRING, P_LOCAL, &sDefault.secrets_file, NULL,0}, {"strict modes", P_BOOL, P_LOCAL, &sDefault.strict_modes, NULL,0}, {"syslog facility", P_ENUM, P_LOCAL, &sDefault.syslog_facility,enum_facilities,0}, @@ -416,6 +420,7 @@ FN_LOCAL_BOOL(lp_list, list) FN_LOCAL_BOOL(lp_munge_symlinks, munge_symlinks) FN_LOCAL_BOOL(lp_numeric_ids, numeric_ids) FN_LOCAL_BOOL(lp_read_only, read_only) +FN_LOCAL_BOOL(lp_reverse_lookup, reverse_lookup) FN_LOCAL_BOOL(lp_strict_modes, strict_modes) FN_LOCAL_BOOL(lp_transfer_logging, transfer_logging) FN_LOCAL_BOOL(lp_use_chroot, use_chroot) @@ -449,8 +454,8 @@ static void copy_section(section *psectionDest, section *psectionSource) for (i = 0; parm_table[i].label; i++) { if (parm_table[i].ptr && parm_table[i].class == P_LOCAL) { void *def_ptr = parm_table[i].ptr; - void *src_ptr = ((char *)psectionSource) + PTR_DIFF(def_ptr, &sDefault); - void *dest_ptr = ((char *)psectionDest) + PTR_DIFF(def_ptr, &sDefault); + void *src_ptr = SECTION_PTR(psectionSource, def_ptr); + void *dest_ptr = SECTION_PTR(psectionDest, def_ptr); switch (parm_table[i].type) { case P_BOOL: @@ -596,8 +601,8 @@ static BOOL set_boolean(BOOL *pb, char *parmvalue) static BOOL do_parameter(char *parmname, char *parmvalue) { int parmnum, i; - void *parm_ptr=NULL; /* where we are going to store the result */ - void *def_ptr=NULL; + void *parm_ptr; /* where we are going to store the result */ + void *def_ptr; char *cp; parmnum = map_parameter(parmname); @@ -616,7 +621,7 @@ static BOOL do_parameter(char *parmname, char *parmvalue) rprintf(FLOG, "Global parameter %s found in module section!\n", parmname); return True; } - parm_ptr = ((char *)&iSECTION(iSectionIndex)) + PTR_DIFF(def_ptr, &sDefault); + parm_ptr = SECTION_PTR(&iSECTION(iSectionIndex), def_ptr); } /* now switch on the type of variable it is */ @@ -655,12 +660,8 @@ static BOOL do_parameter(char *parmname, char *parmvalue) string_set(parm_ptr, parmvalue); break; - case P_GSTRING: - strlcpy((char *)parm_ptr, parmvalue, sizeof (pstring)); - break; - case P_ENUM: - for (i=0;parm_table[parmnum].enum_list[i].name;i++) { + for (i=0; parm_table[parmnum].enum_list[i].name; i++) { if (strequal(parmvalue, parm_table[parmnum].enum_list[i].name)) { *(int *)parm_ptr = parm_table[parmnum].enum_list[i].value; break; @@ -671,8 +672,6 @@ static BOOL do_parameter(char *parmname, char *parmvalue) *(int *)parm_ptr = atoi(parmvalue); } break; - case P_SEP: - break; } return True; @@ -707,8 +706,11 @@ static BOOL do_section(char *sectionname) isglobal = strwicmp(sectionname, GLOBAL_NAME) == 0; /* if we were in a global section then do the local inits */ - if (bInGlobalSection && !isglobal) + if (bInGlobalSection && !isglobal) { + if (!section_list.count) + set_dparams(0); init_locals(); + } /* if we've just struck a global section, note the fact. */ bInGlobalSection = isglobal; @@ -744,17 +746,37 @@ static BOOL do_section(char *sectionname) * False on failure. */ int lp_load(char *pszFname, int globals_only) { - pstring n2; - bInGlobalSection = True; init_globals(); - pstrcpy(n2, pszFname); - /* We get sections first, so have to start 'behind' to make up. */ iSectionIndex = -1; - return pm_process(n2, globals_only ? NULL : do_section, do_parameter); + return pm_process(pszFname, globals_only ? NULL : do_section, do_parameter); +} + +BOOL set_dparams(int syntax_check_only) +{ + char *equal, *val, **params = dparam_list.items; + unsigned j; + + for (j = 0; j < dparam_list.count; j++) { + equal = strchr(params[j], '='); /* options.c verified this */ + *equal = '\0'; + if (syntax_check_only) { + if (map_parameter(params[j]) < 0) { + rprintf(FERROR, "Unknown parameter \"%s\"\n", params[j]); + *equal = '='; + return False; + } + } else { + for (val = equal+1; isSpace(val); val++) {} + do_parameter(params[j], val); + } + *equal = '='; + } + + return True; } /* Return the max number of modules (sections). */