r23779: Change from v2 or later to v3 or later.
[samba.git] / source3 / rpc_server / srv_lsa.c
index 0818ba3eacf9d391d3f98ce9396ec1dd94b73dd6..157f819a3730e8c1cc147728fefcb26df89e13a6 100644 (file)
@@ -10,7 +10,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,
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
 
+static BOOL proxy_lsa_call(pipes_struct *p, uint8 opnum)
+{
+       struct api_struct *fns;
+       int n_fns;
+
+       lsarpc_get_pipe_fns(&fns, &n_fns);
+
+       if (opnum >= n_fns)
+               return False;
+
+       if (fns[opnum].opnum != opnum) {
+               smb_panic("LSA function table not sorted");
+       }
+
+       return fns[opnum].fn(p);
+}
+
 /***************************************************************************
  api_lsa_open_policy2
  ***************************************************************************/
@@ -218,28 +235,7 @@ static BOOL api_lsa_lookup_names(pipes_struct *p)
 
 static BOOL api_lsa_close(pipes_struct *p)
 {
-       LSA_Q_CLOSE q_u;
-       LSA_R_CLOSE r_u;
-       prs_struct *data = &p->in_data.data;
-       prs_struct *rdata = &p->out_data.rdata;
-
-       ZERO_STRUCT(q_u);
-       ZERO_STRUCT(r_u);
-
-       if (!lsa_io_q_close("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_close: lsa_io_q_close failed.\n"));
-               return False;
-       }
-
-       r_u.status = _lsa_close(p, &q_u, &r_u);
-
-       /* store the response in the SMB stream */
-       if (!lsa_io_r_close("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_close: lsa_io_r_close failed.\n"));
-               return False;
-       }
-
-       return True;
+       return proxy_lsa_call(p, DCERPC_LSA_CLOSE);
 }
 
 /***************************************************************************
@@ -248,28 +244,7 @@ static BOOL api_lsa_close(pipes_struct *p)
 
 static BOOL api_lsa_open_secret(pipes_struct *p)
 {
-       LSA_Q_OPEN_SECRET q_u;
-       LSA_R_OPEN_SECRET r_u;
-       prs_struct *data = &p->in_data.data;
-       prs_struct *rdata = &p->out_data.rdata;
-
-       ZERO_STRUCT(q_u);
-       ZERO_STRUCT(r_u);
-
-       if(!lsa_io_q_open_secret("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_open_secret: failed to unmarshall LSA_Q_OPEN_SECRET.\n"));
-               return False;
-       }
-
-       r_u.status = _lsa_open_secret(p, &q_u, &r_u);
-
-       /* store the response in the SMB stream */
-       if(!lsa_io_r_open_secret("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_open_secret: Failed to marshall LSA_R_OPEN_SECRET.\n"));
-               return False;
-       }
-
-       return True;
+       return proxy_lsa_call(p, DCERPC_LSA_OPENSECRET);
 }
 
 /***************************************************************************
@@ -771,38 +746,40 @@ static BOOL api_lsa_lookup_priv_value(pipes_struct *p)
 
 static BOOL api_lsa_open_trust_dom(pipes_struct *p)
 {
-       LSA_Q_OPEN_TRUSTED_DOMAIN q_u;
-       LSA_R_OPEN_TRUSTED_DOMAIN r_u;
-       
-       prs_struct *data = &p->in_data.data;
-       prs_struct *rdata = &p->out_data.rdata;
+       return proxy_lsa_call(p, DCERPC_LSA_OPENTRUSTEDDOMAIN);
+}
 
-       ZERO_STRUCT(q_u);
-       ZERO_STRUCT(r_u);
+/***************************************************************************
+ ***************************************************************************/
 
-       if(!lsa_io_q_open_trusted_domain("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_open_trust_dom: failed to unmarshall LSA_Q_OPEN_TRUSTED_DOMAIN .\n"));
-               return False;
-       }
+static BOOL api_lsa_create_trust_dom(pipes_struct *p)
+{
+       return proxy_lsa_call(p, DCERPC_LSA_CREATETRUSTEDDOMAIN);
+}
 
