The branch, master has been updated
       via  8fdb499497f8d4f4a1ca93ffc94de8b57c2c1568 (commit)
       via  80f0d819fb85bdfbd85e910fccc62e778bea3a83 (commit)
       via  1ddc4829aec61d952aaf3185cc56d53d4a9b5c3c (commit)
       via  8fd3c8902c5e953a0ddf184b08f9e37f954ee12e (commit)
       via  3a2c748cf4626266899103aa719ea6ac2eae3a9f (commit)
       via  e272acf4848b6c5944acc685b0738e520b3039fb (commit)
      from  0a5d99ae7ddc6531895a8c34a922d17515f609bc (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 8fdb499497f8d4f4a1ca93ffc94de8b57c2c1568
Author: Günther Deschner <[email protected]>
Date:   Wed May 13 16:38:26 2009 +0200

    s3-netapi: implement NetShutdownInit_r and NetShutdownAbort_r.
    
    Guenther

commit 80f0d819fb85bdfbd85e910fccc62e778bea3a83
Author: Günther Deschner <[email protected]>
Date:   Wed May 13 16:38:00 2009 +0200

    s3-netapi: add example code for NetShutdownInit and NetShutdownAbort.
    
    Guenther

commit 1ddc4829aec61d952aaf3185cc56d53d4a9b5c3c
Author: Günther Deschner <[email protected]>
Date:   Wed May 13 16:35:45 2009 +0200

    s3-netapi: add NetShutdownInit and NetShutdownAbort to public API.
    
    Guenther

commit 8fd3c8902c5e953a0ddf184b08f9e37f954ee12e
Author: Günther Deschner <[email protected]>
Date:   Wed May 13 16:27:58 2009 +0200

    s3-netapi: add NetShutdownInit and NetShutdownAbort skeletons.
    
    Guenther

commit 3a2c748cf4626266899103aa719ea6ac2eae3a9f
Author: Günther Deschner <[email protected]>
Date:   Wed May 13 16:17:36 2009 +0200

    s3-build: re-run make samba3-idl.
    
    Guenther

commit e272acf4848b6c5944acc685b0738e520b3039fb
Author: Günther Deschner <[email protected]>
Date:   Wed May 13 16:16:33 2009 +0200

    s3-netapi: add NetShutdownInit and NetShutdownAbort.
    
    I know, they don't exist as such calls on windows but having them in
    libnetapi.so would be very handy.
    
    Guenther

-----------------------------------------------------------------------

Summary of changes:
 source3/Makefile.in                                |    3 +-
 source3/lib/netapi/examples/Makefile.in            |   14 +++-
 .../lib/netapi/examples/shutdown/shutdown_abort.c  |   76 ++++++++++++++
 .../lib/netapi/examples/shutdown/shutdown_init.c   |   94 +++++++++++++++++
 source3/lib/netapi/libnetapi.c                     |   88 ++++++++++++++++
 source3/lib/netapi/libnetapi.h                     |   14 +++
 source3/lib/netapi/netapi.h                        |   36 +++++++
 source3/lib/netapi/shutdown.c                      |  108 ++++++++++++++++++++
 source3/librpc/gen_ndr/libnetapi.h                 |   30 ++++++
 source3/librpc/gen_ndr/ndr_libnetapi.c             |   50 +++++++++
 source3/librpc/gen_ndr/ndr_libnetapi.h             |   12 ++-
 source3/librpc/idl/libnetapi.idl                   |   21 ++++
 12 files changed, 543 insertions(+), 3 deletions(-)
 create mode 100644 source3/lib/netapi/examples/shutdown/shutdown_abort.c
 create mode 100644 source3/lib/netapi/examples/shutdown/shutdown_init.c
 create mode 100644 source3/lib/netapi/shutdown.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index 190560a..1e6f681 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -2035,7 +2035,8 @@ LIBNETAPI_OBJ0 = lib/netapi/netapi.o \
                 lib/netapi/samr.o \
                 lib/netapi/sid.o \
                 lib/netapi/share.o \
-                lib/netapi/file.o
+                lib/netapi/file.o \
+                lib/netapi/shutdown.o
 
 LIBNETAPI_OBJ  = $(LIBNETAPI_OBJ0) $(LIBNET_OBJ) \
                 $(LIBSMBCONF_OBJ) \
diff --git a/source3/lib/netapi/examples/Makefile.in 
b/source3/lib/netapi/examples/Makefile.in
index 090bc50..5adedac 100644
--- a/source3/lib/netapi/examples/Makefile.in
+++ b/source3/lib/netapi/examples/Makefile.in
@@ -62,7 +62,9 @@ PROGS = bin/ge...@exeext@ \
        bin/share_seti...@exeext@ \
        bin/file_cl...@exeext@ \
        bin/file_geti...@exeext@ \
-       bin/file_e...@exeext@
+       bin/file_e...@exeext@ \
+       bin/shutdown_i...@exeext@ \
+       bin/shutdown_ab...@exeext@
 
 all: $(PROGS)
 
@@ -137,6 +139,8 @@ SHARESETINFO_OBJ = share/share_setinfo.o $(CMDLINE_OBJ)
 FILECLOSE_OBJ = file/file_close.o $(CMDLINE_OBJ)
 FILEGETINFO_OBJ = file/file_getinfo.o $(CMDLINE_OBJ)
 FILEENUM_OBJ = file/file_enum.o $(CMDLINE_OBJ)
+SHUTDOWNINIT_OBJ = shutdown/shutdown_init.o $(CMDLINE_OBJ)
+SHUTDOWNABORT_OBJ = shutdown/shutdown_abort.o $(CMDLINE_OBJ)
 
 bin/ge...@exeext@: $(BINARY_PREREQS) $(GETDC_OBJ)
        @echo Linking $@
@@ -322,6 +326,14 @@ bin/file_e...@exeext@: $(BINARY_PREREQS) $(FILEENUM_OBJ)
        @echo Linking $@
        @$(CC) $(CCFLAGS) -o $@ $(FILEENUM_OBJ) $(LDFLAGS) $(DYNEXP) 
$(CMDLINE_LIBS)
 
+bin/shutdown_i...@exeext@: $(BINARY_PREREQS) $(SHUTDOWNINIT_OBJ)
+       @echo Linking $@
+       @$(CC) $(CCFLAGS) -o $@ $(SHUTDOWNINIT_OBJ) $(LDFLAGS) $(DYNEXP) 
$(CMDLINE_LIBS)
+
+bin/shutdown_ab...@exeext@: $(BINARY_PREREQS) $(SHUTDOWNABORT_OBJ)
+       @echo Linking $@
+       @$(CC) $(CCFLAGS) -o $@ $(SHUTDOWNABORT_OBJ) $(LDFLAGS) $(DYNEXP) 
$(CMDLINE_LIBS)
+
 clean:
        -rm -f $(PROGS)
        -rm -f core */*~ *~ \
diff --git a/source3/lib/netapi/examples/shutdown/shutdown_abort.c 
b/source3/lib/netapi/examples/shutdown/shutdown_abort.c
new file mode 100644
index 0000000..8f24a7a
--- /dev/null
+++ b/source3/lib/netapi/examples/shutdown/shutdown_abort.c
@@ -0,0 +1,76 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  NetShutdownAbort query
+ *  Copyright (C) Guenther Deschner 2009
+ *
+ *  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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <netapi.h>
+
+#include "common.h"
+
+int main(int argc, const char **argv)
+{
+       NET_API_STATUS status;
+       struct libnetapi_ctx *ctx = NULL;
+       const char *hostname = NULL;
+
+       poptContext pc;
+       int opt;
+
+       struct poptOption long_options[] = {
+               POPT_AUTOHELP
+               POPT_COMMON_LIBNETAPI_EXAMPLES
+               POPT_TABLEEND
+       };
+
+       status = libnetapi_init(&ctx);
+       if (status != 0) {
+               return status;
+       }
+
+       pc = poptGetContext("shutdown_abort", argc, argv, long_options, 0);
+
+       poptSetOtherOptionHelp(pc, "hostname");
+       while((opt = poptGetNextOpt(pc)) != -1) {
+       }
+
+       if (!poptPeekArg(pc)) {
+               poptPrintHelp(pc, stderr, 0);
+               goto out;
+       }
+       hostname = poptGetArg(pc);
+
+       /* NetShutdownAbort */
+
+       status = NetShutdownAbort(hostname);
+       if (status != 0) {
+               printf("NetShutdownAbort failed with: %s\n",
+                       libnetapi_get_error_string(ctx, status));
+               goto out;
+       }
+
+ out:
+       libnetapi_free(ctx);
+       poptFreeContext(pc);
+
+       return status;
+}
diff --git a/source3/lib/netapi/examples/shutdown/shutdown_init.c 
b/source3/lib/netapi/examples/shutdown/shutdown_init.c
new file mode 100644
index 0000000..73d23bb
--- /dev/null
+++ b/source3/lib/netapi/examples/shutdown/shutdown_init.c
@@ -0,0 +1,94 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  NetShutdownInit query
+ *  Copyright (C) Guenther Deschner 2009
+ *
+ *  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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <netapi.h>
+
+#include "common.h"
+
+int main(int argc, const char **argv)
+{
+       NET_API_STATUS status;
+       struct libnetapi_ctx *ctx = NULL;
+       const char *hostname = NULL;
+       const char *message = NULL;
+       uint32_t timeout = 30;
+
+       poptContext pc;
+       int opt;
+
+       struct poptOption long_options[] = {
+               POPT_AUTOHELP
+               POPT_COMMON_LIBNETAPI_EXAMPLES
+               POPT_TABLEEND
+       };
+
+       status = libnetapi_init(&ctx);
+       if (status != 0) {
+               return status;
+       }
+
+       pc = poptGetContext("shutdown_init", argc, argv, long_options, 0);
+
+       poptSetOtherOptionHelp(pc, "hostname message timeout");
+       while((opt = poptGetNextOpt(pc)) != -1) {
+       }
+
+       if (!poptPeekArg(pc)) {
+               poptPrintHelp(pc, stderr, 0);
+               goto out;
+       }
+       hostname = poptGetArg(pc);
+
+       if (!poptPeekArg(pc)) {
+               poptPrintHelp(pc, stderr, 0);
+               goto out;
+       }
+       message = poptGetArg(pc);
+
+       if (!poptPeekArg(pc)) {
+               poptPrintHelp(pc, stderr, 0);
+               goto out;
+       }
+       timeout = atoi(poptGetArg(pc));
+
+       /* NetShutdownInit */
+
+       status = NetShutdownInit(hostname,
+                                message,
+                                timeout,
+                                1, /* close apps */
+                                1); /* reboot */
+       if (status != 0) {
+               printf("NetShutdownInit failed with: %s\n",
+                       libnetapi_get_error_string(ctx, status));
+               goto out;
+       }
+
+ out:
+       libnetapi_free(ctx);
+       poptFreeContext(pc);
+
+       return status;
+}
diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c
index 043190a..6e36667 100644
--- a/source3/lib/netapi/libnetapi.c
+++ b/source3/lib/netapi/libnetapi.c
@@ -2353,3 +2353,91 @@ NET_API_STATUS NetFileEnum(const char * server_name /* 
[in] */,
        return r.out.result;
 }
 
