summaryrefslogtreecommitdiff
path: root/source4/utils/status.c
blob: 76b925364662c6f9164214dc1df3dfec79a031b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/* 
   Unix SMB/CIFS implementation.
   status reporting
   Copyright (C) Andrew Tridgell 1994-1998
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

   Revision History:

   12 aug 96: Erik.Devriendt@te6.siemens.be
   added support for shared memory implementation of share mode locking

   21-Jul-1998: rsharpe@ns.aus.com (Richard Sharpe)
   Added -L (locks only) -S (shares only) flags and code

*/

/*
 * This program reports current SMB connections
 */

#include "includes.h"

static pstring Ucrit_username = "";                   /* added by OH */
static pid_t	Ucrit_pid[100];  /* Ugly !!! */        /* added by OH */
static int            Ucrit_MaxPid=0;                        /* added by OH */
static unsigned int   Ucrit_IsActive = 0;                    /* added by OH */
static int verbose, brief;
static int            shares_only = 0;            /* Added by RJS */
static int            locks_only  = 0;            /* Added by RJS */
static BOOL processes_only=False;
static int show_brl;

/* we need these because we link to locking*.o */
 void become_root(void) {}
 void unbecome_root(void) {}


/* added by OH */
static void Ucrit_addUsername(const char *username)
{
	pstrcpy(Ucrit_username, username);
	if(strlen(Ucrit_username) > 0)
		Ucrit_IsActive = 1;
}

static unsigned int Ucrit_checkUsername(const char *username)
{
	if ( !Ucrit_IsActive) return 1;
	if (strcmp(Ucrit_username,username) ==0) return 1;
	return 0;
}

static unsigned int Ucrit_checkPid(pid_t pid)
{
	int i;
	if ( !Ucrit_IsActive) return 1;
	for (i=0;i<Ucrit_MaxPid;i++)
		if( pid == Ucrit_pid[i] ) return 1;
	return 0;
}