-       r_u.status = _lsa_open_trusted_domain(p, &q_u, &r_u);
+/***************************************************************************
+ ***************************************************************************/
 
-       /* store the response in the SMB stream */
-       if(!lsa_io_r_open_trusted_domain("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_open_trust_dom: Failed to marshall LSA_R_OPEN_TRUSTED_DOMAIN.\n"));
-               return False;
-       }
+static BOOL api_lsa_create_secret(pipes_struct *p)
+{
+       return proxy_lsa_call(p, DCERPC_LSA_CREATESECRET);
+}
 
-       return True;
+/***************************************************************************
+ ***************************************************************************/
+
+static BOOL api_lsa_set_secret(pipes_struct *p)
+{
+       return proxy_lsa_call(p, DCERPC_LSA_SETSECRET);
 }
 
 /***************************************************************************
  ***************************************************************************/
 
-static BOOL api_lsa_create_trust_dom(pipes_struct *p)
+static BOOL api_lsa_delete_object(pipes_struct *p)
 {
-       LSA_Q_CREATE_TRUSTED_DOMAIN q_u;
-       LSA_R_CREATE_TRUSTED_DOMAIN r_u;
+       LSA_Q_DELETE_OBJECT q_u;
+       LSA_R_DELETE_OBJECT r_u;
        
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
@@ -810,16 +787,16 @@ static BOOL api_lsa_create_trust_dom(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       if(!lsa_io_q_create_trusted_domain("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_create_trust_dom: failed to unmarshall LSA_Q_CREATE_TRUSTED_DOMAIN .\n"));
+       if(!lsa_io_q_delete_object("", &q_u, data, 0)) {
+               DEBUG(0,("api_lsa_delete_object: failed to unmarshall LSA_Q_DELETE_OBJECT.\n"));
                return False;
        }
 
-       r_u.status = _lsa_create_trusted_domain(p, &q_u, &r_u);
+       r_u.status = _lsa_delete_object(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!lsa_io_r_create_trusted_domain("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_create_trust_dom: Failed to marshall LSA_R_CREATE_TRUSTED_DOMAIN.\n"));
+       if(!lsa_io_r_delete_object("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_lsa_delete_object: Failed to marshall LSA_R_DELETE_OBJECT.\n"));
                return False;
        }
 
@@ -827,29 +804,29 @@ static BOOL api_lsa_create_trust_dom(pipes_struct *p)
 }
 
 /***************************************************************************
+ api_lsa_lookup_sids2
  ***************************************************************************/
 
-static BOOL api_lsa_create_secret(pipes_struct *p)
+static BOOL api_lsa_lookup_sids2(pipes_struct *p)
 {
-       LSA_Q_CREATE_SECRET q_u;
-       LSA_R_CREATE_SECRET r_u;
-       
+       LSA_Q_LOOKUP_SIDS2 q_u;
+       LSA_R_LOOKUP_SIDS2 r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       if(!lsa_io_q_create_secret("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_create_secret: failed to unmarshall LSA_Q_CREATE_SECRET.\n"));
+       /* grab the info class and policy handle */
+       if(!lsa_io_q_lookup_sids2("", &q_u, data, 0)) {
+               DEBUG(0,("api_lsa_lookup_sids2: failed to unmarshall LSA_Q_LOOKUP_SIDS2.\n"));
                return False;
        }
 
-       r_u.status = _lsa_create_secret(p, &q_u, &r_u);
+       r_u.status = _lsa_lookup_sids2(p, &q_u, &r_u);
 
-       /* store the response in the SMB stream */
-       if(!lsa_io_r_create_secret("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_create_secret: Failed to marshall LSA_R_CREATE_SECRET.\n"));
+       if(!lsa_io_r_lookup_sids2("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_lsa_lookup_sids2: Failed to marshall LSA_R_LOOKUP_SIDS2.\n"));
                return False;
        }
 