+/****************************************************************
+ NetShutdownInit
+****************************************************************/
+
+NET_API_STATUS NetShutdownInit(const char * server_name /* [in] */,
+                              const char * message /* [in] */,
+                              uint32_t timeout /* [in] */,
+                              uint8_t force_apps /* [in] */,
+                              uint8_t do_reboot /* [in] */)
+{
+       struct NetShutdownInit r;
+       struct libnetapi_ctx *ctx = NULL;
+       NET_API_STATUS status;
+       WERROR werr;
+
+       status = libnetapi_getctx(&ctx);
+       if (status != 0) {
+               return status;
+       }
+
+       /* In parameters */
+       r.in.server_name = server_name;
+       r.in.message = message;
+       r.in.timeout = timeout;
+       r.in.force_apps = force_apps;
+       r.in.do_reboot = do_reboot;
+
+       /* Out parameters */
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(NetShutdownInit, &r);
+       }
+
+       if (LIBNETAPI_LOCAL_SERVER(server_name)) {
+               werr = NetShutdownInit_l(ctx, &r);
+       } else {
+               werr = NetShutdownInit_r(ctx, &r);
+       }
+
+       r.out.result = W_ERROR_V(werr);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(NetShutdownInit, &r);
+       }
+
+       return r.out.result;
+}
+
+/****************************************************************
+ NetShutdownAbort
+****************************************************************/
+
+NET_API_STATUS NetShutdownAbort(const char * server_name /* [in] */)
+{
+       struct NetShutdownAbort r;
+       struct libnetapi_ctx *ctx = NULL;
+       NET_API_STATUS status;
+       WERROR werr;
+
+       status = libnetapi_getctx(&ctx);
+       if (status != 0) {
+               return status;
+       }
+
+       /* In parameters */
+       r.in.server_name = server_name;
+
+       /* Out parameters */
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(NetShutdownAbort, &r);
+       }
+
+       if (LIBNETAPI_LOCAL_SERVER(server_name)) {
+               werr = NetShutdownAbort_l(ctx, &r);
+       } else {
+               werr = NetShutdownAbort_r(ctx, &r);
+       }
+
+       r.out.result = W_ERROR_V(werr);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(NetShutdownAbort, &r);
+       }
+
+       return r.out.result;
+}
+
diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h
index 1b84b75..3eab6e6 100644
--- a/source3/lib/netapi/libnetapi.h
+++ b/source3/lib/netapi/libnetapi.h
@@ -426,4 +426,18 @@ WERROR NetFileEnum_r(struct libnetapi_ctx *ctx,
                     struct NetFileEnum *r);
 WERROR NetFileEnum_l(struct libnetapi_ctx *ctx,
                     struct NetFileEnum *r);
