static PE name2psap (DN dn) { int i; AttributeType at; PE pe; static struct ds_read_arg read_arg = { default_common_args, NULLDN, /* read_arg DN */ { /* entry info selection */ FALSE, NULLATTR, EIS_ATTRIBUTESANDVALUES } }; struct DSError error; struct ds_read_result result; if ((at = AttrT_new (DSAADDRESS_OID)) == NULLAttrT) { PY_advise (NULLCP, "build of attribute failed (%s)", DSAADDRESS_OID); return NULLPE; } read_arg.rda_common.ca_servicecontrol.svc_prio = SVC_PRIO_HIGH; read_arg.rda_object = dn; read_arg.rda_eis.eis_select = as_comp_new (AttrT_cpy (at), NULLAV, NULLACL_INFO); i = ds_read (&read_arg, &error, &result); AttrT_free (at); as_free (read_arg.rda_eis.eis_select); if (i != DS_OK) { PY_advise (NULLCP, "DAP lookup failed (%s)", dn2str (dn)); return NULLPE; } if (result.rdr_entry.ent_attr == NULLATTR) { PY_advise (NULLCP, "no '%s' attribute in entry '%s'", DSAADDRESS_OID, dn2str (dn)); return NULLPE; } pe = grab_pe (&result.rdr_entry.ent_attr -> attr_value -> avseq_av); as_free (result.rdr_entry.ent_attr); return pe; }
static bind_to_dsa () { struct ds_bind_arg bindarg; struct ds_bind_arg bindresult; struct ds_bind_error binderr; bindarg.dba_version = DBA_VERSION_V1988; bindarg.dba_dn = username; if (bindarg.dba_passwd_len = strlen (password)) (void) strcpy (bindarg.dba_passwd, password); if (ds_bind (&bindarg,&binderr,&bindresult) != DS_OK) { PY_advise (NULLCP, "unable to bind to directory (%s)", binderr.dbe_type == DBE_TYPE_SECURITY ? "security error" : "DSA unavailable"); return FALSE; } return TRUE; }
static dase_aux (struct type_DASE_Query__REQ *req) { int i; int vecp; char **vp; char *context, **vec; struct type_DASE_Query__RSP *rsp; struct element_DASE_0 *d0; struct element_DASE_1 *d1; envlist el; envlist en, *ep; DN *dn; DNS dns; PE pe; if ((rsp = (struct type_DASE_Query__RSP *) calloc (1, sizeof *rsp)) == NULL) { no_mem: ; adios (NULLCP, "out of memory"); } vec = NULL, el = NULL, context = NULL, dns = NULL; i = 1; for (d0 = req -> name; d0; d0 = d0 -> next) i++; if ((vec = (char **) calloc ((unsigned) i, sizeof *vec)) == NULL) goto no_mem; for (vp = vec, d0 = req -> name; d0; vp++, d0 = d0 -> next) if ((*vp = qb2str (d0 -> IA5String)) == NULL) goto no_mem; #ifdef STATS else advise (LLOG_NOTICE, NULLCP, "lookup: %s", *vp); #endif vecp = i - 1; el = NULL, ep = ⪙ for (d1 = req -> envlist; d1; d1 = d1 -> next) { struct type_DASE_Environment *ev = d1 -> Environment; struct element_DASE_2 *d2; struct dn_seq **dp; if ((en = (envlist) calloc (1, sizeof *en)) == NULL) goto no_mem; *ep = en, ep = &en -> Next; en -> Upper = ev -> upper; en -> Lower = ev -> lower; dp = &en -> Dns; for (d2 = ev -> path; d2; d2 = d2 -> next) { char *cp; struct dn_seq *ds; if ((ds = (struct dn_seq *) calloc (1, sizeof *ds)) == NULL) goto no_mem; *dp = ds, dp = &ds -> dns_next; if ((cp = qb2str (d2 -> IA5String)) == NULL) goto no_mem; if (*cp != '-') ds -> dns_dn = str2dn (cp); free (cp); if (*cp != '-' && ds -> dns_dn == NULLDN) { PY_advise (NULLCP, "bad DN in environment (%s)", cp); goto send_rsp; } } } if ((context = qb2str (req -> context)) == NULL) goto no_mem; #ifdef STATS advise (LLOG_NOTICE, NULLCP, "context: %s", context); #endif if (req -> userdn) { int changed = 0; char *cp; DN newdn; if ((cp = qb2str (req -> userdn)) == NULL) goto no_mem; #ifdef STATS advise (LLOG_NOTICE, NULLCP, "userdn: %s", cp); #endif if ((newdn = str2dn (*cp != '@' ? cp : cp + 1)) == NULLDN) { PY_advise (NULLCP, "bad DN for userdn (%s)", cp); free (cp); goto send_rsp; } if (!userdn || dn_cmp (userdn, newdn)) changed++; if (userdn) dn_free (userdn); userdn = newdn; free (cp); if (req -> passwd) { if ((cp = qb2str (req -> passwd)) == NULL) goto no_mem; if (strcmp (passwd, cp)) changed++; strcpy (passwd, cp); free (cp); } else { if (passwd[0]) changed++; passwd[0] = NULL; } if (isbound && changed) { ds_unbind (); isbound = 0; } } if (!isbound && bind_to_dsa () == NOTOK) goto send_rsp; PY_pepy[0] = NULL; pe = NULLPE; if (vecp == 1 && *vec[0] == '@') { static DN dnstat; if ((dnstat = str2dn (vec[0])) == NULLDN) { PY_advise (NULLCP, "invalid name"); goto send_rsp; } rsp -> value = name2psap (*(dn = &dnstat)); goto all_done; } if (!aet_match (vecp, vec, req -> interactive ? dase_interact : just_say_no, &dns, el, context)) { if (PY_pepy[0] == NULL) PY_advise (NULLCP, "unable to resolve name"); goto send_rsp; } if (dns == NULL) { PY_advise (NULLCP, "search failed to find anything"); goto send_rsp; } dn = NULL; if (dns -> dns_next) { if (req -> interactive) dnSelect (vec[0], &dns, dase_interact, el -> Dns); for (; dns; dns = dns -> dns_next) { dn = &dns -> dns_dn; if (rsp -> value = name2psap (*dn)) break; } } else { dn = &dns -> dns_dn; rsp -> value = name2psap (*dn); } all_done: ; if (dn) { encode_IF_DistinguishedName (&rsp -> name, 1, NULL, NULLCP,*dn); #ifdef STATS advise (LLOG_NOTICE, NULLCP, "answer: %s", dn2str (*dn)); #endif ufn_dn_print_aux (nps, *dn, NULLDN, 0); ps_print (nps, " "); *--nps -> ps_ptr = NULL, nps -> ps_cnt++; rsp -> friendly = str2qb (nps -> ps_base, strlen (nps -> ps_base), 1); nps -> ps_ptr = nps -> ps_base, nps -> ps_cnt = nps -> ps_bufsiz; dn_free (*dn); *dn = NULLDN; } send_rsp: ; if (PY_pepy[0]) { advise (LLOG_NOTICE, NULLCP, "diagnostic: %s", PY_pepy); if ((rsp -> diagnostic = str2qb (PY_pepy, strlen (PY_pepy), 1)) == NULL) goto no_mem; } if (encode_DASE_Query__RSP (&pe, 1, NULL, NULLCP, rsp) == NOTOK) adios (NULLCP, "encode_DASE_Query__RSP: %s", PY_pepy); if (pe2ps (ps, pe) == NOTOK) adios (NULLCP, "pe2ps: %s", ps_error (ps -> ps_errno)); PLOGP (pgm_log,DASE_Message, pe, "message", 0); free_DASE_Query__RSP (rsp); pe_free (pe); if (vec) { for (vp = vec; *vp; vp++) free (*vp); free ((char *) vec); } for (; el; el = en) { en = el -> Next; dn_seq_free (el -> Dns); free ((char *) el); } if (context) free (context); if (dns) dn_seq_free (dns); }