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

enable.c

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

© sourcejam.com 2005-2008