s3-auth use auth_user_info not netr_SamInfo3 in auth3_session_info
[ira/wip.git] / source3 / rpc_server / rpc_ncacn_np.c
index 4446578e3f99f945442179a060f371439a7f99c3..25435b8ea4170d38fd2bb6c0801acc8c1920ce38 100644 (file)
@@ -5,6 +5,7 @@
  *  Largely re-written : 2005
  *  Copyright (C) Jeremy Allison               1998 - 2005
  *  Copyright (C) Simo Sorce                   2010
+ *  Copyright (C) Andrew Bartlett              2011
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -103,11 +104,11 @@ int close_internal_rpc_pipe_hnd(struct pipes_struct *p)
 
        TALLOC_FREE(p->auth.auth_ctx);
 
-       free_pipe_rpc_context_internal( p->contexts );
-
        /* Free the handles database. */
        close_policy_by_pipe(p);
 
+       free_pipe_rpc_context_internal( p->contexts );
+
        DLIST_REMOVE(InternalPipes, p);
 
        ZERO_STRUCTP(p);
@@ -121,8 +122,8 @@ int close_internal_rpc_pipe_hnd(struct pipes_struct *p)
 
 struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx,
                                              const struct ndr_syntax_id *syntax,
-                                             struct client_address *client_id,
-                                             const struct auth_serversupplied_info *session_info,
+                                             const struct tsocket_address *remote_address,
+                                             const struct auth3_session_info *session_info,
                                              struct messaging_context *msg_ctx)
 {
        struct pipes_struct *p;
@@ -131,7 +132,7 @@ struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx,
        DEBUG(4,("Create pipe requested %s\n",
                 get_pipe_name_from_syntax(talloc_tos(), syntax)));
 
-       p = TALLOC_ZERO_P(mem_ctx, struct pipes_struct);
+       p = talloc_zero(mem_ctx, struct pipes_struct);
 
        if (!p) {
                DEBUG(0,("ERROR! no memory for pipes_struct!\n"));
@@ -153,7 +154,7 @@ struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       p->session_info = copy_serverinfo(p, session_info);
+       p->session_info = copy_session_info(p, session_info);
        if (p->session_info == NULL) {
                DEBUG(0, ("open_rpc_pipe_p: copy_serverinfo failed\n"));
                close_policy_by_pipe(p);
@@ -165,7 +166,10 @@ struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx,
 
        DLIST_ADD(InternalPipes, p);
 
-       p->client_id = client_id;
+       p->remote_address = tsocket_address_copy(remote_address, p);
+       if (p->remote_address == NULL) {
+               return false;
+       }
 
        p->endian = RPC_LITTLE_ENDIAN;
 
@@ -451,8 +455,8 @@ static const struct dcerpc_binding_handle_ops rpcint_bh_ops = {
 static NTSTATUS rpcint_binding_handle_ex(TALLOC_CTX *mem_ctx,
                        const struct ndr_syntax_id *abstract_syntax,
                        const struct ndr_interface_table *ndr_table,
-                       struct client_address *client_id,
-                       const struct auth_serversupplied_info *session_info,
+                       const struct tsocket_address *remote_address,
+                       const struct auth3_session_info *session_info,
                        struct messaging_context *msg_ctx,
                        struct dcerpc_binding_handle **binding_handle)
 {
@@ -475,7 +479,7 @@ static NTSTATUS rpcint_binding_handle_ex(TALLOC_CTX *mem_ctx,
        }
        hs->p = make_internal_rpc_pipe_p(hs,
                                         abstract_syntax,
-                                        client_id,
+                                        remote_address,
                                         session_info,
                                         msg_ctx);
        if (hs->p == NULL) {
@@ -493,7 +497,7 @@ static NTSTATUS rpcint_binding_handle_ex(TALLOC_CTX *mem_ctx,
  *
  * @param[in]  ndr_table Normally the ndr_table_<name>.
  *
- * @param[in]  client_id The info about the connected client.
+ * @param[in]  remote_address The info about the connected client.
  *
  * @param[in]  serversupplied_info The server supplied authentication function.
  *
@@ -511,7 +515,7 @@ static NTSTATUS rpcint_binding_handle_ex(TALLOC_CTX *mem_ctx,
  *
  *   status = rpcint_binding_handle(tmp_ctx,
  *                                  &ndr_table_winreg,
- *                                  p->client_id,
+ *                                  p->remote_address,
  *                                  p->session_info,
  *                                  p->msg_ctx
  *                                  &winreg_binding);
@@ -519,12 +523,12 @@ static NTSTATUS rpcint_binding_handle_ex(TALLOC_CTX *mem_ctx,
  */
 NTSTATUS rpcint_binding_handle(TALLOC_CTX *mem_ctx,
                               const struct ndr_interface_table *ndr_table,
-                              struct client_address *client_id,
-                              const struct auth_serversupplied_info *session_info,
+                              const struct tsocket_address *remote_address,
+                              const struct auth3_session_info *session_info,
                               struct messaging_context *msg_ctx,
                               struct dcerpc_binding_handle **binding_handle)
 {
-       return rpcint_binding_handle_ex(mem_ctx, NULL, ndr_table, client_id,
+       return rpcint_binding_handle_ex(mem_ctx, NULL, ndr_table, remote_address,
                                        session_info, msg_ctx, binding_handle);
 }
 
@@ -544,7 +548,7 @@ NTSTATUS rpcint_binding_handle(TALLOC_CTX *mem_ctx,
  *
  * @param[in]  serversupplied_info The server supplied authentication function.
  *
- * @param[in]  client_id The client address information.
+ * @param[in]  remote_address The client address information.
  *
  * @param[in]  msg_ctx  The messaging context to use.
  *
@@ -555,15 +559,15 @@ NTSTATUS rpcint_binding_handle(TALLOC_CTX *mem_ctx,
  */
 static NTSTATUS rpc_pipe_open_internal(TALLOC_CTX *mem_ctx,
                                const struct ndr_syntax_id *abstract_syntax,
-                               const struct auth_serversupplied_info *serversupplied_info,
-                               struct client_address *client_id,
+                               const struct auth3_session_info *session_info,
+                               const struct tsocket_address *remote_address,
                                struct messaging_context *msg_ctx,
                                struct rpc_pipe_client **presult)
 {
        struct rpc_pipe_client *result;
        NTSTATUS status;
 
-       result = TALLOC_ZERO_P(mem_ctx, struct rpc_pipe_client);
+       result = talloc_zero(mem_ctx, struct rpc_pipe_client);
        if (result == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -571,11 +575,21 @@ static NTSTATUS rpc_pipe_open_internal(TALLOC_CTX *mem_ctx,
        result->abstract_syntax = *abstract_syntax;
        result->transfer_syntax = ndr_transfer_syntax;
 
-       if (client_id == NULL) {
-               static struct client_address unknown;
-               strlcpy(unknown.addr, "<UNKNOWN>", sizeof(unknown.addr));
-               unknown.name = "<UNKNOWN>";
-               client_id = &unknown;
+       if (remote_address == NULL) {
+               struct tsocket_address *local;
+               int rc;
+
+               rc = tsocket_address_inet_from_strings(mem_ctx,
+                                                      "ip",
+                                                      "127.0.0.1",
+                                                      0,
+                                                      &local);
+               if (rc < 0) {
+                       TALLOC_FREE(result);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               remote_address = local;
        }
 
        result->max_xmit_frag = -1;
@@ -584,8 +598,8 @@ static NTSTATUS rpc_pipe_open_internal(TALLOC_CTX *mem_ctx,
        status = rpcint_binding_handle_ex(result,
                                          abstract_syntax,
                                          NULL,
-                                         client_id,
-                                         serversupplied_info,
+                                         remote_address,
+                                         session_info,
                                          msg_ctx,
                                          &result->binding_handle);
        if (!NT_STATUS_IS_OK(status)) {
@@ -606,7 +620,7 @@ struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
                                const char *pipe_name,
                                const struct tsocket_address *local_address,
                                const struct tsocket_address *remote_address,
-                               const struct auth_serversupplied_info *session_info)
+                               const struct auth3_session_info *session_info)
 {
        struct np_proxy_state *result;
        char *socket_np_dir;
@@ -615,8 +629,6 @@ struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
        struct tevent_req *subreq;
        struct auth_session_info_transport *session_info_t;
        struct auth_session_info *session_info_npa;
-       struct auth_user_info_dc *user_info_dc;
-       union netr_Validation val;
        NTSTATUS status;
        bool ok;
        int ret;
@@ -668,21 +680,10 @@ struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
        /* Send the named_pipe_auth server the user's full token */
        session_info_npa->security_token = session_info->security_token;
        session_info_npa->session_key = session_info->session_key;
+       session_info_npa->unix_token = session_info->unix_token;
+       session_info_npa->unix_info = session_info->unix_info;
 
-       val.sam3 = session_info->info3;
-
-       /* Convert into something we can build a struct
-        * auth_session_info from.  Most of the work here
-        * will be to convert the SIDS, which we will then ignore, but
-        * this is the easier way to handle it */
-       status = make_user_info_dc_netlogon_validation(talloc_tos(), "", 3, &val, &user_info_dc);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("conversion of info3 into user_info_dc failed!\n"));
-               goto fail;
-       }
-
-       session_info_npa->info = talloc_move(session_info_npa, &user_info_dc->info);
-       talloc_free(user_info_dc);
+       session_info_npa->info = session_info->info;
 
        session_info_t = talloc_zero(talloc_tos(), struct auth_session_info_transport);
        if (session_info_npa == NULL) {
@@ -746,7 +747,7 @@ struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
 static NTSTATUS rpc_pipe_open_external(TALLOC_CTX *mem_ctx,
                                const char *pipe_name,
                                const struct ndr_syntax_id *abstract_syntax,
-                               const struct auth_serversupplied_info *session_info,
+                               const struct auth3_session_info *session_info,
                                struct rpc_pipe_client **_result)
 {
        struct tsocket_address *local, *remote;
@@ -849,7 +850,7 @@ done:
  *
  * @param[in]  serversupplied_info The server supplied authentication function.
  *
- * @param[in]  client_id The client address information.
+ * @param[in]  remote_address The client address information.
  *
  * @param[in]  msg_ctx  The messaging context to use.
  *
@@ -865,15 +866,15 @@ done:
  *   status = rpc_pipe_open_interface(tmp_ctx,
  *                                    &ndr_table_winreg.syntax_id,
  *                                    p->session_info,
- *                                    client_id,
+ *                                    remote_address,
  *                                    &winreg_pipe);
  * @endcode
  */
 
 NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
                                 const struct ndr_syntax_id *syntax,
-                                const struct auth_serversupplied_info *session_info,
-                                struct client_address *client_id,
+                                const struct auth3_session_info *session_info,
+                                const struct tsocket_address *remote_address,
                                 struct messaging_context *msg_ctx,
                                 struct rpc_pipe_client **cli_pipe)
 {
@@ -913,7 +914,7 @@ NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
        if (strcasecmp_m(server_type, "embedded") == 0) {
                status = rpc_pipe_open_internal(tmp_ctx,
                                                syntax, session_info,
-                                               client_id, msg_ctx,
+                                               remote_address, msg_ctx,
                                                &cli);
                if (!NT_STATUS_IS_OK(status)) {
                        goto done;