static void print_share_mode(share_mode_entry *e, char *fname)
{
	static int count;
	if (count==0) {
		d_printf("Locked files:\n");
		d_printf("Pid    DenyMode   Access      R/W        Oplock           Name\n");
		d_printf("--------------------------------------------------------------\n");
	}
	count++;

	if (Ucrit_checkPid(e->pid)) {
          d_printf("%-5d  ",(int)e->pid);
	  switch (GET_DENY_MODE(e->share_mode)) {
	  case DENY_NONE: d_printf("DENY_NONE  "); break;
	  case DENY_ALL:  d_printf("DENY_ALL   "); break;
	  case DENY_DOS:  d_printf("DENY_DOS   "); break;
	  case DENY_READ: d_printf("DENY_READ  "); break;
	  case DENY_WRITE:printf("DENY_WRITE "); break;
	  case DENY_FCB:  d_printf("DENY_FCB "); break;
	  }
	  d_printf("0x%-8x  ",(unsigned int)e->desired_access);
	  switch (e->share_mode&0xF) {
	  case 0: d_printf("RDONLY     "); break;
	  case 1: d_printf("WRONLY     "); break;
	  case 2: d_printf("RDWR       "); break;
	  }

	  if((e->op_type & 
	     (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == 
	      (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
		d_printf("EXCLUSIVE+BATCH ");
	  else if (e->op_type & EXCLUSIVE_OPLOCK)
		d_printf("EXCLUSIVE       ");
	  else if (e->op_type & BATCH_OPLOCK)
		d_printf("BATCH           ");
	  else if (e->op_type & LEVEL_II_OPLOCK)
		d_printf("LEVEL_II        ");
	  else
		d_printf("NONE            ");

	  d_printf(" %s   %s",fname,
             asctime(LocalTime((time_t *)&e->time.tv_sec)));
	}
}

static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, 
		      enum brl_type lock_type,
		      br_off start, br_off size)
{
	static int count;
	if (count==0) {
		d_printf("Byte range locks:\n");
		d_printf("   Pid     dev:inode  R/W      start        size\n");
		d_printf("------------------------------------------------\n");
	}
	count++;

	d_printf("%6d   %05x:%05x    %s  %9.0f   %9.0f\n", 
	       (int)pid, (int)dev, (int)ino, 
	       lock_type==READ_LOCK?"R":"W",
	       (double)start, (double)size);
}


/*******************************************************************
 dump the elements of the profile structure
  ******************************************************************/
static int profile_dump(void)
{
#ifdef WITH_PROFILE
	if (!profile_setup(True)) {
		fprintf(stderr,"Failed to initialise profile memory\n");
		return -1;
	}

	d_printf("smb_count:                      %u\n", profile_p->smb_count);
	d_printf("uid_changes:                    %u\n", profile_p->uid_changes);
	d_printf("************************ System Calls ****************************\n");
	d_printf("opendir_count:                  %u\n", profile_p->syscall_opendir_count);
	d_printf("opendir_time:                   %u\n", profile_p->syscall_opendir_time);
	d_printf("readdir_count:                  %u\n", profile_p->syscall_readdir_count);
	d_printf("readdir_time:                   %u\n", profile_p->syscall_readdir_time);
	d_printf("mkdir_count:                    %u\n", profile_p->syscall_mkdir_count);
	d_printf("mkdir_time:                     %u\n", profile_p->syscall_mkdir_time);
	d_printf("rmdir_count:                    %u\n", profile_p->syscall_rmdir_count);
	d_printf("rmdir_time:                     %u\n", profile_p->syscall_rmdir_time);
	d_printf("closedir_count:                 %u\n", profile_p->syscall_closedir_count);
	d_printf("closedir_time:                  %u\n", profile_p->syscall_closedir_time);
	d_printf("open_count:                     %u\n", profile_p->syscall_open_count);
	d_printf("open_time:                      %u\n", profile_p->syscall_open_time);
	d_printf("close_count:                    %u\n", profile_p->syscall_close_count);
	d_printf("close_time:                     %u\n", profile_p->syscall_close_time);
	d_printf("read_count:                     %u\n", profile_p->syscall_read_count);
	d_printf("read_time:                      %u\n", profile_p->syscall_read_time);
	d_printf("read_bytes:                     %u\n", profile_p->syscall_read_bytes);
	d_printf("write_count:                    %u\n", profile_p->syscall_write_count);
	d_printf("write_time:                     %u\n", profile_p->syscall_write_time);
	d_printf("write_bytes:                    %u\n", profile_p->syscall_write_bytes);
#ifdef WITH_SENDFILE
	d_printf("sendfile_count:                 %u\n", profile_p->syscall_sendfile_count);
	d_printf("sendfile_time:                  %u\n", profile_p->syscall_sendfile_time);
	d_printf("sendfile_bytes:                 %u\n", profile_p->syscall_sendfile_bytes);
#endif
	d_printf("lseek_count:                    %u\n", profile_p->syscall_lseek_count);
	d_printf("lseek_time:                     %u\n", profile_p->syscall_lseek_time);
	d_printf("rename_count:                   %u\n", profile_p->syscall_rename_count);
	d_printf("rename_time:                    %u\n", profile_p->syscall_rename_time);
	d_printf("fsync_count:                    %u\n", profile_p->syscall_fsync_count);
	d_printf("fsync_time:                     %u\n", profile_p->syscall_fsync_time);
	d_printf("stat_count:                     %u\n", profile_p->syscall_stat_count);
	d_printf("stat_time:                      %u\n", profile_p->syscall_stat_time);
	d_printf("fstat_count:                    %u\n", profile_p->syscall_fstat_count);
	d_printf("fstat_time:                     %u\n", profile_p->syscall_fstat_time);
	d_printf("lstat_count:                    %u\n", profile_p->syscall_lstat_count);
	d_printf("lstat_time:                     %u\n", profile_p->syscall_lstat_time);
	d_printf("unlink_count:                   %u\n", profile_p->syscall_unlink_count);
	d_printf("unlink_time:                    %u\n", profile_p->syscall_unlink_time);
	d_printf("chmod_count:                    %u\n", profile_p->syscall_chmod_count);
	d_printf("chmod_time:                     %u\n", profile_p->syscall_chmod_time);
	d_printf("fchmod_count:                   %u\n", profile_p->syscall_fchmod_count);
	d_printf("fchmod_time:                    %u\n", profile_p->syscall_fchmod_time);
	d_printf("chown_count:                    %u\n", profile_p->syscall_chown_count);
	d_printf("chown_time:                     %u\n", profile_p->syscall_chown_time);
	d_printf("fchown_count:                   %u\n", profile_p->syscall_fchown_count);
	d_printf("fchown_time:                    %u\n", profile_p->syscall_fchown_time);
	d_printf("chdir_count:                    %u\n", profile_p->syscall_chdir_count);
	d_printf("chdir_time:                     %u\n", profile_p->syscall_chdir_time);
	d_printf("getwd_count:                    %u\n", profile_p->syscall_getwd_count);
	d_printf("getwd_time:                     %u\n", profile_p->syscall_getwd_time);
	d_printf("utime_count:                    %u\n", profile_p->syscall_utime_count);
	d_printf("utime_time:                     %u\n", profile_p->syscall_utime_time);
	d_printf("ftruncate_count:                %u\n", profile_p->syscall_ftruncate_count);
	d_printf("ftruncate_time:                 %u\n", profile_p->syscall_ftruncate_time);
	d_printf("fcntl_lock_count:               %u\n", profile_p->syscall_fcntl_lock_count);
	d_printf("fcntl_lock_time:                %u\n", profile_p->syscall_fcntl_lock_time);
	d_printf("readlink_count:                 %u\n", profile_p->syscall_readlink_count);
	d_printf("readlink_time:                  %u\n", profile_p->syscall_readlink_time);
	d_printf("symlink_count:                  %u\n", profile_p->syscall_symlink_count);
	d_printf("symlink_time:                   %u\n", profile_p->syscall_symlink_time);
	d_printf("************************ Statcache *******************************\n");
	d_printf("lookups:                        %u\n", profile_p->statcache_lookups);
	d_printf("misses:                         %u\n", profile_p->statcache_misses);
	d_printf("hits:                           %u\n", profile_p->statcache_hits);
	d_printf("************************ Writecache ******************************\n");
	d_printf("read_hits:                      %u\n", profile_p->writecache_read_hits);
	d_printf("abutted_writes:                 %u\n", profile_p->writecache_abutted_writes);
	d_printf("total_writes:                   %u\n", profile_p->writecache_total_writes);
	d_printf("non_oplock_writes:              %u\n", profile_p->writecache_non_oplock_writes);
	d_printf("direct_writes:                  %u\n", profile_p->writecache_direct_writes);
	d_printf("init_writes:                    %u\n", profile_p->writecache_init_writes);
	d_printf("flushed_writes[SEEK]:           %u\n", profile_p->writecache_flushed_writes[SEEK_FLUSH]);
	d_printf("flushed_writes[READ]:           %u\n", profile_p->writecache_flushed_writes[READ_FLUSH]);
	d_printf("flushed_writes[WRITE]:          %u\n", profile_p->writecache_flushed_writes[WRITE_FLUSH]);
	d_printf("flushed_writes[READRAW]:        %u\n", profile_p->writecache_flushed_writes[READRAW_FLUSH]);
	d_printf("flushed_writes[OPLOCK_RELEASE]: %u\n", profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH]);
	d_printf("flushed_writes[CLOSE]:          %u\n", profile_p->writecache_flushed_writes[CLOSE_FLUSH]);
	d_printf("flushed_writes[SYNC]:           %u\n", profile_p->writecache_flushed_writes[SYNC_FLUSH]);
	d_printf("flushed_writes[SIZECHANGE]:     %u\n", profile_p->writecache_flushed_writes[SIZECHANGE_FLUSH]);
	d_printf("num_perfect_writes:             %u\n", profile_p->writecache_num_perfect_writes);
	d_printf("num_write_caches:               %u\n", profile_p->writecache_num_write_caches);
	d_printf("allocated_write_caches:         %u\n", profile_p->writecache_allocated_write_caches);
	d_printf("************************ SMB Calls *******************************\n");
	d_printf("mkdir_count:                    %u\n", profile_p->SMBmkdir_count);
	d_printf("mkdir_time:                     %u\n", profile_p->SMBmkdir_time);
	d_printf("rmdir_count:                    %u\n", profile_p->SMBrmdir_count);
	d_printf("rmdir_time:                     %u\n", profile_p->SMBrmdir_time);
	d_printf("open_count:                     %u\n", profile_p->SMBopen_count);
	d_printf("open_time:                      %u\n", profile_p->SMBopen_time);
	d_printf("create_count:                   %u\n", profile_p->SMBcreate_count);
	d_printf("create_time:                    %u\n", profile_p->SMBcreate_time);
	d_printf("close_count:                    %u\n", profile_p->SMBclose_count);
	d_printf("close_time:                     %u\n", profile_p->SMBclose_time);
	d_printf("flush_count:                    %u\n", profile_p->SMBflush_count);
	d_printf("flush_time:                     %u\n", profile_p->SMBflush_time);
	d_printf("unlink_count:                   %u\n", profile_p->SMBunlink_count);
	d_printf("unlink_time:                    %u\n", profile_p->SMBunlink_time);
	d_printf("mv_count:                       %u\n", profile_p->SMBmv_count);
	d_printf("mv_time:                        %u\n", profile_p->SMBmv_time);
	d_printf("getatr_count:                   %u\n", profile_p->SMBgetatr_count);
	d_printf("getatr_time:                    %u\n", profile_p->SMBgetatr_time);
	d_printf("setatr_count:                   %u\n", profile_p->SMBsetatr_count);
	d_printf("setatr_time:                    %u\n", profile_p->SMBsetatr_time);
	d_printf("read_count:                     %u\n", profile_p->SMBread_count);
	d_printf("read_time:                      %u\n", profile_p->SMBread_time);
	d_printf("write_count:                    %u\n", profile_p->SMBwrite_count);
	d_printf("write_time:                     %u\n", profile_p->SMBwrite_time);
	d_printf("lock_count:                     %u\n", profile_p->SMBlock_count);
	d_printf("lock_time:                      %u\n", profile_p->SMBlock_time);
	d_printf("unlock_count:                   %u\n", profile_p->SMBunlock_count);
	d_printf("unlock_time:                    %u\n", profile_p->SMBunlock_time);
	d_printf("ctemp_count:                    %u\n", profile_p->SMBctemp_count);
	d_printf("ctemp_time:                     %u\n", profile_p->SMBctemp_time);
	d_printf("mknew_count:                    %u\n", profile_p->SMBmknew_count);
	d_printf("mknew_time:                     %u\n", profile_p->SMBmknew_time);
	d_printf("chkpth_count:                   %u\n", profile_p->SMBchkpth_count);
	d_printf("chkpth_time:                    %u\n", profile_p->SMBchkpth_time);
	d_printf("exit_count:                     %u\n", profile_p->SMBexit_count);
	d_printf("exit_time:                      %u\n", profile_p->SMBexit_time);
	d_printf("lseek_count:                    %u\n", profile_p->SMBlseek_count);
	d_printf("lseek_time:                     %u\n", profile_p->SMBlseek_time);
	d_printf("lockread_count:                 %u\n", profile_p->SMBlockread_count);
	d_printf("lockread_time:                  %u\n", profile_p->SMBlockread_time);
	d_printf("writeunlock_count:              %u\n", profile_p->SMBwriteunlock_count);
	d_printf("writeunlock_time:               %u\n", profile_p->SMBwriteunlock_time);
	d_printf("readbraw_count:                 %u\n", profile_p->SMBreadbraw_count);
	d_printf("readbraw_time:                  %u\n", profile_p->SMBreadbraw_time);
	d_printf("readBmpx_count:                 %u\n", profile_p->SMBreadBmpx_count);
	d_printf("readBmpx_time:                  %u\n", profile_p->SMBreadBmpx_time);
	d_printf("readBs_count:                   %u\n", profile_p->SMBreadBs_count);
	d_printf("readBs_time:                    %u\n", profile_p->SMBreadBs_time);
	d_printf("writebraw_count:                %u\n", profile_p->SMBwritebraw_count);
	d_printf("writebraw_time:                 %u\n", profile_p->SMBwritebraw_time);
	d_printf("writeBmpx_count:                %u\n", profile_p->SMBwriteBmpx_count);
	d_printf("writeBmpx_time:                 %u\n", profile_p->SMBwriteBmpx_time);
	d_printf("writeBs_count:                  %u\n", profile_p->SMBwriteBs_count);
	d_printf("writeBs_time:                   %u\n", profile_p->SMBwriteBs_time);
	d_printf("writec_count:                   %u\n", profile_p->SMBwritec_count);
	d_printf("writec_time:                    %u\n", profile_p->SMBwritec_time);
	d_printf("setattrE_count:                 %u\n", profile_p->SMBsetattrE_count);
	d_printf("setattrE_time:                  %u\n", profile_p->SMBsetattrE_time);
	d_printf("getattrE_count:                 %u\n", profile_p->SMBgetattrE_count);
	d_printf("getattrE_time:                  %u\n", profile_p->SMBgetattrE_time);
	d_printf("lockingX_count:                 %u\n", profile_p->SMBlockingX_count);
	d_printf("lockingX_time:                  %u\n", profile_p->SMBlockingX_time);
	d_printf("trans_count:                    %u\n", profile_p->SMBtrans_count);
	d_printf("trans_time:                     %u\n", profile_p->SMBtrans_time);
	d_printf("transs_count:                   %u\n", profile_p->SMBtranss_count);
	d_printf("transs_time:                    %u\n", profile_p->SMBtranss_time);
	d_printf("ioctl_count:                    %u\n", profile_p->SMBioctl_count);
	d_printf("ioctl_time:                     %u\n", profile_p->SMBioctl_time);
	d_printf("ioctls_count:                   %u\n", profile_p->SMBioctls_count);
	d_printf("ioctls_time:                    %u\n", profile_p->SMBioctls_time);
	d_printf("copy_count:                     %u\n", profile_p->SMBcopy_count);
	d_printf("copy_time:                      %u\n", profile_p->SMBcopy_time);
	d_printf("move_count:                     %u\n", profile_p->SMBmove_count);
	d_printf("move_time:                      %u\n", profile_p->SMBmove_time);
	d_printf("echo_count:                     %u\n", profile_p->SMBecho_count);
	d_printf("echo_time:                      %u\n", profile_p->SMBecho_time);
	d_printf("writeclose_count:               %u\n", profile_p->SMBwriteclose_count);
	d_printf("writeclose_time:                %u\n", profile_p->SMBwriteclose_time);
	d_printf("openX_count:                    %u\n", profile_p->SMBopenX_count);
	d_printf("openX_time:                     %u\n", profile_p->SMBopenX_time);
	d_printf("readX_count:                    %u\n", profile_p->SMBreadX_count);
	d_printf("readX_time:                     %u\n", profile_p->SMBreadX_time);
	d_printf("writeX_count:                   %u\n", profile_p->SMBwriteX_count);
	d_printf("writeX_time:                    %u\n", profile_p->SMBwriteX_time);
	d_printf("trans2_count:                   %u\n", profile_p->SMBtrans2_count);
	d_printf("trans2_time:                    %u\n", profile_p->SMBtrans2_time);
	d_printf("transs2_count:                  %u\n", profile_p->SMBtranss2_count);
	d_printf("transs2_time:                   %u\n", profile_p->SMBtranss2_time);
	d_printf("findclose_count:                %u\n", profile_p->SMBfindclose_count);
	d_printf("findclose_time:                 %u\n", profile_p->SMBfindclose_time);
	d_printf("findnclose_count:               %u\n", profile_p->SMBfindnclose_count);
	d_printf("findnclose_time:                %u\n", profile_p->SMBfindnclose_time);
	d_printf("tcon_count:                     %u\n", profile_p->SMBtcon_count);
	d_printf("tcon_time:                      %u\n", profile_p->SMBtcon_time);
	d_printf("tdis_count:                     %u\n", profile_p->SMBtdis_count);
	d_printf("tdis_time:                      %u\n", profile_p->SMBtdis_time);
	d_printf("negprot_count:                  %u\n", profile_p->SMBnegprot_count);
	d_printf("negprot_time:                   %u\n", profile_p->SMBnegprot_time);
	d_printf("sesssetupX_count:               %u\n", profile_p->SMBsesssetupX_count);
	d_printf("sesssetupX_time:                %u\n", profile_p->SMBsesssetupX_time);
	d_printf("ulogoffX_count:                 %u\n", profile_p->SMBulogoffX_count);
	d_printf("ulogoffX_time:                  %u\n", profile_p->SMBulogoffX_time);
	d_printf("tconX_count:                    %u\n", profile_p->SMBtconX_count);
	d_printf("tconX_time:                     %u\n", profile_p->SMBtconX_time);
	d_printf("dskattr_count:                  %u\n", profile_p->SMBdskattr_count);
	d_printf("dskattr_time:                   %u\n", profile_p->SMBdskattr_time);
	d_printf("search_count:                   %u\n", profile_p->SMBsearch_count);
	d_printf("search_time:                    %u\n", profile_p->SMBsearch_time);
	d_printf("ffirst_count:                   %u\n", profile_p->SMBffirst_count);
	d_printf("ffirst_time:                    %u\n", profile_p->SMBffirst_time);
	d_printf("funique_count:                  %u\n", profile_p->SMBfunique_count);
	d_printf("funique_time:                   %u\n", profile_p->SMBfunique_time);
	d_printf("fclose_count:                   %u\n", profile_p->SMBfclose_count);
	d_printf("fclose_time:                    %u\n", profile_p->SMBfclose_time);
	d_printf("nttrans_count:                  %u\n", profile_p->SMBnttrans_count);
	d_printf("nttrans_time:                   %u\n", profile_p->SMBnttrans_time);
	d_printf("nttranss_count:                 %u\n", profile_p->SMBnttranss_count);
	d_printf("nttranss_time:                  %u\n", profile_p->SMBnttranss_time);
	d_printf("ntcreateX_count:                %u\n", profile_p->SMBntcreateX_count);
	d_printf("ntcreateX_time:                 %u\n", profile_p->SMBntcreateX_time);
	d_printf("ntcancel_count:                 %u\n", profile_p->SMBntcancel_count);
	d_printf("ntcancel_time:                  %u\n", profile_p->SMBntcancel_time);
	d_printf("splopen_count:                  %u\n", profile_p->SMBsplopen_count);
	d_printf("splopen_time:                   %u\n", profile_p->SMBsplopen_time);
	d_printf("splwr_count:                    %u\n", profile_p->SMBsplwr_count);
	d_printf("splwr_time:                     %u\n", profile_p->SMBsplwr_time);
	d_printf("splclose_count:                 %u\n", profile_p->SMBsplclose_count);
	d_printf("splclose_time:                  %u\n", profile_p->SMBsplclose_time);
	d_printf("splretq_count:                  %u\n", profile_p->SMBsplretq_count);
	d_printf("splretq_time:                   %u\n", profile_p->SMBsplretq_time);
	d_printf("sends_count:                    %u\n", profile_p->SMBsends_count);
	d_printf("sends_time:                     %u\n", profile_p->SMBsends_time);
	d_printf("sendb_count:                    %u\n", profile_p->SMBsendb_count);
	d_printf("sendb_time:                     %u\n", profile_p->SMBsendb_time);
	d_printf("fwdname_count:                  %u\n", profile_p->SMBfwdname_count);
	d_printf("fwdname_time:                   %u\n", profile_p->SMBfwdname_time);
	d_printf("cancelf_count:                  %u\n", profile_p->SMBcancelf_count);
	d_printf("cancelf_time:                   %u\n", profile_p->SMBcancelf_time);
	d_printf("getmac_count:                   %u\n", profile_p->SMBgetmac_count);
	d_printf("getmac_time:                    %u\n", profile_p->SMBgetmac_time);
	d_printf("sendstrt_count:                 %u\n", profile_p->SMBsendstrt_count);
	d_printf("sendstrt_time:                  %u\n", profile_p->SMBsendstrt_time);
	d_printf("sendend_count:                  %u\n", profile_p->SMBsendend_count);
	d_printf("sendend_time:                   %u\n", profile_p->SMBsendend_time);
	d_printf("sendtxt_count:                  %u\n", profile_p->SMBsendtxt_count);
	d_printf("sendtxt_time:                   %u\n", profile_p->SMBsendtxt_time);
	d_printf("invalid_count:                  %u\n", profile_p->SMBinvalid_count);
	d_printf("invalid_time:                   %u\n", profile_p->SMBinvalid_time);
	d_printf("************************ Pathworks Calls *************************\n");
	d_printf("setdir_count:                   %u\n", profile_p->pathworks_setdir_count);
	d_printf("setdir_time:                    %u\n", profile_p->pathworks_setdir_time);
	d_printf("************************ Trans2 Calls ****************************\n");
	d_printf("open_count:                     %u\n", profile_p->Trans2_open_count);
	d_printf("open_time:                      %u\n", profile_p->Trans2_open_time);
	d_printf("findfirst_count:                %u\n", profile_p->Trans2_findfirst_count);
	d_printf("findfirst_time:                 %u\n", profile_p->Trans2_findfirst_time);
	d_printf("findnext_count:                 %u\n", profile_p->Trans2_findnext_count);
	d_printf("findnext_time:                  %u\n", profile_p->Trans2_findnext_time);
	d_printf("qfsinfo_count:                  %u\n", profile_p->Trans2_qfsinfo_count);
	d_printf("qfsinfo_time:                   %u\n", profile_p->Trans2_qfsinfo_time);
	d_printf("setfsinfo_count:                %u\n", profile_p->Trans2_setfsinfo_count);
	d_printf("setfsinfo_time:                 %u\n", profile_p->Trans2_setfsinfo_time);
	d_printf("qpathinfo_count:                %u\n", profile_p->Trans2_qpathinfo_count);
	d_printf("qpathinfo_time:                 %u\n", profile_p->Trans2_qpathinfo_time);
	d_printf("setpathinfo_count:              %u\n", profile_p->Trans2_setpathinfo_count);
	d_printf("setpathinfo_time:               %u\n", profile_p->Trans2_setpathinfo_time);
	d_printf("qfileinfo_count:                %u\n", profile_p->Trans2_qfileinfo_count);
	d_printf("qfileinfo_time:                 %u\n", profile_p->Trans2_qfileinfo_time);
	d_printf("setfileinfo_count:              %u\n", profile_p->Trans2_setfileinfo_count);
	d_printf("setfileinfo_time:               %u\n", profile_p->Trans2_setfileinfo_time);
	d_printf("fsctl_count:                    %u\n", profile_p->Trans2_fsctl_count);
	d_printf("fsctl_time:                     %u\n", profile_p->Trans2_fsctl_time);
	d_printf("ioctl_count:                    %u\n", profile_p->Trans2_ioctl_count);
	d_printf("ioctl_time:                     %u\n", profile_p->Trans2_ioctl_time);
	d_printf("findnotifyfirst_count:          %u\n", profile_p->Trans2_findnotifyfirst_count);
	d_printf("findnotifyfirst_time:           %u\n", profile_p->Trans2_findnotifyfirst_time);
	d_printf("findnotifynext_count:           %u\n", profile_p->Trans2_findnotifynext_count);
	d_printf("findnotifynext_time:            %u\n", profile_p->Trans2_findnotifynext_time);
	d_printf("mkdir_count:                    %u\n", profile_p->Trans2_mkdir_count);
	d_printf("mkdir_time:                     %u\n", profile_p->Trans2_mkdir_time);
	d_printf("session_setup_count:            %u\n", profile_p->Trans2_session_setup_count);
	d_printf("session_setup_time:             %u\n", profile_p->Trans2_session_setup_time);
	d_printf("get_dfs_referral_count:         %u\n", profile_p->Trans2_get_dfs_referral_count);
	d_printf("get_dfs_referral_time:          %u\n", profile_p->Trans2_get_dfs_referral_time);
	d_printf("report_dfs_inconsistancy_count: %u\n", profile_p->Trans2_report_dfs_inconsistancy_count);
	d_printf("report_dfs_inconsistancy_time:  %u\n", profile_p->Trans2_report_dfs_inconsistancy_time);
	d_printf("************************ NT Transact Calls ***********************\n");
	d_printf("create_count:                   %u\n", profile_p->NT_transact_create_count);
	d_printf("create_time:                    %u\n", profile_p->NT_transact_create_time);
	d_printf("ioctl_count:                    %u\n", profile_p->NT_transact_ioctl_count);
	d_printf("ioctl_time:                     %u\n", profile_p->NT_transact_ioctl_time);
	d_printf("set_security_desc_count:        %u\n", profile_p->NT_transact_set_security_desc_count);
	d_printf("set_security_desc_time:         %u\n", profile_p->NT_transact_set_security_desc_time);
	d_printf("notify_change_count:            %u\n", profile_p->NT_transact_notify_change_count);
	d_printf("notify_change_time:             %u\n", profile_p->NT_transact_notify_change_time);
	d_printf("rename_count:                   %u\n", profile_p->NT_transact_rename_count);
	d_printf("rename_time:                    %u\n", profile_p->NT_transact_rename_time);
	d_printf("query_security_desc_count:      %u\n", profile_p->NT_transact_query_security_desc_count);
	d_printf("query_security_desc_time:       %u\n", profile_p->NT_transact_query_security_desc_time);
	d_printf("************************ ACL Calls *******************************\n");
	d_printf("get_nt_acl_count:               %u\n", profile_p->get_nt_acl_count);
	d_printf("get_nt_acl_time:                %u\n", profile_p->get_nt_acl_time);
	d_printf("fget_nt_acl_count:              %u\n", profile_p->fget_nt_acl_count);
	d_printf("fget_nt_acl_time:               %u\n", profile_p->fget_nt_acl_time);
	d_printf("set_nt_acl_count:               %u\n", profile_p->set_nt_acl_count);
	d_printf("set_nt_acl_time:                %u\n", profile_p->set_nt_acl_time);
	d_printf("fset_nt_acl_count:              %u\n", profile_p->fset_nt_acl_count);
	d_printf("fset_nt_acl_time:               %u\n", profile_p->fset_nt_acl_time);
	d_printf("chmod_acl_count:                %u\n", profile_p->chmod_acl_count);
	d_printf("chmod_acl_time:                 %u\n", profile_p->chmod_acl_time);
	d_printf("fchmod_acl_count:               %u\n", profile_p->fchmod_acl_count);
	d_printf("fchmod_acl_time:                %u\n", profile_p->fchmod_acl_time);
	d_printf("************************ NMBD Calls ****************************\n");
	d_printf("name_release_count:             %u\n", profile_p->name_release_count);
	d_printf("name_release_time:              %u\n", profile_p->name_release_time);
	d_printf("name_refresh_count:             %u\n", profile_p->name_refresh_count);
	d_printf("name_refresh_time:              %u\n", profile_p->name_refresh_time);
	d_printf("name_registration_count:        %u\n", profile_p->name_registration_count);
	d_printf("name_registration_time:         %u\n", profile_p->name_registration_time);
	d_printf("node_status_count:              %u\n", profile_p->node_status_count);
	d_printf("node_status_time:               %u\n", profile_p->node_status_time);
	d_printf("name_query_count:               %u\n", profile_p->name_query_count);
	d_printf("name_query_time:                %u\n", profile_p->name_query_time);
	d_printf("host_announce_count:            %u\n", profile_p->host_announce_count);
	d_printf("host_announce_time:             %u\n", profile_p->host_announce_time);
	d_printf("workgroup_announce_count:       %u\n", profile_p->workgroup_announce_count);
	d_printf("workgroup_announce_time:        %u\n", profile_p->workgroup_announce_time);
	d_printf("local_master_announce_count:    %u\n", profile_p->local_master_announce_count);
	d_printf("local_master_announce_time:     %u\n", profile_p->local_master_announce_time);
	d_printf("master_browser_announce_count:  %u\n", profile_p->master_browser_announce_count);
	d_printf("master_browser_announce_time:   %u\n", profile_p->master_browser_announce_time);
	d_printf("lm_host_announce_count:         %u\n", profile_p->lm_host_announce_count);
	d_printf("lm_host_announce_time:          %u\n", profile_p->lm_host_announce_time);
	d_printf("get_backup_list_count:          %u\n", profile_p->get_backup_list_count);
	d_printf("get_backup_list_time:           %u\n", profile_p->get_backup_list_time);
	d_printf("reset_browser_count:            %u\n", profile_p->reset_browser_count);
	d_printf("reset_browser_time:             %u\n", profile_p->reset_browser_time);
	d_printf("announce_request_count:         %u\n", profile_p->announce_request_count);
	d_printf("announce_request_time:          %u\n", profile_p->announce_request_time);
	d_printf("lm_announce_request_count:      %u\n", profile_p->lm_announce_request_count);
	d_printf("lm_announce_request_time:       %u\n", profile_p->lm_announce_request_time);
	d_printf("domain_logon_count:             %u\n", profile_p->domain_logon_count);
	d_printf("domain_logon_time:              %u\n", profile_p->domain_logon_time);
	d_printf("sync_browse_lists_count:        %u\n", profile_p->sync_browse_lists_count);
	d_printf("sync_browse_lists_time:         %u\n", profile_p->sync_browse_lists_time);
	d_printf("run_elections_count:            %u\n", profile_p->run_elections_count);
	d_printf("run_elections_time:             %u\n", profile_p->run_elections_time);
	d_printf("election_count:                 %u\n", profile_p->election_count);
	d_printf("election_time:                  %u\n", profile_p->election_time);
#else /* WITH_PROFILE */
	fprintf(stderr, "Profile data unavailable\n");
#endif /* WITH_PROFILE */

	return 0;
}


static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
	struct connections_data crec;

	if (dbuf.dsize != sizeof(crec))
		return 0;

	memcpy(&crec, dbuf.dptr, sizeof(crec));

	if (crec.cnum == -1)
		return 0;

	if (!process_exists(crec.pid) || !Ucrit_checkUsername(uidtoname(crec.uid))) {
		return 0;
	}

	d_printf("%-10.10s   %5d   %-12s  %s",
	       crec.name,(int)crec.pid,
	       crec.machine,
	       asctime(LocalTime(&crec.start)));

	return 0;
}

static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
	struct sessionid sessionid;
	TALLOC_CTX *mem_ctx;

	if (dbuf.dsize != sizeof(sessionid))
		return 0;

	memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));

	if (!process_exists(sessionid.pid) || !Ucrit_checkUsername(uidtoname(sessionid.uid))) {
		return 0;
	}

	mem_ctx = talloc_init("smbgroupedit talloc");
	if (!mem_ctx) return -1;
	d_printf("%5d   %-12s  %-12s  %-12s (%s)\n",
	       (int)sessionid.pid, uidtoname(sessionid.uid), 
	       gidtoname(mem_ctx, sessionid.gid), 
	       sessionid.remote_machine, sessionid.hostname);
	talloc_destroy(mem_ctx);
	return 0;
}




 int main(int argc, char *argv[])
{
	int c;
	static int profile_only = 0;
	TDB_CONTEXT *tdb;
	poptContext pc;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"processes",	'p', POPT_ARG_NONE,	&processes_only, 'p', "Show processes only" },
		{"verbose",	'v', POPT_ARG_NONE, &verbose, 'v', "Be verbose" },
		{"locks",	'L', POPT_ARG_NONE,	&locks_only, 'L', "Show locks only" },
		{"shares",	'S', POPT_ARG_NONE,	&shares_only, 'S', "Show shares only" },
		{"user", 'u', POPT_ARG_STRING,	0, 'u', "Switch to user" },
		{"brief",	'b', POPT_ARG_NONE, 	&brief, 'b', "Be brief" },
