fred.c

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

C
2,257
字号
    if (ptr = find_list_cache (la -> lsa_object = dn, SVC_NOSIZELIMIT)) {	sub = ptr -> list_subs;	*complete = 1;    }    else {	if (rebind () != OK)	    return NULLDNSEQ;	for (;;) {	    if (ds_list (la, le, lr) == DS_OK)		break;	    if (dish_error (OPT, le) == NOTOK)		return NULLDNSEQ;	    la -> lsa_object =			    le -> ERR_REFERRAL.DSE_ref_candidates -> cr_name;	}	cache_list (lr -> lsr_subordinates, lr -> lsr_limitproblem, dn,		    SVC_NOSIZELIMIT);	sub = lr -> lsr_subordinates;	*complete = lr -> lsr_limitproblem == LSR_NOLIMITPROBLEM;    }    newdn = dn_comp_new (rdn_comp_new (NULLAttrT, NULLAttrV));    if (adn = dn_cpy (dn))	dn_append (adn, newdn);    else	dn_free (adn), adn = newdn;    for (; sub; sub = sub -> sub_next) {	rdn_free (newdn -> dn_rdn);	dn_comp_fill (newdn, rdn_cpy (sub -> sub_rdn));	result = dn_seq_push (adn, result);    }    dn_free (adn);    subords_free (lr -> lsr_subordinates);    return result;}/*  */static struct dn_seq *expand_partial (dn, complete)DN	dn;int    *complete;{    struct ds_search_arg search_arg;    register struct ds_search_arg *sa = &search_arg;    struct ds_search_result search_result;    register struct ds_search_result *sr = &search_result;    struct DSError error;    register struct DSError *se = &error;    Filter	fi1,		fi2;    EntryInfo *ptr;    register struct dn_seq *result = NULLDNSEQ;    bzero ((char *) sa, sizeof *sa);    sa -> sra_common.ca_servicecontrol.svc_options			= SVC_OPT_PREFERCHAIN | SVC_OPT_DONTDEREFERENCEALIAS;    sa -> sra_common.ca_servicecontrol.svc_timelimit = SVC_NOTIMELIMIT;    sa -> sra_common.ca_servicecontrol.svc_sizelimit = SVC_NOSIZELIMIT;    sa -> sra_subset = SRA_ONELEVEL;    sa -> sra_searchaliases = FALSE;    sa -> sra_eis.eis_allattributes = FALSE;    sa -> sra_eis.eis_select = fred_as ();    sa -> sra_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES;    if (!(fi1 = ocfilter ("dSA")))	fatal (-100, "ocfilter (\"dSA\") failed");    fi1 = joinfilter (fi1, FILTER_NOT);    if (!(fi2 = ocfilter ("domain")))	fatal (-100, "ocfilter (\"domain\") failed");    fi2 = joinfilter (fi2, FILTER_NOT);    fi2 -> flt_next = fi1;    sa -> sra_filter = joinfilter (fi2, FILTER_AND);    sa -> sra_baseobject = dn;    if (rebind () != OK)	goto free_filter;    while (ds_search (sa, se, sr) != DS_OK) {	if (dish_error (OPT, se) == 0) {	    dsa_status = NOTOK;	    goto free_filter;	}	sa -> sra_baseobject =	    se -> ERR_REFERRAL.DSE_ref_candidates -> cr_name;    }    if (sr -> srr_correlated != TRUE)	correlate_search_results (sr);    for (ptr = sr -> CSR_entries; ptr; ptr = ptr -> ent_next) {	cache_entry (ptr, sa -> sra_eis.eis_allattributes,		     sa -> sra_eis.eis_infotypes);	result = dn_seq_push (ptr -> ent_dn, result);    }    *complete = sr -> CSR_limitproblem == LSR_NOLIMITPROBLEM;    dn_free (sr -> CSR_object);    entryinfo_free (sr -> CSR_entries, 0);    crefs_free (sr -> CSR_cr);free_filter: ;    filter_free (sa -> sra_filter);    return result;}/*    UFNRC SUPPORT */static	envlist myel = NULLEL;/*  */static	build_ufnrc (argc, argv)int	argc;char  **argv;{    envlist	el;    register envlist  en,		     *ep;    el = NULL, ep = &el;    while (argc >= 3) {	register char *cp;	char   *xp;	register struct dn_seq **dp;	if ((en = (envlist) calloc (1, sizeof *en)) == NULL) {no_mem: ;	    ps_printf (OPT, "Out of memory!");	    goto losing;	}	*ep = en, ep = &en -> Next;	if (sscanf (argv[0], "%d", &en -> Lower) != 1	        || sscanf (argv[1], "%d", &en -> Upper) != 1)	    goto usage;	dp = &en -> Dns;	for (cp = argv[2]; *cp; cp = xp){	    register struct dn_seq *ds;	    if (xp = index (cp, '$'))		*xp++ = NULL;	    else		xp = cp + strlen (cp);	    if ((ds = (struct dn_seq *) calloc (1, sizeof *ds)) == NULL)		goto no_mem;	    *dp = ds, dp = &ds -> dns_next;	    if (*cp != '-' && (ds -> dns_dn = str2dn (cp)) == NULLDN) {		ps_printf (OPT, "Bad DN in environment: %s", cp);		goto losing;	    }	}	argc -= 3, argv += 3;    }    if (argc > 0) {usage: ;	Usage ("fred");	goto losing;    }        en = myel, myel = el, el = en;    /* and fall... */losing: ;    for (; el; el = en) {	en = el -> Next;	dn_seq_free (el -> Dns);	free ((char *) el);    }    for (el = myel; el; el = el -> Next) {	ps_printf (RPS, "%d,%d:\t    ", el -> Lower, el -> Upper);	dn_seq_print (RPS, el -> Dns, EDBOUT);	ps_printf (RPS, "\n");    }}/*    UFN SUPPORT */#ifndef	SOCKETSextern	char	search_result;#endifextern	char	remote_prob;extern	DN	ufn_bad_dsa;extern	DNS	ufn_partials;/*  */static	do_ufn_match (n, vec)int	n;char  **vec;{    struct dn_seq  *dns;    if (rebind () != OK)	return;    ufn_notify = !frompipe;    if (n > 0 && strcmp (vec[0], "-list") == 0) {	n--, vec++;	fred_list = dad_flag;    }    else	fred_list = FALSE;    if (n > 0 && strcmp (vec[0], "-mailbox") == 0) {	n--, vec++;	fred_mailbox = TRUE;	if (t_mbox == NULL)	    fatal (-100, "rfc822Mailbox: invalid attribute type");    }    else	fred_mailbox = FALSE;    if (n > 0 && strcmp (vec[0], "-phone") == 0) {	n--, vec++;	fred_phone = TRUE;    }    else	fred_phone = FALSE;    if (n > 0 && strcmp (vec[0], "-photo") == 0) {	n--, vec++;	fred_photo = dad_flag;    }    else	fred_photo = FALSE;    if (n > 0 && strncmp (vec[0], "-options ", sizeof "-options " - 1) == 0) {	if (sscanf (vec[0], "-options %x", &ufn_flags) != 1) {	    ps_printf (OPT, "bad option: %s\n", vec[0]);	    return;	}	n--, vec++;    }    else	ufn_flags = UFN_ALL;    dns = NULL;    if (!ufn_match (n, vec, interact, &dns, myel)) {	Entry	e;	if (fred_mailbox) {	    ps_printf (OPT, "unable to resolve name");	    return;	}	if (ufn_bad_dsa) {	    if (e = fredentry (ufn_bad_dsa, TRUE)) {		ps_printf (OPT,			   "Unable to resolve name due to Directory failure, problem with:\n");		(void) showfred (ufn_bad_dsa, TRUE, FALSE);	    }	    dn_free (ufn_bad_dsa), ufn_bad_dsa = NULL;	    if (e)		return;	}	ps_printf (OPT, "Unable to resolve name.\n");	return;    }    if (!fred_mailbox)	done_match (dns, NULLCP);    else {	struct dn_seq  *result;	Entry	e;	Attr_Sequence	eptr;	result = NULL;	while (dns) {	    struct dn_seq *tmp;	    if (!(e = local_find_entry (dns -> dns_dn, FALSE))) {strip_it: ;		tmp = dns;		dns = dns -> dns_next;		tmp -> dns_next = NULL;		dn_seq_free (tmp);		continue;	    }	    for (eptr = e -> e_attributes; eptr; eptr = eptr -> attr_link)		if (AttrT_cmp (eptr -> attr_type, t_mbox) == 0)		    break;	    if (!eptr || !eptr -> attr_value)		goto strip_it;	    tmp = dns -> dns_next;	    dns -> dns_next = result;	    result = dns;	    dns = tmp;	}	if (!(dns = result)) {none_selected: ;	    ps_printf (OPT, "search failed\n");	    return;	}	while (dns -> dns_next) {	    int	i;	    struct dn_seq *ptr;	    i = 0;	    for (ptr = dns; ptr; ptr = ptr -> dns_next)		i++;	    dns_sort (&dns, i);	    if (!(dns = interact (dns, NULLDN, NULLCP)))		goto none_selected;	}	if (!(dns = interact (dns, NULLDN, NULLCP)))	    goto none_selected;	if (!(e = local_find_entry (dns -> dns_dn, FALSE))) {lost_entry: ;	    ps_printf (OPT, "lost entry\n");	    dn_seq_free (dns);	    return;	}	for (eptr = e -> e_attributes; eptr; eptr = eptr -> attr_link)	    if (AttrT_cmp (eptr -> attr_type, t_mbox) == 0)		break;	if (!eptr || !eptr -> attr_value)	    goto lost_entry;	AttrV_print (RPS, &eptr -> attr_value -> avseq_av, READOUT);	ps_print (RPS, "\n");	dn_seq_free (dns);    }}/*  */static struct dn_seq *interact (dns, dn, s)struct dn_seq *dns;DN	dn;char   *s;{    int	    i,	    j;    char    buffer[BUFSIZ];    struct dn_seq *result = NULL,		  *ptr,		  *tmp;    static PS    nps = NULL;    if (dns == NULL)	return NULL;    if (nps == NULLPS	    && ((nps = ps_alloc (str_open)) == NULLPS	            || str_setup (nps, NULLCP, 0, 0) == NOTOK)) {	if (nps)	    ps_free (nps);	return dns;    }    i = 0;    for (ptr = dns; ptr; ptr = ptr -> dns_next)	i++;    if (i == 1 && s)	return dns;    if (fred_list && frompipe && i > 1) {#define	NCHOICES	25	register int *ip;	int	chosen[NCHOICES];	char   *bp;	if (i > NCHOICES) {losing: ;	    dn_seq_free (dns);	    return NULLDNSEQ;	}	dns_sort (&dns, i);	for (ptr = dns; ptr; ptr = ptr -> dns_next) {	    ufn_dn_print_aux (nps, ptr -> dns_dn, dn, 0);	    ps_print (nps, "$");	    dn_print (nps, ptr -> dns_dn, EDBOUT);	    ps_print (nps, " ");	    *--nps -> ps_ptr = NULL, nps -> ps_cnt++;	    (void) sprintf (buffer, "l%s\n", nps -> ps_base);	    nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz;	    send_pipe_aux (buffer);	    if (read_pipe_aux (buffer, sizeof buffer) < 1) {		(void) fprintf (stderr, "read failure\n");		remote_prob = TRUE;		goto losing;	    }	}	if (s)	    (void) sprintf (buffer,			    "LPlease select from the following matches for '%s':\n",			    s);	else	    (void) sprintf (buffer, "LPlease select one of the following:\n");	send_pipe_aux (buffer);	if (read_pipe_aux (buffer, sizeof buffer) < 1) {	    (void) fprintf (stderr, "read failure\n");	    remote_prob = TRUE;	    goto losing;	}	bzero ((char *) chosen, sizeof chosen);	for (bp = buffer + 1; *bp; ) {	    int	    k;	    	    while (!isdigit (*bp))		if (*bp)		    bp++;	        else		    return (NULLDNSEQ);	    if (!*bp || sscanf (bp, "%d", &k) != 1 || k <= 0 || k > NCHOICES)		break;	    chosen[--k] = 1;	    while (isdigit (*bp))	        if (*bp)		   bp++;	        else 		   return (NULLDNSEQ);	}	for (ip = chosen; dns; ip++)	    if (*ip) {		tmp = dns -> dns_next;		dns -> dns_next = result;		result = dns;		dns = tmp;	    }	    else {		tmp = dns;		dns = dns -> dns_next;		tmp -> dns_next = NULL;		dn_seq_free (tmp);	    }	return result;    }    if (i > 10) {	if (s)	    (void) sprintf (buffer,			    "%d imprecise matches for '%s', select from them [y/n] ? ",			    i, s);	else	    (void) sprintf (buffer,			    "%d imprecise matches, select one of them [y/n] ? ");	if (yesno (buffer)) {	    dn_seq_free (dns);	    return NULLDNSEQ;	}    }    else {	if (s)	    (void) sprintf (buffer,			    "mPlease select from the following %d match%s for '%s':\n",			    i, i != 1 ? "es" : "", s);	else	    (void) sprintf (buffer, "mPlease %s of the following:\n",			    i > 1 ? "select one" : "confirm use");	if (frompipe) {	    send_pipe_aux (buffer);	    if (read_pipe_aux (buffer, sizeof buffer) < 1) {		(void) fprintf (stderr, "read failure\n");		remote_prob = TRUE;		goto losing;	    }	}	else	    ps_printf (OPT, "%s", buffer + 1);    }    if (i > 1)	dns_sort (&dns, i);    j = 1;    while (dns) {	ufn_dn_print_aux (nps, dns -> dns_dn, dn, 0);	ps_print (nps, " [y/n] ? ");	ps_print (nps, " ");	*--nps -> ps_ptr = NULL, nps -> ps_cnt++;	(void) strcpy (buffer, nps -> ps_base);	nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz;	switch (yesno (buffer)) {	    case OK:		tmp = dns -> dns_next;		dns -> dns_next = result;		result = dns;		dns = tmp;		break;	    case NOTOK:	    default:		tmp = dns;		dns = dns -> dns_next;		tmp -> dns_next = NULL;		dn_seq_free (tmp);		break;	    case DONE:		dn_seq_free (dns);		goto out;	}	if ((j++ % 10) == 0 && dns) {	    (void) sprintf (buffer, "Continue (%d more) [y/n] ? ", i - j + 1);	    if (yesno (buffer)) {		dn_seq_free (dns);		break;	    }	}    }out: ;    return result;}/*  */static	int	dns_compar (a, b)struct dn_seq **a,	      **b;{    int	    i;    DN	    adn,	    bdn;    for (adn = (*a) -> dns_dn; adn -> dn_parent; adn = adn -> dn_parent)

⌨️ 快捷键说明

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