s3: Use dbwrap_parse_record in fetch_share_mode_unlocked
[kai/samba.git] / source3 / rpcclient / cmd_srvsvc.c
index e5c9f90aee3eadd7ff8f78a6ea08a6be02df1437..0d67639959fc7490f3bd3a0f9017ae4a024647f7 100644 (file)
    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 "rpcclient.h"
+#include "../librpc/gen_ndr/ndr_srvsvc.h"
+#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
+#include "../libcli/security/display_sec.h"
 
 /* Display server query info */
 
@@ -137,55 +139,68 @@ static void display_server(const char *sname, uint32 type, const char *comment)
               comment);
 }
 
-static void display_srv_info_101(struct srvsvc_NetSrvInfo101 *sv101)
+static void display_srv_info_101(struct srvsvc_NetSrvInfo101 *r)
 {
-       display_server(sv101->server_name, sv101->server_type, sv101->comment);
+       display_server(r->server_name, r->server_type, r->comment);
 
-       printf("\tplatform_id     :\t%d\n", sv101->platform_id);
-       printf("\tos version      :\t%d.%d\n", sv101->version_major, 
-              sv101->version_minor);
-
-       printf("\tserver type     :\t0x%x\n", sv101->server_type);
+       printf("\tplatform_id     :\t%d\n", r->platform_id);
+       printf("\tos version      :\t%d.%d\n",
+               r->version_major, r->version_minor);
+       printf("\tserver type     :\t0x%x\n", r->server_type);
 }
 
-static void display_srv_info_102(struct srvsvc_NetSrvInfo102 *sv102)
+static void display_srv_info_102(struct srvsvc_NetSrvInfo102 *r)
 {
-       display_server(sv102->server_name, sv102->server_type, 
-                                  sv102->comment);
-
-       printf("\tplatform_id     :\t%d\n", sv102->platform_id);
-       printf("\tos version      :\t%d.%d\n", sv102->version_major, 
-              sv102->version_minor);
-
-       printf("\tusers           :\t%x\n", sv102->users);
-       printf("\tdisc, hidden    :\t%x, %x\n", sv102->disc, sv102->hidden);
-       printf("\tannounce, delta :\t%d, %d\n", sv102->announce, 
-              sv102->anndelta);
-       printf("\tlicenses        :\t%d\n", sv102->licenses);
-       printf("\tuser path       :\t%s\n", sv102->userpath);
+       display_server(r->server_name, r->server_type, r->comment);
+
+       printf("\tplatform_id     :\t%d\n", r->platform_id);
+       printf("\tos version      :\t%d.%d\n",
+               r->version_major, r->version_minor);
+       printf("\tserver type     :\t0x%x\n", r->server_type);
+
+       printf("\tusers           :\t%x\n", r->users);
+       printf("\tdisc, hidden    :\t%x, %x\n", r->disc, r->hidden);
+       printf("\tannounce, delta :\t%d, %d\n", r->announce,
+              r->anndelta);
+       printf("\tlicenses        :\t%d\n", r->licenses);
+       printf("\tuser path       :\t%s\n", r->userpath);
 }
 
 /* Server query info */
