int rmm_cfg_get_rest_prefix(char *prefix, int max_len)
{
    if (prefix == NULL)
        return -1;
    else
        return get_str_attr(PROC_RESTD, ATTR_REST_PREFIX, prefix, max_len/*MAX_URL*/);
}
static int read_rule(xmlNode *rn, cp_rule_t **dst,
                     cp_read_actions_func read_actions,
                     cp_free_actions_func free_actions)
{
    xmlNode *n;
    int res = RES_OK;
    if ((!rn) || (!dst)) return RES_INTERNAL_ERR;

    *dst = (cp_rule_t*)cds_malloc(sizeof(cp_rule_t));
    if (!*dst) return RES_MEMORY_ERR;
    memset(*dst, 0, sizeof(cp_rule_t));

    get_str_attr(rn, "id", &(*dst)->id);

    n = find_node(rn, "actions", common_policy_ns);
    if (n && (res == 0) && read_actions) res = read_actions(n, &(*dst)->actions);

    n = find_node(rn, "conditions", common_policy_ns);
    if (n && (res == 0)) res = read_conditions(n, &(*dst)->conditions);

    n = find_node(rn, "transformations", common_policy_ns);
    if (n && (res == 0)) res = read_transformations(n, &(*dst)->transformations);

    if (res != 0) {
        free_cp_rule(*dst, free_actions);
        *dst = NULL;
        return res;
    }

    return 0;
}
unsigned char rmm_cfg_get_flow_control()
{
	char data[2] = {};

	if (get_str_attr(PROC_IPMI_MODULE, ATTR_IPMID_SERIAL_FLOWCONTROL, data, sizeof(data)) != 0)
		return 0;

	return data[0];
}
unsigned char rmm_cfg_get_parity(void)
{
	char data[2] = {};

	if (get_str_attr(PROC_IPMI_MODULE, ATTR_IPMID_SERIAL_PARITY, data, sizeof(data)) != 0)
		return 0;

	return data[0];
}
unsigned char rmm_cfg_get_stopbits(void)
{
	char data[2] = {};

	if (get_str_attr(PROC_IPMI_MODULE, ATTR_IPMID_SERIAL_STOPBITS, data, sizeof(data)) != 0)
		return 0;

	return data[0];
}
static int read_except(xmlNode *n, cp_except_t **dst)
{
    *dst = (cp_except_t*)cds_malloc(sizeof(cp_except_t));
    if (!(*dst)) return RES_MEMORY_ERR;
    memset(*dst, 0, sizeof(**dst));
    (*dst)->next = NULL;

    get_str_attr(n, "entity", &(*dst)->entity);
    return RES_OK;
}
static int read_domain(xmlNode *n, cp_domain_t **dst)
{
    *dst = (cp_domain_t*)cds_malloc(sizeof(cp_domain_t));
    if (!(*dst)) return RES_MEMORY_ERR;
    memset(*dst, 0, sizeof(**dst));
    (*dst)->next = NULL;

    get_str_attr(n, "domain", &(*dst)->domain);
    return RES_OK;
}
Beispiel #8
0
/* UPDATED + CHECKED
 */
static inline char *run_remove_location( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	char *p;
	str url;
	int i;

	url.s = (char*)UNDEF_CHAR;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LOG(L_ERR,"ERROR:cpl_c:run_remove_location: REMOVE_LOCATION node "
			"suppose to have max one child, not %d!\n",
			NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	/* dirty hack to speed things up in when loc set is already empty */
	if (intr->loc_set==0)
		goto done;

	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p,attr_name,n,intr,script_error);
		switch (attr_name) {
			case LOCATION_ATTR:
				url.len = n;
				get_str_attr( p, url.s, url.len, intr, script_error,1);
				break;
			default:
				LOG(L_ERR,"ERROR:run_remove_location: unknown attribute "
					"(%d) in REMOVE_LOCATION node\n",attr_name);
				goto script_error;
		}
	}

	if (url.s==(char*)UNDEF_CHAR) {
		DBG("DEBUG:run_remove_location: remove all locs from loc_set\n");
		empty_location_set( &(intr->loc_set) );
	} else {
		remove_location( &(intr->loc_set), url.s, url.len );
	}
	/* set the flag for modifing the location set */
	intr->flags |= CPL_LOC_SET_MODIFIED;

done:
	return get_first_child(intr->ip);
