first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[bbaumbach/samba-autobuild/.git] / source3 / rpcclient / display_sam.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    Samba utility functions
5    Copyright (C) Andrew Tridgell 1992-1999
6    Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful, 
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 /****************************************************************************
26  display alias members
27  ****************************************************************************/
28 void display_alias_members(FILE *out_hnd, enum action_type action, 
29                                 uint32 num_mem, char *const *const sid_mem, 
30                                 uint8 *const type)
31 {
32         switch (action)
33         {
34                 case ACTION_HEADER:
35                 {
36                         if (num_mem == 0)
37                         {
38                                 report(out_hnd, "\tNo Alias Members\n");
39                         }
40                         else
41                         {
42                                 report(out_hnd, "\tAlias Members:\n");
43                                 report(out_hnd, "\t-------------\n");
44                         }
45                         break;
46                 }
47                 case ACTION_ENUMERATE:
48                 {
49                         int i;
50
51                         for (i = 0; i < num_mem; i++)
52                         {
53                                 if (sid_mem[i] != NULL)
54                                 {
55                                         report(out_hnd, "\tMember Name:\t%s\tType:\t%s\n", 
56                                         sid_mem[i], 
57                                         get_sid_name_use_str(type[i]));
58                                 }
59                         }
60
61                         break;
62                 }
63                 case ACTION_FOOTER:
64                 {
65                         report(out_hnd, "\n");
66                         break;
67                 }
68         }
69 }
70
71
72 /****************************************************************************
73  display alias rid info
74  ****************************************************************************/
75 void display_alias_rid_info(FILE *out_hnd, enum action_type action, 
76                                 DOM_SID *const sid, 
77                                 uint32 num_rids, uint32 *const rid)
78 {
79         switch (action)
80         {
81                 case ACTION_HEADER:
82                 {
83                         fstring sid_str;
84                         sid_to_string(sid_str, sid);
85                         if (num_rids == 0)
86                         {
87                                 report(out_hnd, "\tNo Aliases:\tSid %s\n", sid_str);
88                         }
89                         else
90                         {
91                                 report(out_hnd, "\tAlias Info:\tSid %s\n", sid_str);
92                                 report(out_hnd, "\t----------\n");
93                         }
94                         break;
95                 }
96                 case ACTION_ENUMERATE:
97                 {
98                         int i;
99
100                         for (i = 0; i < num_rids; i++)
101                         {
102                                 report(out_hnd, "\tAlias RID:\t%8x\n", rid[i]);
103                         }
104
105                         break;
106                 }
107                 case ACTION_FOOTER:
108                 {
109                         report(out_hnd, "\n");
110                         break;
111                 }
112         }
113 }
114
115 /****************************************************************************
116  display group members
117  ****************************************************************************/
118 void display_group_members(FILE *out_hnd, enum action_type action, 
119                                 uint32 num_mem, char *const *const name, uint32 *const type)
120 {
121         switch (action)
122         {
123                 case ACTION_HEADER:
124                 {
125                         if (num_mem == 0)
126                         {
127                                 report(out_hnd, "\tNo Members\n");
128                         }
129                         else
130                         {
131                                 report(out_hnd, "\tMembers:\n");
132                                 report(out_hnd, "\t-------\n");
133                         }
134                         break;
135                 }
136                 case ACTION_ENUMERATE:
137                 {
138                         int i;
139
140                         for (i = 0; i < num_mem; i++)
141                         {
142                                 report(out_hnd, "\tMember Name:\t%s\tType:\t%s\n", 
143                                         name[i], get_sid_name_use_str(type[i]));
144                         }
145
146                         break;
147                 }
148                 case ACTION_FOOTER:
149                 {
150                         report(out_hnd, "\n");
151                         break;
152                 }
153         }
154 }
155
156
157 /****************************************************************************
158  display group info
159  ****************************************************************************/
160 void display_group_info1(FILE *out_hnd, enum action_type action, GROUP_INFO1 *const info1)
161                                 
162 {
163         switch (action)
164         {
165                 case ACTION_HEADER:
166                 {
167                         break;
168                 }
169                 case ACTION_ENUMERATE:
170                 {
171                         fstring temp;
172
173                         unistr2_to_ascii(temp, &info1->uni_acct_name, sizeof(temp)-1);
174                         report(out_hnd, "\tGroup Name:\t%s\n", temp);
175                         unistr2_to_ascii(temp, &info1->uni_acct_desc, sizeof(temp)-1);
176                         report(out_hnd, "\tDescription:\t%s\n", temp);
177                         report(out_hnd, "\tunk1:%d\n", info1->unknown_1);
178                         report(out_hnd, "\tNum Members:%d\n", info1->num_members);
179                         break;
180                 }
181                 case ACTION_FOOTER:
182                 {
183                         break;
184                 }
185         }
186 }
187
188 /****************************************************************************
189  display group info
190  ****************************************************************************/
191 void display_group_info4(FILE *out_hnd, enum action_type action, GROUP_INFO4 *const info4)
192                                 
193 {
194         switch (action)
195         {
196                 case ACTION_HEADER:
197                 {
198                         break;
199                 }
200                 case ACTION_ENUMERATE:
201                 {
202                         fstring desc;
203
204                         unistr2_to_ascii(desc, &info4->uni_acct_desc, sizeof(desc)-1);
205                         report(out_hnd, "\tGroup Description:%s\n", 
206                                           desc);
207                         break;
208                 }
209                 case ACTION_FOOTER:
210                 {
211                         break;
212                 }
213         }
214 }
215
216 /****************************************************************************
217  display sam sync structure
218  ****************************************************************************/
219 void display_group_info_ctr(FILE *out_hnd, enum action_type action, 
220                                 GROUP_INFO_CTR *const ctr)
221 {
222         switch (action)
223         {
224                 case ACTION_HEADER:
225                 {
226                         report(out_hnd, "\tSAM Group Info\n"); 
227                         report(out_hnd, "\t--------------\n");
228
229                         break;
230                 }
231                 case ACTION_ENUMERATE:
232                 {
233                         switch (ctr->switch_value1)
234                         {
235                                 case 1:
236                                 {
237                                         display_group_info1(out_hnd, ACTION_HEADER   , &ctr->group.info1);
238                                         display_group_info1(out_hnd, ACTION_ENUMERATE, &ctr->group.info1);
239                                         display_group_info1(out_hnd, ACTION_FOOTER   , &ctr->group.info1);
240                                         break;
241                                 }
242                                 case 4:
243                                 {
244                                         display_group_info4(out_hnd, ACTION_HEADER   , &ctr->group.info4);
245                                         display_group_info4(out_hnd, ACTION_ENUMERATE, &ctr->group.info4);
246                                         display_group_info4(out_hnd, ACTION_FOOTER   , &ctr->group.info4);
247                                         break;
248                                 }
249                         }
250                         break;
251                 }
252                 case ACTION_FOOTER:
253                 {
254                         report(out_hnd, "\n");
255                         break;
256                 }
257         }
258 }
259
260 /****************************************************************************
261  display group rid info
262  ****************************************************************************/
263 void display_group_rid_info(FILE *out_hnd, enum action_type action, 
264                                 uint32 num_gids, DOM_GID *const gid)
265 {
266         switch (action)
267         {
268                 case ACTION_HEADER:
269                 {
270                         if (num_gids == 0)
271                         {
272                                 report(out_hnd, "\tNo Groups\n");
273                         }
274                         else
275                         {
276                                 report(out_hnd, "\tGroup Info\n");
277                                 report(out_hnd, "\t----------\n");
278                         }
279                         break;
280                 }
281                 case ACTION_ENUMERATE:
282                 {
283                         int i;
284
285                         for (i = 0; i < num_gids; i++)
286                         {
287                                 report(out_hnd, "\tGroup RID:\t%8x attr:\t%x\n", 
288                                                                   gid[i].g_rid, gid[i].attr);
289                         }
290
291                         break;
292                 }
293                 case ACTION_FOOTER:
294                 {
295                         report(out_hnd, "\n");
296                         break;
297                 }
298         }
299 }
300
301
302 /****************************************************************************
303  display alias name info
304  ****************************************************************************/
305 void display_alias_name_info(FILE *out_hnd, enum action_type action, 
306                                 uint32 num_aliases, fstring *const alias_name, const uint32 *const num_als_usrs)
307 {
308         switch (action)
309         {
310                 case ACTION_HEADER:
311                 {
312                         if (num_aliases == 0)
313                         {
314                                 report(out_hnd, "\tNo Aliases\n");
315                         }
316                         else
317                         {
318                                 report(out_hnd, "\tAlias Names\n");
319                                 report(out_hnd, "\t----------- \n");
320                         }
321                         break;
322                 }
323                 case ACTION_ENUMERATE:
324                 {
325                         int i;
326
327                         for (i = 0; i < num_aliases; i++)
328                         {
329                                 report(out_hnd, "\tAlias Name:\t%s Attributes:\t%3d\n", 
330                                                                   alias_name[i], num_als_usrs[i]);
331                         }
332
333                         break;
334                 }
335                 case ACTION_FOOTER:
336                 {
337                         report(out_hnd, "\n");
338                         break;
339                 }
340         }
341 }
342
343 /****************************************************************************
344  display alias info
345  ****************************************************************************/
346 void display_alias_info3(FILE *out_hnd, enum action_type action, ALIAS_INFO3 *const info3)
347                                 
348 {
349         switch (action)
350         {
351                 case ACTION_HEADER:
352                 {
353                         break;
354                 }
355                 case ACTION_ENUMERATE:
356                 {
357                         fstring temp;
358
359                         unistr2_to_ascii(temp, &info3->uni_acct_desc, sizeof(temp)-1);
360                         report(out_hnd, "\tDescription:\t%s\n", temp);
361                         break;
362                 }
363                 case ACTION_FOOTER:
364                 {
365                         break;
366                 }
367         }
368 }
369
370 /****************************************************************************
371  display sam sync structure
372  ****************************************************************************/
373 void display_alias_info_ctr(FILE *out_hnd, enum action_type action, 
374                                 ALIAS_INFO_CTR *const ctr)
375 {
376         switch (action)
377         {
378                 case ACTION_HEADER:
379                 {
380                         report(out_hnd, "\tSAM Group Info\n"); 
381                         report(out_hnd, "\t--------------\n");
382
383                         break;
384                 }
385                 case ACTION_ENUMERATE:
386                 {
387                         switch (ctr->switch_value1)
388                         {
389                                 case 3:
390                                 {
391                                         display_alias_info3(out_hnd, ACTION_HEADER   , &ctr->alias.info3);
392                                         display_alias_info3(out_hnd, ACTION_ENUMERATE, &ctr->alias.info3);
393                                         display_alias_info3(out_hnd, ACTION_FOOTER   , &ctr->alias.info3);
394                                         break;
395                                 }
396                         }
397                         break;
398                 }
399                 case ACTION_FOOTER:
400                 {
401                         report(out_hnd, "\n");
402                         break;
403                 }
404         }
405 }
406
407
408 /****************************************************************************
409  display sam_user_info_21 structure
410  ****************************************************************************/
411 void display_sam_user_info_21(FILE *out_hnd, enum action_type action, SAM_USER_INFO_21 *const usr)
412 {
413         switch (action)
414         {
415                 case ACTION_HEADER:
416                 {
417                         report(out_hnd, "\tUser Info, Level 0x15\n");
418                         report(out_hnd, "\t---------------------\n");
419
420                         break;
421                 }
422                 case ACTION_ENUMERATE:
423                 {
424                         fstring temp;
425
426                         unistr2_to_ascii(temp, &usr->uni_user_name, sizeof(temp)-1);
427                         report(out_hnd, "\t\tUser Name   :\t%s\n", temp);
428
429                         unistr2_to_ascii(temp, &usr->uni_full_name, sizeof(temp)-1);
430                         report(out_hnd, "\t\tFull Name   :\t%s\n", temp);
431
432                         unistr2_to_ascii(temp, &usr->uni_home_dir, sizeof(temp)-1);
433                         report(out_hnd, "\t\tHome Drive  :\t%s\n", temp);
434
435                         unistr2_to_ascii(temp, &usr->uni_dir_drive, sizeof(temp)-1);
436                         report(out_hnd, "\t\tDir Drive   :\t%s\n", temp);
437
438                         unistr2_to_ascii(temp, &usr->uni_profile_path, sizeof(temp)-1);
439                         report(out_hnd, "\t\tProfile Path:\t%s\n", temp);
440
441                         unistr2_to_ascii(temp, &usr->uni_logon_script, sizeof(temp)-1);
442                         report(out_hnd, "\t\tLogon Script:\t%s\n", temp);
443
444                         unistr2_to_ascii(temp, &usr->uni_acct_desc, sizeof(temp)-1);
445                         report(out_hnd, "\t\tDescription :\t%s\n", temp);
446
447                         unistr2_to_ascii(temp, &usr->uni_workstations, sizeof(temp)-1);
448                         report(out_hnd, "\t\tWorkstations:\t%s\n", temp);
449
450                         unistr2_to_ascii(temp, &usr->uni_unknown_str, sizeof(temp)-1);
451                         report(out_hnd, "\t\tUnknown Str :\t%s\n", temp);
452
453                         unistr2_to_ascii(temp, &usr->uni_munged_dial, sizeof(temp)-1);
454                         report(out_hnd, "\t\tRemote Dial :\t%s\n", temp);
455
456                         report(out_hnd, "\t\tLogon Time               :\t%s\n", http_timestring(nt_time_to_unix(&(usr->logon_time           ))));
457                         report(out_hnd, "\t\tLogoff Time              :\t%s\n", http_timestring(nt_time_to_unix(&(usr->logoff_time          ))));
458                         report(out_hnd, "\t\tKickoff Time             :\t%s\n", http_timestring(nt_time_to_unix(&(usr->kickoff_time         ))));
459                         report(out_hnd, "\t\tPassword last set Time   :\t%s\n", http_timestring(nt_time_to_unix(&(usr->pass_last_set_time   ))));
460                         report(out_hnd, "\t\tPassword can change Time :\t%s\n", http_timestring(nt_time_to_unix(&(usr->pass_can_change_time ))));
461                         report(out_hnd, "\t\tPassword must change Time:\t%s\n", http_timestring(nt_time_to_unix(&(usr->pass_must_change_time))));
462                         
463                         report(out_hnd, "\t\tunknown_2[0..31]...\n"); /* user passwords? */
464
465                         report(out_hnd, "\t\tuser_rid :\t%x\n"  , usr->user_rid ); /* User ID */
466                         report(out_hnd, "\t\tgroup_rid:\t%x\n"  , usr->group_rid); /* Group ID */
467                         report(out_hnd, "\t\tacb_info :\t%04x\n", usr->acb_info ); /* Account Control Info */
468
469                         report(out_hnd, "\t\tunknown_3:\t%08x\n", usr->unknown_3); /* 0x00ff ffff */
470                         report(out_hnd, "\t\tlogon_divs:\t%d\n", usr->logon_divs); /* 0x0000 00a8 which is 168 which is num hrs in a week */
471                         report(out_hnd, "\t\tunknown_5:\t%08x\n", usr->unknown_5); /* 0x0002 0000 */
472
473                         report(out_hnd, "\t\tpadding1[0..7]...\n");
474
475                         if (usr->ptr_logon_hrs)
476                         {
477                                 report(out_hnd, "\t\tlogon_hrs[0..%d]...\n", usr->logon_hrs.len);
478                         }
479
480                         break;
481                 }
482                 case ACTION_FOOTER:
483                 {
484                         report(out_hnd, "\n");
485                         break;
486                 }
487         }
488 }
489
490
491 /****************************************************************************
492  display sam sync structure
493  ****************************************************************************/
494 void display_sam_unk_info_2(FILE *out_hnd, enum action_type action, 
495                                 SAM_UNK_INFO_2 *const info2)
496 {
497         switch (action)
498         {
499                 case ACTION_HEADER:
500                 {
501                         break;
502                 }
503                 case ACTION_ENUMERATE:
504                 {
505                         fstring name;
506                         unistr2_to_ascii(name, &(info2->uni_domain), sizeof(name)-1); 
507                         report(out_hnd, "Domain:\t%s\n", name);
508
509                         unistr2_to_ascii(name, &(info2->uni_server), sizeof(name)-1); 
510                         report(out_hnd, "Server:\t%s\n", name);
511
512                         report(out_hnd, "Total Users:\t%d\n", info2->num_domain_usrs);
513                         report(out_hnd, "Total Groups:\t%d\n", info2->num_domain_grps);
514                         report(out_hnd, "Total Aliases:\t%d\n", info2->num_local_grps);
515
516                         report(out_hnd, "Sequence No:\t%d\n", info2->seq_num);
517
518                         report(out_hnd, "Unknown 0:\t0x%x\n", info2->unknown_0);
519                         report(out_hnd, "Unknown 1:\t0x%x\n", info2->unknown_1);
520                         report(out_hnd, "Unknown 2:\t0x%x\n", info2->unknown_2);
521                         report(out_hnd, "Unknown 3:\t0x%x\n", info2->unknown_3);
522                         report(out_hnd, "Unknown 4:\t0x%x\n", info2->unknown_4);
523                         report(out_hnd, "Unknown 5:\t0x%x\n", info2->unknown_5);
524                         report(out_hnd, "Unknown 6:\t0x%x\n", info2->unknown_6);
525
526                         break;
527                 }
528                 case ACTION_FOOTER:
529                 {
530                         report(out_hnd, "\n");
531                         break;
532                 }
533         }
534 }
535
536 /****************************************************************************
537  display sam sync structure
538  ****************************************************************************/
539 void display_sam_unk_ctr(FILE *out_hnd, enum action_type action, 
540                                 uint32 switch_value, SAM_UNK_CTR *const ctr)
541 {
542         switch (action)
543         {
544                 case ACTION_HEADER:
545                 {
546                         report(out_hnd, "\tSAM Domain Info\n"); 
547                         report(out_hnd, "\t---------------\n");
548
549                         break;
550                 }
551                 case ACTION_ENUMERATE:
552                 {
553                         switch (switch_value)
554                         {
555                                 case 2:
556                                 {
557                                         display_sam_unk_info_2(out_hnd, ACTION_HEADER   , &ctr->info.inf2);
558                                         display_sam_unk_info_2(out_hnd, ACTION_ENUMERATE, &ctr->info.inf2);
559                                         display_sam_unk_info_2(out_hnd, ACTION_FOOTER   , &ctr->info.inf2);
560                                         break;
561                                 }
562                         }
563                         break;
564                 }
565                 case ACTION_FOOTER:
566                 {
567                         report(out_hnd, "\n");
568                         break;
569                 }
570         }
571 }
572
573 /****************************************************************************
574 sam info level 1 display function
575 ****************************************************************************/
576 void display_sam_info_1(FILE *out_hnd, enum action_type action, 
577                 SAM_ENTRY1 *const e1, SAM_STR1 *const s1)
578 {
579         if (e1 == NULL)
580         {
581                 return;
582         }
583
584         switch (action)
585         {
586                 case ACTION_HEADER:
587                 {
588                         report(out_hnd, "Sam Level 1:\n");
589
590                         break;
591                 }
592                 case ACTION_ENUMERATE:
593                 {
594                         fstring tmp;
595
596                         report(out_hnd, "\tIndex:\t%d\n", e1->user_idx);
597                         report(out_hnd, "\tRID:\t0x%x\n", e1->rid_user);
598                         report(out_hnd, "\tACB:\t%s\n", 
599                                      pwdb_encode_acct_ctrl(e1->acb_info,
600                                      NEW_PW_FORMAT_SPACE_PADDED_LEN));
601
602                         unistr_to_ascii(tmp, s1->uni_acct_name.buffer, sizeof(tmp)-1);
603                         report(out_hnd, "\tAccount Name:\t%s\n", tmp);
604                         unistr_to_ascii(tmp, s1->uni_full_name.buffer, sizeof(tmp)-1);
605                         report(out_hnd, "\tFull Name:\t%s\n", tmp);
606                         unistr_to_ascii(tmp, s1->uni_acct_desc.buffer, sizeof(tmp)-1);
607                         report(out_hnd, "\tUser Description:\t%s\n", tmp);
608
609                         break;
610                 }
611                 case ACTION_FOOTER:
612                 {
613                         report(out_hnd, "\n");
614                         break;
615                 }
616         }
617
618 }
619
620 /****************************************************************************
621 connection info level 1 container display function
622 ****************************************************************************/
623 void display_sam_info_1_ctr(FILE *out_hnd, enum action_type action, 
624                                 uint32 count, SAM_DISPINFO_1 *const ctr)
625 {
626         if (ctr == NULL)
627         {
628                 report(out_hnd, "display_sam_info_1_ctr: unavailable due to an internal error\n");
629                 return;
630         }
631
632         switch (action)
633         {
634                 case ACTION_HEADER:
635                 {
636                         break;
637                 }
638                 case ACTION_ENUMERATE:
639                 {
640                         int i;
641
642                         for (i = 0; i < count; i++)
643                         {
644                                 display_sam_info_1(out_hnd, ACTION_HEADER   , &ctr->sam[i], &ctr->str[i]);
645                                 display_sam_info_1(out_hnd, ACTION_ENUMERATE, &ctr->sam[i], &ctr->str[i]);
646                                 display_sam_info_1(out_hnd, ACTION_FOOTER   , &ctr->sam[i], &ctr->str[i]);
647                         }
648                         break;
649                 }
650                 case ACTION_FOOTER:
651                 {
652                         break;
653                 }
654         }
655 }
656
657 /****************************************************************************
658 connection info container display function
659 ****************************************************************************/
660 void display_sam_disp_info_ctr(FILE *out_hnd, enum action_type action, 
661                                 uint16 level, uint32 count,
662                                 SAM_DISPINFO_CTR *const ctr)
663 {
664         if (ctr == NULL)
665         {
666                 report(out_hnd, "display_sam_info_ctr: unavailable due to an internal error\n");
667                 return;
668         }
669
670         switch (level)
671         {
672                 case 1:
673                 {
674                         display_sam_info_1_ctr(out_hnd, action, 
675                                            count, ctr->sam.info1);
676                         break;
677                 }
678                 default:
679                 {
680                         report(out_hnd, "display_sam_info_ctr: Unknown Info Level\n");
681                         break;
682                 }
683         }
684 }
685