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 void print_user_info(CacUserInfo *info) {
00024 printf("\n");
00025 printf(" User Name : %s\n", info->username);
00026 printf(" Full Name : %s\n", info->full_name);
00027 printf(" Home Dir : %s\n", info->home_dir);
00028 printf(" Home Drive : %s\n", info->home_drive);
00029 printf(" Profile Path : %s\n", info->profile_path);
00030 printf(" Logon Script : %s\n", info->logon_script);
00031 printf(" Description : %s\n", info->description);
00032 printf(" Workstations : %s\n", info->workstations);
00033 printf(" Remote Dial : %s\n", info->dial);
00034
00035 printf(" Logon Time : %s\n", http_timestring(info->logon_time));
00036 printf(" Logoff Time : %s\n", http_timestring(info->logoff_time));
00037 printf(" Kickoff Time : %s\n", http_timestring(info->kickoff_time));
00038 printf(" Pass last set : %s\n", http_timestring(info->pass_last_set_time));
00039 printf(" Pass can set : %s\n", http_timestring(info->pass_can_change_time));
00040 printf(" Pass must set : %s\n", http_timestring(info->pass_must_change_time));
00041
00042 printf(" User RID : 0x%x\n", info->rid);
00043 printf(" Group RID : 0x%x\n", info->group_rid);
00044 printf(" User Type : ");
00045
00046 if(info->acb_mask & ACB_NORMAL)
00047 printf("Normal User\n");
00048 else if(info->acb_mask & ACB_TEMPDUP)
00049 printf("Temporary Duplicate Account\n");
00050 else if(info->acb_mask & ACB_DOMTRUST)
00051 printf("Inter-Domain Trust Account\n");
00052 else if(info->acb_mask & ACB_WSTRUST)
00053 printf("Workstation Trust Account\n");
00054 else if(info->acb_mask & ACB_SVRTRUST)
00055 printf("Server Trust Account\n");
00056 else
00057 printf("\n");
00058
00059 printf(" Disabled : %s\n", (info->acb_mask & ACB_DISABLED) ? "Yes" : "No");
00060 printf(" Locked : %s\n", (info->acb_mask & ACB_AUTOLOCK) ? "Yes" : "No");
00061 printf(" Pass Expires : %s\n", (info->acb_mask & ACB_PWNOEXP) ? "No" : "Yes");
00062 printf(" Pass Required : %s\n", (info->acb_mask & ACB_PWNOTREQ) ? "No" : "Yes");
00063
00064 }
00065
00066 CacUserInfo *modify_user_info(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, POLICY_HND *user_hnd) {
00067 CacUserInfo *info = NULL;
00068 fstring tmp;
00069
00070 struct SamGetUserInfo getinfo;
00071 struct SamSetUserInfo setinfo;
00072
00073 ZERO_STRUCT(getinfo);
00074 ZERO_STRUCT(setinfo);
00075
00076 getinfo.in.user_hnd = user_hnd;
00077
00078 if(!cac_SamGetUserInfo(hnd, mem_ctx, &getinfo)) {
00079 printerr("Could not get user info.", hnd->status);
00080 return NULL;
00081 }
00082
00083 info = getinfo.out.info;
00084
00085 printf("\n");
00086 printf(" User Name [%s]: ", info->username);
00087 mgr_getline(tmp);
00088 if(tmp[0] != '\0')
00089 info->username = talloc_strdup(mem_ctx, tmp);
00090
00091 printf(" Full Name [%s]: ", info->full_name);
00092 mgr_getline(tmp);
00093 if(tmp[0] != '\0')
00094 info->full_name = talloc_strdup(mem_ctx, tmp);
00095
00096 printf(" Description [%s]: ", info->description);
00097 mgr_getline(tmp);
00098 if(tmp[0] != '\0')
00099 info->description = talloc_strdup(mem_ctx, tmp);
00100
00101 printf(" Home Dir [%s]: ", info->home_dir);
00102 mgr_getline(tmp);
00103 if(tmp[0] != '\0')
00104 info->home_dir = talloc_strdup(mem_ctx, tmp);
00105
00106 printf(" Home Drive [%s]: ", info->home_drive);
00107 mgr_getline(tmp);
00108 if(tmp[0] != '\0')
00109 info->home_drive = talloc_strdup(mem_ctx, tmp);
00110
00111 printf(" Profile Path [%s]: ", info->profile_path);
00112 mgr_getline(tmp);
00113 if(tmp[0] != '\0')
00114 info->profile_path = talloc_strdup(mem_ctx, tmp);
00115
00116 printf(" Logon Script [%s]: ", info->logon_script);
00117 mgr_getline(tmp);
00118 if(tmp[0] != '\0')
00119 info->logon_script = talloc_strdup(mem_ctx, tmp);
00120
00121 printf(" Workstations [%s]: ", info->workstations);
00122 mgr_getline(tmp);
00123 if(tmp[0] != '\0')
00124 info->workstations = talloc_strdup(mem_ctx, tmp);
00125
00126 printf(" Remote Dial [%s]: ", info->dial);
00127 mgr_getline(tmp);
00128 if(tmp[0] != '\0')
00129 info->dial = talloc_strdup(mem_ctx, tmp);
00130
00131 printf(" Disabled [%s] (y/n): ", (info->acb_mask & ACB_DISABLED) ? "Yes" : "No");
00132 mgr_getline(tmp);
00133 if(tmp[0] == 'y' || tmp[0] == 'Y')
00134 info->acb_mask |= ACB_DISABLED;
00135 else if(tmp[0] == 'n' || tmp[0] == 'N')
00136 info->acb_mask ^= (info->acb_mask & ACB_DISABLED) ? ACB_DISABLED : 0x0;
00137
00138 printf(" Pass Expires [%s] (y/n): ", (info->acb_mask & ACB_PWNOEXP) ? "No" : "Yes");
00139 mgr_getline(tmp);
00140 if(tmp[0] == 'n' || tmp[0] == 'N')
00141 info->acb_mask |= ACB_PWNOEXP;
00142 else if(tmp[0] == 'y' || tmp[0] == 'Y')
00143 info->acb_mask ^= (info->acb_mask & ACB_PWNOEXP) ? ACB_PWNOEXP : 0x0;
00144
00145 printf(" Pass Required [%s] (y/n): ", (info->acb_mask & ACB_PWNOTREQ) ? "No" : "Yes");
00146 mgr_getline(tmp);
00147 if(tmp[0] == 'n' || tmp[0] == 'N')
00148 info->acb_mask |= ACB_PWNOTREQ;
00149 else if(tmp[0] == 'y' || tmp[0] == 'Y')
00150 info->acb_mask ^= (info->acb_mask & ACB_PWNOTREQ) ? ACB_PWNOTREQ : 0x0;
00151
00152 setinfo.in.user_hnd = user_hnd;
00153 setinfo.in.info = info;
00154
00155 if(!cac_SamSetUserInfo(hnd, mem_ctx, &setinfo)) {
00156 printerr("Could not set user info.", hnd->status);
00157 }
00158
00159 return info;
00160 }
00161
00162 void add_user_to_group(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, CacUserInfo *info, POLICY_HND *dom_hnd) {
00163 int rid_type = 0;
00164
00165 char *tmp = NULL;
00166
00167 struct SamOpenGroup og;
00168 struct SamAddGroupMember add;
00169
00170 ZERO_STRUCT(og);
00171 ZERO_STRUCT(add);
00172
00173 printf("Group RID or Name:");
00174
00175 og.in.dom_hnd = dom_hnd;
00176 og.in.access = MAXIMUM_ALLOWED_ACCESS;
00177 rid_type = rid_or_name(hnd, mem_ctx, dom_hnd, &og.in.rid, &tmp);
00178
00179 if(!cac_SamOpenGroup(hnd, mem_ctx, &og)) {
00180 printerr("Could not open group.", hnd->status);
00181 return;
00182 }
00183
00184 add.in.group_hnd = og.out.group_hnd;
00185 add.in.rid = info->rid;
00186
00187 if(!cac_SamAddGroupMember(hnd, mem_ctx, &add)) {
00188 printerr("Could not add user to group.", hnd->status);
00189 }
00190
00191 cac_SamClose(hnd, mem_ctx, og.out.group_hnd);
00192 }
00193
00194 void remove_user_from_group(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, CacUserInfo *info, POLICY_HND *dom_hnd) {
00195 int rid_type = 0;
00196
00197 char *tmp = NULL;
00198
00199 struct SamOpenGroup og;
00200 struct SamRemoveGroupMember del;
00201
00202 ZERO_STRUCT(og);
00203 ZERO_STRUCT(del);
00204
00205 printf("Group RID or Name:");
00206
00207 og.in.dom_hnd = dom_hnd;
00208 og.in.access = MAXIMUM_ALLOWED_ACCESS;
00209 rid_type = rid_or_name(hnd, mem_ctx, dom_hnd, &og.in.rid, &tmp);
00210
00211 if(!cac_SamOpenGroup(hnd, mem_ctx, &og)) {
00212 printerr("Could not open group.", hnd->status);
00213 return;
00214 }
00215
00216 del.in.group_hnd = og.out.group_hnd;
00217 del.in.rid = info->rid;
00218
00219 if(!cac_SamRemoveGroupMember(hnd, mem_ctx, &del)) {
00220 printerr("Could not add user to group.", hnd->status);
00221 }
00222
00223 cac_SamClose(hnd, mem_ctx, og.out.group_hnd);
00224 }
00225
00226 void user_menu(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, POLICY_HND *dom_hnd, POLICY_HND *user_hnd) {
00227 fstring in;
00228
00229 struct SamGetUserInfo getinfo;
00230 struct SamSetPassword setpass;
00231 struct SamGetGroupsForUser groups;
00232 struct SamGetNamesFromRids gnfr;
00233
00234 CacUserInfo *info = NULL;
00235
00236 if(!hnd || !mem_ctx || !user_hnd) {
00237 printf("Must open user.\n");
00238 return;
00239 }
00240
00241
00242 ZERO_STRUCT(getinfo);
00243 getinfo.in.user_hnd = user_hnd;
00244
00245 if(!cac_SamGetUserInfo(hnd, mem_ctx, &getinfo)) {
00246 printerr("Could not get info.", hnd->status);
00247 info = NULL;
00248 }
00249 else {
00250 info = getinfo.out.info;
00251 print_user_info(info);
00252 }
00253
00254
00255 in[0] = '\0';
00256 while(in[0] != 'b' && in[0] != 'B' && in[0] != 'q' && in[0] != 'Q') {
00257 printf("\n");
00258 printf("[s] Set Password\n");
00259
00260 if(info && (info->acb_mask & ACB_DISABLED))
00261 printf("[e] Enable User\n");
00262 else if(info)
00263 printf("[d] Disable User\n");
00264
00265 printf("[v] View User Info\n");
00266 printf("[m] Modify User Info\n");
00267 printf("[x] Delete User\n\n");
00268
00269 printf("[g] List Group Membership\n");
00270 printf("[a] Add User To Group\n");
00271 printf("[l] List Domain Groups\n");
00272 printf("[r] Remove User From Group\n\n");
00273
00274 printf("[b] Back\n\n");
00275
00276 printf("Command: ");
00277 mgr_getline(in);
00278
00279 printf("\n");
00280
00281 switch(in[0]) {
00282 case 'g':
00283 case 'G':
00284 ZERO_STRUCT(groups);
00285 groups.in.user_hnd = user_hnd;
00286
00287 if(!cac_SamGetGroupsForUser(hnd, mem_ctx, &groups)) {
00288 printerr("Could not get groups.", hnd->status);
00289 break;
00290 }
00291
00292 ZERO_STRUCT(gnfr);
00293 gnfr.in.dom_hnd = dom_hnd;
00294 gnfr.in.rids = groups.out.rids;
00295 gnfr.in.num_rids = groups.out.num_groups;
00296
00297 if(!cac_SamGetNamesFromRids(hnd, mem_ctx, &gnfr)) {
00298 printerr("Could not map RIDs to names.", hnd->status);
00299 break;
00300 }
00301
00302 print_lookup_records(gnfr.out.map, gnfr.out.num_names);
00303
00304 break;
00305 case 's':
00306 case 'S':
00307 ZERO_STRUCT(setpass);
00308 setpass.in.user_hnd = user_hnd;
00309 setpass.in.password = get_new_password(mem_ctx);
00310
00311 if(!setpass.in.password) {
00312 printf("Out of memory.\n");
00313 break;
00314 }
00315
00316 if(!cac_SamSetPassword(hnd, mem_ctx, &setpass)) {
00317 printerr("Could not set password.", hnd->status);
00318 }
00319 else {
00320 printf("Reset password.\n");
00321 }
00322 break;
00323
00324 case 'e':
00325 case 'E':
00326 if(info && !(info->acb_mask & ACB_DISABLED))
00327 break;
00328
00329 if(!cac_SamEnableUser(hnd, mem_ctx, user_hnd)) {
00330 printerr("Could not enable user.", hnd->status);
00331 }
00332 else {
00333 printf("Enabled User.\n");
00334
00335 info->acb_mask ^= ACB_DISABLED;
00336 }
00337 break;
00338
00339 case 'd':
00340 case 'D':
00341 if(info && (info->acb_mask & ACB_DISABLED))
00342 break;
00343
00344 if(!cac_SamDisableUser(hnd, mem_ctx, user_hnd)) {
00345 printerr("Could not disable user.", hnd->status);
00346 }
00347 else {
00348 printf("Disabled User.\n");
00349
00350 info->acb_mask ^= ACB_DISABLED;
00351 }
00352 break;
00353
00354 case 'v':
00355 case 'V':
00356 ZERO_STRUCT(getinfo);
00357 getinfo.in.user_hnd = user_hnd;
00358
00359 if(!cac_SamGetUserInfo(hnd, mem_ctx, &getinfo)) {
00360 printerr("Could not get info.", hnd->status);
00361 info = NULL;
00362 }
00363 else {
00364 info = getinfo.out.info;
00365 print_user_info(info);
00366 }
00367
00368 break;
00369
00370 case 'm':
00371 case 'M':
00372 info = modify_user_info(hnd, mem_ctx, user_hnd);
00373
00374 if(info)
00375 printf("Updated user info.\n");
00376 break;
00377
00378 case 'l':
00379 case 'L':
00380 list_groups(hnd, mem_ctx, dom_hnd);
00381 break;
00382
00383 case 'a':
00384 case 'A':
00385 add_user_to_group(hnd, mem_ctx, info, dom_hnd);
00386 break;
00387
00388 case 'r':
00389 case 'R':
00390 remove_user_from_group(hnd, mem_ctx, info, dom_hnd);
00391 break;
00392
00393 case 'x':
00394 case 'X':
00395 if(!cac_SamDeleteUser(hnd, mem_ctx, user_hnd))
00396 printerr("Could not delete user.", hnd->status);
00397
00398
00399 in[0] = 'b';
00400 break;
00401
00402 case 'b':
00403 case 'B':
00404 case 'q':
00405 case 'Q':
00406
00407 break;
00408
00409 default:
00410 printf("Invalid command.\n");
00411 }
00412 }
00413
00414
00415 cac_SamClose(hnd, mem_ctx, user_hnd);
00416 }