Пример #1
0
/**
 *  Scan off the xml element name, and the rest of the header, too.
 *  Set the value type to NONE if it ends with "/>".
 *
 * @param[in]  name    the first name character (alphabetic)
 * @param[out] nm_len  the length of the name
 * @param[out] val     set valType field to STRING or NONE.
 *
 * @returns the scan resumption point, or NULL on error
 */
static char const *
scan_xml_name(char const * name, size_t * nm_len, tOptionValue * val)
{
    char const * scan = SPN_VALUE_NAME_CHARS(name + 1);
    *nm_len = (size_t)(scan - name);
    if (*nm_len > 64)
        return NULL;
    val->valType = OPARG_TYPE_STRING;

    if (IS_WHITESPACE_CHAR(*scan)) {
        /*
         * There are attributes following the name.  Parse 'em.
         */
        scan = SPN_WHITESPACE_CHARS(scan);
        scan = parse_attrs(NULL, scan, &option_load_mode, val);
        if (scan == NULL)
            return NULL; /* oops */
    }

    if (! IS_END_XML_TOKEN_CHAR(*scan))
        return NULL; /* oops */

    if (*scan == '/') {
        /*
         * Single element XML entries get inserted as an empty string.
         */
        if (*++scan != '>')
            return NULL;
        val->valType = OPARG_TYPE_NONE;
    }
    return scan+1;
}
Пример #2
0
int packet_fxp_mkdir(Buffer *buff, Buffer *preped_buff) {
    u_int msg_len;
    u_int xmsg_len;
    
    // File names
    u_int file_len;
    u_char *filename;
    
    // Copy first part of packet over to prepared buffer
    msg_len = get_u32(buffer_ptr(buff));
    xmsg_len = msg_len;
    
    buffer_append(preped_buff, buffer_ptr(buff), 9);
    buffer_consume(buff, 9);
    xmsg_len -= 5;
    
    // Rewrite path
    filename = buffer_get_string(buff, &file_len);
    filename = unchroot_filename(filename, (u_char*) user_homedir);
    buffer_put_cstring(preped_buff, (char*) filename);
    xmsg_len -= (file_len + 4);
    msg_len += (strlen((char*) filename) - file_len);
    
    // Copy attributes through, cleaning extensions where required
    parse_attrs(buff, preped_buff, &msg_len, &xmsg_len);
    
    // Copy any remaining packet data over
    buffer_append(preped_buff, buffer_ptr(buff), xmsg_len);
    buffer_consume(buff, xmsg_len);
    
    // Rewrite message length
    put_u32(buffer_end(preped_buff)-msg_len-4, msg_len);
    
    return 1;
}
Пример #3
0
int packet_fxp_fsetstat(Buffer *buff, Buffer *preped_buff) {
    u_int msg_len;
    u_int xmsg_len;
    
    // File names
    u_int file_len;
    u_char *handle;
    
    // Copy first part of packet over to prepared buffer
    msg_len = get_u32(buffer_ptr(buff));
    xmsg_len = msg_len;
    
    buffer_append(preped_buff, buffer_ptr(buff), 9);
    buffer_consume(buff, 9);
    xmsg_len -= 5;
    
    // Copy handle
    handle = buffer_get_string(buff, &file_len);
    buffer_put_string(preped_buff, (char*) handle, file_len);
    xmsg_len -= (file_len + 4);
    
    // Copy attributes through, cleaning extensions where required
    parse_attrs(buff, preped_buff, &msg_len, &xmsg_len);
    
    // Copy any remaining packet data over
    buffer_append(preped_buff, buffer_ptr(buff), xmsg_len);
    buffer_consume(buff, xmsg_len);
    
    // Rewrite message length
    put_u32(buffer_end(preped_buff)-msg_len-4, msg_len);
    
    return 1;
}
Пример #4
0
static int mod_init(void)
{
	load_tm_f load_tm;

	     /* import the TM auto-loading function */
	if ( !(load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) {
		LOG(L_ERR, "ERROR:acc:mod_init: can't import load_tm\n");
		return -1;
	}
	     /* let the auto-loading function load all TM stuff */
	if (load_tm( &tmb )==-1) return -1;
	if (verify_fmt(log_fmt)==-1) return -1;

	     /* register callbacks*/
	     /* listen for all incoming requests  */
	if (tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, on_req, 0, 0) <= 0) {
		LOG(L_ERR,"ERROR:acc:mod_init: cannot register TMCB_REQUEST_IN "
		    "callback\n");
		return -1;
	}

	init_data(log_fmt);

	if (parse_attrs(&avps, &avps_n, attrs) < 0) {
		ERR("Error while parsing 'attrs' module parameter\n");
		return -1;
	}

	return 0;
}
Пример #5
0
Файл: xml.c Проект: arader/crt
static char parse_attrb( const char *name, const char **attr, int def ) {
    const char *truefalse = parse_attrs( name, attr );

    if( truefalse != NULL && strcmp( truefalse, "true" ) == 0 ) {
        return 1;
    }
    else {
        return 0;
    }

    return def;
}
Пример #6
0
Файл: xml.c Проект: arader/crt
static void parse_light( primitive *p, const char **attr ) {
    const char *light = parse_attrs( "light", attr );
    int i;
    float y,z;

    if( light == NULL ) {
        p->is_light = NOT_LIGHT;
    }
    else if( strcmp( light, "point" ) == 0 ) {
        p->is_light = POINT_LIGHT;
    }
    else {
        p->is_light = AREA_LIGHT;

        if( p->type == BOX ) {
            p->grid = (float*)malloc( 192 * sizeof( float ) );

            p->dx = ((box_data*)p->data)->size.x * 0.25f;
            p->dy = ((box_data*)p->data)->size.y * 0.25f;
            p->dz = ((box_data*)p->data)->size.z * 0.25f;

            for( i = 0; i < 64; i++ ) {
                p->grid[ i*3 ] = ((box_data*)p->data)->point.x + (i%4)*p->dx;

                if( i % 4 == 0 ) {
                    z = ((box_data*)p->data)->point.z + ((float)(i>=16?i%16:i)/4.0f)*p->dz;
                    if( i % 16 == 0 ) {
                        y = ((box_data*)p->data)->point.y + ((float)i/16.0f)*p->dy;
                    }
                }

                p->grid[ i*3+1 ] = y;
                p->grid[ i*3+2 ] = z;
            }

            /*
            for( i = 0; i < 16; i++ ) {
                p->grid[i*2] = ((box_data*)p->data)->point.x + (i%4)*p->dx;
                if( i % 4 == 0 ) {
                    z = ((box_data*)p->data)->point.z + ((float)i/4.0f)*p->dz;
                }

                p->grid[i*2+1] = z;
            }
            */
        }
    }
}
Пример #7
0
static int mod_init(void)
{
	load_tm_f load_tm;

	     /* import the TM auto-loading function */
	if ( !(load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) {
		LOG(L_ERR, "ERROR:acc:mod_init: can't import load_tm\n");
		return -1;
	}
	     /* let the auto-loading function load all TM stuff */
	if (load_tm( &tmb )==-1) return -1;
	if (verify_fmt(log_fmt)==-1) return -1;

	     /* register callbacks*/
	     /* listen for all incoming requests  */
	if (tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, on_req, 0 ) <= 0) {
		LOG(L_ERR,"ERROR:acc:mod_init: cannot register TMCB_REQUEST_IN "
		    "callback\n");
		return -1;
	}

	if (bind_dbmod(db_url.s, &acc_dbf) < 0) {
		LOG(L_ERR, "ERROR:acc:mod_init: bind_db failed\n");
		return -1;
	}

	     /* Check database capabilities */
	if (!DB_CAPABILITY(acc_dbf, DB_CAP_INSERT)) {
		LOG(L_ERR, "ERROR:acc:mod_init: Database module does not implement insert function\n");
		return -1;
	}

	init_data(log_fmt);

	if (parse_attrs(&avps, &avps_n, attrs) < 0) {
		ERR("Error while parsing 'attrs' module parameter\n");
		return -1;
	}

	return 0;
}
Пример #8
0
void
notify(const struct sockaddr_nl *nlp, struct nlmsghdr *nlmsgp)
{
    int len;
    int host_len;
    unsigned char cmd;
    struct in_addr any;
    struct iovec iov[NUM_RESP];
    struct rtmsg *rtmp;
    struct rtattr *attrs[RTA_MAX + 1];

    switch (nlmsgp->nlmsg_type) {
    case RTM_NEWROUTE:
        cmd = RTM_CMD_ROUTE_ADD;
        break;
    case RTM_DELROUTE:
        cmd = RTM_CMD_ROUTE_DEL;
        break;
    default:
        error_reply("not a route");
        return;
    }

    len = nlmsgp->nlmsg_len - NLMSG_LENGTH(sizeof(*nlmsgp));
    if (len < 0) {
        error_reply("wrong message length");
        return;
    }

    rtmp = NLMSG_DATA(nlmsgp);

    /* Don't notify routes added by ourselves. */
    if (rtmp->rtm_protocol == RTPROT_ROUTEMACHINE)
        return;

    if (rtmp->rtm_table != RT_TABLE_MAIN)
        return;

    switch (rtmp->rtm_family) {
    case AF_INET:
        host_len = 4;
        break;
    case AF_INET6:
        host_len = 16;
        break;
    default:
        error_reply("bad message family");
        return;
    }

    parse_attrs(attrs, RTM_RTA(rtmp), len);

    iov[CMD].iov_base = &cmd;
    iov[CMD].iov_len  = 1;

    iov[MASK].iov_base = &rtmp->rtm_dst_len;
    iov[MASK].iov_len  = 1;

    any.s_addr = INADDR_ANY;

    if (attrs[RTA_DST] != NULL) {
        iov[DST].iov_base = RTA_DATA(attrs[RTA_DST]);
        iov[DST].iov_len  = (rtmp->rtm_dst_len + 7)/8;
    } else {
        iov[DST].iov_base = &any;
        iov[DST].iov_len  = sizeof(any);
    }

    if (attrs[RTA_GATEWAY] != NULL) {
        iov[GW].iov_base = RTA_DATA(attrs[RTA_GATEWAY]);
        iov[GW].iov_len  = host_len;
    } else {
        iov[GW].iov_base = &any;
        iov[GW].iov_len  = sizeof(any);
    }

    if (attrs[RTA_PRIORITY] != NULL) {
        uint32_t prio = htonl(*(uint32_t *)RTA_DATA(attrs[RTA_PRIORITY]));
        iov[PRIO].iov_base = &prio;
        iov[PRIO].iov_len = 4;
    } else {
        uint32_t prio = htonl(0);
        iov[PRIO].iov_base = &prio;
        iov[PRIO].iov_len = 4;
    }

    writev(STDOUT_FILENO, iov, NUM_RESP);
}
Пример #9
0
/**
 *  "txt" points to a '<' character, followed by an alpha.
 *  The end of the entry is either the "/>" following the name, or else a
 *  "</name>" string.
 */
