当前位置: 首页>>代码示例>>C++>>正文


C++ dict_attrbyname函数代码示例

本文整理汇总了C++中dict_attrbyname函数的典型用法代码示例。如果您正苦于以下问题:C++ dict_attrbyname函数的具体用法?C++ dict_attrbyname怎么用?C++ dict_attrbyname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dict_attrbyname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mod_instantiate

/*
 *	Do any per-module initialization that is separate to each
 *	configured instance of the module.  e.g. set up connections
 *	to external databases, read configuration files, set up
 *	dictionary entries, etc.
 *
 *	If configuration information is given in the config section
 *	that must be referenced in later calls, store a handle to it
 *	in *instance otherwise put a null pointer there.
 */
static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
	rlm_example_t *inst = instance;
	ATTR_FLAGS flags;

	memset(&flags, 0, sizeof(flags));
	/*
	 *	Do more work here
	 */
	if (!inst->boolean) {
		cf_log_err_cs(conf, "Boolean is false: forcing error!");
		return -1;
	}

	if (dict_addattr("Example-Paircmp", -1, 0, PW_TYPE_STRING, flags) < 0) {
		ERROR("Failed creating paircmp attribute: %s", fr_strerror());

		return -1;
	}

	paircompare_register(dict_attrbyname("Example-Paircmp"), dict_attrbyvalue(PW_USER_NAME, 0), false,
			     rlm_example_cmp, inst);

	return 0;
}
开发者ID:LarsKollstedt,项目名称:freeradius-server,代码行数:35,代码来源:rlm_example.c

示例2: talloc_zero

/** Convert module specific attribute id to value_pair_tmpl_t.
 *
 * @param[in] ctx for talloc
 * @param[in] name string to convert.
 * @param[in] type Type of quoting around value.
 * @return pointer to new VPT.
 */
value_pair_tmpl_t *radius_str2tmpl(TALLOC_CTX *ctx, char const *name, FR_TOKEN type)
{
	value_pair_tmpl_t *vpt;

	vpt = talloc_zero(ctx, value_pair_tmpl_t);
	vpt->name = talloc_strdup(vpt, name);

	switch (type)
	{
		case T_BARE_WORD:
			if (!isdigit((int) *name)) {
				request_refs_t ref;
				pair_lists_t list;
				const char *p = name;

				ref = radius_request_name(&p, REQUEST_CURRENT);
				list = radius_list_name(&p, PAIR_LIST_REQUEST);

				if ((p != name) && !*p) {
					vpt->type = VPT_TYPE_LIST;

				} else {
					const DICT_ATTR *da;
					da = dict_attrbyname(p);
					if (!da) {
						vpt->type = VPT_TYPE_LITERAL;
						break;
					}
					vpt->da = da;
					vpt->type = VPT_TYPE_ATTR;
				}

				vpt->request = ref;
				vpt->list = list;
				break;
			}
			/* FALL-THROUGH */

		case T_SINGLE_QUOTED_STRING:
			vpt->type = VPT_TYPE_LITERAL;
			break;
		case T_DOUBLE_QUOTED_STRING:
			vpt->type = VPT_TYPE_XLAT;
			break;
		case T_BACK_QUOTED_STRING:
			vpt->type = VPT_TYPE_EXEC;
			break;
		case T_OP_REG_EQ: /* hack */
			vpt->type = VPT_TYPE_REGEX;
			break;
		default:
			rad_assert(0);
			return NULL;
	}

	return vpt;
}
开发者ID:chevot,项目名称:freeradius-server,代码行数:64,代码来源:map.c

示例3: cisco_vsa_hack

/*
 *	This hack strips out Cisco's VSA duplicities in lines
 *	(Cisco not implemented VSA's in standard way.
 *
 *	Cisco sends it's VSA attributes with the attribute name *again*
 *	in the string, like:  H323-Attribute = "h323-attribute=value".
 *	This sort of behaviour is nonsense.
 */
