int cli_credentials_update_keytab(struct cli_credentials *cred) 
{
	krb5_error_code ret;
	struct keytab_container *ktc;
	struct smb_krb5_context *smb_krb5_context;
	TALLOC_CTX *mem_ctx;
	
	mem_ctx = talloc_new(cred);
	if (!mem_ctx) {
		return ENOMEM;
	}

	ret = cli_credentials_get_krb5_context(cred, &smb_krb5_context);
	if (ret) {
		talloc_free(mem_ctx);
		return ret;
	}

	ret = cli_credentials_get_keytab(cred, &ktc);
	if (ret != 0) {
		talloc_free(mem_ctx);
		return ret;
	}

	ret = smb_krb5_update_keytab(mem_ctx, cred, smb_krb5_context, ktc);

	talloc_free(mem_ctx);
	return ret;
}
Exemple #2
0
krb5_error_code smb_krb5_create_memory_keytab(TALLOC_CTX *parent_ctx,
        krb5_context context,
        const char *new_secret,
        const char *samAccountName,
        const char *realm,
        int kvno,
        krb5_keytab *keytab,
        const char **keytab_name)
{
    krb5_error_code ret;
    TALLOC_CTX *mem_ctx = talloc_new(parent_ctx);
    const char *rand_string;
    const char *error_string;
    if (!mem_ctx) {
        return ENOMEM;
    }

    rand_string = generate_random_str(mem_ctx, 16);
    if (!rand_string) {
        talloc_free(mem_ctx);
        return ENOMEM;
    }

    *keytab_name = talloc_asprintf(mem_ctx, "MEMORY:%s", rand_string);
    if (*keytab_name == NULL) {
        talloc_free(mem_ctx);
        return ENOMEM;
    }


    ret = smb_krb5_update_keytab(mem_ctx, context,
                                 *keytab_name, samAccountName, realm,
                                 NULL, 0, NULL, new_secret, NULL,
                                 kvno, ENC_ALL_TYPES,
                                 false, keytab, &error_string);
    if (ret == 0) {
        talloc_steal(parent_ctx, *keytab_name);
    } else {
        DEBUG(0, ("Failed to create in-memory keytab: %s\n",
                  error_string));
        *keytab_name = NULL;
    }
    talloc_free(mem_ctx);
    return ret;
}
_PUBLIC_ int smb_krb5_create_memory_keytab(TALLOC_CTX *parent_ctx,
					   struct cli_credentials *machine_account,
					   struct smb_krb5_context *smb_krb5_context,
					   const char **enctype_strings,
					   struct keytab_container **keytab_container) 
{
	krb5_error_code ret;
	TALLOC_CTX *mem_ctx = talloc_new(parent_ctx);
	const char *rand_string;
	const char *keytab_name;
	if (!mem_ctx) {
		return ENOMEM;
	}
	
	*keytab_container = talloc(mem_ctx, struct keytab_container);

	rand_string = generate_random_str(mem_ctx, 16);
	if (!rand_string) {
		talloc_free(mem_ctx);
		return ENOMEM;
	}

	keytab_name = talloc_asprintf(mem_ctx, "MEMORY:%s", 
				      rand_string);
	if (!keytab_name) {
		talloc_free(mem_ctx);
		return ENOMEM;
	}

	ret = smb_krb5_open_keytab(mem_ctx, smb_krb5_context, keytab_name, keytab_container);
	if (ret) {
		return ret;
	}

	ret = smb_krb5_update_keytab(mem_ctx, machine_account, smb_krb5_context, enctype_strings, *keytab_container);
	if (ret == 0) {
		talloc_steal(parent_ctx, *keytab_container);
	} else {
		*keytab_container = NULL;
	}
	talloc_free(mem_ctx);
	return ret;
}