Restructure inner workings of libnetapi a bit.
[samba.git] / source / lib / netapi / serverinfo.c
index a9749a12f96f6f98b4551c5a7faf6e24621ec2f4..e2a458cdc1835f52b655f1677363a7c62ea489a9 100644 (file)
 
 #include "includes.h"
 
+#include "librpc/gen_ndr/libnetapi.h"
 #include "lib/netapi/netapi.h"
+#include "lib/netapi/libnetapi.h"
 #include "libnet/libnet.h"
 
 /****************************************************************
 ****************************************************************/
 
-static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx,
-                                        uint8_t **buffer)
+static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx,
+                                     uint8_t **buffer)
 {
        struct srvsvc_NetSrvInfo1005 info1005;
 
@@ -42,14 +44,12 @@ static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx,
 /****************************************************************
 ****************************************************************/
 
-static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx,
-                                   const char *server_name,
-                                   uint32_t level,
-                                   uint8_t **buffer)
+WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx,
+                         struct NetServerGetInfo *r)
 {
-       switch (level) {
+       switch (r->in.level) {
                case 1005:
-                       return NetServerGetInfoLocal_1005(ctx, buffer);
+                       return NetServerGetInfo_l_1005(ctx, r->out.buffer);
                default:
                        return WERR_UNKNOWN_LEVEL;
        }
@@ -60,10 +60,8 @@ static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx,
 /****************************************************************
 ****************************************************************/
 
-static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx,
-                                    const char *server_name,
-                                    uint32_t level,
-                                    uint8_t **buffer)
+WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
+                         struct NetServerGetInfo *r)
 {
        struct cli_state *cli = NULL;
        struct rpc_pipe_client *pipe_cli = NULL;
@@ -71,7 +69,7 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx,
        WERROR werr;
        union srvsvc_NetSrvInfo info;
 
-       status = cli_full_connection(&cli, NULL, server_name,
+       status = cli_full_connection(&cli, NULL, r->in.server_name,
                                     NULL, 0,
                                     "IPC$", "IPC",
                                     ctx->username,
@@ -92,8 +90,8 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx,
        };
 
        status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
-                                            server_name,
-                                            level,
+                                            r->in.server_name,
+                                            r->in.level,
                                             &info,
                                             &werr);
        if (!NT_STATUS_IS_OK(status)) {
@@ -101,7 +99,11 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx,
                goto done;
        }
 
-       *buffer = (uint8_t *)&info;
+       *r->out.buffer = talloc_memdup(ctx, &info, sizeof(info));
+       if (!*r->out.buffer) {
+               werr = WERR_NOMEM;
+               goto done;
+       }
 
  done:
        if (cli) {
@@ -114,73 +116,22 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx,
 /****************************************************************
 ****************************************************************/
 
-static WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx,
-                                        const char *server_name,
-                                        uint32_t level,
-                                        uint8_t **buffer)
-{
-       if (!server_name || is_myname_or_ipaddr(server_name)) {
-               return NetServerGetInfoLocal(ctx,
-                                            server_name,
-                                            level,
-                                            buffer);
-       }
-
-       return NetServerGetInfoRemote(ctx,
-                                     server_name,
-                                     level,
-                                     buffer);
-
-}
-
-/****************************************************************
- NetServerGetInfo
-****************************************************************/
-
-NET_API_STATUS NetServerGetInfo(const char *server_name,
-                               uint32_t level,
-                               uint8_t **buffer)
-{
-       struct libnetapi_ctx *ctx = NULL;
-       NET_API_STATUS status;
-       WERROR werr;
-
-       status = libnetapi_getctx(&ctx);
-       if (status != 0) {
-               return status;
-       }
-
-       werr = libnetapi_NetServerGetInfo(ctx,
-                                         server_name,
-                                         level,
-                                         buffer);
-       if (!W_ERROR_IS_OK(werr)) {
-               return W_ERROR_V(werr);
-       }
-
-       return NET_API_STATUS_SUCCESS;
-}
-
-/****************************************************************
-****************************************************************/
-
-static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx,
-                                        uint8_t *buffer,
-                                        uint32_t *parm_error)
+static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
+                                     struct NetServerSetInfo *r)
 {
        WERROR werr;
        struct smbconf_ctx *conf_ctx;
        struct srvsvc_NetSrvInfo1005 *info1005;
 
-       if (!buffer) {
-               *parm_error = 1005; /* sure here ? */
+       if (!r->in.buffer) {
+               *r->out.parm_error = 1005; /* sure here ? */
                return WERR_INVALID_PARAM;
        }
 
-       info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
+       info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
 
        if (!info1005->comment) {
-               *parm_error = 1005;
+               *r->out.parm_error = 1005;
                return WERR_INVALID_PARAM;
        }
 
@@ -207,15 +158,12 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx,
 /****************************************************************
 ****************************************************************/
 
-static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx,
-                                   const char *server_name,
-                                   uint32_t level,
-                                   uint8_t *buffer,
-                                   uint32_t *parm_error)
+WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
+                         struct NetServerSetInfo *r)
 {
-       switch (level) {
+       switch (r->in.level) {
                case 1005:
-                       return NetServerSetInfoLocal_1005(ctx, buffer, parm_error);
+                       return NetServerSetInfo_l_1005(ctx, r);
                default:
                        return WERR_UNKNOWN_LEVEL;
        }
@@ -226,11 +174,8 @@ static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx,
 /****************************************************************
 ****************************************************************/
 
-static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
-                                    const char *server_name,
-                                    uint32_t level,
-                                    uint8_t *buffer,
-                                    uint32_t *parm_error)
+WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
+                         struct NetServerSetInfo *r)
 {
        struct cli_state *cli = NULL;
        struct rpc_pipe_client *pipe_cli = NULL;
@@ -238,7 +183,7 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
        WERROR werr;
        union srvsvc_NetSrvInfo info;
 
-       status = cli_full_connection(&cli, NULL, server_name,
+       status = cli_full_connection(&cli, NULL, r->in.server_name,
                                     NULL, 0,
                                     "IPC$", "IPC",
                                     ctx->username,
@@ -258,9 +203,9 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
                goto done;
        };
 
-       switch (level) {
+       switch (r->in.level) {
                case 1005:
-                       info.info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
+                       info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
                        break;
                default:
                        werr = WERR_NOT_SUPPORTED;
@@ -268,10 +213,10 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
        }
 
        status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
-                                            server_name,
-                                            level,
+                                            r->in.server_name,
+                                            r->in.level,
                                             &info,
-                                            parm_error,
+                                            r->out.parm_error,
                                             &werr);
        if (!NT_STATUS_IS_OK(status)) {
                werr = ntstatus_to_werror(status);
@@ -285,57 +230,3 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
 
        return werr;
 }
-
-/****************************************************************
-****************************************************************/
-
-static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx,
-                                        const char *server_name,
-                                        uint32_t level,
-                                        uint8_t *buffer,
-                                        uint32_t *parm_error)
-{
-       if (!server_name || is_myname_or_ipaddr(server_name)) {
-               return NetServerSetInfoLocal(ctx,
-                                            server_name,
-                                            level,
-                                            buffer,
-                                            parm_error);
-       }
-
-       return NetServerSetInfoRemote(ctx,
-                                     server_name,
-                                     level,
-                                     buffer,
-                                     parm_error);
-}
-
-/****************************************************************
- NetServerSetInfo
-****************************************************************/
-
-NET_API_STATUS NetServerSetInfo(const char *server_name,
-                               uint32_t level,
-                               uint8_t *buffer,
-                               uint32_t *parm_error)
-{
-       struct libnetapi_ctx *ctx = NULL;
-       NET_API_STATUS status;
-       WERROR werr;
-
-       status = libnetapi_getctx(&ctx);
-       if (status != 0) {
-               return status;
-       }
-
-       werr = libnetapi_NetServerSetInfo(ctx,
-                                         server_name,
-                                         level,
-                                         buffer,
-                                         parm_error);
-       if (!W_ERROR_IS_OK(werr)) {
-               return W_ERROR_V(werr);
-       }
-
-       return NET_API_STATUS_SUCCESS;
-}