static SyntaxTypeMatch CheckParseInt(const char *lval, const char *s, const char *range)
{
Item *split;
int n;
long max = CF_LOWINIT, min = CF_HIGHINIT, val;
/* Numeric types are registered by range separated by comma str "min,max" */
CfDebug("\nCheckParseInt(%s => %s/%s)\n", lval, s, range);
split = SplitString(range, ',');
if ((n = ListLen(split)) != 2)
{
ProgrammingError("INTERN: format specifier for int rvalues is not ok for lval %s - got %d items", lval, n);
}
sscanf(split->name, "%ld", &min);
if (strcmp(split->next->name, "inf") == 0)
{
max = CF_INFINITY;
}
else
{
sscanf(split->next->name, "%ld", &max);
}
DeleteItemList(split);
if (min == CF_HIGHINIT || max == CF_LOWINIT)
{
ProgrammingError("INTERN: could not parse format specifier for int rvalues for lval %s", lval);
}
if (IsCf3VarString(s))
{
return SYNTAX_TYPE_MATCH_ERROR_UNEXPANDED;
}
val = IntFromString(s);
if (val == CF_NOINT)
{
return SYNTAX_TYPE_MATCH_ERROR_INT_PARSE;
}
if (val > max || val < min)
{
return SYNTAX_TYPE_MATCH_ERROR_INT_OUT_OF_RANGE;
}
CfDebug("CheckParseInt - syntax verified\n\n");
return SYNTAX_TYPE_MATCH_OK;
}
开发者ID:jooooooon,项目名称:core,代码行数:55,代码来源:syntax.c
示例9: HailServer
//.........这里部分代码省略.........
if (!IsDefinedClass(ctx, cp->classes))
{
continue;
}
VarRef *ref = VarRefParseFromScope(cp->lval, "control_runagent");
const void *value = EvalContextVariableGet(ctx, ref, NULL);
VarRefDestroy(ref);
if (!value)
{
Log(LOG_LEVEL_ERR, "Unknown lval '%s' in runagent control body", cp->lval);
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_FORCE_IPV4].lval) == 0)
{
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_TRUSTKEY].lval) == 0)
{
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_ENCRYPT].lval) == 0)
{
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_PORT_NUMBER].lval) == 0)
{
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_BACKGROUND].lval) == 0)
{
/*
* Only process this option if are is no -b or -i options specified on
* command line.
*/
if (BACKGROUND || INTERACTIVE)
{
Log(LOG_LEVEL_WARNING,
"'background_children' setting from 'body runagent control' is overridden by command-line option.");
}
else
{
BACKGROUND = BooleanFromString(value);
}
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_MAX_CHILD].lval) == 0)
{
MAXCHILD = (short) IntFromString(value);
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_OUTPUT_TO_FILE].lval) == 0)
{
OUTPUT_TO_FILE = BooleanFromString(value);
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_OUTPUT_DIRECTORY].lval) == 0)
{
if (IsAbsPath(value))
{
strlcpy(OUTPUT_DIRECTORY, value, CF_BUFSIZE);
Log(LOG_LEVEL_VERBOSE, "Setting output direcory to '%s'", OUTPUT_DIRECTORY);
}
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_TIMEOUT].lval) == 0)
{
continue;
}
if (strcmp(cp->lval, CFR_CONTROLBODY[RUNAGENT_CONTROL_HOSTS].lval) == 0)
{
if (HOSTLIST == NULL) // Don't override if command line setting
{
HOSTLIST = value;
}
continue;
}
}
}
const char *expire_after = EvalContextVariableControlCommonGet(ctx, COMMON_CONTROL_LASTSEEN_EXPIRE_AFTER);
if (expire_after)
{
LASTSEENEXPIREAFTER = IntFromString(expire_after) * 60;
}
}
static int VerifyTablePromise(EvalContext *ctx, CfdbConn *cfdb, char *table_path, Rlist *columns, Attributes a, Promise *pp)
{
char name[CF_MAXVARSIZE], type[CF_MAXVARSIZE], query[CF_MAXVARSIZE], table[CF_MAXVARSIZE], db[CF_MAXVARSIZE];
int i, count, size, no_of_cols, *size_table, *done, identified, retval = true;
char **name_table, **type_table;
CfOut(OUTPUT_LEVEL_VERBOSE, "", " -> Verifying promised table structure for \"%s\"", table_path);
if (!ValidateSQLTableName(table_path, db, table))
{
CfOut(OUTPUT_LEVEL_ERROR, "",
" !! The structure of the promiser did not match that for an SQL table, i.e. \"database.table\"\n");
return false;
}
else
{
CfOut(OUTPUT_LEVEL_VERBOSE, "", " -> Assuming database \"%s\" with table \"%s\"", db, table);
}
/* Verify the existence of the tables within the database */
if (!TableExists(cfdb, table))
{
CfOut(OUTPUT_LEVEL_ERROR, "", " !! The database did not contain the promised table \"%s\"\n", table_path);
if ((a.database.operation) && (strcmp(a.database.operation, "create") == 0))
{
if ((!DONTDO) && ((a.transaction.action) != cfa_warn))
{
cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_CHANGE, "", pp, a, " -> Database.table %s doesn't seem to exist, creating\n",
table_path);
return CreateTableColumns(cfdb, table, columns);
}
else
{
CfOut(OUTPUT_LEVEL_ERROR, "", " -> Database.table %s doesn't seem to exist, but only a warning was promised\n",
table_path);
}
}
return false;
}
/* Get a list of the columns in the table */
QueryTableColumns(query, db, table);
CfNewQueryDB(cfdb, query);
if (cfdb->maxcolumns != 3)
{
cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_FAIL, "", pp, a, "Could not make sense of the columns");
CfDeleteQuery(cfdb);
return false;
}
/* Assume that the Rlist has been validated and consists of a,b,c */
count = 0;
no_of_cols = RlistLen(columns);
if (!NewSQLColumns(table, columns, &name_table, &type_table, &size_table, &done))
{
cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_FAIL, "", pp, a, "Could not make sense of the columns");
return false;
}
/* Obtain columns from the named table - if any */
while (CfFetchRow(cfdb))
{
char *sizestr;
name[0] = '\0';
type[0] = '\0';
size = CF_NOINT;
strlcpy(name, CfFetchColumn(cfdb, 0), CF_MAXVARSIZE);
strlcpy(type, CfFetchColumn(cfdb, 1), CF_MAXVARSIZE);
ToLowerStrInplace(type);
sizestr = CfFetchColumn(cfdb, 2);
if (sizestr)
{
size = IntFromString(sizestr);
}
CfOut(OUTPUT_LEVEL_VERBOSE, "", " ... discovered column (%s,%s,%d)", name, type, size);
if (sizestr && (size == CF_NOINT))
{
cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, "", pp, a,
" !! Integer size of SQL datatype could not be determined or was not specified - invalid promise.");
DeleteSQLColumns(name_table, type_table, size_table, done, no_of_cols);
CfDeleteQuery(cfdb);
return false;
}
identified = false;
for (i = 0; i < no_of_cols; i++)
//.........这里部分代码省略.........
//.........这里部分代码省略.........
FnCall *fp = (FnCall *) rval.item;
if (opts.cp_save->rval.type == RVAL_TYPE_FNCALL)
{
if (existing_var_type != DATA_TYPE_NONE)
{
// Already did this
free(scope);
BufferDestroy(&qualified_scope);
return;
}
FnCallResult res = FnCallEvaluate(ctx, fp, pp);
if (res.status == FNCALL_FAILURE)
{
/* We do not assign variables to failed fn calls */
RvalDestroy(res.rval);
free(scope);
BufferDestroy(&qualified_scope);
return;
}
else
{
rval = res.rval;
}
}
else
{
Buffer *conv = BufferNew();
if (strcmp(opts.cp_save->lval, "int") == 0)
{
result = BufferPrintf(conv, "%ld", IntFromString(opts.cp_save->rval.item));
if (result < 0)
{
/*
* Even though there will be no problems with memory allocation, there
* might be other problems.
*/
UnexpectedError("Problems writing to buffer");
free(scope);
BufferDestroy(&qualified_scope);
BufferDestroy(&conv);
return;
}
rval = RvalCopy((Rval) {(char *)BufferData(conv), opts.cp_save->rval.type});
}
else if (strcmp(opts.cp_save->lval, "real") == 0)
{
double real_value = 0.0;
if (DoubleFromString(opts.cp_save->rval.item, &real_value))
{
result = BufferPrintf(conv, "%lf", real_value);
}
else
{
result = BufferPrintf(conv, "(double conversion error)");
}
if (result < 0)
{
/*
* Even though there will be no problems with memory allocation, there
* might be other problems.
*/
开发者ID:baptr,项目名称:core,代码行数:67,代码来源:verify_vars.c
示例12: NewSQLColumns
static int NewSQLColumns(char *table, Rlist *columns, char ***name_table, char ***type_table, int **size_table,
int **done)
{
int i, no_of_cols = RlistLen(columns);
Rlist *cols, *rp;
*name_table = (char **) xmalloc(sizeof(char *) * (no_of_cols + 1));
*type_table = (char **) xmalloc(sizeof(char *) * (no_of_cols + 1));
*size_table = (int *) xmalloc(sizeof(int) * (no_of_cols + 1));
*done = (int *) xmalloc(sizeof(int) * (no_of_cols + 1));
for (i = 0, rp = columns; rp != NULL; rp = rp->next, i++)
{
(*done)[i] = 0;
cols = RlistFromSplitString(RlistScalarValue(rp), ',');
if (!cols)
{
Log(LOG_LEVEL_ERR, "No columns promised for table '%s' - makes no sense", table);
return false;
}
if (cols->val.item == NULL)
{
Log(LOG_LEVEL_ERR, "Malformed column promise for table '%s' - found not even a name", table);
free(*name_table);
free(*type_table);
free(*size_table);
free(*done);
return false;
}
(*name_table)[i] = xstrdup(RlistScalarValue(cols));
if (cols->next == NULL)
{
Log(LOG_LEVEL_ERR, "Malformed column '%s' promised for table '%s' - missing a type", (*name_table)[i],
table);
free(*name_table);
free(*type_table);
free(*size_table);
free(*done);
return false;
}
(*type_table)[i] = xstrdup(RlistScalarValue(cols->next));
if (cols->next->next == NULL)
{
(*size_table)[i] = 0;
}
else
{
if (cols->next->next->val.item)
{
(*size_table)[i] = IntFromString(RlistScalarValue(cols->next->next));
}
else
{
(*size_table)[i] = 0;
}
}
RlistDestroy(cols);
}
return true;
}
static void KeepControlPromises(EvalContext *ctx, const Policy *policy, GenericAgentConfig *config)
{
CFD_MAXPROCESSES = 30;
MAXTRIES = 5;
DENYBADCLOCKS = true;
CFRUNCOMMAND[0] = '\0';
SetChecksumUpdatesDefault(ctx, true);
/* Keep promised agent behaviour - control bodies */
Banner("Server control promises..");
PolicyResolve(ctx, policy, config);
/* Now expand */
Seq *constraints = ControlBodyConstraints(policy, AGENT_TYPE_SERVER);
if (constraints)
{
for (size_t i = 0; i < SeqLength(constraints); i++)
{
Constraint *cp = SeqAt(constraints, i);
#define IsControlBody(e) (strcmp(cp->lval, CFS_CONTROLBODY[e].lval) == 0)
if (!IsDefinedClass(ctx, cp->classes))
{
continue;
}
VarRef *ref = VarRefParseFromScope(cp->lval, "control_server");
const void *value = EvalContextVariableGet(ctx, ref, NULL);
VarRefDestroy(ref);
if (!value)
{
Log(LOG_LEVEL_ERR,
"Unknown lval '%s' in server control body",
cp->lval);
}
else if (IsControlBody(SERVER_CONTROL_SERVER_FACILITY))
{
SetFacility(value);
}
else if (IsControlBody(SERVER_CONTROL_DENY_BAD_CLOCKS))
{
DENYBADCLOCKS = BooleanFromString(value);
Log(LOG_LEVEL_VERBOSE,
"Setting denybadclocks to '%s'",
DENYBADCLOCKS ? "true" : "false");
}
else if (IsControlBody(SERVER_CONTROL_LOG_ENCRYPTED_TRANSFERS))
{
LOGENCRYPT = BooleanFromString(value);
Log(LOG_LEVEL_VERBOSE,
"Setting logencrypt to '%s'",
LOGENCRYPT ? "true" : "false");
}
else if (IsControlBody(SERVER_CONTROL_LOG_ALL_CONNECTIONS))
{
SV.logconns = BooleanFromString(value);
Log(LOG_LEVEL_VERBOSE, "Setting logconns to %d", SV.logconns);
}
else if (IsControlBody(SERVER_CONTROL_MAX_CONNECTIONS))
{
CFD_MAXPROCESSES = (int) IntFromString(value);
MAXTRIES = CFD_MAXPROCESSES / 3;
Log(LOG_LEVEL_VERBOSE,
"Setting maxconnections to %d",
CFD_MAXPROCESSES);
/* The handling of max_readers in LMDB is not ideal, but
* here is how it is right now: We know that both cf-serverd and
* cf-hub will access the lastseen database. Worst case every
* single thread and process will do it at the same time, and
* this has in fact been observed. So we add the maximum of
* those two values together to provide a safe ceiling. In
* addition, cf-agent can access the database occasionally as
* well, so add a few extra for that too. */
DBSetMaximumConcurrentTransactions(CFD_MAXPROCESSES
+ EnterpriseGetMaxCfHubProcesses() + 10);
continue;
}
else if (IsControlBody(SERVER_CONTROL_CALL_COLLECT_INTERVAL))
{
COLLECT_INTERVAL = (int) 60 * IntFromString(value);
Log(LOG_LEVEL_VERBOSE,
"Setting call_collect_interval to %d (seconds)",
COLLECT_INTERVAL);
}
else if (IsControlBody(SERVER_CONTROL_LISTEN))
{
SERVER_LISTEN = BooleanFromString(value);
Log(LOG_LEVEL_VERBOSE,
"Setting server listen to '%s' ",
SERVER_LISTEN ? "true" : "false");
}
else if (IsControlBody(SERVER_CONTROL_CALL_COLLECT_WINDOW))
{
COLLECT_WINDOW = (int) IntFromString(value);
Log(LOG_LEVEL_VERBOSE,
"Setting collect_window to %d (seconds)",
//.........这里部分代码省略.........
请发表评论