+NET_API_STATUS NetShutdownInit(const char * server_name /* [in] */,
+                              const char * message /* [in] */,
+                              uint32_t timeout /* [in] */,
+                              uint8_t force_apps /* [in] */,
+                              uint8_t do_reboot /* [in] */);
+WERROR NetShutdownInit_r(struct libnetapi_ctx *ctx,
+                        struct NetShutdownInit *r);
+WERROR NetShutdownInit_l(struct libnetapi_ctx *ctx,
+                        struct NetShutdownInit *r);
+NET_API_STATUS NetShutdownAbort(const char * server_name /* [in] */);
+WERROR NetShutdownAbort_r(struct libnetapi_ctx *ctx,
+                         struct NetShutdownAbort *r);
+WERROR NetShutdownAbort_l(struct libnetapi_ctx *ctx,
+                         struct NetShutdownAbort *r);
 #endif /* __LIBNETAPI_LIBNETAPI__ */
diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h
index e8cd71e..e3ab03e 100644
--- a/source3/lib/netapi/netapi.h
+++ b/source3/lib/netapi/netapi.h
@@ -2445,6 +2445,42 @@ NET_API_STATUS NetFileEnum(const char * server_name /* 
[in] */,
                           uint32_t *total_entries /* [out] [ref] */,
                           uint32_t *resume_handle /* [in,out] [ref] */);
 
