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