示例#1
0
OM_uint32
_netlogon_delete_sec_context(OM_uint32 * minor_status,
                             gss_ctx_id_t * context_handle,
                             gss_buffer_t output_token)
{
    if (context_handle != NULL && *context_handle != GSS_C_NO_CONTEXT) {
        gssnetlogon_ctx ctx = (gssnetlogon_ctx)*context_handle;

        *context_handle = GSS_C_NO_CONTEXT;

        _netlogon_release_name(minor_status, (gss_name_t *)&ctx->SourceName);
        _netlogon_release_name(minor_status, (gss_name_t *)&ctx->TargetName);
        HEIMDAL_MUTEX_destroy(&ctx->Mutex);
        memset(ctx, 0, sizeof(*ctx));
        free(ctx);
    }

    if (output_token != GSS_C_NO_BUFFER) {
        output_token->length = 0;
        output_token->value  = NULL;
    }

    *minor_status = 0;
    return GSS_S_COMPLETE;
}
示例#2
0
OM_uint32 _netlogon_import_name
           (OM_uint32 * minor_status,
            const gss_buffer_t input_name_buffer,
            const gss_OID input_name_type,
            gss_name_t * output_name
           )
{
    gssnetlogon_name name;
    const char *netbiosName;
    const char *dnsName = NULL;
    size_t len, i;

    if (!gss_oid_equal(input_name_type, GSS_NETLOGON_NT_NETBIOS_DNS_NAME)) {
        return GSS_S_BAD_NAME;
    }

    /* encoding is NetBIOS name \0 DNS name \0 */

    netbiosName = input_name_buffer->value;
    len = strlen(netbiosName);
    if (len < input_name_buffer->length)
        dnsName = netbiosName + len + 1;

    name = (gssnetlogon_name)calloc(1, sizeof(*name));
    if (name == NULL)
        goto cleanup;

    name->NetbiosName.value = malloc(len + 1);
    if (name->NetbiosName.value == NULL)
        goto cleanup;
    memcpy(name->NetbiosName.value, netbiosName, len + 1);
    name->NetbiosName.length = len;

    /* normalise name to uppercase XXX UTF-8 OK? */
    for (i = 0; i < len; i++) {
        ((char *)name->NetbiosName.value)[i] =
            toupper(((char *)name->NetbiosName.value)[i]);
    }

    if (dnsName != NULL && dnsName[0] != '\0') {
        name->DnsName.value = strdup(dnsName);
        if (name->DnsName.value == NULL)
            goto cleanup;
        name->DnsName.length = strlen(dnsName);
    }

    *output_name = (gss_name_t)name;
    *minor_status = 0;
    return GSS_S_COMPLETE;

cleanup:
    _netlogon_release_name(minor_status, (gss_name_t *)&name);
    *minor_status = ENOMEM;
    return GSS_S_FAILURE;
}
示例#3
0
OM_uint32 _netlogon_release_cred
           (OM_uint32 * minor_status,
            gss_cred_id_t * cred_handle
           )
{
    gssnetlogon_cred cred = (gssnetlogon_cred)*cred_handle;

    if (cred != NULL) {
        _netlogon_release_name(minor_status, (gss_name_t *)&cred->Name);
        memset(cred, 0, sizeof(*cred));
        free(cred);
        *cred_handle = GSS_C_NO_CREDENTIAL;
    }

    return GSS_S_COMPLETE;
}
示例#4
0
OM_uint32 _netlogon_duplicate_name (
            OM_uint32 * minor_status,
            gss_const_name_t src_name,
            gss_name_t * dest_name
           )
{
    const gssnetlogon_name src = (const gssnetlogon_name)src_name;
    gssnetlogon_name dst = NULL;

    dst = calloc(1, sizeof(*dst));
    if (dst == NULL)
        goto fail;

    dst->NetbiosName.value = malloc(src->NetbiosName.length + 1);
    if (dst->NetbiosName.value == NULL)
        goto fail;
    memcpy(dst->NetbiosName.value, src->NetbiosName.value,
           src->NetbiosName.length);
    dst->NetbiosName.length = src->NetbiosName.length;
    ((char *)dst->NetbiosName.value)[dst->NetbiosName.length] = '\0';

    if (src->DnsName.length != 0) {
        dst->DnsName.value = malloc(src->DnsName.length + 1);
        if (dst->DnsName.value == NULL)
            goto fail;
        memcpy(dst->DnsName.value, src->DnsName.value, src->DnsName.length);
        dst->DnsName.length = src->DnsName.length;
        ((char *)dst->DnsName.value)[dst->DnsName.length] = '\0';
    }

    *minor_status = 0;
    *dest_name = (gss_name_t)dst;
    return GSS_S_COMPLETE;

fail:
    _netlogon_release_name(minor_status, (gss_name_t *)&dst);
    *minor_status = ENOMEM;
    return GSS_S_FAILURE;
}