Пример #1
0
void
pass_to_motor(gpointer args) {

	PyObject *pcheck, *pyobj_proxy, *py_arguments;
	pcheck = pyobj_proxy = py_arguments = NULL;

	do {
		data_2_python(args, &pyobj_proxy);
		if (pyobj_proxy == NULL){
			ERROR("Not able to generate the python diction proxy");
			break;
		}

		py_arguments = Py_BuildValue("(O,i)", pyobj_proxy, ((struct motor_args*)args)->type_id);
		if (py_arguments == NULL) {
			ERROR("Not able to build the args");
			break;
		}

		if(update_rules(((struct motor_args*)args)->motor_env, ((struct motor_args*)args)->ns_name) == -1){
			ERROR("No rules available, not passing to rules motor");
			break;
		}
		pcheck = PyEval_CallObject((*((struct motor_args*)args)->motor_env)->py_function, py_arguments);
		if (pcheck == NULL) {
			ERROR("Not able to evaluate the function");
			break;
		}
	} while (0);
	Py_XDECREF(pcheck);
	Py_XDECREF(pyobj_proxy);
	Py_XDECREF(py_arguments);
}
Пример #2
0
int main()
{
#ifndef USE_SQL
 FILE *fs_smtp_cur;
 FILE *fs_smtp_tmp;
 char *tmpstr;
 time_t file_time;
#endif /* ndef USE_SQL */
 time_t mytime;
 time_t clear_minutes;

	if( vauth_open( 0 )) {
		vexiterror( stderr, "Initial open." );
	}

	clear_minutes = RELAY_CLEAR_MINUTES * 60;
	mytime = time(NULL);

#ifdef USE_SQL
        /* scan the relays table in mysql, and purge out any
         * entries that are older than our specified timestamp
         */
	vclear_open_smtp(clear_minutes, mytime);
#else
        /* OPEN_SMTP_CUR_FILE is typically ~vpopmail/etc/open-smtp */
	fs_smtp_cur = fopen(OPEN_SMTP_CUR_FILE, "r+");
	if ( fs_smtp_cur != NULL ) {

                /* OPEN_SMTP_TMP_FILE is typically ~vpopmail/etc/open-smtp.tmp */
 		/* create this file */
		fs_smtp_tmp = fopen(OPEN_SMTP_TMP_FILE, "w+");
		if ( fs_smtp_tmp == NULL ) {
			printf ("Error, could not create open-smtp.tmp\n");
			vexit(-1);
		}

		/* read in the contents of the open-smtp file */
		while ( fgets(TmpBuf1, MAX_BUFF, fs_smtp_cur ) != NULL ) {
			/* format is x.x.x.x:ALLOW,RELAYCLIENT="",RBLSMTPD=""<TAB>timestamp */
			snprintf(TmpBuf2, sizeof(TmpBuf2), "%s", TmpBuf1);

			tmpstr = strtok( TmpBuf2, "\t");
			tmpstr = strtok( NULL, "\t");
			/* extract the timestamp for this line */
			if ( tmpstr != NULL ) {
				/* compare the timestamp to see if it is not too old */
				file_time = atoi(tmpstr);
				if ( file_time + clear_minutes > mytime) {
					/* if not too old, copy line out to .tmp file */
					fputs(TmpBuf1, fs_smtp_tmp);
				}
			}
		}
		fclose(fs_smtp_cur);
		fclose(fs_smtp_tmp);

		/* replace open-relay with open-relay.tmp */
		rename(OPEN_SMTP_TMP_FILE, OPEN_SMTP_CUR_FILE);
		/* set correct permissions on file */
		chown(OPEN_SMTP_CUR_FILE,VPOPMAILUID,VPOPMAILGID);
	}
#endif
	/* Now, regardless of backend, build a new tcp.smtp.cdb file
	 *
	 * For mysql this involves combining the tcp.smtp file with
         * the contents of the relay table.
         * For cdb this involves combining the tcp.smtp file with
         * the contents of the open-relay file.
         * The resultant file will then be compiled by the tcprules tool
         * to make a new tcp.smtp.cdb file for tcpserver to use
         */
	update_rules();
	return(vexit(0));
}
Пример #3
0
int read_rules(FILE * fp)
{
    char buf[1024];
    DCELL oLow, oHigh, nLow, nHigh;
    int line, n;

    in_type = DCELL_TYPE;
    out_type = CELL_TYPE;

    rules = (char **)G_malloc(INCR * sizeof(char *));
    rule_size = INCR;

    if (isatty(fileno(fp))) {
	report_range();
	G_message(_("Enter the rule or 'help' for the format description"));
    }
    Rast_fpreclass_init(&rcl_struct);
    for (line = 1;; line++) {
	if (isatty(fileno(fp)))
	    fprintf(stderr, "> ");

	if (!G_getl2(buf, 1024, fp))
	    return nrules;

	G_debug(5, "buf = [%s], strlen(buf)=%d", buf, strlen(buf));

	for (n = 0; buf[n]; n++)
	    if (buf[n] == ',')
		buf[n] = ' ';
	G_strip(buf);
	if (*buf == 0)
	    continue;
	if (*buf == '#')
	    continue;
	if (strcmp(buf, "end") == 0)
	    break;

	if (strcmp(buf, "help") == 0) {
	    G_message(_("Enter a rule in one of these formats:"));
	    G_message(" ");
	    G_message(_("old_low:old_high:new_low:new_high"));
	    G_message(_("old_low:old_high:new_val      (i.e. new_high == new_low)"));
	    G_message(_("*:old_val:new_val             (interval [inf, old_val])"));
	    G_message(_("old_val:*:new_val             (interval [old_val, inf])"));
	    G_message(" ");
	    G_message(_("When finished type \"end\"."));

	    continue;
	}

	/* we read and record into quant table all values, even int as doubles
	   we convert the range and domain values to the right format when we 
	   lookup the values in the quant table */
	switch (sscanf(buf, "%lf:%lf:%lf:%lf", &oLow, &oHigh, &nLow, &nHigh)) {
	case 3:
	    update_type(&out_type, nLow);
	    update_rules(buf);
	    Rast_fpreclass_add_rule(&rcl_struct, oLow, oHigh, nLow, nLow);
	    break;

	case 4:
	    update_type(&out_type, nLow);
	    update_type(&out_type, nHigh);
	    update_rules(buf);
	    Rast_fpreclass_add_rule(&rcl_struct, oLow, oHigh, nLow, nHigh);
	    break;

	default:
	    if (sscanf(buf, "%lf:*:%lf", &oLow, &nLow) == 2) {
		update_type(&out_type, nLow);
		update_rules(buf);
		Rast_fpreclass_set_pos_infinite_rule(&rcl_struct, oLow, nLow);
	    }
	    else if (sscanf(buf, "*:%lf:%lf", &oHigh, &nLow) == 2) {
		update_type(&out_type, nLow);
		update_rules(buf);
		Rast_fpreclass_set_neg_infinite_rule(&rcl_struct, oHigh, nLow);
	    }
	    else
		G_message(_("%s is not a valid rule"), buf);
	    break;
	}			/* switch */
    }				/* loop */
    return nrules;
}