static void cisco_vsa_hack(REQUEST *request)
{
	int		vendorcode;
	char		*ptr;
	char		newattr[MAX_STRING_LEN];
	VALUE_PAIR	*vp;
	vp_cursor_t	cursor;
	for (vp = fr_cursor_init(&cursor, &request->packet->vps);
	     vp;
	     vp = fr_cursor_next(&cursor)) {
		vendorcode = vp->da->vendor;
		if (!((vendorcode == 9) || (vendorcode == 6618))) {
			continue; /* not a Cisco or Quintum VSA, continue */
		}

		if (vp->da->type != PW_TYPE_STRING) {
			continue;
		}

		/*
		 *  No weird packing.  Ignore it.
		 */
		ptr = strchr(vp->vp_strvalue, '='); /* find an '=' */
		if (!ptr) {
			continue;
		}

		/*
		 *	Cisco-AVPair's get packed as:
		 *
		 *	Cisco-AVPair = "h323-foo-bar = baz"
		 *	Cisco-AVPair = "h323-foo-bar=baz"
		 *
		 *	which makes sense only if you're a lunatic.
		 *	This code looks for the attribute named inside
		 *	of the string, and if it exists, adds it as a new
		 *	attribute.
		 */
		if (vp->da->attr == 1) {
			char const *p;

			p = vp->vp_strvalue;
			gettoken(&p, newattr, sizeof(newattr), false);

			if (dict_attrbyname(newattr) != NULL) {
				pairmake_packet(newattr, ptr + 1, T_OP_EQ);
			}
		} else {	/* h322-foo-bar = "h323-foo-bar = baz" */
			/*
			 *	We strip out the duplicity from the
			 *	value field, we use only the value on
			 *	the right side of the '=' character.
			 */
			pairstrcpy(vp, ptr + 1);
		}
	}
}
开发者ID:RockalotofPokadots,项目名称:freeradius-server,代码行数:65,代码来源:rlm_preprocess.c

示例4: parse_named_policy

/*
 *	Parse a named policy "policy foo {...}"
 */
static int parse_named_policy(policy_lex_file_t *lexer)
{
    int rcode;
    policy_lex_t token;
    char mystring[256];
    policy_named_t *this;
    DICT_ATTR *dattr;

    debug_tokens("[POLICY] ");

    this = rad_malloc(sizeof(*this));
    memset(this, 0, sizeof(*this));

    this->item.type = POLICY_TYPE_NAMED_POLICY;
    this->item.lineno = lexer->lineno;

    token = policy_lex_file(lexer, 0, mystring, sizeof(mystring));
    if (token != POLICY_LEX_BARE_WORD) {
        fprintf(stderr, "%s[%d]: Expected policy name, got \"%s\"\n",
                lexer->filename, lexer->lineno,
                fr_int2str(rlm_policy_tokens, token, "?"));
        rlm_policy_free_item((policy_item_t *) this);
        return 0;
    }

    dattr = dict_attrbyname(mystring);
    if (dattr) {
        fprintf(stderr, "%s[%d]: Invalid policy name \"%s\": it is already defined as a dictionary attribute\n",
                lexer->filename, lexer->lineno, mystring);
        rlm_policy_free_item((policy_item_t *) this);
        return 0;
    }

    this->name = strdup(mystring);
    rcode = parse_block(lexer, &(this->policy));
    if (!rcode) {
        rlm_policy_free_item((policy_item_t *) this);
        return rcode;
    }

    /*
     *	And insert it into the tree of policies.
     *
     *	For now, policy names aren't scoped, they're global.
     */
    if (!rlm_policy_insert(lexer->policies, this)) {
        radlog(L_ERR, "Failed to insert policy \"%s\"", this->name);
        rlm_policy_free_item((policy_item_t *) this);
        return 0;
    }

    if ((lexer->debug & POLICY_DEBUG_PRINT_POLICY) != 0) {
        rlm_policy_print(this);
    }

    return 1;
}
开发者ID:jacques,项目名称:freeradius-server,代码行数:60,代码来源:parse.c

