⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modcall.c

📁 新的radius程序
💻 C
📖 第 1 页 / 共 3 页
字号:
			3,			/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			1,			/* notfound */			2,			/* noop     */			4			/* updated  */		},		/* redundant */		{			MOD_ACTION_RETURN,	/* reject   */			1,			/* fail     */			MOD_ACTION_RETURN,	/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			MOD_ACTION_RETURN,	/* notfound */			MOD_ACTION_RETURN,	/* noop     */			MOD_ACTION_RETURN	/* updated  */		},		/* append */		{			MOD_ACTION_RETURN,	/* reject   */			1,			/* fail     */			MOD_ACTION_RETURN,	/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			2,			/* notfound */			MOD_ACTION_RETURN,	/* noop     */			MOD_ACTION_RETURN	/* updated  */		}	},	/* post-proxy */	{		/* group */		{			MOD_ACTION_RETURN,	/* reject   */			MOD_ACTION_RETURN,	/* fail     */			3,			/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			1,			/* notfound */			2,			/* noop     */			4			/* updated  */		},		/* redundant */		{			MOD_ACTION_RETURN,	/* reject   */			1,			/* fail     */			MOD_ACTION_RETURN,	/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			MOD_ACTION_RETURN,	/* notfound */			MOD_ACTION_RETURN,	/* noop     */			MOD_ACTION_RETURN	/* updated  */		},		/* append */		{			MOD_ACTION_RETURN,	/* reject   */			1,			/* fail     */			MOD_ACTION_RETURN,	/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			2,			/* notfound */			MOD_ACTION_RETURN,	/* noop     */			MOD_ACTION_RETURN	/* updated  */		}	},	/* post-auth */	{		/* group */		{			MOD_ACTION_RETURN,	/* reject   */			MOD_ACTION_RETURN,	/* fail     */			3,			/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			1,			/* notfound */			2,			/* noop     */			4			/* updated  */		},		/* redundant */		{			MOD_ACTION_RETURN,	/* reject   */			1,			/* fail     */			MOD_ACTION_RETURN,	/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			MOD_ACTION_RETURN,	/* notfound */			MOD_ACTION_RETURN,	/* noop     */			MOD_ACTION_RETURN	/* updated  */		},		/* append */		{			MOD_ACTION_RETURN,	/* reject   */			1,			/* fail     */			MOD_ACTION_RETURN,	/* ok       */			MOD_ACTION_RETURN,	/* handled  */			MOD_ACTION_RETURN,	/* invalid  */			MOD_ACTION_RETURN,	/* userlock */			2,			/* notfound */			MOD_ACTION_RETURN,	/* noop     */			MOD_ACTION_RETURN	/* updated  */		}	}};static modcallable *do_compile_modsingle(int component, CONF_ITEM *ci,					 const char *filename, int grouptype,					 const char **modname){	int lineno;	const char *modrefname;	modsingle *single;	modcallable *csingle;	module_instance_t *this;	if (cf_item_is_section(ci)) {		CONF_SECTION *cs = cf_itemtosection(ci);		const char *name2 = cf_section_name2(cs);		lineno = cf_section_lineno(cs);		modrefname = cf_section_name1(cs);		if (!name2) name2 = "_UnNamedGroup";		/*		 *	group{}, redundant{}, or append{} may appear		 *	where a single module instance was expected.		 *	In that case, we hand it off to		 *	compile_modgroup		 */		if (strcmp(modrefname, "group") == 0) {			*modname = name2;			return do_compile_modgroup(component, cs, filename,					GROUPTYPE_SIMPLE, grouptype);		} else if (strcmp(modrefname, "redundant") == 0) {			*modname = name2;			return do_compile_modgroup(component, cs, filename,					GROUPTYPE_REDUNDANT, grouptype);		} else if (strcmp(modrefname, "append") == 0) {			*modname = name2;			return do_compile_modgroup(component, cs, filename,					GROUPTYPE_APPEND, grouptype);		} else if (strcmp(modrefname, "load-balance") == 0) {			*modname = name2;			csingle= do_compile_modgroup(component, cs, filename,					GROUPTYPE_SIMPLE, grouptype);			if (!csingle) return NULL;			csingle->type = MOD_LOAD_BALANCE;			return csingle;		} else if (strcmp(modrefname, "redundant-load-balance") == 0) {			*modname = name2;			csingle= do_compile_modgroup(component, cs, filename,					GROUPTYPE_REDUNDANT, grouptype);			if (!csingle) return NULL;			csingle->type = MOD_REDUNDANT_LOAD_BALANCE;			return csingle;		}	} else {		CONF_PAIR *cp = cf_itemtopair(ci);		lineno = cf_pair_lineno(cp);		modrefname = cf_pair_attr(cp);	}	/*	 *	FIXME: See if the module is a virtual one.  If so,	 *	return that, rather than doing anything here.	 */	this = find_module_instance(modrefname);	if (!this) {		*modname = NULL;		radlog(L_ERR|L_CONS, "%s[%d] Unknown module \"%s\".", filename,		       lineno, modrefname);		return NULL;	}	/*	 *	We know it's all OK, allocate the structures, and fill	 *	them in.	 */	single = rad_malloc(sizeof(*single));	csingle = mod_singletocallable(single);	csingle->next = NULL;	memcpy(csingle->actions, defaultactions[component][grouptype],	       sizeof csingle->actions);	rad_assert(modrefname != NULL);	csingle->name = modrefname;	csingle->type = MOD_SINGLE;	/*	 *	Singles can override the actions, virtual modules cannot.	 *	 *	FIXME: We may want to re-visit how to do this...	 *	maybe a csingle as a ref?	 */	if (cf_item_is_section(ci)) {		CONF_SECTION *cs = cf_itemtosection(ci);		CONF_PAIR *cp;		const char *attr, *value;		for (ci=cf_item_find_next(cs, NULL);		     ci != NULL;		     ci=cf_item_find_next(cs, ci)) {			if (cf_item_is_section(ci)) {				radlog(L_ERR|L_CONS,				       "%s[%d] Subsection of module instance call "				       "not allowed\n", filename,				       cf_section_lineno(cf_itemtosection(ci)));				modcallable_free(&csingle);				return NULL;			}			cp = cf_itemtopair(ci);			attr = cf_pair_attr(cp);			value = cf_pair_value(cp);			lineno = cf_pair_lineno(cp);			if (!compile_action(csingle, attr, value, filename,					    lineno)) {				modcallable_free(&csingle);				return NULL;			}		}	}	/*	 *	Bail out if the module in question does not supply the	 *	wanted component	 */	if (!this->entry->module->methods[component]) {		radlog(L_ERR|L_CONS,		       "%s: \"%s\" modules aren't allowed in '%s' sections -- they have no such method.",		       filename, this->entry->module->name,		       component_names[component]);		modcallable_free(&csingle);		return NULL;	}	single->modinst = this;	*modname = this->entry->module->name;	return csingle;}modcallable *compile_modsingle(int component, CONF_ITEM *ci,			       const char *filename, const char **modname){	modcallable *ret = do_compile_modsingle(component, ci, filename,						GROUPTYPE_SIMPLE,						modname);	dump_tree(component, ret);	return ret;}static modcallable *do_compile_modgroup(int component, CONF_SECTION *cs,					const char *filename, int grouptype,					int parentgrouptype){	modgroup *g;	modcallable *c;	CONF_ITEM *ci;	g = rad_malloc(sizeof *g);	g->grouptype = grouptype;	c = mod_grouptocallable(g);	c->next = NULL;	memcpy(c->actions, defaultactions[component][parentgrouptype],	       sizeof(c->actions));	/*	 *	Remember the name for printing, etc.	 *	 *	FIXME: We may also want to put the names into a	 *	rbtree, so that groups can reference each other...	 */	c->name = cf_section_name2(cs);	if (!c->name) c->name = "";	c->type = MOD_GROUP;	g->children = NULL;	for (ci=cf_item_find_next(cs, NULL);	     ci != NULL;	     ci=cf_item_find_next(cs, ci)) {		if(cf_item_is_section(ci)) {			const char *junk = NULL;			modcallable *single;			int lineno;			CONF_SECTION *subcs = cf_itemtosection(ci);			lineno = cf_section_lineno(subcs);			single = do_compile_modsingle(component, ci, filename,						      grouptype, &junk);			if (!single) {				radlog(L_ERR|L_CONS,				       "%s[%d] Failed to parse \"%s\" subsection.\n",				       filename, lineno,				       cf_section_name1(subcs));				modcallable_free(&c);				return NULL;			}			add_child(g, single);		} else {			const char *attr, *value;			CONF_PAIR *cp = cf_itemtopair(ci);			int lineno;			attr = cf_pair_attr(cp);			value = cf_pair_value(cp);			lineno = cf_pair_lineno(cp);			/*			 *	A CONF_PAIR is either a module			 *	instance with no actions			 *	specified ...			 */			if (value[0] == 0) {				modcallable *single;				const char *junk = NULL;				single = do_compile_modsingle(component,						cf_pairtoitem(cp), filename,						grouptype, &junk);				if (!single) {					radlog(L_ERR|L_CONS,					       "%s[%d] Failed to parse \"%s\" entry.\n",					       filename, lineno, attr);					modcallable_free(&c);					return NULL;				}				add_child(g, single);				/*				 *	Or a module instance with action.				 */			} else if (!compile_action(c, attr, value, filename,						   lineno)) {				modcallable_free(&c);				return NULL;			} /* else it worked */		}	}	/*	 *	FIXME: If there are no children, return NULL?	 */	return mod_grouptocallable(g);}modcallable *compile_modgroup(int component, CONF_SECTION *cs,		const char *filename){	modcallable *ret = do_compile_modgroup(component, cs, filename,					       GROUPTYPE_SIMPLE,					       GROUPTYPE_SIMPLE);	dump_tree(component, ret);	return ret;}void add_to_modcallable(modcallable **parent, modcallable *this,			int component, char *name){	modgroup *g;		rad_assert(this != NULL);	if (*parent == NULL) {		modcallable *c;		g = rad_malloc(sizeof *g);		g->grouptype = GROUPTYPE_SIMPLE;		c = mod_grouptocallable(g);		c->next = NULL;		memcpy(c->actions,		       defaultactions[component][GROUPTYPE_SIMPLE],		       sizeof(c->actions));		rad_assert(name != NULL);		c->name = name;		c->type = MOD_GROUP;		g->children = NULL;		*parent = mod_grouptocallable(g);	} else {		g = mod_callabletogroup(*parent);	}	add_child(g, this);}void modcallable_free(modcallable **pc){	modcallable *c, *loop, *next;	c = *pc;	if(c->type==MOD_GROUP) {		for(loop = mod_callabletogroup(c)->children;		    loop ;		    loop = next) {			next = loop->next;			modcallable_free(&loop);		}	}	free(c);	*pc = NULL;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -