diff options
Diffstat (limited to 'examples/libmsrpc/test/sam')
-rw-r--r-- | examples/libmsrpc/test/sam/adduser.c | 92 | ||||
-rw-r--r-- | examples/libmsrpc/test/sam/disable.c | 63 | ||||
-rw-r--r-- | examples/libmsrpc/test/sam/dominfo.c | 55 | ||||
-rw-r--r-- | examples/libmsrpc/test/sam/enable.c | 64 | ||||
-rw-r--r-- | examples/libmsrpc/test/sam/samenum.c | 117 | ||||
-rw-r--r-- | examples/libmsrpc/test/sam/samgroup.c | 480 | ||||
-rw-r--r-- | examples/libmsrpc/test/sam/samlookup.c | 140 | ||||
-rw-r--r-- | examples/libmsrpc/test/sam/samuser.c | 294 |
8 files changed, 0 insertions, 1305 deletions
diff --git a/examples/libmsrpc/test/sam/adduser.c b/examples/libmsrpc/test/sam/adduser.c deleted file mode 100644 index 94482d0704..0000000000 --- a/examples/libmsrpc/test/sam/adduser.c +++ /dev/null @@ -1,92 +0,0 @@ -/*add's a user to a domain*/ -#include "libmsrpc.h" -#include "test_util.h" - -int main(int argc, char **argv) { - CacServerHandle *hnd = NULL; - TALLOC_CTX *mem_ctx = NULL; - - fstring tmp; - - struct SamOpenUser ou; - - POLICY_HND *user_hnd = NULL; - - mem_ctx = talloc_init("cac_adduser"); - - hnd = cac_NewServerHandle(True); - - cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn); - - cac_parse_cmd_line(argc, argv, hnd); - - if(!cac_Connect(hnd, NULL)) { - fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); - exit(-1); - } - - struct SamOpenDomain sod; - ZERO_STRUCT(sod); - - sod.in.access = MAXIMUM_ALLOWED_ACCESS; - - if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { - fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - struct SamCreateUser cdu; - ZERO_STRUCT(cdu); - - printf("Enter account name: "); - cactest_readline(stdin, tmp); - - cdu.in.dom_hnd = sod.out.dom_hnd; - cdu.in.name = talloc_strdup(mem_ctx, tmp); - cdu.in.acb_mask = ACB_NORMAL; - - if(!cac_SamCreateUser(hnd, mem_ctx, &cdu)) { - fprintf(stderr, "Could not create user %s. Error: %s\n", cdu.in.name, nt_errstr(hnd->status)); - } - - printf("would you like to delete this user? [y/n]: "); - cactest_readline(stdin, tmp); - - if(tmp[0] == 'y') { - - if(!cdu.out.user_hnd) { - ZERO_STRUCT(ou); - ou.in.dom_hnd = sod.out.dom_hnd; - ou.in.access = MAXIMUM_ALLOWED_ACCESS; - ou.in.name = talloc_strdup(mem_ctx, cdu.in.name); - - if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) { - fprintf(stderr, "Could not open user for deletion. Error: %s\n", nt_errstr(hnd->status)); - } - - user_hnd = ou.out.user_hnd; - } - - else { - user_hnd = cdu.out.user_hnd; - } - - if(!cac_SamDeleteUser(hnd, mem_ctx, user_hnd)) - fprintf(stderr, "Could not delete user. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Nope..ok\n"); - } - - cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); - cac_SamClose(hnd, mem_ctx, sod.out.sam); - -done: - talloc_destroy(mem_ctx); - - cac_FreeHandle(hnd); - - return 0; -} - -/*TODO: add a function that will create a user and set userinfo and set the password*/ diff --git a/examples/libmsrpc/test/sam/disable.c b/examples/libmsrpc/test/sam/disable.c deleted file mode 100644 index f140bad50b..0000000000 --- a/examples/libmsrpc/test/sam/disable.c +++ /dev/null @@ -1,63 +0,0 @@ -/*disable a user*/ -#include "libmsrpc.h" -#include "test_util.h" - -int main(int argc, char **argv) { - CacServerHandle *hnd = NULL; - TALLOC_CTX *mem_ctx = NULL; - - struct SamOpenUser ou; - - fstring tmp; - - mem_ctx = talloc_init("cac_disable"); - - hnd = cac_NewServerHandle(True); - - cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn); - - cac_parse_cmd_line(argc, argv, hnd); - - if(!cac_Connect(hnd, NULL)) { - fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); - exit(-1); - } - - struct SamOpenDomain sod; - ZERO_STRUCT(sod); - - sod.in.access = MAXIMUM_ALLOWED_ACCESS; - - if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { - fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - ZERO_STRUCT(ou); - printf("Enter username: "); - cactest_readline(stdin, tmp); - - ou.in.name = talloc_strdup(mem_ctx, tmp); - ou.in.access = MAXIMUM_ALLOWED_ACCESS; - ou.in.dom_hnd = sod.out.dom_hnd; - - if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) { - fprintf(stderr, "Could not open user. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - /*enable the user*/ - if(!cac_SamDisableUser(hnd, mem_ctx, ou.out.user_hnd)) { - fprintf(stderr, "Could not disable user: %s\n", nt_errstr(hnd->status)); - } - -done: - cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); - - cac_FreeHandle(hnd); - - talloc_destroy(mem_ctx); - - return 0; -} - diff --git a/examples/libmsrpc/test/sam/dominfo.c b/examples/libmsrpc/test/sam/dominfo.c deleted file mode 100644 index cd2eccefba..0000000000 --- a/examples/libmsrpc/test/sam/dominfo.c +++ /dev/null @@ -1,55 +0,0 @@ -/*gets domain info and prints it out*/ - -#include "libmsrpc.h" -#include "test_util.h" - -int main(int argc, char **argv) { - CacServerHandle *hnd = NULL; - TALLOC_CTX *mem_ctx = NULL; - - mem_ctx = talloc_init("cac_dominfo"); - - hnd = cac_NewServerHandle(True); - - cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn); - - cac_parse_cmd_line(argc, argv, hnd); - - if(!cac_Connect(hnd, NULL)) { - fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); - exit(-1); - } - - struct SamOpenDomain sod; - ZERO_STRUCT(sod); - - sod.in.access = MAXIMUM_ALLOWED_ACCESS; - - if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { - fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - struct SamGetDomainInfo gdi; - ZERO_STRUCT(gdi); - - gdi.in.dom_hnd = sod.out.dom_hnd; - - if(!cac_SamGetDomainInfo(hnd, mem_ctx, &gdi)) { - fprintf(stderr, "Could not get domain info. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - printf("Got domain info:\n"); - print_cac_domain_info(gdi.out.info); - -done: - cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); - - cac_FreeHandle(hnd); - - talloc_destroy(mem_ctx); - - return 0; -} - diff --git a/examples/libmsrpc/test/sam/enable.c b/examples/libmsrpc/test/sam/enable.c deleted file mode 100644 index bb91fb241c..0000000000 --- a/examples/libmsrpc/test/sam/enable.c +++ /dev/null @@ -1,64 +0,0 @@ -/*enable a user*/ - -#include "libmsrpc.h" -#include "test_util.h" - -int main(int argc, char **argv) { - CacServerHandle *hnd = NULL; - TALLOC_CTX *mem_ctx = NULL; - - struct SamOpenUser ou; - - fstring tmp; - - mem_ctx = talloc_init("cac_samgroup"); - - hnd = cac_NewServerHandle(True); - - cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn); - - cac_parse_cmd_line(argc, argv, hnd); - - if(!cac_Connect(hnd, NULL)) { - fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); - exit(-1); - } - - struct SamOpenDomain sod; - ZERO_STRUCT(sod); - - sod.in.access = MAXIMUM_ALLOWED_ACCESS; - - if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { - fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - ZERO_STRUCT(ou); - printf("Enter username: "); - cactest_readline(stdin, tmp); - - ou.in.name = talloc_strdup(mem_ctx, tmp); - ou.in.access = MAXIMUM_ALLOWED_ACCESS; - ou.in.dom_hnd = sod.out.dom_hnd; - - if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) { - fprintf(stderr, "Could not open user. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - /*enable the user*/ - if(!cac_SamEnableUser(hnd, mem_ctx, ou.out.user_hnd)) { - fprintf(stderr, "Could not enable user: %s\n", nt_errstr(hnd->status)); - } - -done: - cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); - - cac_FreeHandle(hnd); - - talloc_destroy(mem_ctx); - - return 0; -} - diff --git a/examples/libmsrpc/test/sam/samenum.c b/examples/libmsrpc/test/sam/samenum.c deleted file mode 100644 index f1b9ebdf84..0000000000 --- a/examples/libmsrpc/test/sam/samenum.c +++ /dev/null @@ -1,117 +0,0 @@ -/*enumerate users/groups/aliases*/ - -#include "libmsrpc.h" -#include "test_util.h" - -int main(int argc, char **argv) { - CacServerHandle *hnd = NULL; - TALLOC_CTX *mem_ctx = NULL; - - - struct SamEnumUsers eu; - struct SamEnumGroups eg; - struct SamEnumAliases ea; - - fstring tmp; - - int i; - - mem_ctx = talloc_init("cac_samenum"); - - hnd = cac_NewServerHandle(True); - - cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn); - - cac_parse_cmd_line(argc, argv, hnd); - - if(!cac_Connect(hnd, NULL)) { - fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); - exit(-1); - } - - struct SamOpenDomain sod; - ZERO_STRUCT(sod); - - sod.in.access = MAXIMUM_ALLOWED_ACCESS; - - if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { - fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - tmp[0] = 0x00; - while(tmp[0] != 'q') { - printf("Enumerate [u]sers, [g]roups or [a]liases or [q]uit: "); - cactest_readline(stdin, tmp); - - switch(tmp[0]) { - case 'u': - ZERO_STRUCT(eu); - - eu.in.dom_hnd = sod.out.dom_hnd; - - printf("ACB mask (can be 0): "); - scanf("%x", &eu.in.acb_mask); - - while(cac_SamEnumUsers(hnd, mem_ctx, &eu)) { - printf("Enumerated %d users:\n", eu.out.num_users); - for(i = 0; i < eu.out.num_users; i++) { - printf(" Name: %s\n", eu.out.names[i]); - printf(" RID: %d\n", eu.out.rids[i]); - } - } - - if(CAC_OP_FAILED(hnd->status)) { - printf("Could not enumerate users. Error: %s\n", nt_errstr(hnd->status)); - } - break; - case 'g': - ZERO_STRUCT(eg); - eg.in.dom_hnd = sod.out.dom_hnd; - - printf("Enumerating groups...\n"); - while(cac_SamEnumGroups(hnd, mem_ctx, &eg)) { - printf("Enumerated %d groups:\n", eg.out.num_groups); - for(i = 0; i < eg.out.num_groups; i++) { - printf("RID: %d\n", eg.out.rids[i]); - printf("Name: %s\n", eg.out.names[i]); - printf("Desc: %s\n", eg.out.descriptions[i]); - } - } - - if(CAC_OP_FAILED(hnd->status)) { - printf("Could not enumerate Groups. Error: %s\n", nt_errstr(hnd->status)); - } - break; - case 'a': - ZERO_STRUCT(ea); - ea.in.dom_hnd = sod.out.dom_hnd; - - printf("Enumerating Aliases...\n"); - while(cac_SamEnumAliases(hnd, mem_ctx, &ea)) { - printf("Enumerated %d aliases:\n", ea.out.num_aliases); - - for(i = 0; i < ea.out.num_aliases; i++) { - printf("RID: %d\n", ea.out.rids[i]); - printf("Name: %s\n", ea.out.names[i]); - printf("Desc: %s\n", ea.out.descriptions[i]); - } - } - if(CAC_OP_FAILED(hnd->status)) { - printf("Could not enumerate Aliases. Error: %s\n", nt_errstr(hnd->status)); - } - break; - } - } - - cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); - cac_SamClose(hnd, mem_ctx, sod.out.sam); - -done: - talloc_destroy(mem_ctx); - cac_FreeHandle(hnd); - - return 0; - -} - diff --git a/examples/libmsrpc/test/sam/samgroup.c b/examples/libmsrpc/test/sam/samgroup.c deleted file mode 100644 index 39d9fa1137..0000000000 --- a/examples/libmsrpc/test/sam/samgroup.c +++ /dev/null @@ -1,480 +0,0 @@ -/*Some group management stuff*/ - -#include "libmsrpc.h" -#include "test_util.h" - -int main(int argc, char **argv) { - CacServerHandle *hnd = NULL; - TALLOC_CTX *mem_ctx = NULL; - - - struct SamEnumGroups eg; - struct SamEnumUsers eu; - struct SamCreateGroup cg; - struct SamOpenGroup og; - struct SamGetGroupMembers ggm; - struct SamGetNamesFromRids gn; - struct SamAddGroupMember add; - struct SamRemoveGroupMember del; - struct SamSetGroupMembers set; - struct SamGetGroupsForUser gg; - struct SamOpenUser ou; - struct SamGetGroupInfo gi; - struct SamSetGroupInfo si; - struct SamRenameGroup rg; - struct SamGetSecurityObject gso; - - POLICY_HND *group_hnd = NULL; - - fstring tmp; - fstring input; - - int i; - - mem_ctx = talloc_init("cac_samgroup"); - - hnd = cac_NewServerHandle(True); - - cac_parse_cmd_line(argc, argv, hnd); - - if(!cac_Connect(hnd, NULL)) { - fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); - exit(-1); - } - - struct SamOpenDomain sod; - ZERO_STRUCT(sod); - - sod.in.access = MAXIMUM_ALLOWED_ACCESS; - - if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { - fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - tmp[0] = 0x00; - while(tmp[0] != 'q') { - printf("\n"); - printf("[l]ist groups\n"); - printf("[c]reate group\n"); - printf("[o]pen group\n"); - printf("[d]elete group\n"); - printf("list [m]embers\n"); - printf("list [u]sers\n"); - printf("list [g]roup for users\n"); - printf("[a]dd member\n"); - printf("[r]emove member\n"); - printf("[x] clear members\n"); - printf("get group [i]nfo\n"); - printf("[e]dit group info\n"); - printf("[s]et members\n"); - printf("re[n]ame group\n"); - printf("[z] close group\n"); - printf("[t] get security info\n"); - - printf("[q]uit\n\n"); - printf("Enter option: "); - cactest_readline(stdin, tmp); - - printf("\n"); - - switch(tmp[0]) { - case 'c': /*create group*/ - if(group_hnd != NULL) { - /*then we have an open handle.. close it*/ - cac_SamClose(hnd, mem_ctx, group_hnd); - group_hnd = NULL; - } - - printf("Enter group name: "); - cactest_readline(stdin, input); - - ZERO_STRUCT(cg); - - cg.in.name = talloc_strdup(mem_ctx, input); - cg.in.access = MAXIMUM_ALLOWED_ACCESS; - cg.in.dom_hnd = sod.out.dom_hnd; - - if(!cac_SamCreateGroup(hnd, mem_ctx, &cg)) { - fprintf(stderr, "Could not create group. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Created group %s\n", cg.in.name); - - group_hnd = cg.out.group_hnd; - } - break; - - case 'o': /*open group*/ - if(group_hnd != NULL) { - /*then we have an open handle.. close it*/ - cac_SamClose(hnd, mem_ctx, group_hnd); - group_hnd = NULL; - } - - ZERO_STRUCT(og); - - og.in.dom_hnd = sod.out.dom_hnd; - og.in.access = MAXIMUM_ALLOWED_ACCESS; - - printf("Enter RID: 0x"); - scanf("%x", &og.in.rid); - - if(!cac_SamOpenGroup(hnd, mem_ctx, &og)) { - fprintf(stderr, "Could not open group. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Opened group\n"); - group_hnd = og.out.group_hnd; - } - - break; - - case 'l': /*list groups*/ - ZERO_STRUCT(eg); - eg.in.dom_hnd = sod.out.dom_hnd; - - while(cac_SamEnumGroups(hnd, mem_ctx, &eg)) { - for(i = 0; i < eg.out.num_groups; i++) { - printf("RID: 0x%x Name: %s\n", eg.out.rids[i], eg.out.names[i]); - } - } - - if(CAC_OP_FAILED(hnd->status)) { - printf("Could not enumerate Groups. Error: %s\n", nt_errstr(hnd->status)); - } - - break; - - case 'm': /*list group members*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - ZERO_STRUCT(ggm); - ggm.in.group_hnd = group_hnd; - - if(!cac_SamGetGroupMembers(hnd, mem_ctx, &ggm)) { - fprintf(stderr, "Could not get group members. Error: %s\n", nt_errstr(hnd->status)); - break; - } - - printf("Group has %d members:\n", ggm.out.num_members); - - if(ggm.out.num_members == 0) /*just skip the rest of this case*/ - break; - - /**get the user names*/ - gn.in.dom_hnd = sod.out.dom_hnd; - gn.in.num_rids = ggm.out.num_members; - gn.in.rids = ggm.out.rids; - - if(!cac_SamGetNamesFromRids(hnd, mem_ctx, &gn)) { - fprintf(stderr, "Could not lookup names. Error: %s\n", nt_errstr(hnd->status)); - break; - } - - for(i = 0; i < gn.out.num_names; i++) { - printf("RID: 0x%x Name: %s\n", gn.out.map[i].rid, gn.out.map[i].name); - } - - break; - - case 'd': /*delete group*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - if(!cac_SamDeleteGroup(hnd, mem_ctx, group_hnd)) { - fprintf(stderr, "Could not delete group. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Deleted group.\n"); - group_hnd = NULL; - } - break; - - case 'u': /*list users*/ - ZERO_STRUCT(eu); - - eu.in.dom_hnd = sod.out.dom_hnd; - - while(cac_SamEnumUsers(hnd, mem_ctx, &eu)) { - for(i = 0; i < eu.out.num_users; i++) { - printf(" RID: 0x%x Name: %s\n", eu.out.rids[i], eu.out.names[i]); - } - } - - if(CAC_OP_FAILED(hnd->status)) { - printf("Could not enumerate users. Error: %s\n", nt_errstr(hnd->status)); - } - - break; - - case 'a': /*add member to group*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - ZERO_STRUCT(add); - - add.in.group_hnd = group_hnd; - - printf("Enter user RID: 0x"); - scanf("%x", &add.in.rid); - - if(!cac_SamAddGroupMember(hnd, mem_ctx, &add)) { - fprintf(stderr, "Could not add user to group. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Successfully added user to group\n"); - } - break; - - case 'r': /*remove user from group*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - ZERO_STRUCT(del); - del.in.group_hnd = group_hnd; - - printf("Enter RID: 0x"); - scanf("%x", &del.in.rid); - - if(!cac_SamRemoveGroupMember(hnd, mem_ctx, &del)) { - fprintf(stderr, "Could not remove user from group. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Removed user from group.\n"); - } - - break; - - case 'x': /*clear group members*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - if(!cac_SamClearGroupMembers(hnd, mem_ctx, group_hnd)) { - fprintf(stderr, "Could not clear group members. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Cleared group members\n"); - } - - break; - - case 's': /*set members*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - ZERO_STRUCT(set); - - set.in.group_hnd = group_hnd; - - printf("Enter the number of members: "); - scanf("%d", &set.in.num_members); - - set.in.rids = TALLOC_ARRAY(mem_ctx, uint32, set.in.num_members); - - for(i = 0; i < set.in.num_members; i++) { - printf("Enter RID #%d: 0x", (i+1)); - scanf("%x", (set.in.rids + i)); - } - - if(!cac_SamSetGroupMembers(hnd, mem_ctx, &set)) { - printf("could not set members. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Set users\n"); - } - - break; - - case 'g': /*list groups for user*/ - ZERO_STRUCT(ou); - ZERO_STRUCT(gg); - - printf("Enter username: "); - cactest_readline(stdin, input); - - if(input[0] != '\0') { - ou.in.name = talloc_strdup(mem_ctx, input); - } - else { - printf("Enter RID: 0x"); - scanf("%x", &ou.in.rid); - } - - ou.in.access = MAXIMUM_ALLOWED_ACCESS; - ou.in.dom_hnd = sod.out.dom_hnd; - - if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) { - fprintf(stderr, "Could not open user %s. Error: %s\n", ou.in.name, nt_errstr(hnd->status)); - break; - } - - /*now find the groups*/ - gg.in.user_hnd = ou.out.user_hnd; - - if(!cac_SamGetGroupsForUser(hnd, mem_ctx, &gg)) { - fprintf(stderr, "Could not get groups for user. Error: %s\n", nt_errstr(hnd->status)); - break; - } - - cac_SamClose(hnd, mem_ctx, ou.out.user_hnd); - - ZERO_STRUCT(gn); - - gn.in.dom_hnd = sod.out.dom_hnd; - gn.in.num_rids = gg.out.num_groups; - gn.in.rids = gg.out.rids; - - if(!cac_SamGetNamesFromRids(hnd, mem_ctx, &gn)) { - fprintf(stderr, "Could not get names from RIDs. Error: %s\n", nt_errstr(hnd->status)); - break; - } - - printf("%d groups: \n", gn.out.num_names); - - for(i = 0; i < gn.out.num_names; i++) { - printf("RID: 0x%x ", gn.out.map[i].rid); - - if(gn.out.map[i].found) - printf("Name: %s\n", gn.out.map[i].name); - else - printf("Unknown RID\n"); - } - - break; - - case 'z': /*close group*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - if(!cac_SamClose(hnd, mem_ctx, group_hnd)) { - printf("Could not close group\n"); - break; - } - - group_hnd = NULL; - break; - - case 'i': /*get group info*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - ZERO_STRUCT(gi); - gi.in.group_hnd = group_hnd; - - if(!cac_SamGetGroupInfo(hnd, mem_ctx, &gi)) { - printf("Could not get group info. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Retrieved Group info\n"); - print_cac_group_info(gi.out.info); - } - - break; - - case 'e': /*edit group info*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - ZERO_STRUCT(gi); - ZERO_STRUCT(si); - - gi.in.group_hnd = group_hnd; - - if(!cac_SamGetGroupInfo(hnd, mem_ctx, &gi)) { - printf("Could not get group info. Error: %s\n", nt_errstr(hnd->status)); - break; - } - - edit_cac_group_info(mem_ctx, gi.out.info); - - si.in.group_hnd = group_hnd; - si.in.info = gi.out.info; - - if(!cac_SamSetGroupInfo(hnd, mem_ctx, &si)) { - printf("Could not set group info. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf(" Done.\n"); - } - - break; - - case 'n': /*rename group*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - ZERO_STRUCT(rg); - - printf("Enter new group name: "); - cactest_readline(stdin, tmp); - - rg.in.group_hnd = group_hnd; - rg.in.new_name = talloc_strdup(mem_ctx, tmp); - - if(!cac_SamRenameGroup(hnd, mem_ctx, &rg)) - printf("Could not rename group. Error: %s\n", nt_errstr(hnd->status)); - else - printf("Done.\n"); - - break; - case 't': /*get security info*/ - if(!group_hnd) { - printf("Must open group first!\n"); - break; - } - - ZERO_STRUCT(gso); - - gso.in.pol = group_hnd; - - if(!cac_SamGetSecurityObject(hnd, mem_ctx, &gso)) { - printf("Could not get security descriptor info. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Got it.\n"); - } - break; - - case 'q': - break; - - default: - printf("Invalid command\n"); - } - } - - cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); - - if(group_hnd) - cac_SamClose(hnd, mem_ctx, group_hnd); - -done: - cac_FreeHandle(hnd); - - talloc_destroy(mem_ctx); - - return 0; -} - diff --git a/examples/libmsrpc/test/sam/samlookup.c b/examples/libmsrpc/test/sam/samlookup.c deleted file mode 100644 index 32be50d4b9..0000000000 --- a/examples/libmsrpc/test/sam/samlookup.c +++ /dev/null @@ -1,140 +0,0 @@ -/*lookup names or rids*/ - -#include "libmsrpc.h" -#include "test_util.h" - -int main(int argc, char **argv) { - CacServerHandle *hnd = NULL; - TALLOC_CTX *mem_ctx = NULL; - - - struct SamGetNamesFromRids sgn; - struct SamGetRidsFromNames sgr; - - fstring tmp; - fstring input; - - int i; - - mem_ctx = talloc_init("cac_samenum"); - - hnd = cac_NewServerHandle(True); - - cac_parse_cmd_line(argc, argv, hnd); - - if(!cac_Connect(hnd, NULL)) { - fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); - exit(-1); - } - - struct SamOpenDomain sod; - ZERO_STRUCT(sod); - - sod.in.access = MAXIMUM_ALLOWED_ACCESS; - - if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { - fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - tmp[0] = 0x00; - while(tmp[0] != 'q') { - printf("get [n]ames or get [r]ids or [q]uit: "); - cactest_readline(stdin, tmp); - - switch(tmp[0]) { - case 'n': - ZERO_STRUCT(sgn); - - sgn.in.dom_hnd = sod.out.dom_hnd; - - printf("How many rids will you enter: "); - scanf("%d", &sgn.in.num_rids); - - sgn.in.rids = talloc_array(mem_ctx, int, sgn.in.num_rids); - - for(i = 0; i < sgn.in.num_rids; i++) { - printf(" Enter RID %d: 0x", i); - scanf("%x", &sgn.in.rids[i]); - } - - printf("Getting names...\n"); - - if(!cac_SamGetNamesFromRids(hnd, mem_ctx, &sgn)) { - fprintf(stderr, "could not lookup names. Error: %s\n", nt_errstr(hnd->status)); - talloc_free(sgn.in.rids); - continue; - } - - printf("Found %d names:\n", sgn.out.num_names); - - for(i = 0; i < sgn.out.num_names; i++) { - printf(" RID: 0x%x ", sgn.out.map[i].rid); - - if(sgn.out.map[i].found) { - printf("Name: %s\n", sgn.out.map[i].name); - } - else { - printf("Unknown RID\n"); - } - - } - - break; - - case 'r': - ZERO_STRUCT(sgr); - - sgr.in.dom_hnd = sod.out.dom_hnd; - - printf("How many names will you enter: "); - scanf("%d", &sgr.in.num_names); - - sgr.in.names = talloc_array(mem_ctx, char *, sgr.in.num_names); - - for(i = 0; i < sgr.in.num_names; i++) { - printf(" Enter name %d: ", (i+1)); - cactest_readline(stdin, input); - - sgr.in.names[i] = talloc_strdup(mem_ctx, input); - } - - if(!cac_SamGetRidsFromNames(hnd, mem_ctx, &sgr)) { - fprintf(stderr, "Could not lookup names. Error: %s\n", nt_errstr(hnd->status)); - continue; - } - - printf("Found %d RIDs:\n", sgr.out.num_rids); - - for(i = 0; i < sgr.out.num_rids; i++) { - printf(" Name: %s ", sgr.out.map[i].name); - - if(sgr.out.map[i].found) { - printf("RID: 0x%x\n", sgr.out.map[i].rid); - } - else { - printf("Unknown name\n"); - } - } - - break; - case 'q': - printf("\n"); - break; - default: - printf("Invalid command!\n"); - } - } - - - cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); - cac_SamClose(hnd, mem_ctx, sod.out.sam); - -done: - talloc_destroy(mem_ctx); - cac_FreeHandle(hnd); - - return 0; - -} - diff --git a/examples/libmsrpc/test/sam/samuser.c b/examples/libmsrpc/test/sam/samuser.c deleted file mode 100644 index df56a2d991..0000000000 --- a/examples/libmsrpc/test/sam/samuser.c +++ /dev/null @@ -1,294 +0,0 @@ -/*Some user management stuff*/ - -#include "libmsrpc.h" -#include "test_util.h" - -int main(int argc, char **argv) { - CacServerHandle *hnd = NULL; - TALLOC_CTX *mem_ctx = NULL; - - - struct SamOpenUser ou; - struct SamEnumUsers eu; - struct SamCreateUser cu; - struct SamGetUserInfo gi; - struct SamSetUserInfo si; - struct SamRenameUser ru; - struct SamSetPassword sp; - - POLICY_HND *user_hnd = NULL; - - fstring tmp; - fstring input; - - char *pass1 = NULL; - char *pass2 = NULL; - - int i; - - mem_ctx = talloc_init("cac_samgroup"); - - hnd = cac_NewServerHandle(True); - - cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn); - - cac_parse_cmd_line(argc, argv, hnd); - - if(!cac_Connect(hnd, NULL)) { - fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status)); - exit(-1); - } - - struct SamOpenDomain sod; - ZERO_STRUCT(sod); - - sod.in.access = MAXIMUM_ALLOWED_ACCESS; - - if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) { - fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status)); - goto done; - } - - tmp[0] = 0x00; - while(tmp[0] != 'q') { - printf("\n"); - printf("[l]ist users\n"); - printf("[c]reate user\n"); - printf("[o]pen user\n"); - printf("[d]elete user\n"); - printf("[g]et user info\n"); - printf("[e]dit user info\n"); - printf("[r]ename user\n"); - printf("reset [p]assword\n"); - printf("[n] close user\n"); - - printf("[q]uit\n\n"); - printf("Enter option: "); - cactest_readline(stdin, tmp); - - printf("\n"); - - switch(tmp[0]) { - case 'c': /*create user*/ - if(user_hnd != NULL) { - /*then we have an open handle.. close it*/ - cac_SamClose(hnd, mem_ctx, user_hnd); - user_hnd = NULL; - } - - printf("Enter user name: "); - cactest_readline(stdin, input); - - ZERO_STRUCT(cu); - - cu.in.name = talloc_strdup(mem_ctx, input); - cu.in.dom_hnd = sod.out.dom_hnd; - cu.in.acb_mask = ACB_NORMAL; - - if(!cac_SamCreateUser(hnd, mem_ctx, &cu)) { - printf("Could not create user. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Created user %s with RID 0x%x\n", cu.in.name, cu.out.rid); - user_hnd = cu.out.user_hnd; - } - - break; - - case 'o': /*open group*/ - if(user_hnd != NULL) { - /*then we have an open handle.. close it*/ - cac_SamClose(hnd, mem_ctx, user_hnd); - user_hnd = NULL; - } - - ZERO_STRUCT(ou); - - ou.in.dom_hnd = sod.out.dom_hnd; - ou.in.access = MAXIMUM_ALLOWED_ACCESS; - - printf("Enter RID: 0x"); - scanf("%x", &ou.in.rid); - - if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) { - fprintf(stderr, "Could not open user. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Opened user\n"); - user_hnd = ou.out.user_hnd; - } - - break; - - case 'l': /*list users*/ - ZERO_STRUCT(eu); - eu.in.dom_hnd = sod.out.dom_hnd; - - while(cac_SamEnumUsers(hnd, mem_ctx, &eu)) { - for(i = 0; i < eu.out.num_users; i++) { - printf("RID: 0x%x Name: %s\n", eu.out.rids[i], eu.out.names[i]); - } - } - - if(CAC_OP_FAILED(hnd->status)) { - printf("Could not enumerate Users. Error: %s\n", nt_errstr(hnd->status)); - } - - break; - - break; - - case 'd': /*delete group*/ - if(!user_hnd) { - printf("Must open group first!\n"); - break; - } - - if(!cac_SamDeleteGroup(hnd, mem_ctx, user_hnd)) { - fprintf(stderr, "Could not delete group. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Deleted group.\n"); - user_hnd = NULL; - } - break; - - - case 'n': - if(!user_hnd) { - printf("Must open user first!\n"); - break; - } - - if(!cac_SamClose(hnd, mem_ctx, user_hnd)) { - printf("Could not user group\n"); - break; - } - - user_hnd = NULL; - break; - - case 'g': /*get user info*/ - if(!user_hnd) { - printf("Must open user first!\n"); - break; - } - - ZERO_STRUCT(gi); - gi.in.user_hnd = ou.out.user_hnd; - - if(!cac_SamGetUserInfo(hnd, mem_ctx, &gi)) { - printf("Could not get user info. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Retrieved User information:\n"); - print_cac_user_info(gi.out.info); - } - - break; - - case 'e': /*edit user info*/ - if(!user_hnd) { - printf("Must Open user first!\n"); - break; - } - - ZERO_STRUCT(gi); - gi.in.user_hnd = ou.out.user_hnd; - if(!cac_SamGetUserInfo(hnd, mem_ctx, &gi)) { - printf("Could not get user info. Error: %s\n", nt_errstr(hnd->status)); - break; - } - - edit_cac_user_info(mem_ctx, gi.out.info); - - printf("setting following info:\n"); - print_cac_user_info(gi.out.info); - - ZERO_STRUCT(si); - - si.in.user_hnd = user_hnd; - si.in.info = gi.out.info; - - if(!cac_SamSetUserInfo(hnd, mem_ctx, &si)) { - printf("Could not set user info. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Done.\n"); - } - - break; - - case 'r': /*rename user*/ - if(!user_hnd) { - printf("Must open user first!\n"); - break; - } - - ZERO_STRUCT(ru); - - printf("Enter new username: "); - cactest_readline(stdin, tmp); - - ru.in.user_hnd = user_hnd; - ru.in.new_name = talloc_strdup(mem_ctx, tmp); - - if(!cac_SamRenameUser(hnd, mem_ctx, &ru)) { - printf("Could not rename user. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Renamed user\n"); - } - - break; - - case 'p': /*reset password*/ - - if(!user_hnd) { - printf("Must open user first!\n"); - break; - } - - do { - if(pass1 && pass2) { - printf("Passwords do not match. Please try again\n"); - } - - pass1 = getpass("Enter new password: "); - pass2 = getpass("Re-enter new password: "); - } while(strncmp(pass1, pass2, MAX_PASS_LEN)); - - ZERO_STRUCT(sp); - sp.in.user_hnd = user_hnd; - sp.in.password = talloc_strdup(mem_ctx, pass1); - - if(!cac_SamSetPassword(hnd, mem_ctx, &sp)) { - printf("Could not set password. Error: %s\n", nt_errstr(hnd->status)); - } - else { - printf("Done.\n"); - } - - break; - - case 'q': - break; - - default: - printf("Invalid command\n"); - } - } - - cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd); - - if(user_hnd) - cac_SamClose(hnd, mem_ctx, user_hnd); - -done: - cac_FreeHandle(hnd); - - talloc_destroy(mem_ctx); - - return 0; -} - |