示例5: csv_map_getvalue

/*
 *	Convert field X to a VP.
 */
static int csv_map_getvalue(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, void *uctx)
{
	char const *str = uctx;
	VALUE_PAIR *head = NULL, *vp;
	vp_cursor_t cursor;
	DICT_ATTR const *da;

	rad_assert(ctx != NULL);
	fr_cursor_init(&cursor, &head);

	/*
	 *	FIXME: allow multiple entries.
	 */
	if (map->lhs->type == TMPL_TYPE_ATTR) {
		da = map->lhs->tmpl_da;

	} else {
		char *attr;

		if (tmpl_aexpand(ctx, &attr, request, map->lhs, NULL, NULL) <= 0) {
			RWDEBUG("Failed expanding string");
			return -1;
		}

		da = dict_attrbyname(attr);
		if (!da) {
			RWDEBUG("No such attribute '%s'", attr);
			return -1;
		}

		talloc_free(attr);
	}

	vp = pairalloc(ctx, da);
	rad_assert(vp);

	if (pairparsevalue(vp, str, talloc_array_length(str) - 1) < 0) {
		char *escaped;

		escaped = fr_aprints(vp, str, talloc_array_length(str) - 1, '\'');
		RWDEBUG("Failed parsing value \"%s\" for attribute %s: %s", escaped,
			map->lhs->tmpl_da->name, fr_strerror());

		talloc_free(vp); /* also frees escaped */
		return -1;
	}

	vp->op = map->op;
	fr_cursor_merge(&cursor, vp);

	*out = head;
	return 0;
}
开发者ID:K1ngR1chard,项目名称:freeradius-server,代码行数:56,代码来源:rlm_csv.c

示例6: radius_parse_attr

/** Parse qualifiers to convert attrname into a value_pair_tmpl_t.
 *
 * VPTs are used in various places where we need to pre-parse configuration 
 * sections into attribute mappings.
 *
 * Note: name field is just a copy of the input pointer, if you know that
 * string might be freed before you're done with the vpt use radius_attr2tmpl
 * instead.
 * 
 * @param[in] name attribute name including qualifiers.
 * @param[out] vpt to modify.
 * @param[in] request_def The default request to insert unqualified 
 *	attributes into.
 * @param[in] list_def The default list to insert unqualified attributes into.
 * @return -1 on error or 0 on success.
 */
int radius_parse_attr(const char *name, value_pair_tmpl_t *vpt,
		      request_refs_t request_def,
		      pair_lists_t list_def)
{
	char buffer[128];
	const char *p;
	size_t len;

	vpt->name = name;
	p = name;
	
	vpt->request = radius_request_name(&p, request_def);
	len = p - name;
	if (vpt->request == REQUEST_UNKNOWN) {
		strlcpy(buffer, name, len < sizeof(buffer) ?
			len + 1 : sizeof(buffer));
		
		radlog(L_ERR, "Invalid request qualifier \"%s\"", buffer);
		
		return -1;
	}
	name += len;
	
	vpt->list = radius_list_name(&p, list_def);
	if (vpt->list == PAIR_LIST_UNKNOWN) {
		len = p - name;
		strlcpy(buffer, name, len < sizeof(buffer) ?
			len + 1 : sizeof(buffer));
				
		radlog(L_ERR, "Invalid list qualifier \"%s\"", buffer);
		
		return -1;
	}
	
	if (*p == '\0') {
		vpt->type = VPT_TYPE_LIST;
		
		return 0;
	}
	
	vpt->da = dict_attrbyname(p);
	if (!vpt->da) {
		radlog(L_ERR, "Attribute \"%s\" unknown", p);
	
		return -1;
	}
	
	vpt->type = VPT_TYPE_ATTR;
	
	return 0;
}
开发者ID:FabioPedretti,项目名称:freeradius-server,代码行数:67,代码来源:valuepair.c

