Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

shutdown.c File Reference

#include "libmsrpc.h"
#include "test_util.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)


Function Documentation

int main int  argc,
char **  argv
 

Definition at line 7 of file shutdown.c.

References _CACSERVERHANDLE::_internal, cac_AbortShutdown(), cac_Connect(), cac_FreeHandle(), cac_NewServerHandle(), cac_parse_cmd_line(), cac_SetAuthDataFn(), cac_Shutdown(), cactest_GetAuthDataFn(), cactest_readline(), False, fprintf(), Shutdown::in, nt_errstr(), printf(), _CACSERVERHANDLE::server, CacServerHandleInternal::srv_level, SRV_WIN_NT4, _CACSERVERHANDLE::status, talloc_destroy, talloc_init(), talloc_strdup(), True, and ZERO_STRUCT.

00007                                 {
00008    CacServerHandle *hnd = NULL;
00009    TALLOC_CTX *mem_ctx  = NULL;
00010 
00011    fstring tmp;
00012    
00013    mem_ctx = talloc_init("cac_shutdown");
00014 
00015    hnd = cac_NewServerHandle(True);
00016 
00017    cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
00018 
00019    cac_parse_cmd_line(argc, argv, hnd);
00020 
00021    hnd->_internal.srv_level = SRV_WIN_NT4;
00022 
00023    if(!cac_Connect(hnd, NULL)) {
00024       fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
00025       exit(-1);
00026    }
00027 
00028    struct Shutdown s;
00029    ZERO_STRUCT(s);
00030 
00031    printf("Message: ");
00032    cactest_readline(stdin, tmp);
00033 
00034    s.in.message = talloc_strdup(mem_ctx, tmp);
00035 
00036    printf("timeout: ");
00037    scanf("%d", &s.in.timeout);
00038 
00039    printf("Reboot? [y/n]: ");
00040    cactest_readline(stdin, tmp);
00041 
00042    s.in.reboot = ( tmp[0] == 'y') ? True : False;
00043 
00044    printf("Force? [y/n]: ");
00045    cactest_readline(stdin, tmp);
00046 
00047    s.in.force = (tmp[0] == 'y') ? True : False;
00048 
00049    if(!cac_Shutdown(hnd, mem_ctx, &s)) {
00050       fprintf(stderr, "could not shut down server: error %s\n", nt_errstr(hnd->status));
00051       goto done;
00052    }
00053 
00054    printf("Server %s is shutting down. Would you like to try to abort? [y/n]: ", hnd->server);
00055    fscanf(stdin, "%s", tmp);
00056 
00057    if(tmp[0] == 'y') {
00058       if(!cac_AbortShutdown(hnd, mem_ctx)) {
00059          fprintf(stderr, "Could not abort shutdown. Error %s\n", nt_errstr(hnd->status));
00060       }
00061    }
00062 
00063 done:
00064    cac_FreeHandle(hnd);
00065    talloc_destroy(mem_ctx);
00066 
00067    return 0;
00068 }


© sourcejam.com 2005-2008