Fix some type-punned warnings
[ira/wip.git] / source3 / winbindd / winbindd_cm.c
index 35768fe7f2492c21fcd28be01b88fb818d6c8650..396a30377fc7a1a37e6d36659516f869dbb67ae1 100644 (file)
@@ -60,6 +60,7 @@
 
 #include "includes.h"
 #include "winbindd.h"
+#include "../libcli/auth/libcli_auth.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
@@ -768,7 +769,8 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
        struct sockaddr peeraddr;
        socklen_t peeraddr_len;
 
-       struct sockaddr_in *peeraddr_in = (struct sockaddr_in *)&peeraddr;
+       struct sockaddr_in *peeraddr_in =
+               (struct sockaddr_in *)(void *)&peeraddr;
 
        DEBUG(10,("cm_prepare_connection: connecting to DC %s for domain %s\n",
                controller, domain->name ));
@@ -821,8 +823,6 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
                }
        }
 
-       cli_setup_signing_state(*cli, Undefined);
-
        result = cli_negprot(*cli);
 
        if (!NT_STATUS_IS_OK(result)) {
@@ -868,7 +868,10 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
                        result = ads_ntstatus(ads_status);
                        if (NT_STATUS_IS_OK(result)) {
                                /* Ensure creds are stored for NTLMSSP authenticated pipe access. */
-                               cli_init_creds(*cli, machine_account, lp_workgroup(), machine_password);
+                               result = cli_init_creds(*cli, machine_account, lp_workgroup(), machine_password);
+                               if (!NT_STATUS_IS_OK(result)) {
+                                       goto done;
+                               }
                                goto session_setup_done;
                        }
                }
@@ -893,7 +896,10 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
                result = ads_ntstatus(ads_status);
                if (NT_STATUS_IS_OK(result)) {
                        /* Ensure creds are stored for NTLMSSP authenticated pipe access. */
-                       cli_init_creds(*cli, machine_account, lp_workgroup(), machine_password);
+                       result = cli_init_creds(*cli, machine_account, lp_workgroup(), machine_password);
+                       if (!NT_STATUS_IS_OK(result)) {
+                               goto done;
+                       }
                        goto session_setup_done;
                }
        }