示例7: if

/*
 *	Return a VALUE_PAIR, given an attribute name.
 *
 *	FIXME: Have it return the N'th one, too, like
 *	doc/variables.txt?
 *
 *	The amount of duplicated code is getting annoying...
 */
static VALUE_PAIR *find_vp(REQUEST *request, const char *name)
{
	const char *p;
	const DICT_ATTR *dattr;
	VALUE_PAIR *vps;

	p = name;
	vps = request->packet->vps;;

	/*
	 *	FIXME: use names from reserved word list?
	 */
	if (strncasecmp(name, "request:", 8) == 0) {
		p += 8;
	} else if (strncasecmp(name, "reply:", 6) == 0) {
		p += 6;
		vps = request->reply->vps;
#ifdef WITH_PROXY
	} else if (strncasecmp(name, "proxy-request:", 14) == 0) {
		p += 14;
		if (request->proxy) {
			vps = request->proxy->vps;
		}
	} else if (strncasecmp(name, "proxy-reply:", 12) == 0) {
		p += 12;
		if (request->proxy_reply) {
			vps = request->proxy_reply->vps;
		}
#endif
	} else if (strncasecmp(name, "control:", 8) == 0) {
		p += 8;
		vps = request->config_items;
	} /* else it must be a bare attribute name */

	if (!vps) {
		return NULL;
	}

	dattr = dict_attrbyname(p);
	if (!dattr) {
		fprintf(stderr, "No such attribute %s\n", p);
		return NULL;	/* no such attribute */
	}

	return pairfind(vps, dattr->attr, dattr->vendor);
}
开发者ID:joyphone,项目名称:freeradius-server,代码行数:54,代码来源:evaluate.c

示例8: otp_pwe_init

/* Initialize the pwattr array for supported password encodings. */
void
otp_pwe_init(void)
{
  DICT_ATTR *da;

  /*
   * Setup known password types.  These are pairs.
   * NB: Increase pwattr array size when adding a type.
   *     It should be sized as (number of password types * 2)
   * NB: Array indices must match otp_pwe_t! (see otp.h)
   */
  (void) memset(pwattr, 0, sizeof(pwattr));

  /* PAP */
  if ((da = dict_attrbyname("User-Password")) != NULL) {
    pwattr[0] = da->attr;
    pwattr[1] = da->attr;
  }

  /* CHAP */
  if ((da = dict_attrbyname("CHAP-Challenge")) != NULL) {
    pwattr[2] = da->attr;
    if ((da = dict_attrbyname("CHAP-Password")) != NULL)
      pwattr[3] = da->attr;
    else
      pwattr[2] = 0;
  }

#if 0
  /* MS-CHAP (recommended not to use) */
  if ((da = dict_attrbyname("MS-CHAP-Challenge")) != NULL) {
    pwattr[4] = da->attr;
    if ((da = dict_attrbyname("MS-CHAP-Response")) != NULL)
      pwattr[5] = da->attr;
    else
      pwattr[4] = 0;
  }
#endif /* 0 */

  /* MS-CHAPv2 */
  if ((da = dict_attrbyname("MS-CHAP-Challenge")) != NULL) {
    pwattr[6] = da->attr;
    if ((da = dict_attrbyname("MS-CHAP2-Response")) != NULL)
      pwattr[7] = da->attr;
    else
      pwattr[6] = 0;
  }
}
开发者ID:101,项目名称:freeradius-server,代码行数:49,代码来源:otp_pwe.c

示例9: radius_parse_attr

/** Parse qualifiers to convert attrname into a value_pair_tmpl_t.
 *
 * VPTs are used in various places where we need to pre-parse configuration
 * sections into attribute mappings.
 *
 * Note: name field is just a copy of the input pointer, if you know that
 * string might be freed before you're done with the vpt use radius_attr2tmpl
 * instead.
 *
 * @param[in] name attribute name including qualifiers.
 * @param[out] vpt to modify.
 * @param[in] request_def The default request to insert unqualified
 *	attributes into.
 * @param[in] list_def The default list to insert unqualified attributes into.
 * @return -1 on error or 0 on success.
 */
