s3-rpc: Avoid including every pipe's client and server stubs everywhere in samba.
[kamenim/samba.git] / source3 / lib / netapi / share.c
index 414900a11d0c56a51d23f8aa381d422a4ec9af3d..65bcd9a3a26f65f7c10f303d282bd32c32354ab1 100644 (file)
@@ -23,6 +23,7 @@
 #include "lib/netapi/netapi.h"
 #include "lib/netapi/netapi_private.h"
 #include "lib/netapi/libnetapi.h"
+#include "../librpc/gen_ndr/cli_srvsvc.h"
 
 /****************************************************************
 ****************************************************************/
@@ -181,7 +182,6 @@ WERROR NetShareAdd_r(struct libnetapi_ctx *ctx,
 {
        WERROR werr;
        NTSTATUS status;
-       struct cli_state *cli = NULL;
        struct rpc_pipe_client *pipe_cli = NULL;
        union srvsvc_NetShareInfo info;
 
@@ -201,7 +201,6 @@ WERROR NetShareAdd_r(struct libnetapi_ctx *ctx,
 
        werr = libnetapi_open_pipe(ctx, r->in.server_name,
                                   &ndr_table_srvsvc.syntax_id,
-                                  &cli,
                                   &pipe_cli);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
@@ -227,10 +226,6 @@ WERROR NetShareAdd_r(struct libnetapi_ctx *ctx,
        }
 
  done:
-       if (!cli) {
-               return werr;
-       }
-
        return werr;
 }
 
@@ -251,7 +246,6 @@ WERROR NetShareDel_r(struct libnetapi_ctx *ctx,
 {
        WERROR werr;
        NTSTATUS status;
-       struct cli_state *cli = NULL;
        struct rpc_pipe_client *pipe_cli = NULL;
 
        if (!r->in.net_name) {
@@ -260,7 +254,6 @@ WERROR NetShareDel_r(struct libnetapi_ctx *ctx,
 
        werr = libnetapi_open_pipe(ctx, r->in.server_name,
                                   &ndr_table_srvsvc.syntax_id,
-                                  &cli,
                                   &pipe_cli);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
@@ -271,15 +264,12 @@ WERROR NetShareDel_r(struct libnetapi_ctx *ctx,
                                           r->in.net_name,
                                           r->in.reserved,
                                           &werr);
-       if (!W_ERROR_IS_OK(werr)) {
+       if (!NT_STATUS_IS_OK(status)) {
+               werr = ntstatus_to_werror(status);
                goto done;
        }
 
  done:
-       if (!cli) {
-               return werr;
-       }
-
        return werr;
 }
 
@@ -300,7 +290,6 @@ WERROR NetShareEnum_r(struct libnetapi_ctx *ctx,
 {
        WERROR werr;
        NTSTATUS status;
-       struct cli_state *cli = NULL;
        struct rpc_pipe_client *pipe_cli = NULL;
        struct srvsvc_NetShareInfoCtr info_ctr;
        struct srvsvc_NetShareCtr0 ctr0;
@@ -328,7 +317,6 @@ WERROR NetShareEnum_r(struct libnetapi_ctx *ctx,
 
        werr = libnetapi_open_pipe(ctx, r->in.server_name,
                                   &ndr_table_srvsvc.syntax_id,
-                                  &cli,
                                   &pipe_cli);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
@@ -337,23 +325,26 @@ WERROR NetShareEnum_r(struct libnetapi_ctx *ctx,
        info_ctr.level = r->in.level;
        switch (r->in.level) {
                case 0:
+                       ZERO_STRUCT(ctr0);
                        info_ctr.ctr.ctr0 = &ctr0;
-                        break;
+                       break;
                case 1:
+                       ZERO_STRUCT(ctr1);
                        info_ctr.ctr.ctr1 = &ctr1;
                        break;
                case 2:
+                       ZERO_STRUCT(ctr2);
                        info_ctr.ctr.ctr2 = &ctr2;
                        break;
        }
 
-       status = rpccli_srvsvc_NetShareEnum(pipe_cli, ctx,
-                                           r->in.server_name,
-                                           &info_ctr,
-                                           r->in.prefmaxlen,
-                                           r->out.total_entries,
-                                           r->out.resume_handle,
-                                           &werr);
+       status = rpccli_srvsvc_NetShareEnumAll(pipe_cli, ctx,
+                                              r->in.server_name,
+                                              &info_ctr,
+                                              r->in.prefmaxlen,
+                                              r->out.total_entries,
+                                              r->out.resume_handle,
+                                              &werr);
        if (NT_STATUS_IS_ERR(status)) {
                goto done;
        }
@@ -383,10 +374,6 @@ WERROR NetShareEnum_r(struct libnetapi_ctx *ctx,
        }
 
  done:
-       if (!cli) {
-               return werr;
-       }
-
        return werr;
 }
 
@@ -407,12 +394,11 @@ WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx,
 {
        WERROR werr;
        NTSTATUS status;
-       struct cli_state *cli = NULL;
        struct rpc_pipe_client *pipe_cli = NULL;
        union srvsvc_NetShareInfo info;
        uint32_t num_entries = 0;
 
-       if (!r->in.net_name) {
+       if (!r->in.net_name || !r->out.buffer) {
                return WERR_INVALID_PARAM;
        }
 
@@ -432,7 +418,6 @@ WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx,
 
        werr = libnetapi_open_pipe(ctx, r->in.server_name,
                                   &ndr_table_srvsvc.syntax_id,
-                                  &cli,
                                   &pipe_cli);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
@@ -459,10 +444,6 @@ WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx,
        }
 
  done:
-       if (!cli) {
-               return werr;
-       }
-
        return werr;
 }
 
@@ -481,7 +462,59 @@ WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx,
 WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx,
                         struct NetShareSetInfo *r)
 {
-       return WERR_NOT_SUPPORTED;
+       WERROR werr;
+       NTSTATUS status;
+       struct rpc_pipe_client *pipe_cli = NULL;
+       union srvsvc_NetShareInfo info;
+
+       if (!r->in.buffer) {
+               return WERR_INVALID_PARAM;
+       }
+
+       switch (r->in.level) {
+               case 2:
+               case 1004:
+                       break;
+               case 1:
+               case 502:
+               case 503:
+               case 1005:
+               case 1006:
+               case 1501:
+                       return WERR_NOT_SUPPORTED;
+               default:
+                       return WERR_UNKNOWN_LEVEL;
+       }
+
+       werr = libnetapi_open_pipe(ctx, r->in.server_name,
+                                  &ndr_table_srvsvc.syntax_id,
+                                  &pipe_cli);
+       if (!W_ERROR_IS_OK(werr)) {
+               goto done;
+       }
+
+       status = map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx,
+                                                           r->in.buffer,
+                                                           r->in.level,
+                                                           &info);
+       if (!NT_STATUS_IS_OK(status)) {
+               werr = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       status = rpccli_srvsvc_NetShareSetInfo(pipe_cli, ctx,
+                                              r->in.server_name,
+                                              r->in.net_name,
+                                              r->in.level,
+                                              &info,
+                                              r->out.parm_err,
+                                              &werr);
+       if (!W_ERROR_IS_OK(werr)) {
+               goto done;
+       }
+
+ done:
+       return werr;
 }
 
 /****************************************************************