+/************************************************************//**
+ *
+ * NetShutdownInit
+ *
+ * @brief Start a machine shutdown
+ *
+ * @param[in] server_name The server name to connect to
+ * @param[in] message The message that is displayed before the shutdown
+ * @param[in] timeout The amount of seconds to wait until shutting down
+ * @param[in] force_apps Whether to close all applications before the shutdown
+ * @param[in] do_reboot Whether to reboot after the shutdown
+ * @return NET_API_STATUS
+ *
+ * example shutdown/shutdown_init.c
+ ***************************************************************/
+
+NET_API_STATUS NetShutdownInit(const char * server_name /* [in] */,
+                              const char * message /* [in] */,
+                              uint32_t timeout /* [in] */,
+                              uint8_t force_apps /* [in] */,
+                              uint8_t do_reboot /* [in] */);
+
+/************************************************************//**
+ *
+ * NetShutdownAbort
+ *
+ * @brief Abort an initiated machine shutdown
+ *
+ * @param[in] server_name The server name to connect to
+ * @return NET_API_STATUS
+ *
+ * example shutdown/shutdown_abort.c
+ ***************************************************************/
+
+NET_API_STATUS NetShutdownAbort(const char * server_name /* [in] */);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/source3/lib/netapi/shutdown.c b/source3/lib/netapi/shutdown.c
new file mode 100644
index 0000000..f9eb93b
--- /dev/null
+++ b/source3/lib/netapi/shutdown.c
@@ -0,0 +1,108 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  NetApi Shutdown Support
+ *  Copyright (C) Guenther Deschner 2009
+ *
+ *  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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+
+#include "librpc/gen_ndr/libnetapi.h"
+#include "lib/netapi/netapi.h"
+#include "lib/netapi/netapi_private.h"
+#include "lib/netapi/libnetapi.h"
+
+/****************************************************************
+****************************************************************/
+
+WERROR NetShutdownInit_r(struct libnetapi_ctx *ctx,
+                        struct NetShutdownInit *r)
+{
+       WERROR werr;
+       NTSTATUS status;
+       struct rpc_pipe_client *pipe_cli = NULL;
+       struct lsa_StringLarge message;
+
+       werr = libnetapi_open_pipe(ctx, r->in.server_name,
+                                  &ndr_table_initshutdown.syntax_id,
+                                  &pipe_cli);
+       if (!W_ERROR_IS_OK(werr)) {
+               goto done;
+       }
+
+       init_lsa_StringLarge(&message, r->in.message);
+
+       status = rpccli_initshutdown_Init(pipe_cli, ctx,
+                                         NULL,
+                                         &message,
+                                         r->in.timeout,
+                                         r->in.force_apps,
+                                         r->in.do_reboot,
+                                         &werr);
+       if (!NT_STATUS_IS_OK(status)) {
+               werr = ntstatus_to_werror(status);
+               goto done;
+       }
+
+ done:
+       return werr;
+}
+
+/****************************************************************
+****************************************************************/
+
+WERROR NetShutdownInit_l(struct libnetapi_ctx *ctx,
+                        struct NetShutdownInit *r)
+{
+       LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShutdownInit);
+}
+
+/****************************************************************
+****************************************************************/
+
+WERROR NetShutdownAbort_r(struct libnetapi_ctx *ctx,
+                         struct NetShutdownAbort *r)
+{
+       WERROR werr;
+       NTSTATUS status;
+       struct rpc_pipe_client *pipe_cli = NULL;
+
+       werr = libnetapi_open_pipe(ctx, r->in.server_name,
+                                  &ndr_table_initshutdown.syntax_id,
+                                  &pipe_cli);
+       if (!W_ERROR_IS_OK(werr)) {
+               goto done;
+       }
+
+       status = rpccli_initshutdown_Abort(pipe_cli, ctx,
+                                          NULL,
+                                          &werr);
+       if (!NT_STATUS_IS_OK(status)) {
+               werr = ntstatus_to_werror(status);


-- 
Samba Shared Repository

Reply via email to