00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "cacusermgr.h"
00022
00023 CacGroupInfo *get_group_info(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, POLICY_HND *group_hnd) {
00024 struct SamGetGroupInfo getinfo;
00025
00026 if(!hnd || !mem_ctx ||!group_hnd)
00027 return NULL;
00028
00029 ZERO_STRUCT(getinfo);
00030 getinfo.in.group_hnd = group_hnd;
00031
00032 if(!cac_SamGetGroupInfo(hnd, mem_ctx, &getinfo))
00033 printerr("Could not get group info.", hnd->status);
00034
00035 return getinfo.out.info;
00036 }
00037
00038 void print_group_info(CacGroupInfo *info) {
00039 if(!info)
00040 return;
00041
00042 printf(" Group Name : %s\n", info->name);
00043 printf(" Description : %s\n", info->description);
00044 printf(" Number of Members : %d\n", info->num_members);
00045 }
00046
00047 CacGroupInfo *modify_group_info(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, POLICY_HND *group_hnd) {
00048 struct SamSetGroupInfo setinfo;
00049 CacGroupInfo *info = NULL;
00050 fstring tmp;
00051
00052 info = get_group_info(hnd, mem_ctx, group_hnd);
00053
00054 if(!info)
00055 return NULL;
00056
00057 printf("Description [%s]: ", info->description);
00058 mgr_getline(tmp);
00059 if(tmp[0] != '\0')
00060 info->description = talloc_strdup(mem_ctx, tmp);
00061
00062 ZERO_STRUCT(setinfo);
00063 setinfo.in.group_hnd = group_hnd;
00064 setinfo.in.info = info;
00065
00066 if(!cac_SamSetGroupInfo(hnd, mem_ctx, &setinfo)) {
00067 printerr("Could not set info.", hnd->status);
00068 info = NULL;
00069 }
00070
00071 return info;
00072 }
00073
00074 void group_menu(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, POLICY_HND *dom_hnd, POLICY_HND *group_hnd) {
00075 CacGroupInfo *info = NULL;
00076 int rid_type = 0;
00077
00078 fstring in;
00079
00080 char *buf;
00081
00082 struct SamGetGroupMembers getmem;
00083 struct SamGetNamesFromRids getnames;
00084 struct SamAddGroupMember add;
00085 struct SamRemoveGroupMember del;
00086
00087 info = get_group_info(hnd, mem_ctx, group_hnd);
00088
00089 printf("\n");
00090 print_group_info(info);
00091
00092 while(in[0] != 'b' && in[0] != 'B' && in[0] != 'q' && in[0] != 'Q') {
00093 printf("\n");
00094 printf("[m] List Group Members\n");
00095 printf("[a] Add User To Group\n");
00096 printf("[r] Remove User From Group\n");
00097 printf("[l] List Users\n");
00098 printf("[v] View Group Info\n");
00099 printf("[d] Set Group Description\n");
00100 printf("[x] Delete Group\n");
00101 printf("[b] Back\n\n");
00102
00103 printf("Command: ");
00104 mgr_getline(in);
00105
00106 printf("\n");
00107
00108 switch(in[0]) {
00109 case 'a':
00110 case 'A':
00111 ZERO_STRUCT(add);
00112 add.in.group_hnd = group_hnd;
00113
00114 printf("Enter RID or Name: ");
00115 rid_type = rid_or_name(hnd, mem_ctx, dom_hnd, &add.in.rid, &buf);
00116
00117 if(rid_type != CAC_USER_RID) {
00118 printf("Invalid User.\n");
00119 break;
00120 }
00121
00122 if(!cac_SamAddGroupMember(hnd, mem_ctx, &add)) {
00123 printerr("Could not add user to group.", hnd->status);
00124 }
00125 break;
00126
00127 case 'r':
00128 case 'R':
00129 ZERO_STRUCT(del);
00130 del.in.group_hnd = group_hnd;
00131
00132 printf("Enter RID or Name: ");
00133 rid_type = rid_or_name(hnd, mem_ctx, dom_hnd, &del.in.rid, &buf);
00134
00135 if(rid_type != CAC_USER_RID) {
00136 printf("Invalid User.\n");
00137 break;
00138 }
00139
00140 if(!cac_SamRemoveGroupMember(hnd, mem_ctx, &del)) {
00141 printerr("Could not remove use from group.", hnd->status);
00142 }
00143 break;
00144
00145 case 'l':
00146 case 'L':
00147 list_users(hnd, mem_ctx, dom_hnd);
00148 break;
00149
00150 case 'm':
00151 case 'M':
00152 ZERO_STRUCT(getmem);
00153 getmem.in.group_hnd = group_hnd;
00154
00155 if(!cac_SamGetGroupMembers(hnd, mem_ctx, &getmem)) {
00156 printerr("Could not get members.", hnd->status);
00157 break;
00158 }
00159
00160 ZERO_STRUCT(getnames);
00161 getnames.in.dom_hnd = dom_hnd;
00162 getnames.in.rids = getmem.out.rids;
00163 getnames.in.num_rids = getmem.out.num_members;
00164
00165 if(!cac_SamGetNamesFromRids(hnd, mem_ctx, &getnames)) {
00166 printerr("Could not lookup names.", hnd->status);
00167 break;
00168 }
00169
00170 printf("Group has %d members:\n", getnames.out.num_names);
00171 print_lookup_records(getnames.out.map, getnames.out.num_names);
00172
00173 break;
00174
00175 case 'd':
00176 case 'D':
00177 info = modify_group_info(hnd, mem_ctx, group_hnd);
00178
00179 if(info)
00180 printf("Set Group Info.\n");
00181 break;
00182
00183 case 'v':
00184 case 'V':
00185 info = get_group_info(hnd, mem_ctx, group_hnd);
00186 print_group_info(info);
00187 break;
00188
00189 case 'x':
00190 case 'X':
00191 if(!cac_SamDeleteGroup(hnd, mem_ctx, group_hnd))
00192 printerr("Could Not Delete Group.", hnd->status);
00193
00194
00195 in[0] = 'b';
00196 break;
00197
00198 case 'b':
00199 case 'B':
00200 case 'q':
00201 case 'Q':
00202 break;
00203
00204 default:
00205 printf("Invalid Command.\n");
00206 }
00207 }
00208
00209 cac_SamClose(hnd, mem_ctx, group_hnd);
00210 }