Beispiel #1
0
khm_int32 KHMAPI
addr_list_toString(const void *d, khm_size cb_d,
		   wchar_t *buf, khm_size *pcb_buf,
		   khm_int32 flags)
{
    HostAddresses as;
    size_t len;
    size_t i;

    wchar_t wstr[2048] = L"";
    wchar_t *wstr_d = &wstr[0];
    khm_size cch_wstr = ARRAYLENGTH(wstr);

    if ( decode_HostAddresses((const unsigned char *) d, cb_d, &as, &len) ) {
	assert(FALSE);
	return KHM_ERROR_INVALID_PARAM;
    }

    for (i=0; i < as.len; i++) {
	char buf[1024];
	wchar_t wbuf[1024];

	len = sizeof(buf);
	if (krb5_print_address(&as.val[i], buf, sizeof(buf), &len)) {
	    assert(FALSE);
	    continue;
	}

	AnsiStrToUnicode(wbuf, sizeof(wbuf), buf);
	if (FAILED(StringCchCatEx(wstr_d, cch_wstr, wbuf, &wstr_d, &cch_wstr,
				  STRSAFE_NO_TRUNCATION))) {
	    assert(FALSE);
	    continue;
	}

	if (i + 1 < as.len) {
	    if (FAILED(StringCchCatEx(wstr_d, cch_wstr, L",", &wstr_d, &cch_wstr,
				      STRSAFE_NO_TRUNCATION))) {
		assert(FALSE);
		continue;
	    }
	}
    }

    len = (ARRAYLENGTH(wstr) - cch_wstr) * sizeof(wchar_t);

    if (buf == NULL || *pcb_buf < len) {
	*pcb_buf = len;
	return KHM_ERROR_TOO_LONG;
    }

    StringCbCopy(buf, *pcb_buf, wstr);
    *pcb_buf = len;
    free_HostAddresses(&as);

    return KHM_ERROR_SUCCESS;
}
void
free_KrbCredInfo(KrbCredInfo *data)
{
free_EncryptionKey(&(data)->key);
if((data)->prealm) {
free_Realm((data)->prealm);
free((data)->prealm);
(data)->prealm = NULL;
}
if((data)->pname) {
free_PrincipalName((data)->pname);
free((data)->pname);
(data)->pname = NULL;
}
if((data)->flags) {
free_TicketFlags((data)->flags);
free((data)->flags);
(data)->flags = NULL;
}
if((data)->authtime) {
free_KerberosTime((data)->authtime);
free((data)->authtime);
(data)->authtime = NULL;
}
if((data)->starttime) {
free_KerberosTime((data)->starttime);
free((data)->starttime);
(data)->starttime = NULL;
}
if((data)->endtime) {
free_KerberosTime((data)->endtime);
free((data)->endtime);
(data)->endtime = NULL;
}
if((data)->renew_till) {
free_KerberosTime((data)->renew_till);
free((data)->renew_till);
(data)->renew_till = NULL;
}
if((data)->srealm) {
free_Realm((data)->srealm);
free((data)->srealm);
(data)->srealm = NULL;
}
if((data)->sname) {
free_PrincipalName((data)->sname);
free((data)->sname);
(data)->sname = NULL;
}
if((data)->caddr) {
free_HostAddresses((data)->caddr);
free((data)->caddr);
(data)->caddr = NULL;
}
}
Beispiel #3
0
static krb5_error_code
set_address (krb5_context context,
	     krb5_kdc_configuration *config,
	     EncTicketPart *et,
	     struct sockaddr *addr,
	     const char *from)
{
    krb5_error_code ret;
    krb5_address *v4_addr;

    v4_addr = malloc (sizeof(*v4_addr));
    if (v4_addr == NULL)
	return ENOMEM;

    ret = krb5_sockaddr2address(context, addr, v4_addr);
    if(ret) {
	free (v4_addr);
	kdc_log(context, config, 0, "Failed to convert address (%s)", from);
	return ret;
    }
	
    if (et->caddr && !krb5_address_search (context, v4_addr, et->caddr)) {
	kdc_log(context, config, 0, "Incorrect network address (%s)", from);
	krb5_free_address(context, v4_addr);
	free (v4_addr);
	return KRB5KRB_AP_ERR_BADADDR;
    }
    if(v4_addr->addr_type == KRB5_ADDRESS_INET) {
	/* we need to collapse the addresses in the ticket to a
	   single address; best guess is to use the address the
	   connection came from */
	
	if (et->caddr != NULL) {
	    free_HostAddresses(et->caddr);
	} else {
	    et->caddr = malloc (sizeof (*et->caddr));
	    if (et->caddr == NULL) {
		krb5_free_address(context, v4_addr);
		free(v4_addr);
		return ENOMEM;
	    }
	}
	et->caddr->val = v4_addr;
	et->caddr->len = 1;
    } else {
	krb5_free_address(context, v4_addr);
	free(v4_addr);
    }
    return 0;
}