1 /*some utility functions for the registry tests*/
7 void cactest_print_usage(char **argv
) {
9 printf(" %s server [-U username] [-W domain] [-P passwprd] [-N netbios_name]\n", argv
[0]);
12 /*allocates memory for auth info and parses domain/user/server out of command line*/
13 void cac_parse_cmd_line(int argc
, char **argv
, CacServerHandle
*hnd
) {
16 ZERO_STRUCTP(hnd
->username
);
17 ZERO_STRUCTP(hnd
->domain
);
18 ZERO_STRUCTP(hnd
->netbios_name
);
19 ZERO_STRUCTP(hnd
->password
);
21 for(i
= 1; i
< argc
; i
++) {
22 if( strncmp(argv
[i
], "-U", sizeof(fstring
)) == 0) {
23 strncpy(hnd
->username
, argv
[i
+1], sizeof(fstring
));
27 else if(strncmp(argv
[i
], "-W", sizeof(fstring
)) == 0) {
28 strncpy(hnd
->domain
, argv
[i
+1], sizeof(fstring
));
33 else if(strncmp(argv
[i
], "-P", sizeof(fstring
)) == 0) {
34 strncpy(hnd
->password
, argv
[i
+1], sizeof(fstring
));
39 else if(strncmp(argv
[i
], "-N", sizeof(fstring
)) == 0) {
40 strncpy(hnd
->netbios_name
, argv
[i
+1], sizeof(fstring
));
44 else if(strncmp(argv
[i
], "-d", sizeof(fstring
)) == 0) {
45 sscanf(argv
[i
+1], "%d", &hnd
->debug
);
49 else { /*assume this is the server name*/
50 strncpy(hnd
->server
, argv
[i
], sizeof(fstring
));
55 cactest_print_usage(argv
);
62 void print_value(uint32 type
, REG_VALUE_DATA
*data
) {
67 printf(" Type: REG_SZ\n");
68 printf(" Value: %s\n", data
->reg_sz
);
71 printf(" Type: REG_EXPAND_SZ\n");
72 printf(" Value: %s\n", data
->reg_expand_sz
);
75 printf(" Type: REG_MULTI_SZ\n");
78 for(i
= 0; i
< data
->reg_multi_sz
.num_strings
; i
++) {
79 printf(" %d: %s\n", i
, data
->reg_multi_sz
.strings
[i
]);
83 printf(" Type: REG_DWORD\n");
84 printf(" Value: %d\n", data
->reg_dword
);
87 printf(" Type: REG_DWORD_BE\n");
88 printf(" Value: 0x%x\n", data
->reg_dword_be
);
91 printf(" Type: REG_BINARY\n");
94 printf(" Invalid type: %d\n", type
);
102 void cactest_readline(FILE *in
, fstring line
) {
110 fgets(line
, sizeof(fstring
), in
);
112 if(line
[strlen(line
) - 1] == '\n')
113 line
[strlen(line
) - 1] = '\0';
117 void cactest_GetAuthDataFn(const char * pServer
,
127 char temp
[sizeof(fstring
)];
129 static char authUsername
[sizeof(fstring
)];
130 static char authWorkgroup
[sizeof(fstring
)];
131 static char authPassword
[sizeof(fstring
)];
132 static char authSet
= 0;
138 strncpy(pWorkgroup
, authWorkgroup
, maxLenWorkgroup
- 1);
139 strncpy(pUsername
, authUsername
, maxLenUsername
- 1);
140 strncpy(pPassword
, authPassword
, maxLenPassword
- 1);
144 if(pWorkgroup
[0] != '\0') {
145 strncpy(authWorkgroup
, pWorkgroup
, maxLenWorkgroup
- 1);
148 d_printf("Domain: [%s] ", pWorkgroup
);
149 fscanf(stdin
, "%s", temp
);
153 strncpy(pWorkgroup
, temp
, maxLenWorkgroup
- 1);
154 strncpy(authWorkgroup
, temp
, maxLenWorkgroup
- 1);
159 if(pUsername
[0] != '\0') {
160 strncpy(authUsername
, pUsername
, maxLenUsername
- 1);
163 d_printf("Username: [%s] ", pUsername
);
164 fscanf(stdin
, "%s", temp
);
166 if (temp
[strlen(temp
) - 1] == '\n') /* A new line? */
168 temp
[strlen(temp
) - 1] = '\0';
173 strncpy(pUsername
, temp
, maxLenUsername
- 1);
174 strncpy(authUsername
, pUsername
, maxLenUsername
- 1);
177 if(pPassword
[0] != '\0') {
178 strncpy(authPassword
, pPassword
, maxLenPassword
- 1);
181 pass
= getpass("Password: ");
184 if (temp
[strlen(temp
) - 1] == '\n') /* A new line? */
186 temp
[strlen(temp
) - 1] = '\0';
190 strncpy(pPassword
, temp
, maxLenPassword
- 1);
191 strncpy(authPassword
, pPassword
, maxLenPassword
- 1);
198 void cactest_reg_input_val(TALLOC_CTX
*mem_ctx
, int *type
, char **name
, REG_VALUE_DATA
*data
) {
202 printf("Enter value name: \n");
203 cactest_readline(stdin
, tmp
);
204 *name
= talloc_strdup(mem_ctx
, tmp
);
207 printf("Enter type. %d = REG_SZ, %d = REG_DWORD, %d = REG_MULTI_SZ: ", REG_SZ
, REG_DWORD
, REG_MULTI_SZ
);
209 } while(*type
!= REG_SZ
&& *type
!= REG_DWORD
&& *type
!= REG_MULTI_SZ
);
213 printf("Enter string:\n");
214 cactest_readline(stdin
, tmp
);
216 data
->reg_sz
= talloc_strdup(mem_ctx
, tmp
);
220 printf("Enter dword: ");
221 scanf("%d", &data
->reg_dword
);
225 printf("Enter number of strings: ");
226 scanf("%d", &data
->reg_multi_sz
.num_strings
);
228 data
->reg_multi_sz
.strings
= talloc_array(mem_ctx
, char *, data
->reg_multi_sz
.num_strings
);
230 for(i
= 0; i
< data
->reg_multi_sz
.num_strings
; i
++) {
231 printf("String %d: ", i
+1);
232 cactest_readline(stdin
, tmp
);
234 data
->reg_multi_sz
.strings
[i
] = talloc_strdup(mem_ctx
, tmp
);
240 void print_cac_user_info(CacUserInfo
*info
) {
241 printf(" User Name : %s\n", info
->username
);
242 printf(" Full Name : %s\n", info
->full_name
);
243 printf(" Home Dir : %s\n", info
->home_dir
);
244 printf(" Home Drive : %s\n", info
->home_drive
);
245 printf(" Profile Path : %s\n", info
->profile_path
);
246 printf(" Logon Script : %s\n", info
->logon_script
);
247 printf(" Description : %s\n", info
->description
);
248 printf(" Workstations : %s\n", info
->workstations
);
249 printf(" Remote Dial : %s\n", info
->dial
);
251 printf(" Logon Time : %s\n", http_timestring(info
->logon_time
));
252 printf(" Logoff Time : %s\n", http_timestring(info
->logoff_time
));
253 printf(" Kickoff Time : %s\n", http_timestring(info
->kickoff_time
));
254 printf(" Pass last set: %s\n", http_timestring(info
->pass_last_set_time
));
255 printf(" Pass can set : %s\n", http_timestring(info
->pass_can_change_time
));
256 printf(" Pass must set: %s\n", http_timestring(info
->pass_must_change_time
));
258 printf(" User RID : 0x%x\n", info
->rid
);
259 printf(" Group RID : 0x%x\n", info
->group_rid
);
260 printf(" ACB Mask : 0x%x\n", info
->acb_mask
);
262 printf(" Bad pwd count: %d\n", info
->bad_passwd_count
);
263 printf(" Logon Cuont : %d\n", info
->logon_count
);
265 printf(" NT Password : %s\n", info
->nt_password
);
266 printf(" LM Password : %s\n", info
->lm_password
);
270 void edit_readline(fstring line
) {
271 fgets(line
, sizeof(fstring
), stdin
);
273 if(line
[strlen(line
)-1] == '\n')
274 line
[strlen(line
)-1] = '\0';
276 void edit_cac_user_info(TALLOC_CTX
*mem_ctx
, CacUserInfo
*info
) {
279 printf(" User Name [%s]: ", info
->username
);
283 info
->username
= talloc_strdup(mem_ctx
, tmp
);
285 printf(" Full Name [%s]: ", info
->full_name
);
289 info
->full_name
= talloc_strdup(mem_ctx
, tmp
);
291 printf(" Description [%s]: ", info
->description
);
294 info
->description
= talloc_strdup(mem_ctx
, tmp
);
296 printf(" Remote Dial [%s]: ", info
->dial
);
299 info
->dial
= talloc_strdup(mem_ctx
, tmp
);
301 printf(" ACB Mask [0x%x]: ", info
->acb_mask
);
304 sscanf(tmp
, "%x", &info
->acb_mask
);
306 printf(" Must change pass at next logon? [y/N]: ");
309 if(tmp
[0] == 'y' || tmp
[0] == 'Y')
310 info
->pass_must_change
= True
;
314 void print_cac_group_info(CacGroupInfo
*info
) {
315 printf(" Group Name : %s\n", info
->name
);
316 printf(" Description : %s\n", info
->description
);
317 printf(" Num Members : %d\n", info
->num_members
);
320 void edit_cac_group_info(TALLOC_CTX
*mem_ctx
, CacGroupInfo
*info
) {
323 printf("Group Name [%s]: ", info
->name
);
326 info
->name
= talloc_strdup(mem_ctx
, tmp
);
328 printf("Description [%s]: ", info
->description
);
331 info
->description
= talloc_strdup(mem_ctx
, tmp
);
334 char *srv_role_str(uint32 role
) {
336 case ROLE_STANDALONE
:
339 case ROLE_DOMAIN_MEMBER
:
340 return "DOMAIN_MEMBER";
342 case ROLE_DOMAIN_BDC
:
345 case ROLE_DOMAIN_PDC
:
350 return "Invalid role!\n";
353 char *cactime_str(CacTime ctime
, fstring tmp
) {
355 snprintf(tmp
, sizeof(fstring
), "%u Days, %u Hours, %u Minutes, %u Seconds", ctime
.days
, ctime
.hours
, ctime
.minutes
, ctime
.seconds
);
360 void print_cac_domain_info(CacDomainInfo
*info
) {
363 printf(" Server Role : %s\n", srv_role_str(info
->server_role
));
364 printf(" Num Users : %d\n", info
->num_users
);
365 printf(" Num Domain Groups: %d\n", info
->num_domain_groups
);
366 printf(" Num Local Groups : %d\n", info
->num_local_groups
);
367 printf(" Comment : %s\n", info
->comment
);
368 printf(" Domain Name : %s\n", info
->domain_name
);
369 printf(" Server Name : %s\n", info
->server_name
);
370 printf(" Min. Pass. Length: %d\n", info
->min_pass_length
);
371 printf(" Password History : %d\n", info
->pass_history
);
373 printf(" Passwords Expire In : %s\n", cactime_str(info
->expire
, tmp
));
374 printf(" Passwords Can Change in: %s\n", cactime_str(info
->min_pass_age
, tmp
));
375 printf(" Lockouts last : %s\n", cactime_str(info
->lockout_duration
, tmp
));
376 printf(" Allowed Bad Attempts : %d\n", info
->num_bad_attempts
);
379 void print_cac_service(CacService svc
) {
380 printf("\tService Name: %s\n", svc
.service_name
);
381 printf("\tDisplay Name: %s\n", svc
.display_name
);
382 print_service_status(svc
.status
);
385 void print_service_status(SERVICE_STATUS status
) {
386 printf("\tStatus:\n");
387 printf("\t Type: 0x%x\n", status
.type
);
388 printf("\t State: 0x%x\n", status
.state
);
389 printf("\t Controls: 0x%x\n", status
.controls_accepted
);
390 printf("\t W32 Exit Code: 0x%x\n", status
.win32_exit_code
);
391 printf("\t SVC Exit Code: 0x%x\n", status
.service_exit_code
);
392 printf("\t Checkpoint: 0x%x\n", status
.check_point
);
393 printf("\t Wait Hint: 0x%x\n", status
.wait_hint
);
397 void print_service_config(CacServiceConfig
*config
) {
398 printf("\tConfig:\n");
399 printf("\tType: 0x%x\n", config
->type
);
400 printf("\tStart Type: 0x%x\n", config
->start_type
);
401 printf("\tError config: 0x%x\n", config
->error_control
);
402 printf("\tExecutable Path: %s\n", config
->exe_path
);
403 printf("\tLoad Order Group: %s\n", config
->load_order_group
);
404 printf("\tTag ID: 0x%x\n", config
->tag_id
);
405 printf("\tDependencies: %s\n", config
->dependencies
);
406 printf("\tStart Name: %s\n", config
->start_name
);
407 printf("\tDisplay Name: %s\n", config
->display_name
);