s3-netapi: allow to use default krb5 credential cache for libnetapi users.
authorGünther Deschner <gd@samba.org>
Wed, 21 Sep 2011 15:28:02 +0000 (17:28 +0200)
committerGünther Deschner <gd@samba.org>
Wed, 21 Sep 2011 15:39:08 +0000 (17:39 +0200)
Guenther

source3/lib/netapi/netapi.c
source3/lib/netapi/netapi.h

index a4a8e447c18d294c9f200cd1d8f1d84b9c38da73..9ed13fcc71c528136c58fc4a083ee9756e618959 100644 (file)
@@ -106,8 +106,6 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context)
 {
        NET_API_STATUS status;
        struct libnetapi_ctx *ctx = NULL;
-       char *krb5_cc_env = NULL;
-
        TALLOC_CTX *frame = talloc_stackframe();
 
        ctx = talloc_zero(frame, struct libnetapi_ctx);
@@ -118,12 +116,6 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context)
 
        BlockSignals(True, SIGPIPE);
 
-       krb5_cc_env = getenv(KRB5_ENV_CCNAME);
-       if (!krb5_cc_env || (strlen(krb5_cc_env) == 0)) {
-               ctx->krb5_cc_env = talloc_strdup(ctx, "MEMORY:libnetapi");
-               setenv(KRB5_ENV_CCNAME, ctx->krb5_cc_env, 1);
-       }
-
        if (getenv("USER")) {
                ctx->username = talloc_strdup(ctx, getenv("USER"));
        } else {
@@ -276,12 +268,29 @@ NET_API_STATUS libnetapi_set_use_kerberos(struct libnetapi_ctx *ctx)
        return NET_API_STATUS_SUCCESS;
 }
 
+/****************************************************************
+****************************************************************/
+
 NET_API_STATUS libnetapi_set_use_ccache(struct libnetapi_ctx *ctx)
 {
        ctx->use_ccache = true;
        return NET_API_STATUS_SUCCESS;
 }
 
+/****************************************************************
+****************************************************************/
+
+NET_API_STATUS libnetapi_set_use_memory_krb5_ccache(struct libnetapi_ctx *ctx)
+{
+       ctx->krb5_cc_env = talloc_strdup(ctx, "MEMORY:libnetapi");
+       if (!ctx->krb5_cc_env) {
+               return W_ERROR_V(WERR_NOMEM);
+       }
+       setenv(KRB5_ENV_CCNAME, ctx->krb5_cc_env, 1);
+       ctx->use_memory_krb5_ccache = 1;
+       return NET_API_STATUS_SUCCESS;
+}
+
 /****************************************************************
 Return a libnetapi error as a string, caller must free with NetApiBufferFree
 ****************************************************************/
index 620d8cf5910f7281cb960a461c506b740d379be5..2a523214155aa62b8dc47adb94735ae8c41c301c 100644 (file)
@@ -1356,6 +1356,7 @@ struct libnetapi_ctx {
        char *krb5_cc_env;
        int use_kerberos;
        int use_ccache;
+       int use_memory_krb5_ccache;
        int disable_policy_handle_cache;
 
        void *private_data;
@@ -1410,6 +1411,11 @@ NET_API_STATUS libnetapi_set_use_kerberos(struct libnetapi_ctx *ctx);
 
 NET_API_STATUS libnetapi_set_use_ccache(struct libnetapi_ctx *ctx);
 
+/****************************************************************
+****************************************************************/
+
+NET_API_STATUS libnetapi_set_use_memory_krb5_ccache(struct libnetapi_ctx *ctx);
+
 /****************************************************************
 Return a specific libnetapi error as a string, caller must free with NetApiBufferFree
 ****************************************************************/