@@ -919,7 +925,10 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
                                            ipc_password, strlen(ipc_password)+1,
                                            ipc_domain))) {
                        /* Successful logon with given username. */
-                       cli_init_creds(*cli, ipc_username, ipc_domain, ipc_password);
+                       result = cli_init_creds(*cli, ipc_username, ipc_domain, ipc_password);
+                       if (!NT_STATUS_IS_OK(result)) {
+                               goto done;
+                       }
                        goto session_setup_done;
                } else {
                        DEBUG(4, ("authenticated session setup with user %s\\%s failed.\n",
@@ -937,7 +946,10 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
        if (NT_STATUS_IS_OK(cli_session_setup(*cli, "", NULL, 0,
                                              NULL, 0, ""))) {
                DEBUG(5, ("Connected anonymously\n"));
-               cli_init_creds(*cli, "", "", "");
+               result = cli_init_creds(*cli, "", "", "");
+               if (!NT_STATUS_IS_OK(result)) {
+                       goto done;
+               }
                goto session_setup_done;
        }
 
@@ -972,8 +984,11 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
        *retry = False;
 
        /* set the domain if empty; needed for schannel connections */
-       if ( !*(*cli)->domain ) {
-               fstrcpy( (*cli)->domain, domain->name );
+       if ( !(*cli)->domain[0] ) {
+               result = cli_set_domain((*cli), domain->name);
+               if (!NT_STATUS_IS_OK(result)) {
+                       return result;
+               }
        }
 
        result = NT_STATUS_OK;
@@ -1026,7 +1041,9 @@ static bool add_one_dc_unique(TALLOC_CTX *mem_ctx, const char *domain_name,
 
        /* Make sure there's no duplicates in the list */
        for (i=0; i<*num; i++)
-               if (sockaddr_equal((struct sockaddr *)&(*dcs)[i].ss, (struct sockaddr *)pss))
+               if (sockaddr_equal(
+                           (struct sockaddr *)(void *)&(*dcs)[i].ss,
+                           (struct sockaddr *)(void *)pss))
                        return False;
 
        *dcs = TALLOC_REALLOC_ARRAY(mem_ctx, *dcs, struct dc_name_ip, (*num)+1);
@@ -1759,8 +1776,8 @@ static void set_dc_type_and_flags_connect( struct winbindd_domain *domain )
        NTSTATUS                result;
        WERROR werr;
        TALLOC_CTX              *mem_ctx = NULL;
-       struct rpc_pipe_client  *cli;
-       POLICY_HND pol;
+       struct rpc_pipe_client  *cli = NULL;
+       struct policy_handle pol;
        union dssetup_DsRoleInfo info;
        union lsa_PolicyInformation *lsa_info = NULL;
 
@@ -1838,7 +1855,7 @@ no_dssetup:
        }
 
        result = rpccli_lsa_open_policy2(cli, mem_ctx, True, 
-                                        SEC_RIGHTS_MAXIMUM_ALLOWED, &pol);
+                                        SEC_FLAG_MAXIMUM_ALLOWED, &pol);
 
        if (NT_STATUS_IS_OK(result)) {
                /* This particular query is exactly what Win2k clients use 
@@ -1880,7 +1897,7 @@ no_dssetup:
                domain->active_directory = False;
 
                result = rpccli_lsa_open_policy(cli, mem_ctx, True, 
-                                               SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                               SEC_FLAG_MAXIMUM_ALLOWED,
                                                &pol);
 
                if (!NT_STATUS_IS_OK(result)) {
@@ -1950,8 +1967,8 @@ static void set_dc_type_and_flags( struct winbindd_domain *domain )
 /**********************************************************************
 ***********************************************************************/
 
-static bool cm_get_schannel_dcinfo(struct winbindd_domain *domain,
-                                  struct dcinfo **ppdc)
+static bool cm_get_schannel_creds(struct winbindd_domain *domain,
+                                  struct netlogon_creds_CredentialState **ppdc)
 {
        NTSTATUS result;
        struct rpc_pipe_client *netlogon_pipe;
@@ -1965,7 +1982,7 @@ static bool cm_get_schannel_dcinfo(struct winbindd_domain *domain,
                return False;
        }
 
-       /* Return a pointer to the struct dcinfo from the
+       /* Return a pointer to the struct netlogon_creds_CredentialState from the
           netlogon pipe. */
 
        if (!domain->conn.netlogon_pipe->dc) {
@@ -1977,12 +1994,11 @@ static bool cm_get_schannel_dcinfo(struct winbindd_domain *domain,
 }
 
 NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
-                       struct rpc_pipe_client **cli, POLICY_HND *sam_handle)
+                       struct rpc_pipe_client **cli, struct policy_handle *sam_handle)
 {
        struct winbindd_cm_conn *conn;
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-       fstring conn_pwd;
-       struct dcinfo *p_dcinfo;
+       struct netlogon_creds_CredentialState *p_creds;
        char *machine_password = NULL;
        char *machine_account = NULL;
        char *domain_name = NULL;
@@ -2006,10 +2022,9 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
         * anonymous.
         */
 
-       pwd_get_cleartext(&conn->cli->pwd, conn_pwd);
        if ((conn->cli->user_name[0] == '\0') ||
            (conn->cli->domain[0] == '\0') || 
-           (conn_pwd[0] == '\0'))
+           (conn->cli->password == NULL || conn->cli->password[0] == '\0'))
        {
                result = get_trust_creds(domain, &machine_password,
                                         &machine_account, NULL);
@@ -2020,7 +2035,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
                }
                domain_name = domain->name;
        } else {
-               machine_password = SMB_STRDUP(conn_pwd);                
+               machine_password = SMB_STRDUP(conn->cli->password);
                machine_account = SMB_STRDUP(conn->cli->user_name);
                domain_name = conn->cli->domain;
        }
@@ -2056,7 +2071,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
 
        result = rpccli_samr_Connect2(conn->samr_pipe, mem_ctx,
                                      conn->samr_pipe->desthost,
-                                     SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                     SEC_FLAG_MAXIMUM_ALLOWED,
                                      &conn->sam_connect_handle);
        if (NT_STATUS_IS_OK(result)) {
                goto open_domain;
@@ -2070,7 +2085,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
 
        /* Fall back to schannel if it's a W2K pre-SP1 box. */
 
-       if (!cm_get_schannel_dcinfo(domain, &p_dcinfo)) {
+       if (!cm_get_schannel_creds(domain, &p_creds)) {
                /* If this call fails - conn->cli can now be NULL ! */
                DEBUG(10, ("cm_connect_sam: Could not get schannel auth info "
                           "for domain %s, trying anon\n", domain->name));
@@ -2078,7 +2093,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
        }
        result = cli_rpc_pipe_open_schannel_with_key
                (conn->cli, &ndr_table_samr.syntax_id, PIPE_AUTH_LEVEL_PRIVACY,
-                domain->name, p_dcinfo, &conn->samr_pipe);
+                domain->name, &p_creds, &conn->samr_pipe);
 
        if (!NT_STATUS_IS_OK(result)) {
                DEBUG(10,("cm_connect_sam: failed to connect to SAMR pipe for "
@@ -2091,7 +2106,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
 
        result = rpccli_samr_Connect2(conn->samr_pipe, mem_ctx,
                                      conn->samr_pipe->desthost,
-                                     SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                     SEC_FLAG_MAXIMUM_ALLOWED,
                                      &conn->sam_connect_handle);
        if (NT_STATUS_IS_OK(result)) {
                goto open_domain;
@@ -2113,7 +2128,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
 
        result = rpccli_samr_Connect2(conn->samr_pipe, mem_ctx,
                                      conn->samr_pipe->desthost,
-                                     SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                     SEC_FLAG_MAXIMUM_ALLOWED,
                                      &conn->sam_connect_handle);
        if (!NT_STATUS_IS_OK(result)) {
                DEBUG(10,("cm_connect_sam: rpccli_samr_Connect2 failed "
@@ -2126,7 +2141,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
        result = rpccli_samr_OpenDomain(conn->samr_pipe,
                                        mem_ctx,
                                        &conn->sam_connect_handle,
-                                       SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                       SEC_FLAG_MAXIMUM_ALLOWED,
                                        &domain->sid,
                                        &conn->sam_domain_handle);
 
@@ -2145,12 +2160,11 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
 }
 
 NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
-                       struct rpc_pipe_client **cli, POLICY_HND *lsa_policy)
+                       struct rpc_pipe_client **cli, struct policy_handle *lsa_policy)
 {
        struct winbindd_cm_conn *conn;
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-       fstring conn_pwd;
-       struct dcinfo *p_dcinfo;
+       struct netlogon_creds_CredentialState *p_creds;
 
        result = init_dc_connection(domain);
        if (!NT_STATUS_IS_OK(result))
@@ -2162,10 +2176,9 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       pwd_get_cleartext(&conn->cli->pwd, conn_pwd);
        if ((conn->cli->user_name[0] == '\0') ||
            (conn->cli->domain[0] == '\0') || 
-           (conn_pwd[0] == '\0')) {
+           (conn->cli->password == NULL || conn->cli->password[0] == '\0')) {
                DEBUG(10, ("cm_connect_lsa: No no user available for "
                           "domain %s, trying schannel\n", conn->cli->domain));
                goto schannel;
@@ -2176,7 +2189,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
        result = cli_rpc_pipe_open_spnego_ntlmssp
                (conn->cli, &ndr_table_lsarpc.syntax_id,
                 PIPE_AUTH_LEVEL_PRIVACY,
-                conn->cli->domain, conn->cli->user_name, conn_pwd,
+                conn->cli->domain, conn->cli->user_name, conn->cli->password,
                 &conn->lsa_pipe);
 
        if (!NT_STATUS_IS_OK(result)) {
@@ -2193,7 +2206,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
                  domain->name, conn->cli->domain, conn->cli->user_name ));
 
        result = rpccli_lsa_open_policy(conn->lsa_pipe, mem_ctx, True,
-                                       SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                       SEC_FLAG_MAXIMUM_ALLOWED,
                                        &conn->lsa_policy);
        if (NT_STATUS_IS_OK(result)) {
                goto done;
@@ -2208,7 +2221,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
 
        /* Fall back to schannel if it's a W2K pre-SP1 box. */
 
-       if (!cm_get_schannel_dcinfo(domain, &p_dcinfo)) {
+       if (!cm_get_schannel_creds(domain, &p_creds)) {
                /* If this call fails - conn->cli can now be NULL ! */
                DEBUG(10, ("cm_connect_lsa: Could not get schannel auth info "
                           "for domain %s, trying anon\n", domain->name));
@@ -2217,7 +2230,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
        result = cli_rpc_pipe_open_schannel_with_key
                (conn->cli, &ndr_table_lsarpc.syntax_id,
                 PIPE_AUTH_LEVEL_PRIVACY,
-                domain->name, p_dcinfo, &conn->lsa_pipe);
+                domain->name, &p_creds, &conn->lsa_pipe);
 
        if (!NT_STATUS_IS_OK(result)) {
                DEBUG(10,("cm_connect_lsa: failed to connect to LSA pipe for "
@@ -2229,7 +2242,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
                  "schannel.\n", domain->name ));
 
        result = rpccli_lsa_open_policy(conn->lsa_pipe, mem_ctx, True,
-                                       SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                       SEC_FLAG_MAXIMUM_ALLOWED,
                                        &conn->lsa_policy);
        if (NT_STATUS_IS_OK(result)) {
                goto done;
@@ -2251,7 +2264,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
        }
 
        result = rpccli_lsa_open_policy(conn->lsa_pipe, mem_ctx, True,
-                                       SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                       SEC_FLAG_MAXIMUM_ALLOWED,
                                        &conn->lsa_policy);
  done:
        if (!NT_STATUS_IS_OK(result)) {
@@ -2363,7 +2376,7 @@ NTSTATUS cm_connect_netlogon(struct winbindd_domain *domain,
 
        result = cli_rpc_pipe_open_schannel_with_key(
                conn->cli, &ndr_table_netlogon.syntax_id,
-               PIPE_AUTH_LEVEL_PRIVACY, domain->name, netlogon_pipe->dc,
+               PIPE_AUTH_LEVEL_PRIVACY, domain->name, &netlogon_pipe->dc,
                &conn->netlogon_pipe);
 
        /* We can now close the initial netlogon pipe. */