script_error:
	return CPL_SCRIPT_ERROR;
}
int rmm_cfg_get_rmcp_password(char *password, int max_len)
{
	int rc = 0;
	char ciphertxt[CIPHER_LENGTH_MAX] = {};
	char plaintxt[PLAIN_LENGTH_MAX] = {};

	rc = get_str_attr(PROC_IPMI_MODULE, ATTR_RMCP_PASSWORD, ciphertxt, CIPHER_LENGTH_MAX);
	if (rc == 0) {
		rc = rmm_decrypt(ciphertxt, RMM_DECRYPT_KEYFILE, plaintxt);
		if (rc == 0) {
			strncpy_safe(password, plaintxt, max_len, max_len - 1);
		}
	}
	return rc;
}
int rmm_cfg_get_rmcp_username(char *username, int max_len)
{
	int rc = 0;
	char ciphertxt[CIPHER_LENGTH_MAX] = {};
	char plaintxt[PLAIN_LENGTH_MAX] = {};

	rc = get_str_attr(PROC_IPMI_MODULE, ATTR_RMCP_USERNAME, ciphertxt, CIPHER_LENGTH_MAX);
	if (rc == 0) {
		rc = rmm_decrypt(ciphertxt, RMM_DECRYPT_KEYFILE, plaintxt);
		if (rc == 0) {
			strncpy_safe(username, plaintxt, max_len, max_len - 1);
		}
	}
	return rc;
}
static int read_id(xmlNode *n, cp_id_t **dst)
{
    *dst = (cp_id_t*)cds_malloc(sizeof(cp_id_t));
    if (!(*dst)) return RES_MEMORY_ERR;
    memset(*dst, 0, sizeof(**dst));
    (*dst)->next = NULL;

    get_str_attr(n, "entity", &(*dst)->entity);
    if ((*dst)->entity.len == 0) {
        /* hack - eyeBeams format differs from draft ! */
        str_dup_zt(&(*dst)->entity, get_node_value(n));
    }

    return RES_OK;
}
Beispiel #12
0
/* UPDATED + CHECKED
 */
static inline char *run_mail( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	char  *p;
	str subject = {0,0};
	str body    = {0,0};
	str to      = {0,0};
	int i;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LM_ERR("MAIL node suppose to have max one"
			" child, not %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	/* read the attributes of the MAIL node*/
	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p, attr_name, n, intr, script_error);
		switch (attr_name) {
			case TO_ATTR:
				get_str_attr(p, to.s, n, intr, script_error,0);
				to.len = n;
				break;
			case SUBJECT_ATTR:
				get_str_attr(p, subject.s, n, intr, script_error,0);
				subject.len = n;
				break;
			case BODY_ATTR:
				get_str_attr(p, body.s, n, intr, script_error,0);
				body.len = n;
				break;
			default:
				LM_ERR("unknown attribute (%d) in MAIL node\n",attr_name);
				goto script_error;
		}
	}

	if (to.len==0) {
		LM_ERR("email has an empty TO hdr!\n");
		goto script_error;
	}
	if (body.len==0 && subject.len==0) {
		LM_WARN("I refuse to send email with no "
			"body and no subject -> skipping...\n");
		goto done;
	}

	/* duplicate the attrs in shm memory */
	p = (char*)shm_malloc( to.len + subject.len + body.len );
	if (!p) {
		LM_ERR("no more shm memory!\n");
		goto runtime_error;
	}
	/* copy the TO */
	memcpy( p, to.s, to.len );
	to.s = p;
	p += to.len;
	/* copy the subject */
	if (subject.len) {
		memcpy( p, subject.s, subject.len );
		subject.s = p;
		p += subject.len;
	}
	/* copy the body */
	if (body.len) {
		memcpy( p, body.s, body.len );
		body.s = p;
		p += body.len;
	}

	/* send the command */
	write_cpl_cmd( CPL_MAIL_CMD, &to, &subject, &body);

done:
	return get_first_child(intr->ip);
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
Beispiel #13
0
/* UPDATED + CHECKED
 */
