r10003: in the rush for 10k, I forgot to run add the rest of Chris' libmsrpc files
[sfrench/samba-autobuild/.git] / examples / libmsrpc / test / sam / disable.c
1 /*disable a user*/
2 #include "libmsrpc.h"
3 #include "test_util.h"
4
5 int main(int argc, char **argv) {
6    CacServerHandle *hnd = NULL;
7    TALLOC_CTX *mem_ctx = NULL;
8
9    struct SamOpenUser ou;
10
11    fstring tmp;
12
13    mem_ctx = talloc_init("cac_disable");
14
15    hnd = cac_NewServerHandle(True);
16
17    cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
18
19    cac_parse_cmd_line(argc, argv, hnd);
20
21    if(!cac_Connect(hnd, NULL)) {
22       fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
23       exit(-1);
24    }
25
26    struct SamOpenDomain sod;
27    ZERO_STRUCT(sod);
28
29    sod.in.access = MAXIMUM_ALLOWED_ACCESS; 
30
31    if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) {
32       fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status));
33       goto done;
34    }
35
36    ZERO_STRUCT(ou);
37    printf("Enter username: ");
38    cactest_readline(stdin, tmp);
39
40    ou.in.name = talloc_strdup(mem_ctx, tmp);
41    ou.in.access = MAXIMUM_ALLOWED_ACCESS;
42    ou.in.dom_hnd = sod.out.dom_hnd;
43
44    if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) {
45       fprintf(stderr, "Could not open user. Error: %s\n", nt_errstr(hnd->status));
46       goto done;
47    }
48
49    /*enable the user*/
50    if(!cac_SamDisableUser(hnd, mem_ctx, ou.out.user_hnd)) {
51       fprintf(stderr, "Could not disable user: %s\n", nt_errstr(hnd->status));
52    }
53
54 done:
55    cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
56
57    cac_FreeHandle(hnd);
58
59    talloc_destroy(mem_ctx);
60    
61    return 0;
62 }
63