int radius_parse_attr(char const *name, value_pair_tmpl_t *vpt,
		      request_refs_t request_def,
		      pair_lists_t list_def)
{
	DICT_ATTR const *da;
	char const *p;
	size_t len;

	memset(vpt, 0, sizeof(*vpt));
	vpt->name = name;
	p = name;

	vpt->request = radius_request_name(&p, request_def);
	len = p - name;
	if (vpt->request == REQUEST_UNKNOWN) {
		ERROR("Invalid request qualifier \"%.*s\"", (int) len, name);
		return -1;
	}
	name += len;

	vpt->list = radius_list_name(&p, list_def);
	if (vpt->list == PAIR_LIST_UNKNOWN) {
		len = p - name;
		ERROR("Invalid list qualifier \"%.*s\"", (int) len, name);
		return -1;
	}

	if (*p == '\0') {
		vpt->type = VPT_TYPE_LIST;
		return 0;
	}

	da = dict_attrbyname(p);
	if (!da) {
		da = dict_attrunknownbyname(p, false);
		if (!da) {
			ERROR("Unknown attribute \"%s\"", p);
			return -1;
		}
	}
	vpt->da = da;

	vpt->type = VPT_TYPE_ATTR;
	return 0;
}
开发者ID:OsvaldoTCF,项目名称:freeradius-server,代码行数:61,代码来源:map.c

示例10: rbtree_finddata

/*
 *	find the appropriate registered xlat function.
 */
static xlat_t *xlat_find(const char *module)
{
	xlat_t my_xlat;

	/*
	 *	Look for dictionary attributes first.
	 */
	if ((dict_attrbyname(module) != NULL) ||
	    (strchr(module, '[') != NULL) ||
	    (strchr(module, '#') != NULL)) {
		module = "request";
	}

	strlcpy(my_xlat.module, module, sizeof(my_xlat.module));
	my_xlat.length = strlen(my_xlat.module);

	return rbtree_finddata(xlat_root, &my_xlat);
}
开发者ID:HAJC,项目名称:freeradius-server,代码行数:21,代码来源:xlat.c

示例11: mod_instantiate

static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
	rlm_sometimes_t *inst = instance;

	/*
	 *	Convert the rcode string to an int, and get rid of it
	 */
	inst->rcode = fr_str2int(mod_rcode_table, inst->rcode_str, RLM_MODULE_UNKNOWN);
	if (inst->rcode == RLM_MODULE_UNKNOWN) {
		cf_log_err_cs(conf, "Unknown module return code '%s'", inst->rcode_str);
		return -1;
	}

	inst->da = dict_attrbyname(inst->key);
	rad_assert(inst->da);

	return 0;
}
开发者ID:johnnywalker,项目名称:freeradius-server,代码行数:18,代码来源:rlm_sometimes.c

示例12: sometimes_instantiate

static int sometimes_instantiate(CONF_SECTION *conf, void **instance)
{
	rlm_sometimes_t *inst;

	/*
	 *	Set up a storage area for instance data
	 */
	inst = rad_malloc(sizeof(*inst));
	if (!inst) {
		return -1;
	}
	memset(inst, 0, sizeof(*inst));

	/*
	 *	If the configuration parameters can't be parsed, then
	 *	fail.
	 */
	if (cf_section_parse(conf, inst, module_config) < 0) {
		sometimes_detach(inst);
		return -1;
	}

	/*
	 *	Convert the rcode string to an int, and get rid of it
	 */
	inst->rcode = str2rcode(inst->rcode_str);
	if (inst->rcode == -1) {
		sometimes_detach(inst);
		return -1;
	}

	inst->da = dict_attrbyname(inst->key);
	if (!inst->da) {
		radlog(L_ERR, "rlm_sometimes; Unknown attributes %s", inst->key);
		return -1;
		return -1;
	}

	*instance = inst;

	return 0;
}
开发者ID:binjetztauchimnetz,项目名称:freeradius-server,代码行数:42,代码来源:rlm_sometimes.c