static inline char *run_log( struct cpl_interpreter *intr )
{
	char  *p;
	unsigned short attr_name;
	unsigned short n;
	str name    = {0,0};
	str comment = {0,0};
	str user;
	int i;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LM_ERR("LOG node suppose to have max one child"
			", not %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	/* is logging enabled? */
	if ( cpl_env.log_dir==0 )
		goto done;

	/* read the attributes of the LOG node*/
	p = ATTR_PTR(intr->ip);
	for( i=NR_OF_ATTR(intr->ip); i>0 ; i-- ) {
		get_basic_attr( p, attr_name, n, intr, script_error);
		switch (attr_name) {
			case NAME_ATTR:
				get_str_attr( p, name.s, n, intr, script_error,1);
				name.len = n;
				break;
			case COMMENT_ATTR:
				get_str_attr( p, comment.s, n, intr, script_error,1);
				comment.len = n;
				break;
			default:
				LM_ERR("unknown attribute "
					"(%d) in LOG node\n",attr_name);
				goto script_error;
		}
	}

	if (comment.len==0) {
		LM_NOTICE("LOG node has no comment attr -> skipping\n");
		goto done;
	}

	user.len = intr->user.len + name.len + comment.len;
	/* duplicate the attrs in shm memory */
	user.s = p = (char*)shm_malloc( user.len );
	if (!user.s) {
		LM_ERR("no more shm memory!\n");
		goto runtime_error;
	}
	/* copy the user name */
	memcpy( p, intr->user.s, intr->user.len);
	user.len = intr->user.len;
	p += intr->user.len;
	/* copy the log name */
	if (name.len) {
		memcpy( p, name.s, name.len );
		name.s = p;
		p += name.len;
	}
	/* copy the comment */
	memcpy( p, comment.s, comment.len);
	comment.s = p;

	/* send the command */
	write_cpl_cmd( CPL_LOG_CMD, &user, &name, &comment );

done:
	return get_first_child(intr->ip);
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
Beispiel #14
0
/* UPDATED + CHECKED
 */
static inline char *run_reject( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short status;
	unsigned short n;
	str reason;
	char *p;
	int i;

	reason.s = (char*)UNDEF_CHAR;
	status = UNDEF_CHAR;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)!=0) {
		LM_ERR("REJECT node doesn't suppose to have "
			"any sub-nodes. Found %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr( p, attr_name, n, intr, script_error);
		switch (attr_name) {
			case STATUS_ATTR:
				status = n;
				break;
			case REASON_ATTR:
				reason.len = n;
				get_str_attr( p, reason.s, reason.len, intr, script_error,1);
				break;
			default:
				LM_ERR("unknown attribute "
					"(%d) in REJECT node\n",attr_name);
				goto script_error;
		}
	}

	if (status==UNDEF_CHAR) {
		LM_ERR("mandatory attribute STATUS not found\n");
		goto script_error;
	}
	if (status<400 || status>=700) {
		LM_ERR("bad attribute STATUS (%d)\n",status);
		goto script_error;
	}

	if (reason.s==(char*)UNDEF_CHAR ) {
		switch (status) {
			case 486:
				reason.s = "Busy Here";
				reason.len = 9;
				break;
			case 404:
				reason.s = "Not Found";
				reason.len = 9;
				break;
			case 603:
				reason.s = "Decline";
				reason.len = 7;
				break;
			case 500:
				reason.s = "Internal Server Error";
				reason.len = 21;
				break;
			default:
				reason.s = "Generic Error";
				reason.len = 13;
		}
	}

	/* if still stateless and FORCE_STATEFUL set -> build the transaction */
	if ( !(intr->flags&CPL_IS_STATEFUL) && intr->flags&CPL_FORCE_STATEFUL) {
		i = cpl_fct.tmb.t_newtran( intr->msg );
		if (i<0) {
			LM_ERR("failed to build new transaction!\n");
			goto runtime_error;
		} else if (i==0) {
			LM_ERR(" processed INVITE is a retransmission!\n");
			/* instead of generating an error is better just to break the
			 * script by returning EO_SCRIPT */
			return EO_SCRIPT;
		}
		intr->flags |= CPL_IS_STATEFUL;
	}

	/* send the reply */
	i = cpl_fct.slb.freply(intr->msg, (int)status, &reason );

	if ( i!=1 ) {
		LM_ERR("unable to send reject reply!\n");
		goto runtime_error;
	}

	return EO_SCRIPT;
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
Beispiel #15
0
/* UPDATED + CHECKED
 */
static inline char *run_location( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	char  *p;
	unsigned char  prio;
	unsigned char  clear;
	str url;
	int i;

	clear = NO_VAL;
	prio = 10;
	url.s = (char*)UNDEF_CHAR;
	url.len = 0;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LM_ERR("LOCATION node suppose to have max "
			"one child, not %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p,attr_name,n,intr,script_error);
		switch (attr_name) {
			case URL_ATTR:
				url.len = n;
				get_str_attr( p, url.s, url.len, intr, script_error,1);
				break;
			case PRIORITY_ATTR:
				if ( n>10)
					LM_WARN("invalid value (%u) found"
						" for param. PRIORITY in LOCATION node -> using "
						"default (%u)!\n",n,prio);
				else
					prio = n;
				break;
			case CLEAR_ATTR:
				if (n!=YES_VAL && n!=NO_VAL)
					LM_WARN("invalid value (%u) found"
						" for param. CLEAR in LOCATION node -> using "
						"default (%u)!\n",n,clear);
				else
					clear = n;
				break;
			default:
				LM_ERR("unknown attribute (%d) in "
					"LOCATION node\n",attr_name);
				goto script_error;
		}
	}

	if (url.s==(char*)UNDEF_CHAR) {
		LM_ERR("param. URL missing in LOCATION node\n");
		goto script_error;
	}

	if (clear)
		empty_location_set( &(intr->loc_set) );
	if (add_location( &(intr->loc_set), &url, 0, prio, 0/*no dup*/ )==-1) {
		LM_ERR("unable to add location to set :-(\n");
		goto runtime_error;
	}
	/* set the flag for modifying the location set */
	intr->flags |= CPL_LOC_SET_MODIFIED;

	return get_first_child(intr->ip);
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
int rmm_cfg_get_platform(char *platform)
{
	return get_str_attr(PROC_RMM, ATTR_RACK_PLATFORM, platform, sizeof(platform));
}