Initial import
[samba] / examples / libmsrpc / test / reg / shutdown.c
1 /*tries to shut down a remote pc*/
2
3 #include "libmsrpc.h"
4 #include "test_util.h"
5
6
7 int main(int argc, char **argv) {
8    CacServerHandle *hnd = NULL;
9    TALLOC_CTX *mem_ctx  = NULL;
10
11    fstring tmp;
12    
13    mem_ctx = talloc_init("cac_shutdown");
14
15    hnd = cac_NewServerHandle(True);
16
17    cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
18
19    cac_parse_cmd_line(argc, argv, hnd);
20
21    hnd->_internal.srv_level = SRV_WIN_NT4;
22
23    if(!cac_Connect(hnd, NULL)) {
24       fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
25       exit(-1);
26    }
27
28    struct Shutdown s;
29    ZERO_STRUCT(s);
30
31    printf("Message: ");
32    cactest_readline(stdin, tmp);
33
34    s.in.message = talloc_strdup(mem_ctx, tmp);
35
36    printf("timeout: ");
37    scanf("%d", &s.in.timeout);
38
39    printf("Reboot? [y/n]: ");
40    cactest_readline(stdin, tmp);
41
42    s.in.reboot = ( tmp[0] == 'y') ? True : False;
43
44    printf("Force? [y/n]: ");
45    cactest_readline(stdin, tmp);
46
47    s.in.force = (tmp[0] == 'y') ? True : False;
48
49    if(!cac_Shutdown(hnd, mem_ctx, &s)) {
50       fprintf(stderr, "could not shut down server: error %s\n", nt_errstr(hnd->status));
51       goto done;
52    }
53
54    printf("Server %s is shutting down. Would you like to try to abort? [y/n]: ", hnd->server);
55    fscanf(stdin, "%s", tmp);
56
57    if(tmp[0] == 'y') {
58       if(!cac_AbortShutdown(hnd, mem_ctx)) {
59          fprintf(stderr, "Could not abort shutdown. Error %s\n", nt_errstr(hnd->status));
60       }
61    }
62
63 done:
64    cac_FreeHandle(hnd);
65    talloc_destroy(mem_ctx);
66
67    return 0;
68 }