@@ -857,29 +834,29 @@ static BOOL api_lsa_create_secret(pipes_struct *p)
 }
 
 /***************************************************************************
+ api_lsa_lookup_sids3
  ***************************************************************************/
 
-static BOOL api_lsa_set_secret(pipes_struct *p)
+static BOOL api_lsa_lookup_sids3(pipes_struct *p)
 {
-       LSA_Q_SET_SECRET q_u;
-       LSA_R_SET_SECRET r_u;
-       
+       LSA_Q_LOOKUP_SIDS3 q_u;
+       LSA_R_LOOKUP_SIDS3 r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       if(!lsa_io_q_set_secret("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_set_secret: failed to unmarshall LSA_Q_SET_SECRET.\n"));
+       /* grab the info class and policy handle */
+       if(!lsa_io_q_lookup_sids3("", &q_u, data, 0)) {
+               DEBUG(0,("api_lsa_lookup_sids3: failed to unmarshall LSA_Q_LOOKUP_SIDS3.\n"));
                return False;
        }
 
-       r_u.status = _lsa_set_secret(p, &q_u, &r_u);
+       r_u.status = _lsa_lookup_sids3(p, &q_u, &r_u);
 
-       /* store the response in the SMB stream */
-       if(!lsa_io_r_set_secret("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_set_secret: Failed to marshall LSA_R_SET_SECRET.\n"));
+       if(!lsa_io_r_lookup_sids3("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_lsa_lookup_sids3: Failed to marshall LSA_R_LOOKUP_SIDS3.\n"));
                return False;
        }
 
@@ -887,29 +864,30 @@ static BOOL api_lsa_set_secret(pipes_struct *p)
 }
 
 /***************************************************************************
+ api_lsa_lookup_names2
  ***************************************************************************/
 
-static BOOL api_lsa_delete_object(pipes_struct *p)
+static BOOL api_lsa_lookup_names2(pipes_struct *p)
 {
-       LSA_Q_DELETE_OBJECT q_u;
-       LSA_R_DELETE_OBJECT r_u;
-       
+       LSA_Q_LOOKUP_NAMES2 q_u;
+       LSA_R_LOOKUP_NAMES2 r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       if(!lsa_io_q_delete_object("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_delete_object: failed to unmarshall LSA_Q_DELETE_OBJECT.\n"));
+       /* grab the info class and policy handle */
+       if(!lsa_io_q_lookup_names2("", &q_u, data, 0)) {
+               DEBUG(0,("api_lsa_lookup_names2: failed to unmarshall LSA_Q_LOOKUP_NAMES2.\n"));
                return False;
        }
 
-       r_u.status = _lsa_delete_object(p, &q_u, &r_u);
+       r_u.status = _lsa_lookup_names2(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!lsa_io_r_delete_object("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_delete_object: Failed to marshall LSA_R_DELETE_OBJECT.\n"));
+       if(!lsa_io_r_lookup_names2("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_lsa_lookup_names2: Failed to marshall LSA_R_LOOKUP_NAMES2.\n"));
                return False;
        }
 
@@ -917,13 +895,13 @@ static BOOL api_lsa_delete_object(pipes_struct *p)
 }
 
 /***************************************************************************
- api_lsa_lookup_sids2
+ api_lsa_lookup_names3
  ***************************************************************************/
 
-static BOOL api_lsa_lookup_sids2(pipes_struct *p)
+static BOOL api_lsa_lookup_names3(pipes_struct *p)
 {
-       LSA_Q_LOOKUP_SIDS2 q_u;
-       LSA_R_LOOKUP_SIDS2 r_u;
+       LSA_Q_LOOKUP_NAMES3 q_u;
+       LSA_R_LOOKUP_NAMES3 r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
@@ -931,15 +909,16 @@ static BOOL api_lsa_lookup_sids2(pipes_struct *p)
        ZERO_STRUCT(r_u);
 
        /* grab the info class and policy handle */
-       if(!lsa_io_q_lookup_sids2("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_lookup_sids2: failed to unmarshall LSA_Q_LOOKUP_SIDS2.\n"));
+       if(!lsa_io_q_lookup_names3("", &q_u, data, 0)) {
+               DEBUG(0,("api_lsa_lookup_names3: failed to unmarshall LSA_Q_LOOKUP_NAMES3.\n"));
                return False;
        }
 
-       r_u.status = _lsa_lookup_sids2(p, &q_u, &r_u);
+       r_u.status = _lsa_lookup_names3(p, &q_u, &r_u);
 
-       if(!lsa_io_r_lookup_sids2("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_lookup_sids2: Failed to marshall LSA_R_LOOKUP_SIDS2.\n"));
+       /* store the response in the SMB stream */
+       if(!lsa_io_r_lookup_names3("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_lsa_lookup_names3: Failed to marshall LSA_R_LOOKUP_NAMES3.\n"));
                return False;
        }
 