static char *
handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir)
{
    tOptionLoadMode mode = option_load_mode;
    tOptionValue    valu;

    char* pzName = ++txt;
    char* pzData;
    char* pcNulPoint;

    txt = SPN_VALUE_NAME_CHARS(txt);
    pcNulPoint = txt;
    valu.valType = OPARG_TYPE_STRING;

    switch (*txt) {
    case ' ':
    case '\t':
        txt = (void *)parse_attrs(
            opts, SPN_WHITESPACE_CHARS(txt), &mode, &valu);
        if (txt == NULL)
            return txt;
        if (*txt == '>')
            break;
        if (*txt != '/')
            return NULL;
        /* FALLTHROUGH */

    case '/':
        if (txt[1] != '>')
            return NULL;
        *txt = NUL;
        txt += 2;
        loadOptionLine(opts, ost, pzName, dir, mode);
        return txt;

    case '>':
        break;

    default:
        txt = strchr(txt, '>');
        if (txt != NULL)
            txt++;
        return txt;
    }

    /*
     *  If we are here, we have a value.  "txt" points to a closing angle
     *  bracket.  Separate the name from the value for a moment.
     */
    *pcNulPoint = NUL;
    pzData = ++txt;
    txt = trim_xml_text(txt, pzName, mode);
    if (txt == NULL)
        return txt;

    /*
     *  Rejoin the name and value for parsing by "loadOptionLine()".
     *  Erase any attributes parsed by "parse_attrs()".
     */
    memset(pcNulPoint, ' ', (size_t)(pzData - pcNulPoint));

    /*
     *  If we are getting a "string" value that is to be cooked,
     *  then process the XML-ish &xx; XML-ish and %XX hex characters.
     */
    if (  (valu.valType == OPARG_TYPE_STRING)
       && (mode == OPTION_LOAD_COOKED))
        cook_xml_text(pzData);

    /*
     *  "pzName" points to what looks like text for one option/configurable.
     *  It is NUL terminated.  Process it.
     */
    loadOptionLine(opts, ost, pzName, dir, mode);

    return txt;
}
Пример #10
0
int main(int argc, char **argv)
{
	const char *guid_str;
    const char *attr_str;
    const char *varname;
	const char *keyfilename;
    const char *certfilename;
	varsign_context *ctx;
	bool include_attrs;
	int c = 0;
    	unsigned char no_signing = 0;
	unsigned char no_repack = 0;

	ctx = talloc_zero(NULL, varsign_context);

	keyfilename = NULL;
	certfilename = NULL;
	guid_str = NULL;
	attr_str= NULL;
	include_attrs = false;

	for (;;) {
		int idx;

		c = getopt_long(argc, argv, "o:g:a:k:c:n:ivVh", options, &idx);

		if (c == -1) {
			break;
        }

		switch (c) {
	case 'o':
			ctx->outfilename = optarg;
			break;

        case 'g':
			guid_str = optarg;
			break;

        case 'a':
			attr_str = optarg;
			break;

        case 'k':
			keyfilename = optarg;
			break;

        case 'c':
			certfilename = optarg;
			break;

        case 'i':
			include_attrs = true;
			break;

        case 'v':
			ctx->verbose = 1;
			break;

        case 'V':
			version();
			return EXIT_SUCCESS;

        case 'n':
            no_signing = 1;
            break;

        case 'N':
            no_signing = 1;
            break;

        case 'r':
            no_repack = 1;
            do_direct = 1;
            break;

        case 'R':
            no_repack = 1;
            do_direct = 1;
            break;

        case 'h':
			usage();
			return EXIT_SUCCESS;
		}
	}

	if (argc != (optind + 2)) {
		usage();

		return EXIT_FAILURE;
	}

	if ((!keyfilename) && (!no_signing)) {
		fprintf(stderr, "No signing key specified\n");

		return EXIT_FAILURE;
	}

	if ((!certfilename) && (!no_signing)) {
		fprintf(stderr, "No signing certificate specified\n");

		return EXIT_FAILURE;
	}

	/* initialise openssl */
	OpenSSL_add_all_digests();
	OpenSSL_add_all_ciphers();
	ERR_load_crypto_strings();

	/* set up the variable signing context */
	varname = argv[optind];
	set_varname(ctx, varname);
	ctx->infilename = argv[optind+1];

	if (!ctx->outfilename) {
		set_default_outfilename(ctx);
    }

	if (attr_str) {
		ctx->var_attrs = parse_attrs(attr_str);

		if (ctx->var_attrs == attr_invalid) {
			return EXIT_FAILURE;
        }
	} else {
		ctx->var_attrs = default_attrs;
	}

	if (guid_str) {
		if (parse_guid(guid_str, &ctx->var_guid)) {
			fprintf(stderr, "Invalid GUID '%s'\n", guid_str);

			return EXIT_FAILURE;
		}
	} else {
		set_default_guid(ctx, varname);
	}

	if (fileio_read_file(ctx, ctx->infilename, &ctx->data, &ctx->data_len)) {
		return EXIT_FAILURE;
    }

    if (!no_signing)
    {
        ctx->key = fileio_read_pkey(keyfilename);
        if (!ctx->key) {
            return EXIT_FAILURE;
        }
        
        ctx->cert = fileio_read_cert(certfilename);
        if (!ctx->cert) {
            return EXIT_FAILURE;
        }
    }

	/* do the signing */
	if (add_auth_descriptor(ctx, no_signing)) {
		return EXIT_FAILURE;
    }

	/* write the resulting image */
	if (write_signed(ctx, include_attrs, no_repack)) {
		return EXIT_FAILURE;
    }

	return EXIT_SUCCESS;
}
Пример #11
0
static int mod_init(void)
{
	DICT_VENDOR *vend;
	load_tm_f load_tm;

	     /* import the TM auto-loading function */
	if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) {
		LOG(L_ERR, "ERROR:acc:mod_init: can't import load_tm\n");
		return -1;
	}
	     /* let the auto-loading function load all TM stuff */
	if (load_tm( &tmb )==-1) return -1;
	if (verify_fmt(log_fmt)==-1) return -1;

	     /* register callbacks*/
	     /* listen for all incoming requests  */
	if (tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, on_req, 0, 0) <= 0) {
		LOG(L_ERR,"ERROR:acc:mod_init: cannot register TMCB_REQUEST_IN "
		    "callback\n");
		return -1;
	}

	memset(attrs, 0, sizeof(attrs));
	memset(vals, 0, sizeof(vals));

	attrs[A_USER_NAME].n		     = "User-Name";
	attrs[A_SERVICE_TYPE].n		     = "Service-Type";
	attrs[A_CALLED_STATION_ID].n	     = "Called-Station-Id";
	attrs[A_CALLING_STATION_ID].n	     = "Calling-Station-Id";
	attrs[A_ACCT_STATUS_TYPE].n	     = "Acct-Status-Type";
	attrs[A_ACCT_SESSION_ID].n	     = "Acct-Session-Id";

	attrs[A_SIP_METHOD].n		     = "Sip-Method";
	attrs[A_SIP_RESPONSE_CODE].n	     = "Sip-Response-Code";
	attrs[A_SIP_CSEQ].n		     = "Sip-CSeq";
	attrs[A_SIP_TO_TAG].n		     = "Sip-To-Tag";
	attrs[A_SIP_FROM_TAG].n		     = "Sip-From-Tag";
	attrs[A_SIP_TRANSLATED_REQUEST_ID].n = "Sip-Translated-Request-Id";
	attrs[A_SIP_SOURCE_IP_ADDRESS].n     = "Sip-Source-IP-Address";
	attrs[A_SIP_SOURCE_PORT].n           = "Sip-Source-Port";

	attrs[A_SER_ATTR].n                  = "SER-Attr";
	attrs[A_SER_FROM].n                  = "SER-From";
	attrs[A_SER_FLAGS].n                 = "SER-Flags";
	attrs[A_SER_ORIGINAL_REQUEST_ID].n   = "SER-Original-Request-Id";
	attrs[A_SER_TO].n                    = "SER-To";
	attrs[A_SER_DIGEST_USERNAME].n       = "SER-Digest-Username";
	attrs[A_SER_DIGEST_REALM].n          = "SER-Digest-Realm";
	attrs[A_SER_REQUEST_TIMESTAMP].n     = "SER-Request-Timestamp";
	attrs[A_SER_TO_DID].n                = "SER-To-DID";
	attrs[A_SER_FROM_UID].n              = "SER-From-UID";
	attrs[A_SER_FROM_DID].n              = "SER-From-DID";
	attrs[A_SER_TO_UID].n                = "SER-To-UID";
	attrs[A_SER_RESPONSE_TIMESTAMP].n    = "SER-Response-Timestamp";
	attrs[A_SER_SERVER_ID].n             = "SER-Server-ID";

	vals[V_START].n			     = "Start";
	vals[V_STOP].n			     = "Stop";
	vals[V_INTERIM_UPDATE].n             = "Interim-Update";
	vals[V_FAILED].n		     = "Failed";
	vals[V_SIP_SESSION].n		     = "Sip-Session";

	     /* open log */
	rc_openlog("ser");
	     /* read config */
	if ((rh = rc_read_config(radius_config)) == NULL) {
		LOG(L_ERR, "ERROR:acc:mod_init: Error opening radius config file: %s\n",
		    radius_config);
		return -1;
	}
	     /* read dictionary */
	if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {
		LOG(L_ERR, "ERROR:acc:mod_init: Error reading radius dictionary\n");
		return -1;
	}

	vend = rc_dict_findvend(rh, "iptelorg");
	if (vend == NULL) {
		ERR("RADIUS dictionary is missing required vendor 'iptelorg'\n");
		return -1;
	}

	INIT_AV(rh, attrs, vals, "acc", -1, -1);

	if (service_type != -1) {
		vals[V_SIP_SESSION].v = service_type;
	}

	if (parse_attrs(&avps, &avps_n, attrs_param) < 0) {
		ERR("Error while parsing 'attrs' module parameter\n");
		return -1;
	}

	return 0;
}