s3-rpc_client: Move client pipe functions to own header.
[vlendec/samba-autobuild/.git] / source3 / utils / netlookup.c
index 33b6c4bb257f3cde765b33ac786e7961befc74a6..b160ee5586380ac4ba51102932c8bebdfc5cde3c 100644 (file)
@@ -7,7 +7,7 @@
 
    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
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "utils/net.h"
+#include "rpc_client/cli_pipe.h"
+#include "../librpc/gen_ndr/ndr_lsa.h"
+#include "rpc_client/cli_lsarpc.h"
 
 /********************************************************
  Connection cachine struct. Goes away when ctx destroyed.
 ********************************************************/
 
 struct con_struct {
-       BOOL failed_connect;
+       bool failed_connect;
        NTSTATUS err;
        struct cli_state *cli;
        struct rpc_pipe_client *lsapipe;
-       POLICY_HND pol;
+       struct policy_handle pol;
 };
 
 static struct con_struct *cs;
@@ -54,13 +56,19 @@ static int cs_destructor(struct con_struct *p)
  Create the connection to localhost.
 ********************************************************/
 
-static struct con_struct *create_cs(TALLOC_CTX *ctx, NTSTATUS *perr)
+static struct con_struct *create_cs(struct net_context *c,
+                                   TALLOC_CTX *ctx, NTSTATUS *perr)
 {
        NTSTATUS nt_status;
-       struct in_addr loopback_ip = *interpret_addr2("127.0.0.1");
+       struct sockaddr_storage loopback_ss;
 
        *perr = NT_STATUS_OK;
 
+       if (!interpret_string_addr(&loopback_ss, "127.0.0.1", AI_NUMERICHOST)) {
+               *perr = NT_STATUS_INVALID_PARAMETER;
+               return NULL;
+       }
+
        if (cs) {
                if (cs->failed_connect) {
                        *perr = cs->err;
@@ -90,48 +98,47 @@ static struct con_struct *create_cs(TALLOC_CTX *ctx, NTSTATUS *perr)
 #endif
 
        nt_status = cli_full_connection(&cs->cli, global_myname(), global_myname(),
-                                       &loopback_ip, 0,
+                                       &loopback_ss, 0,
                                        "IPC$", "IPC",
 #if 0
-                                       opt_user_name,
-                                       opt_workgroup,
-                                       opt_password,
+                                       c->opt_user_name,
+                                       c->opt_workgroup,
+                                       c->opt_password,
 #else
                                        "",
-                                       opt_workgroup,
+                                       c->opt_workgroup,
                                        "",
 #endif
                                        0,
-                                       Undefined,
-                                       NULL);
+                                       Undefined);
 
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(2,("create_cs: Connect failed. Error was %s\n", nt_errstr(nt_status)));
-               cs->failed_connect = True;
+               cs->failed_connect = true;
                cs->err = nt_status;
                *perr = nt_status;
                return NULL;
        }
 
-       cs->lsapipe = cli_rpc_pipe_open_noauth(cs->cli,
-                                       PI_LSARPC,
-                                       &nt_status);
+       nt_status = cli_rpc_pipe_open_noauth(cs->cli,
+                                       &ndr_table_lsarpc.syntax_id,
+                                       &cs->lsapipe);
 
-       if (cs->lsapipe == NULL) {
+       if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(2,("create_cs: open LSA pipe failed. Error was %s\n", nt_errstr(nt_status)));
-               cs->failed_connect = True;
+               cs->failed_connect = true;
                cs->err = nt_status;
                *perr = nt_status;
                return NULL;
        }
 
-       nt_status = rpccli_lsa_open_policy(cs->lsapipe, ctx, True,
-                               SEC_RIGHTS_MAXIMUM_ALLOWED,
+       nt_status = rpccli_lsa_open_policy(cs->lsapipe, ctx, true,
+                               SEC_FLAG_MAXIMUM_ALLOWED,
                                &cs->pol);
 
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(2,("create_cs: rpccli_lsa_open_policy failed. Error was %s\n", nt_errstr(nt_status)));
-               cs->failed_connect = True;
+               cs->failed_connect = true;
                cs->err = nt_status;
                *perr = nt_status;
                return NULL;
@@ -148,8 +155,9 @@ static struct con_struct *create_cs(TALLOC_CTX *ctx, NTSTATUS *perr)
  The local smbd will also ask winbindd for us, so we don't have to.
 ********************************************************/
 
-NTSTATUS net_lookup_name_from_sid(TALLOC_CTX *ctx,
-                               DOM_SID *psid,
+NTSTATUS net_lookup_name_from_sid(struct net_context *c,
+                               TALLOC_CTX *ctx,
+                               struct dom_sid *psid,
                                const char **ppdomain,
                                const char **ppname)
 {
@@ -162,7 +170,7 @@ NTSTATUS net_lookup_name_from_sid(TALLOC_CTX *ctx,
        *ppdomain = NULL;
        *ppname = NULL;
 
-       csp = create_cs(ctx, &nt_status);
+       csp = create_cs(c, ctx, &nt_status);
        if (csp == NULL) {
                return nt_status;
        }
@@ -190,14 +198,15 @@ NTSTATUS net_lookup_name_from_sid(TALLOC_CTX *ctx,
  Do a lookup_names call to localhost.
 ********************************************************/
 
-NTSTATUS net_lookup_sid_from_name(TALLOC_CTX *ctx, const char *full_name, DOM_SID *pret_sid)
+NTSTATUS net_lookup_sid_from_name(struct net_context *c, TALLOC_CTX *ctx,
+                                 const char *full_name, struct dom_sid *pret_sid)
 {
        NTSTATUS nt_status;
        struct con_struct *csp = NULL;
-       DOM_SID *sids = NULL;
+       struct dom_sid *sids = NULL;
        enum lsa_SidType *types = NULL;
 
-       csp = create_cs(ctx, &nt_status);
+       csp = create_cs(c, ctx, &nt_status);
        if (csp == NULL) {
                return nt_status;
        }
@@ -206,8 +215,8 @@ NTSTATUS net_lookup_sid_from_name(TALLOC_CTX *ctx, const char *full_name, DOM_SI
                                                &csp->pol,
                                                1,
                                                &full_name,
-                                               NULL, &sids,
-                                               &types);
+                                               NULL, 1,
+                                               &sids, &types);
 
        if (!NT_STATUS_IS_OK(nt_status)) {
                return nt_status;