-static NTSTATUS cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli, 
+static WERROR cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli, 
                                           TALLOC_CTX *mem_ctx,
                                           int argc, const char **argv)
 {
        uint32 info_level = 101;
-       union srvsvc_NetSrvInfo ctr;
-       NTSTATUS result;
+       union srvsvc_NetSrvInfo info;
+       WERROR result;
+       NTSTATUS status;
+       const char *server_unc = cli->srv_name_slash;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
 
-       if (argc > 2) {
-               printf("Usage: %s [infolevel]\n", argv[0]);
-               return NT_STATUS_OK;
+       if (argc > 3) {
+               printf("Usage: %s [infolevel] [server_unc]\n", argv[0]);
+               return WERR_OK;
        }
 
-       if (argc == 2)
+       if (argc >= 2) {
                info_level = atoi(argv[1]);
+       }
 
-       result = rpccli_srvsvc_NetSrvGetInfo(cli, mem_ctx, NULL, info_level,
-                                            &ctr);
+       if (argc >= 3) {
+               server_unc = argv[2];
+       }
+
+       status = dcerpc_srvsvc_NetSrvGetInfo(b, mem_ctx,
+                                            server_unc,
+                                            info_level,
+                                            &info,
+                                            &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               return ntstatus_to_werror(status);
+       }
 
-       if (!NT_STATUS_IS_OK(result)) {
+       if (!W_ERROR_IS_OK(result)) {
                goto done;
        }
 
@@ -193,10 +208,10 @@ static NTSTATUS cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli,
 
        switch (info_level) {
        case 101:
-               display_srv_info_101(ctr.info101);
+               display_srv_info_101(info.info101);
                break;
        case 102:
-               display_srv_info_102(ctr.info102);
+               display_srv_info_102(info.info102);
                break;
        default:
                printf("unsupported info level %d\n", info_level);
@@ -207,106 +222,168 @@ static NTSTATUS cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli,
        return result;
 }
 
-static void display_share_info_1(struct srvsvc_NetShareInfo1 *info1)
+static void display_share_info_1(struct srvsvc_NetShareInfo1 *r)
 {
-       printf("netname: %s\n", info1->name);
-       printf("\tremark:\t%s\n", info1->comment);
+       printf("netname: %s\n", r->name);
+       printf("\tremark:\t%s\n", r->comment);
 }
 
-static void display_share_info_2(struct srvsvc_NetShareInfo2 *info2)
+static void display_share_info_2(struct srvsvc_NetShareInfo2 *r)
 {
-       printf("netname: %s\n", info2->name);
-       printf("\tremark:\t%s\n", info2->comment);
-       printf("\tpath:\t%s\n", info2->path);
-       printf("\tpassword:\t%s\n", info2->password);
+       printf("netname: %s\n", r->name);
+       printf("\tremark:\t%s\n", r->comment);
+       printf("\tpath:\t%s\n", r->path);
+       printf("\tpassword:\t%s\n", r->password);
 }
 
-static void display_share_info_502(struct srvsvc_NetShareInfo502 *info502)
+static void display_share_info_502(struct srvsvc_NetShareInfo502 *r)
 {
-       printf("netname: %s\n", info502->name);
-       printf("\tremark:\t%s\n", info502->comment);
-       printf("\tpath:\t%s\n", info502->path);
-       printf("\tpassword:\t%s\n", info502->password);
-
-       printf("\ttype:\t0x%x\n", info502->type);
-       printf("\tperms:\t%d\n", info502->permissions);
-       printf("\tmax_uses:\t%d\n", info502->max_users);
-       printf("\tnum_uses:\t%d\n", info502->current_users);
-       
-       if (info502->sd)
-               display_sec_desc(info502->sd);
+       printf("netname: %s\n", r->name);
+       printf("\tremark:\t%s\n", r->comment);
+       printf("\tpath:\t%s\n", r->path);
+       printf("\tpassword:\t%s\n", r->password);
+
+       printf("\ttype:\t0x%x\n", r->type);
+       printf("\tperms:\t%d\n", r->permissions);
+       printf("\tmax_uses:\t%d\n", r->max_users);
+       printf("\tnum_uses:\t%d\n", r->current_users);
+
+       if (r->sd_buf.sd)
+               display_sec_desc(r->sd_buf.sd);
 
 }
 
-static NTSTATUS cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli, 
-                                          TALLOC_CTX *mem_ctx,
-                                          int argc, const char **argv)
+static WERROR cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client *cli,
+                                           TALLOC_CTX *mem_ctx,
+                                           int argc, const char **argv,
+                                           uint32_t opcode)
 {
        uint32 info_level = 2;
+       struct srvsvc_NetShareInfoCtr info_ctr;
+       struct srvsvc_NetShareCtr0 ctr0;
        struct srvsvc_NetShareCtr1 ctr1;
        struct srvsvc_NetShareCtr2 ctr2;
+       struct srvsvc_NetShareCtr501 ctr501;
        struct srvsvc_NetShareCtr502 ctr502;
-       union srvsvc_NetShareCtr ctr;
-       NTSTATUS result;
-       uint32 hnd;
+       struct srvsvc_NetShareCtr1004 ctr1004;
+       struct srvsvc_NetShareCtr1005 ctr1005;
+       struct srvsvc_NetShareCtr1006 ctr1006;
+       struct srvsvc_NetShareCtr1007 ctr1007;
+       struct srvsvc_NetShareCtr1501 ctr1501;
+       WERROR result;
+       NTSTATUS status;
+       uint32_t totalentries = 0;
+       uint32_t resume_handle = 0;
+       uint32_t *resume_handle_p = NULL;
        uint32 preferred_len = 0xffffffff, i;
-       uint32 numentries;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
 
-       ZERO_STRUCT(ctr);
-
-       if (argc > 2) {
-               printf("Usage: %s [infolevel]\n", argv[0]);
-               return NT_STATUS_OK;
+       if (argc > 3) {
+               printf("Usage: %s [infolevel] [resume_handle]\n", argv[0]);
+               return WERR_OK;
        }
 
-       if (argc == 2)
+       if (argc >= 2) {
                info_level = atoi(argv[1]);
+       }
+
+       if (argc == 3) {
+               resume_handle = atoi(argv[2]);
+               resume_handle_p = &resume_handle;
+       }
+
+       ZERO_STRUCT(info_ctr);
 
-       hnd = 0;
+       info_ctr.level = info_level;
 
        switch (info_level) {
-       case 1: {
+       case 0:
+               ZERO_STRUCT(ctr0);
+               info_ctr.ctr.ctr0 = &ctr0;
+               break;
+       case 1:
                ZERO_STRUCT(ctr1);
-               ctr.ctr1 = &ctr1;
-               }
+               info_ctr.ctr.ctr1 = &ctr1;
                break;
-
-       case 2: {
+       case 2:
                ZERO_STRUCT(ctr2);
-               ctr.ctr2 = &ctr2;
-               }
+               info_ctr.ctr.ctr2 = &ctr2;
                break;
-       case 502: {
+       case 501:
+               ZERO_STRUCT(ctr501);
+               info_ctr.ctr.ctr501 = &ctr501;
+               break;
+       case 502:
                ZERO_STRUCT(ctr502);
-               ctr.ctr502 = &ctr502;
-               }
+               info_ctr.ctr.ctr502 = &ctr502;
                break;
-
-       default:
+       case 1004:
+               ZERO_STRUCT(ctr1004);
+               info_ctr.ctr.ctr1004 = &ctr1004;
+               break;
+       case 1005:
+               ZERO_STRUCT(ctr1005);
+               info_ctr.ctr.ctr1005 = &ctr1005;
+               break;
+       case 1006:
+               ZERO_STRUCT(ctr1006);
+               info_ctr.ctr.ctr1006 = &ctr1006;
+               break;
+       case 1007:
+               ZERO_STRUCT(ctr1007);
+               info_ctr.ctr.ctr1007 = &ctr1007;
+               break;
+       case 1501:
+               ZERO_STRUCT(ctr1501);
+               info_ctr.ctr.ctr1501 = &ctr1501;
                break;
        }
 
-       result = rpccli_srvsvc_NetShareEnum(
-               cli, mem_ctx, cli->cli->desthost, &info_level, &ctr, preferred_len, &numentries, 
-               &hnd);
+       switch (opcode) {
+               case NDR_SRVSVC_NETSHAREENUM:
+                       status = dcerpc_srvsvc_NetShareEnum(b, mem_ctx,
+                                                           cli->desthost,
+                                                           &info_ctr,
+                                                           preferred_len,
+                                                           &totalentries,
+                                                           resume_handle_p,
+                                                           &result);
+                       break;
+               case NDR_SRVSVC_NETSHAREENUMALL:
+                       status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx,
+                                                              cli->desthost,
+                                                              &info_ctr,
+                                                              preferred_len,
+                                                              &totalentries,
+                                                              resume_handle_p,
+                                                              &result);
+                       break;
+               default:
+                       return WERR_INVALID_PARAM;
+       }
 
-       if (!NT_STATUS_IS_OK(result) || !numentries)
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+       if (!W_ERROR_IS_OK(result)) {
                goto done;
+       }
 
        /* Display results */
 
        switch (info_level) {
        case 1:
-               for (i = 0; i < numentries; i++)
-                       display_share_info_1(&ctr.ctr1->array[i]);
+               for (i = 0; i < totalentries; i++)
+                       display_share_info_1(&info_ctr.ctr.ctr1->array[i]);
                break;
        case 2:
-               for (i = 0; i < numentries; i++)
-                       display_share_info_2(&ctr.ctr2->array[i]);
+               for (i = 0; i < totalentries; i++)
+                       display_share_info_2(&info_ctr.ctr.ctr2->array[i]);
                break;
        case 502:
-               for (i = 0; i < numentries; i++)
-                       display_share_info_502(&ctr.ctr502->array[i]);
+               for (i = 0; i < totalentries; i++)
+                       display_share_info_502(&info_ctr.ctr.ctr502->array[i]);
                break;
        default:
                printf("unsupported info level %d\n", info_level);
@@ -317,26 +394,56 @@ static NTSTATUS cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli,
        return result;
 }
 
-static NTSTATUS cmd_srvsvc_net_share_get_info(struct rpc_pipe_client *cli, 
+static WERROR cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli,
+                                       TALLOC_CTX *mem_ctx,
+                                       int argc, const char **argv)
+{
+       return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
+                                            argc, argv,
+                                            NDR_SRVSVC_NETSHAREENUM);
+}
+
+static WERROR cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client *cli,
+                                           TALLOC_CTX *mem_ctx,
+                                           int argc, const char **argv)
+{
+       return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
+                                            argc, argv,
+                                            NDR_SRVSVC_NETSHAREENUMALL);
+}
+
+static WERROR cmd_srvsvc_net_share_get_info(struct rpc_pipe_client *cli, 
                                            TALLOC_CTX *mem_ctx,
                                            int argc, const char **argv)
 {
        uint32 info_level = 502;
        union srvsvc_NetShareInfo info;
-       NTSTATUS result;
+       WERROR result;
+       NTSTATUS status;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
 
-       if (argc > 3) {
+       if (argc < 2 || argc > 3) {
                printf("Usage: %s [sharename] [infolevel]\n", argv[0]);
-               return NT_STATUS_OK;
+               return WERR_OK;
        }
 
        if (argc == 3)
                info_level = atoi(argv[2]);
 
-       result = rpccli_srvsvc_NetShareGetInfo(cli, mem_ctx, NULL, argv[1], info_level, &info);
+       status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
+                                              cli->desthost,
+                                              argv[1],
+                                              info_level,
+                                              &info,
+                                              &result);
 
-       if (!NT_STATUS_IS_OK(result))
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+       if (!W_ERROR_IS_OK(result)) {
                goto done;
+       }
 
        /* Display results */
 
@@ -359,111 +466,497 @@ static NTSTATUS cmd_srvsvc_net_share_get_info(struct rpc_pipe_client *cli,
        return result;
 }
 
-static NTSTATUS cmd_srvsvc_net_share_set_info(struct rpc_pipe_client *cli, 
+static WERROR cmd_srvsvc_net_share_set_info(struct rpc_pipe_client *cli, 
                                            TALLOC_CTX *mem_ctx,
                                            int argc, const char **argv)
 {
        uint32 info_level = 502;
        union srvsvc_NetShareInfo info_get;
-       NTSTATUS result;
-       uint32 parm_error = 0;
+       WERROR result;
+       NTSTATUS status;
+       uint32_t parm_err = 0;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
 
        if (argc > 3) {
                printf("Usage: %s [sharename] [comment]\n", argv[0]);
-               return NT_STATUS_OK;
+               return WERR_OK;
        }
 
        /* retrieve share info */
-       result = rpccli_srvsvc_NetShareGetInfo(cli, mem_ctx, NULL, argv[1], info_level, &info_get);
-       if (!NT_STATUS_IS_OK(result))
+       status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
+                                              cli->desthost,
+                                              argv[1],
+                                              info_level,
+                                              &info_get,
+                                              &result);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+       if (!W_ERROR_IS_OK(result)) {
                goto done;
+       }
 
-       /* set share info */
-       result = rpccli_srvsvc_NetShareSetInfo(cli, mem_ctx, NULL, argv[1], info_level, info_get, &parm_error);
+       info_get.info502->comment = argv[2];
 
-       if (!NT_STATUS_IS_OK(result))
+       /* set share info */
+       status = dcerpc_srvsvc_NetShareSetInfo(b, mem_ctx,
+                                              cli->desthost,
+                                              argv[1],
+                                              info_level,
+                                              &info_get,
+                                              &parm_err,
+                                              &result);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
                goto done;
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
 
        /* re-retrieve share info and display */
-       result = rpccli_srvsvc_NetShareGetInfo(cli, mem_ctx, NULL, argv[1], info_level, &info_get);
-       if (!NT_STATUS_IS_OK(result))
+       status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
+                                              cli->desthost,
+                                              argv[1],
+                                              info_level,
+                                              &info_get,
+                                              &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
                goto done;
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
 
        display_share_info_502(info_get.info502);
-       
+
  done:
        return result;
 }
 
-static NTSTATUS cmd_srvsvc_net_remote_tod(struct rpc_pipe_client *cli, 
+static WERROR cmd_srvsvc_net_remote_tod(struct rpc_pipe_client *cli, 
                                           TALLOC_CTX *mem_ctx,
                                           int argc, const char **argv)
 {
-       fstring srv_name_slash;
-       NTSTATUS result;
-       struct srvsvc_NetRemoteTODInfo tod;
+       struct srvsvc_NetRemoteTODInfo *tod = NULL;
+       WERROR result;
+       NTSTATUS status;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
 
        if (argc > 1) {
                printf("Usage: %s\n", argv[0]);
-               return NT_STATUS_OK;
+               return WERR_OK;
        }
 
-       fstr_sprintf(srv_name_slash, "\\\\%s", cli->cli->desthost);
-       result = rpccli_srvsvc_NetRemoteTOD(
-               cli, mem_ctx, srv_name_slash, &tod);
+       status = dcerpc_srvsvc_NetRemoteTOD(b, mem_ctx,
+                                           cli->srv_name_slash,
+                                           &tod,
+                                           &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
 
-       if (!NT_STATUS_IS_OK(result))
+       if (!W_ERROR_IS_OK(result))
                goto done;
 
  done:
        return result;
 }
 
-static NTSTATUS cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli, 
+static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli, 
                                         TALLOC_CTX *mem_ctx,
                                         int argc, const char **argv)
 {
        uint32 info_level = 3;
-       union srvsvc_NetFileCtr ctr;
-       NTSTATUS result;
-       uint32 hnd;
+       struct srvsvc_NetFileInfoCtr info_ctr;
+       struct srvsvc_NetFileCtr3 ctr3;
+       WERROR result;
+       NTSTATUS status;
        uint32 preferred_len = 0xffff;
-       uint32 numentries;
+       uint32_t total_entries = 0;
+       uint32_t resume_handle = 0;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
 
        if (argc > 2) {
                printf("Usage: %s [infolevel]\n", argv[0]);
-               return NT_STATUS_OK;
+               return WERR_OK;
        }
 
        if (argc == 2)
                info_level = atoi(argv[1]);
 
-       hnd = 0;
+       ZERO_STRUCT(info_ctr);
+       ZERO_STRUCT(ctr3);
+
+       info_ctr.level = info_level;
+       info_ctr.ctr.ctr3 = &ctr3;
+
+       status = dcerpc_srvsvc_NetFileEnum(b, mem_ctx,
+                                          cli->desthost,
+                                          NULL,
+                                          NULL,
+                                          &info_ctr,
+                                          preferred_len,
+                                          &total_entries,
+                                          &resume_handle,
+                                          &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
 
-       ZERO_STRUCT(ctr);
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+ done:
+       return result;
+}
 
-       result = rpccli_srvsvc_NetFileEnum(
-               cli, mem_ctx, NULL, NULL, NULL, &info_level, &ctr, preferred_len, &numentries, &hnd);
+static WERROR cmd_srvsvc_net_name_validate(struct rpc_pipe_client *cli,
+                                          TALLOC_CTX *mem_ctx,
+                                          int argc, const char **argv)
+{
+       WERROR result;
+       NTSTATUS status;
+       uint32_t name_type = 9;
+       uint32_t flags = 0;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
+
+       if (argc < 2 || argc > 3) {
+               printf("Usage: %s [sharename] [type]\n", argv[0]);
+               return WERR_OK;
+       }
+
+       if (argc == 3) {
+               name_type = atoi(argv[2]);
+       }
 
-       if (!NT_STATUS_IS_OK(result))
+       status = dcerpc_srvsvc_NetNameValidate(b, mem_ctx,
+                                              cli->desthost,
+                                              argv[1],
+                                              name_type,
+                                              flags,
+                                              &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       if (!W_ERROR_IS_OK(result))
                goto done;
 
  done:
        return result;
 }
 
+static WERROR cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client *cli,
+                                         TALLOC_CTX *mem_ctx,
+                                         int argc, const char **argv)
+{
+       WERROR result;
+       NTSTATUS status;
+       struct sec_desc_buf *sd_buf = NULL;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
+
+       if (argc < 2 || argc > 4) {
+               printf("Usage: %s [sharename] [file]\n", argv[0]);
+               return WERR_OK;
+       }
+
+       status = dcerpc_srvsvc_NetGetFileSecurity(b, mem_ctx,
+                                                 cli->desthost,
+                                                 argv[1],
+                                                 argv[2],
+                                                 SECINFO_DACL,
+                                                 &sd_buf,
+                                                 &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       display_sec_desc(sd_buf->sd);
+
+ done:
+       return result;
+}
+
+static WERROR cmd_srvsvc_net_sess_del(struct rpc_pipe_client *cli,
+                                     TALLOC_CTX *mem_ctx,
+                                     int argc, const char **argv)
+{
+       WERROR result;
+       NTSTATUS status;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
+
+       if (argc < 2 || argc > 4) {
+               printf("Usage: %s [client] [user]\n", argv[0]);
+               return WERR_OK;
+       }
+
+       status = dcerpc_srvsvc_NetSessDel(b, mem_ctx,
+                                         cli->desthost,
+                                         argv[1],
+                                         argv[2],
+                                         &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+ done:
+       return result;
+}
+
+static WERROR cmd_srvsvc_net_sess_enum(struct rpc_pipe_client *cli,
+                                      TALLOC_CTX *mem_ctx,
+                                      int argc, const char **argv)
+{
+       WERROR result;
+       NTSTATUS status;
+       struct srvsvc_NetSessInfoCtr info_ctr;
+       struct srvsvc_NetSessCtr0 ctr0;
+       struct srvsvc_NetSessCtr1 ctr1;
+       struct srvsvc_NetSessCtr2 ctr2;
+       struct srvsvc_NetSessCtr10 ctr10;
+       struct srvsvc_NetSessCtr502 ctr502;
+       uint32_t total_entries = 0;
+       uint32_t resume_handle = 0;
+       uint32_t *resume_handle_p = NULL;
+       uint32_t level = 1;
+       const char *client = NULL;
+       const char *user = NULL;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
+
+       if (argc > 6) {
+               printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv[0]);
+               return WERR_OK;
+       }
+
+       if (argc >= 2) {
+               client = argv[1];
+       }
+
+       if (argc >= 3) {
+               user = argv[2];
+       }
+
+       if (argc >= 4) {
+               level = atoi(argv[3]);
+       }
+
+       if (argc >= 5) {
+               resume_handle = atoi(argv[4]);
+               resume_handle_p = &resume_handle;
+       }
+
+       ZERO_STRUCT(info_ctr);
+
+       info_ctr.level = level;
+
+       d_printf("trying level: %d\n", level);
+
+       switch (level) {
+       case 0:
+               ZERO_STRUCT(ctr0);
+               info_ctr.ctr.ctr0 = &ctr0;
+               break;
+       case 1:
+               ZERO_STRUCT(ctr1);
+               info_ctr.ctr.ctr1 = &ctr1;
+               break;
+       case 2:
+               ZERO_STRUCT(ctr2);
+               info_ctr.ctr.ctr2 = &ctr2;
+               break;
+       case 10:
+               ZERO_STRUCT(ctr10);
+               info_ctr.ctr.ctr10 = &ctr10;
+               break;
+       case 502:
+               ZERO_STRUCT(ctr502);
+               info_ctr.ctr.ctr502 = &ctr502;
+               break;
+       }
+
+       status = dcerpc_srvsvc_NetSessEnum(b, mem_ctx,
+                                         cli->desthost,
+                                         client,
+                                         user,
+                                         &info_ctr,
+                                         0xffffffff,
+                                         &total_entries,
+                                         resume_handle_p,
+                                         &result);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+ done:
+       return result;
+}
+
+static WERROR cmd_srvsvc_net_disk_enum(struct rpc_pipe_client *cli,
+                                      TALLOC_CTX *mem_ctx,
+                                      int argc, const char **argv)
+{
+       struct srvsvc_NetDiskInfo info;
+       WERROR result;
+       NTSTATUS status;
+       uint32_t total_entries = 0;
+       uint32_t resume_handle = 0;
+       uint32_t level = 0;
+       struct dcerpc_binding_handle *b = cli->binding_handle;
+
+       if (argc > 4) {
+               printf("Usage: %s [level] [resume_handle]\n", argv[0]);
+               return WERR_OK;
+       }
+
+       if (argc >= 2) {
+               level = atoi(argv[1]);
+       }
+
+       if (argc >= 3) {
+               resume_handle = atoi(argv[2]);
+       }
+
+       ZERO_STRUCT(info);
+
+       status = dcerpc_srvsvc_NetDiskEnum(b, mem_ctx,
+                                          cli->desthost,
+                                          level,
+                                          &info,
+                                          0xffffffff,
+                                          &total_entries,
+                                          &resume_handle,
+                                          &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+ done:
+       return result;
+}
+
+static WERROR cmd_srvsvc_net_conn_enum(struct rpc_pipe_client *cli,
+                                      TALLOC_CTX *mem_ctx,
+                                      int argc, const char **argv)
+{
+       struct srvsvc_NetConnInfoCtr info_ctr;
+       struct srvsvc_NetConnCtr0 ctr0;
+       struct srvsvc_NetConnCtr1 ctr1;
+       WERROR result;
+       NTSTATUS status;
+       uint32_t total_entries = 0;
+       uint32_t resume_handle = 0;
+       uint32_t *resume_handle_p = NULL;
+       uint32_t level = 1;
+       const char *path = "IPC$";
+       struct dcerpc_binding_handle *b = cli->binding_handle;
+
+       if (argc > 4) {
+               printf("Usage: %s [level] [path] [resume_handle]\n", argv[0]);
+               return WERR_OK;
+       }
+
+       if (argc >= 2) {
+               level = atoi(argv[1]);
+       }
+
+       if (argc >= 3) {
+               path = argv[2];
+       }
+
+       if (argc >= 4) {
+               resume_handle = atoi(argv[3]);
+               resume_handle_p = &resume_handle;
+       }
+
+       ZERO_STRUCT(info_ctr);
+
+       info_ctr.level = level;
+
+       switch (level) {
+               case 0:
+                       ZERO_STRUCT(ctr0);
+                       info_ctr.ctr.ctr0 = &ctr0;
+                       break;
+               case 1:
+                       ZERO_STRUCT(ctr1);
+                       info_ctr.ctr.ctr1 = &ctr1;
+                       break;
+               default:
+                       return WERR_INVALID_PARAM;
+       }
+
+       status = dcerpc_srvsvc_NetConnEnum(b, mem_ctx,
+                                          cli->desthost,
+                                          path,
+                                          &info_ctr,
+                                          0xffffffff,
+                                          &total_entries,
+                                          resume_handle_p,
+                                          &result);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+ done:
+       return result;
+}
+
+
 /* List of commands exported by this module */
 
 struct cmd_set srvsvc_commands[] = {
 
        { "SRVSVC" },
 
-       { "srvinfo",     RPC_RTYPE_NTSTATUS, cmd_srvsvc_srv_query_info, NULL, PI_SRVSVC, NULL, "Server query info", "" },
-       { "netshareenum",RPC_RTYPE_NTSTATUS, cmd_srvsvc_net_share_enum, NULL, PI_SRVSVC, NULL, "Enumerate shares", "" },
-       { "netsharegetinfo",RPC_RTYPE_NTSTATUS, cmd_srvsvc_net_share_get_info, NULL, PI_SRVSVC, NULL, "Get Share Info", "" },
-       { "netsharesetinfo",RPC_RTYPE_NTSTATUS, cmd_srvsvc_net_share_set_info, NULL, PI_SRVSVC, NULL, "Set Share Info", "" },
-       { "netfileenum", RPC_RTYPE_NTSTATUS, cmd_srvsvc_net_file_enum, NULL, PI_SRVSVC, NULL, "Enumerate open files", "" },
-       { "netremotetod",RPC_RTYPE_NTSTATUS, cmd_srvsvc_net_remote_tod, NULL, PI_SRVSVC, NULL, "Fetch remote time of day", "" },
+       { "srvinfo",     RPC_RTYPE_WERROR, NULL, cmd_srvsvc_srv_query_info, &ndr_table_srvsvc, NULL, "Server query info", "" },
+       { "netshareenum",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum, &ndr_table_srvsvc, NULL, "Enumerate shares", "" },
+       { "netshareenumall",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum_all, &ndr_table_srvsvc, NULL, "Enumerate all shares", "" },
+       { "netsharegetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_get_info, &ndr_table_srvsvc, NULL, "Get Share Info", "" },
+       { "netsharesetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_set_info, &ndr_table_srvsvc, NULL, "Set Share Info", "" },
+       { "netfileenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_enum,  &ndr_table_srvsvc, NULL, "Enumerate open files", "" },
+       { "netremotetod",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_remote_tod, &ndr_table_srvsvc, NULL, "Fetch remote time of day", "" },
+       { "netnamevalidate", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_name_validate, &ndr_table_srvsvc, NULL, "Validate sharename", "" },
+       { "netfilegetsec", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_get_sec, &ndr_table_srvsvc, NULL, "Get File security", "" },
+       { "netsessdel", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_del, &ndr_table_srvsvc, NULL, "Delete Session", "" },
+       { "netsessenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_enum, &ndr_table_srvsvc, NULL, "Enumerate Sessions", "" },
+       { "netdiskenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_disk_enum, &ndr_table_srvsvc, NULL, "Enumerate Disks", "" },
+       { "netconnenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_conn_enum, &ndr_table_srvsvc, NULL, "Enumerate Connections", "" },
 
        { NULL }
 };