ufn_parse.c

来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 907 行 · 第 1/2 页

C
907
字号
			return 0;		    filtd -> flt_next = filtb;		    filt = joinfilter (filtd, FILTER_OR);		}		else		    filt = joinfilter (filtc, FILTER_OR);		filtg->flt_next = filt;		filtf = joinfilter (filtg, FILTER_AND);	}    return ufn_search (base,FALSE,filtf,result,s,interact,el);}static leafSearch (base,s,subtree,interact,el,result)DN base;char * s;char subtree;DNS (* interact) ();DNS el;DNS * result;{Filter filt, filta, filtb, filtc, filtd, filte, filtf;	if ((filta = strfilter (at_CommonName,s,SUBSTRINGS ())) == NULLFILTER)	    return 0;	if ((filtc = strfilter (at_Surname,s,SUBSTRINGS ())) == NULLFILTER)	    return 0;	filtc -> flt_next = filta;	if ((filte = strfilter (at_Userid,s,SUBSTRINGS ())) == NULLFILTER)	    return 0;	filte -> flt_next = filtc;	if ((ufn_flags & UFN_APPROX) && !index (s, '*')) {	    if ((filtb = strfilter (at_CommonName,s,FILTERITEM_APPROX)) == NULLFILTER)		return 0;	    filtb -> flt_next = filte;	    if ((filtd = strfilter (at_Surname,s,FILTERITEM_APPROX)) == NULLFILTER)		return 0;	    filtd -> flt_next = filtb;	    if ((filtf = strfilter (at_Userid,s,FILTERITEM_APPROX)) == NULLFILTER)		return 0;	    filtf -> flt_next = filtd;	    filt = joinfilter (filtf, FILTER_OR);	}	else	    filt = joinfilter (filte, FILTER_OR);	return ufn_search (base,subtree,filt,result,s,interact,el);}static keyedSearch (base,t,v,interact,el,result)DN base;char * t, *v; DNS (* interact) ();DNS el;DNS * result;{Filter filt, filta, filtb;AttributeType at;	if ((at = AttrT_new (t)) == NULLAttrT) {		NOTIFY (("Invalid Key !"));		return FALSE;	}	if ( ! sub_string (at->oa_syntax)) {		NOTIFY (("String types only !"));		return FALSE;	}	if ((filta = strfilter (at,v,SUBSTRINGS ())) == NULLFILTER)	    return 0;	if ((ufn_flags & UFN_APPROX) && !index (v, '*')) {	    if ((filtb = strfilter (at,v,FILTERITEM_APPROX)) == NULLFILTER)		return 0;	    filtb -> flt_next = filta;	    filt = joinfilter (filtb, FILTER_OR);	}	else	    filt = filta;	return ufn_search (base, base && base -> dn_parent				      && present (base, at_Organisation),			   filt, result, v, interact, el);}static purportedMatch(base,c,v,interact,el,result)DN base;int c;char ** v;DNS (* interact) ();DNS el;DNS * result;{char * s;DNS root, x, new = NULLDNS;char * ptr;int matches;int bad_purported = FALSE;	s = TidyString (v[c-1]);	if (c == 1) {		if ((ptr = index (s,'=')) != NULLCP) {			*ptr++ = 0;			matches = keyedSearch (base,SkipSpace(s),SkipSpace(ptr),interact,el,result);			*(--ptr) = '=';			return matches;		} else if (base == NULLDN) {			matches = rootSearch(s,interact,el,result);			if (*result != NULLDNS)				return matches;			else if (matches == TRUE)				return TRUE;			else				return leafSearch (base,s,FALSE,interact,el,result);		} else if (base->dn_parent == NULLDN			       || !present (base, at_Organisation)) {			/* length == 1 or still in geography */			matches = intSearch (base,s,interact,el,result);			if (*result != NULLDNS)				return matches;			else if (matches == TRUE)				return TRUE;			else				return leafSearch (base,s,						   base -> dn_parent == NULLDN,						   interact,el,result);		} else {			matches = leafSearch (base,s,TRUE,interact,el,result);			if (*result != NULLDNS)				return matches;			else if (matches == TRUE)				return TRUE;			else				return intSearch (base,s,interact,el,result);		}	}	if ((ptr = index (s,'=')) != NULLCP) {		*ptr++ = 0;		if ( ! (matches = keyedSearch (base,SkipSpace(s),SkipSpace(ptr),interact,el,&root))) {			*(--ptr) = '=';			return FALSE;		}		*(--ptr) = '=';	} else if (base == NULLDN) {		if ( ! (matches = rootSearch (s,interact,el,&root)))			return FALSE;	} else {		if ( ! (matches = intSearch (base,s,interact,el,&root)))			return FALSE;	}	for (x = root; x != NULLDNS; x = x->dns_next) {		if (purportedMatch (x->dns_dn, c-1, v,interact,el,&new)) {			if (new != NULLDNS)				*result = DNS_append (*result,new);		} else			bad_purported = TRUE;	}	if (bad_purported)		if (*result == NULLDNS)		    return FALSE;		else		    NOTIFY (("Remote failure: Not all subtrees searched"));			return matches;}static envMatch (c,v,el,interact,result)int c;char ** v;DNS el;DNS (* interact) ();DNS * result;{int res;	if (el == NULLDNS)		return TRUE;	if ( ! ( res = purportedMatch(el->dns_dn,c,v,interact,el,result)))		return FALSE;	if (*result != NULLDNS)			return res;	if (res == TRUE)		return TRUE;			return envMatch(c,v,el->dns_next,interact,result);}static	friendlyMatch_aux (c,v,el,interact,result)int c;char ** v;envlist el;DNS (* interact) ();DNS * result;{	if (el == NULLEL)		return TRUE;	if ( ( c <= el->Upper) && (c >= el->Lower) ) 		return envMatch (c,v,el->Dns,interact,result);	return (friendlyMatch_aux (c,v,el->Next,interact,result));}envlist read_envlist(){char * home, *p, *ptr;char ufnrc [LINESIZE];char * def, *opened;char buffer [LINESIZE];envlist env, top = NULLEL, trail = NULLEL;DNS dtail = NULLDNS;FILE * file;DN dn;int i = 0;	if (home = getenv ("UFNRC"))		(void) strcpy (ufnrc, home);	else 		if (home = getenv ("HOME"))			(void) sprintf (ufnrc, "%s/.ufnrc", home);		else			(void) strcpy (ufnrc, "./.ufnrc");	opened = ufnrc;	if ((file = fopen (ufnrc,"r")) == 0) {		def = isodefile("ufnrc",0);		if ((file = fopen(def,"r")) == 0) {			(void) sprintf (PY_pepy,"Can't open '%s' or '%s'",ufnrc,def);			return NULLEL;		}		opened = def;	}	while (fgets (buffer, LINESIZE, file) != 0) {		i++;		p = buffer;		if (( *p == '#') || (*p == '\0') || (*p == '\n'))			continue; 	/* ignore comments and blanks */		if (isspace (*p)) {			/* part of current environment */			if (!dtail) {				(void) sprintf (PY_pepy, "Unexpected blank at start of line %d in %s",i,opened);				(void) fclose (file);				return NULLEL;			}			p = TidyString(p);			if (*p == '-')				dn = NULLDN;			else if ((dn = str2dn (p)) == NULLDN) {				(void) sprintf (PY_pepy, "Bad DN in environment file (%s) line %d",opened,i);				(void) fclose (file);				return NULLEL;			}			dtail->dns_next = dn_seq_alloc();			dtail = dtail->dns_next;			dtail->dns_next = NULLDNS;			dtail->dns_dn   = dn;			continue;		}		p = TidyString (p);		if ((ptr = index (p,':')) == NULLCP) {			(void) sprintf (PY_pepy, "':' missing in environment file (%s) line %d",opened,i);			(void) fclose (file);			return NULLEL;		}		*ptr++ = 0;		ptr = SkipSpace (ptr);		if (*ptr == '-')			dn = NULLDN;		else if ((dn = str2dn (ptr)) == NULLDN) {			(void) sprintf (PY_pepy, "Bad DN in environment file (%s) line %d",opened,i);			(void) fclose (file);			return NULLEL;		}		env = (envlist) smalloc (sizeof (*env));		dtail = env->Dns = dn_seq_alloc();		dtail->dns_next = NULLDNS;		dtail->dns_dn   = dn;		env->Next = NULLEL;		if (top == NULLEL)			top = env;		else 			trail->Next = env;		trail = env;		if ((ptr = index (p,',')) != NULLCP) {			*ptr++ = 0;			ptr = SkipSpace(ptr);			if (*ptr == '+')				env->Upper = 32767;	/* ~= infinity */			else 				env->Upper = atoi (ptr);	/* how to test error ? */		} else			env->Upper = 0;				p = SkipSpace(p);		env->Lower = atoi (p);		/* how to test error ? */		if ( ! env->Upper)			env->Upper = env->Lower;	}	(void) fclose (file);	return top;}ufn_match (c,v,interact,result,el)int c;char ** v;DNS (* interact) ();DNS * result;envlist el;{static int inited = FALSE;	if ( (!ufnas) && !(inited = ufn_init()))		return inited;	if (ufn_bad_dsa)	    dn_free (ufn_bad_dsa), ufn_bad_dsa = NULL;	if (ufn_partials)	    dn_seq_free (ufn_partials), ufn_partials = NULL;	PY_pepy[0] = NULL;	if (el == NULLEL) {		if ((el = read_envlist ()) == NULLEL) {			(void) sprintf (PY_pepy,"Can't read environment");			return 0;		}	}	ufn_abort = FALSE;	return (friendlyMatch_aux (c,v,el,interact,result));}ufn_init (){Attr_Sequence as;int result = TRUE;	if (ufnas)	    return result;	if ((at_ObjectClass = AttrT_new ("ObjectClass")) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("ObjectClass attribute unknown"));	}	if ((at_OrgUnit	= AttrT_new ("ou")) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("ou attribute unknown"));	}	if ((at_Organisation = AttrT_new ("o")) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("o attribute unknown"));	}	if ((at_Locality = AttrT_new ("l")) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("l attribute unknown"));	}	if ((at_CountryName = AttrT_new ("c")) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("c attribute unknown"));	}	if ((at_FriendlyCountryName = AttrT_new ("FriendlyCountryName")) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("FriendlyCountryName attribute unknown"));	}	if ((at_CommonName = AttrT_new (CN_OID)) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("cn attribute unknown"));	}	if ((at_Surname	= AttrT_new ("sn")) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("sn attribute unknown"));	}	if ((at_Userid = AttrT_new ("uid")) == NULLAttrT) {		result = FALSE;		LLOG (log_dsap,LLOG_EXCEPTIONS,("uid attribute unknown"));	}	ufnas = as_comp_new (at_OrgUnit,NULLAV,NULLACL_INFO);	as = as_comp_new (at_Organisation,NULLAV,NULLACL_INFO);	ufnas = as_merge (ufnas,as);	as = as_comp_new (at_Locality,NULLAV,NULLACL_INFO);	ufnas = as_merge (ufnas,as);	as = as_comp_new (at_CountryName,NULLAV,NULLACL_INFO);	ufnas = as_merge (ufnas,as);	as = as_comp_new (at_FriendlyCountryName,NULLAV,NULLACL_INFO);	ufnas = as_merge (ufnas,as);	as = as_comp_new (at_CommonName,NULLAV,NULLACL_INFO);	ufnas = as_merge (ufnas,as);	as = as_comp_new (at_Surname,NULLAV,NULLACL_INFO);	ufnas = as_merge (ufnas,as);	as = as_comp_new (at_Userid,NULLAV,NULLACL_INFO);	ufnas = as_merge (ufnas,as);	return result;}#ifdef	DEBUGstatic	print_search (dn, subtree, fi)DN	dn;char	subtree;Filter	fi;{static	PS	nps = NULLPS;    if (nps == NULLPS) {	if ((nps = ps_alloc (std_open)) == NULL) {	    (void) fprintf (stderr, "ps_alloc(std_open): you lose\n");	    return;	}	if (std_setup (nps, stdout) == NOTOK) {	    (void) fprintf (stderr, "std_setup(stdout): you lose\n");	    ps_free (nps);	    nps = NULL;	    return;	}    }        ps_printf (nps, "search starting at @");    dn_print (nps, dn, EDBOUT);    ps_printf (nps, "(%s) for ", subtree ? "subtree" : "singlelevel");    print_filter (nps, fi, 0);    ps_print (nps, "\n\n");    (void) ps_flush (nps);}#endif

⌨️ 快捷键说明

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