示例13: evaluate_assignment

/*
 *	Evaluate an assignment
 *
 *	Not really used much...
 */
static int evaluate_assignment(UNUSED policy_state_t *state, const policy_item_t *item)
{
	const policy_assignment_t *this;
#if 0
	const DICT_ATTR *dattr;
#endif

	this = (const policy_assignment_t *) item;

	rad_assert(this->lhs != NULL);
	rad_assert(this->rhs != NULL);

#if 0
	dattr = dict_attrbyname(this->lhs);
	if (!dattr) {
		fprintf(stderr, "HUH?\n");
		return 0;
	}
#endif

	return 1;
}
开发者ID:joyphone,项目名称:freeradius-server,代码行数:27,代码来源:evaluate.c

示例14: arp_socket_decode

static int arp_socket_decode(UNUSED rad_listen_t *listener, UNUSED REQUEST *request)
{
	int i;
	arp_over_ether_t const *arp;
	uint8_t const *p;

	arp = (arp_over_ether_t const *) request->packet->data;
	/*
	 *	arp_socket_recv() takes care of validating it's really
	 *	our kind of ARP.
	 */
	for (i = 0, p = (uint8_t const *) arp;
	     header_names[i].name != NULL;
	     p += header_names[i].len, i++) {
		ssize_t len;
		DICT_ATTR const *da;
		VALUE_PAIR *vp;

		da = dict_attrbyname(header_names[i].name);
		if (!da) return 0;

		vp = NULL;
		len = data2vp(request->packet, NULL, NULL, da, p,
			      header_names[i].len, header_names[i].len,
			      &vp);
		if (len <= 0) {
			RDEBUG("Failed decoding %s: %s",
			       header_names[i].name, fr_strerror());
			return 0;
		}

		debug_pair(vp);
		pairadd(&request->packet->vps, vp);
	}

	return 0;
}
开发者ID:AirspeedTelecom,项目名称:freeradius,代码行数:37,代码来源:proto_arp.c

示例15: radius_get_vp

/** Return a VP from the specified request.
 *
 * @param request current request.
 * @param name attribute name including qualifiers.
 * @param vp_p where to write the pointer to the resolved VP. 
 *	Will be NULL if the attribute couldn't be resolved.
 * @return False if either the attribute or qualifier were invalid, else true
 */
int radius_get_vp(REQUEST *request, const char *name, VALUE_PAIR **vp_p)
{
	VALUE_PAIR **vps;
	pair_lists_t list;
	
	const DICT_ATTR *da;
	
	*vp_p = NULL;
	
	if (!radius_ref_request(&request, &name)) {
		RDEBUG("WARNING: Attribute name refers to outer request"
		       " but not in a tunnel.");
		return TRUE;	/* Discuss, we don't actually know if
				   the attrname was valid... */
	}
	
	list = radius_list_name(&name, PAIR_LIST_REQUEST);
	if (list == PAIR_LIST_UNKNOWN) {
		RDEBUG("ERROR: Invalid list qualifier");
		return FALSE;
	}
	
	da = dict_attrbyname(name);
	if (!da) {
		RDEBUG("ERROR: Attribute \"%s\" unknown", name);
		return FALSE;
	}

	vps = radius_list(request, list);
	rad_assert(vps);
	
	/*
	 *	May not may not be found, but it *is* a known name.
	 */
	*vp_p = pairfind(*vps, da->attr, da->vendor);
	return TRUE;
}
开发者ID:iliyap,项目名称:freeradius-server,代码行数:45,代码来源:valuepair.c


注:本文中的dict_attrbyname函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。