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

regdelete.c File Reference

#include "libmsrpc.h"
#include "test_util.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)


Function Documentation

int main int  argc,
char **  argv
 

Definition at line 6 of file regdelete.c.

References cac_Connect(), cac_FreeHandle(), cac_NewServerHandle(), cac_parse_cmd_line(), cac_RegClose(), cac_RegDeleteKey(), cac_RegDeleteValue(), cac_RegGetVersion(), cac_RegOpenKey(), cac_SetAuthDataFn(), cactest_GetAuthDataFn(), cactest_readline(), False, fprintf(), RegDeleteKey::in, RegDeleteValue::in, RegGetVersion::in, RegOpenKey::in, nt_errstr(), RegGetVersion::out, RegOpenKey::out, printf(), REG_KEY_ALL, _CACSERVERHANDLE::server, _CACSERVERHANDLE::status, talloc_destroy, talloc_init(), talloc_strdup(), True, and ZERO_STRUCT.

00006                                 {
00007    CacServerHandle *hnd = NULL;
00008    TALLOC_CTX *mem_ctx  = NULL;
00009 
00010    fstring tmp;
00011    char input = 'v';
00012    
00013    mem_ctx = talloc_init("regdelete");
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    printf("enter key to open: \n");
00027    cactest_readline(stdin, tmp);
00028 
00029    struct RegOpenKey rok;
00030    ZERO_STRUCT(rok);
00031 
00032    rok.in.name = talloc_strdup(mem_ctx, tmp);
00033    rok.in.access = REG_KEY_ALL;
00034 
00035    if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
00036       fprintf(stderr, "Could not open key %s. Error %s\n", rok.in.name, nt_errstr(hnd->status));
00037       exit(-1);
00038    }
00039 
00040    printf("getting version (just for testing\n");
00041 
00042    struct RegGetVersion rgv;
00043    ZERO_STRUCT(rgv);
00044 
00045    rgv.in.key = rok.out.key;
00046 
00047    if(!cac_RegGetVersion(hnd, mem_ctx, &rgv))
00048       fprintf(stderr, "Could not get version. Error: %s\n", nt_errstr(hnd->status));
00049    else
00050       printf("Version: %d\n", rgv.out.version);
00051 
00052 
00053    while(input == 'v' || input == 'k') {
00054       printf("Delete [v]alue [k]ey or [q]uit: ");
00055       scanf("%c", &input);
00056 
00057       switch(input) {
00058          case 'v':
00059             printf("Value to delete: ");
00060             cactest_readline(stdin, tmp);
00061             
00062             struct RegDeleteValue rdv;
00063             ZERO_STRUCT(rdv);
00064             
00065             rdv.in.parent_key = rok.out.key;
00066             rdv.in.name   = talloc_strdup(mem_ctx, tmp);
00067 
00068             if(!cac_RegDeleteValue(hnd, mem_ctx, &rdv))
00069                fprintf(stderr, "Could not delete value %s. Error: %s\n", rdv.in.name, nt_errstr(hnd->status));
00070 
00071             break;
00072          case 'k':
00073             printf("Key to delete: ");
00074             cactest_readline(stdin, tmp);
00075             
00076             struct RegDeleteKey rdk;
00077             ZERO_STRUCT(rdk);
00078 
00079             rdk.in.parent_key = rok.out.key;
00080             rdk.in.name   = talloc_strdup(mem_ctx, tmp);
00081 
00082             printf("delete recursively? [y/n]: ");
00083             cactest_readline(stdin, tmp);
00084 
00085             rdk.in.recursive = (tmp[0] == 'y') ? True : False;
00086 
00087             if(!cac_RegDeleteKey(hnd, mem_ctx, &rdk))
00088                fprintf(stderr, "Could not delete key %s. Error %s\n", rdk.in.name, nt_errstr(hnd->status));
00089 
00090             break;
00091       }
00092    }
00093    cac_RegClose(hnd, mem_ctx, rok.out.key);
00094 
00095    cac_FreeHandle(hnd);
00096 
00097    talloc_destroy(mem_ctx);
00098 
00099    return 0;
00100 }


© sourcejam.com 2005-2008