#ifdef WITH_PROFILE
		{"profile",	'P', POPT_ARG_NONE,	&profile_only, 'P', "Do profiling" },
#endif /* WITH_PROFILE */
		{"byterange",	'B', POPT_ARG_NONE,	&show_brl, 'B', "Include byte range locks"},
		POPT_COMMON_SAMBA
		POPT_COMMON_CONNECTION
		POPT_COMMON_CREDENTIALS
		POPT_TABLEEND
	};

	setup_logging(argv[0],True);
	
	dbf = x_stderr;
	
	if (getuid() != geteuid()) {
		d_printf("smbstatus should not be run setuid\n");
		return(1);
	}

	pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 
			    POPT_CONTEXT_KEEP_FIRST);
	
	while ((c = poptGetNextOpt(pc)) != EOF) {
		switch (c) {
		case 'u':                                      
			Ucrit_addUsername(poptGetOptArg(pc));             
			break;
		}
	}

	if (verbose) {
		d_printf("using configfile = %s\n", dyn_CONFIGFILE);
	}

	if (!lp_load(dyn_CONFIGFILE,False,False,False)) {
		fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
		return (-1);
	}
	
	if (profile_only) {
		return profile_dump();
	}
	
	tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
	if (!tdb) {
		d_printf("sessionid.tdb not initialised\n");
	} else {
		if (locks_only) goto locks;

		d_printf("\nSamba version %s\n",SAMBA_VERSION);
		d_printf("PID     Username      Group         Machine                        \n");
		d_printf("-------------------------------------------------------------------\n");

		tdb_traverse(tdb, traverse_sessionid, NULL);
		tdb_close(tdb);
	}
  
	tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
	if (!tdb) {
		d_printf("%s not initialised\n", lock_path("connections.tdb"));
		d_printf("This is normal if an SMB client has never connected to your server.\n");
	}  else  {
		if (verbose) {
			d_printf("Opened %s\n", lock_path("connections.tdb"));
		}

		if (brief) 
			exit(0);
		
		d_printf("\nService      pid     machine       Connected at\n");
		d_printf("-------------------------------------------------------\n");

		tdb_traverse(tdb, traverse_fn1, NULL);
		tdb_close(tdb);
	}

 locks:
	if (processes_only) exit(0);

	if (!shares_only) {
		int ret;

		if (!locking_init(1)) {
			d_printf("Can't initialise locking module - exiting\n");
			exit(1);
		}
		
		ret = share_mode_forall(print_share_mode);

		if (ret == 0) {
			d_printf("No locked files\n");
		} else if (ret == -1) {
			d_printf("locked file list truncated\n");
		}
		
		d_printf("\n");

		if (show_brl) {
			brl_forall(print_brl);
		}
		
		locking_end();
	}

	return (0);
}