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

disable.c

Go to the documentation of this file.
00001 /*disable a user*/
00002 #include "libmsrpc.h"
00003 #include "test_util.h"
00004 
00005 int main(int argc, char **argv) {
00006    CacServerHandle *hnd = NULL;
00007    TALLOC_CTX *mem_ctx = NULL;
00008 
00009    struct SamOpenUser ou;
00010 
00011    fstring tmp;
00012 
00013    mem_ctx = talloc_init("cac_disable");
00014 
00015    hnd = cac_NewServerHandle(True);
00016 
00017    cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
00018 
00019    cac_parse_cmd_line(argc, argv, hnd);
00020 
00021    if(!cac_Connect(hnd, NULL)) {
00022       fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
00023       exit(-1);
00024    }
00025 
00026    struct SamOpenDomain sod;
00027    ZERO_STRUCT(sod);
00028 
00029    sod.in.access = MAXIMUM_ALLOWED_ACCESS; 
00030 
00031    if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) {
00032       fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status));
00033       goto done;
00034    }
00035 
00036    ZERO_STRUCT(ou);
00037    printf("Enter username: ");
00038    cactest_readline(stdin, tmp);
00039 
00040    ou.in.name = talloc_strdup(mem_ctx, tmp);
00041    ou.in.access = MAXIMUM_ALLOWED_ACCESS;
00042    ou.in.dom_hnd = sod.out.dom_hnd;
00043 
00044    if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) {
00045       fprintf(stderr, "Could not open user. Error: %s\n", nt_errstr(hnd->status));
00046       goto done;
00047    }
00048 
00049    /*enable the user*/
00050    if(!cac_SamDisableUser(hnd, mem_ctx, ou.out.user_hnd)) {
00051       fprintf(stderr, "Could not disable user: %s\n", nt_errstr(hnd->status));
00052    }
00053 
00054 done:
00055    cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
00056 
00057    cac_FreeHandle(hnd);
00058 
00059    talloc_destroy(mem_ctx);
00060    
00061    return 0;
00062 }
00063 

© sourcejam.com 2005-2008