@@ -947,13 +926,13 @@ static BOOL api_lsa_lookup_sids2(pipes_struct *p)
 }
 
 /***************************************************************************
- api_lsa_lookup_sids3
+ api_lsa_lookup_names4
  ***************************************************************************/
 
-static BOOL api_lsa_lookup_sids3(pipes_struct *p)
+static BOOL api_lsa_lookup_names4(pipes_struct *p)
 {
-       LSA_Q_LOOKUP_SIDS3 q_u;
-       LSA_R_LOOKUP_SIDS3 r_u;
+       LSA_Q_LOOKUP_NAMES4 q_u;
+       LSA_R_LOOKUP_NAMES4 r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
@@ -961,15 +940,16 @@ static BOOL api_lsa_lookup_sids3(pipes_struct *p)
        ZERO_STRUCT(r_u);
 
        /* grab the info class and policy handle */
-       if(!lsa_io_q_lookup_sids3("", &q_u, data, 0)) {
-               DEBUG(0,("api_lsa_lookup_sids3: failed to unmarshall LSA_Q_LOOKUP_SIDS3.\n"));
+       if(!lsa_io_q_lookup_names4("", &q_u, data, 0)) {
+               DEBUG(0,("api_lsa_lookup_names4: failed to unmarshall LSA_Q_LOOKUP_NAMES4.\n"));
                return False;
        }
 
-       r_u.status = _lsa_lookup_sids3(p, &q_u, &r_u);
+       r_u.status = _lsa_lookup_names4(p, &q_u, &r_u);
 
-       if(!lsa_io_r_lookup_sids3("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_lsa_lookup_sids3: Failed to marshall LSA_R_LOOKUP_SIDS3.\n"));
+       /* store the response in the SMB stream */
+       if(!lsa_io_r_lookup_names4("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_lsa_lookup_names4: Failed to marshall LSA_R_LOOKUP_NAMES4.\n"));
                return False;
        }
 
@@ -1046,7 +1026,10 @@ static struct api_struct api_lsa_cmds[] =
        { "LSA_SETSECRET"       , LSA_SETSECRET       , api_lsa_set_secret },
        { "LSA_DELETEOBJECT"    , LSA_DELETEOBJECT    , api_lsa_delete_object },
        { "LSA_LOOKUPSIDS2"     , LSA_LOOKUPSIDS2     , api_lsa_lookup_sids2 },
-       { "LSA_LOOKUPSIDS3"     , LSA_LOOKUPSIDS3     , api_lsa_lookup_sids3 }
+       { "LSA_LOOKUPNAMES2"    , LSA_LOOKUPNAMES2    , api_lsa_lookup_names2 },
+       { "LSA_LOOKUPNAMES3"    , LSA_LOOKUPNAMES3    , api_lsa_lookup_names3 },
+       { "LSA_LOOKUPSIDS3"     , LSA_LOOKUPSIDS3     , api_lsa_lookup_sids3 },
+       { "LSA_LOOKUPNAMES4"    , LSA_LOOKUPNAMES4    , api_lsa_lookup_names4 }
 #if 0  /* AD DC work in ongoing in Samba 4 */
        /* be careful of the adding of new RPC's.  See commentrs below about
           ADS DC capabilities                                               */