fixed error check which caused domain logons to fail
[Samba.git] / source / utils / status.c
blob293eb3d0adee76aa77463edfa48294d049e62644
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 status reporting
5 Copyright (C) Andrew Tridgell 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 Revision History:
23 12 aug 96: Erik.Devriendt@te6.siemens.be
24 added support for shared memory implementation of share mode locking
26 21-Jul-1998: rsharpe@ns.aus.com (Richard Sharpe)
27 Added -L (locks only) -S (shares only) flags and code
32 * This program reports current SMB connections
35 #define NO_SYSLOG
37 #include "includes.h"
39 struct session_record{
40 pid_t pid;
41 uid_t uid;
42 char machine[31];
43 time_t start;
44 struct session_record *next;
45 } *srecs;
47 extern FILE *dbf;
49 static pstring Ucrit_username = ""; /* added by OH */
50 static pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */
51 static int Ucrit_MaxPid=0; /* added by OH */
52 static unsigned int Ucrit_IsActive = 0; /* added by OH */
53 static int verbose, brief;
54 static int shares_only = 0; /* Added by RJS */
55 static int locks_only = 0; /* Added by RJS */
56 static BOOL processes_only=False;
57 static int show_brl;
59 /* we need these because we link to locking*.o */
60 void become_root(void) {}
61 void unbecome_root(void) {}
64 /* added by OH */
65 static void Ucrit_addUsername(char *username)
67 pstrcpy(Ucrit_username, username);
68 if(strlen(Ucrit_username) > 0)
69 Ucrit_IsActive = 1;
72 static unsigned int Ucrit_checkUsername(char *username)
74 if ( !Ucrit_IsActive) return 1;
75 if (strcmp(Ucrit_username,username) ==0) return 1;
76 return 0;
79 static void Ucrit_addPid(pid_t pid)
81 int i;
82 if ( !Ucrit_IsActive) return;
83 for (i=0;i<Ucrit_MaxPid;i++)
84 if( pid == Ucrit_pid[i] ) return;
85 Ucrit_pid[Ucrit_MaxPid++] = pid;
88 static unsigned int Ucrit_checkPid(pid_t pid)
90 int i;
91 if ( !Ucrit_IsActive) return 1;
92 for (i=0;i<Ucrit_MaxPid;i++)
93 if( pid == Ucrit_pid[i] ) return 1;
94 return 0;
98 static void print_share_mode(share_mode_entry *e, char *fname)
100 static int count;
101 if (count==0) {
102 printf("Locked files:\n");
103 printf("Pid DenyMode R/W Oplock Name\n");
104 printf("--------------------------------------------------\n");
106 count++;
108 if (Ucrit_checkPid(e->pid)) {
109 printf("%-5d ",(int)e->pid);
110 switch (GET_DENY_MODE(e->share_mode)) {
111 case DENY_NONE: printf("DENY_NONE "); break;
112 case DENY_ALL: printf("DENY_ALL "); break;
113 case DENY_DOS: printf("DENY_DOS "); break;
114 case DENY_READ: printf("DENY_READ "); break;
115 case DENY_WRITE:printf("DENY_WRITE "); break;
116 case DENY_FCB: printf("DENY_FCB "); break;
118 switch (e->share_mode&0xF) {
119 case 0: printf("RDONLY "); break;
120 case 1: printf("WRONLY "); break;
121 case 2: printf("RDWR "); break;
124 if((e->op_type &
125 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
126 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
127 printf("EXCLUSIVE+BATCH ");
128 else if (e->op_type & EXCLUSIVE_OPLOCK)
129 printf("EXCLUSIVE ");
130 else if (e->op_type & BATCH_OPLOCK)
131 printf("BATCH ");
132 else if (e->op_type & LEVEL_II_OPLOCK)
133 printf("LEVEL_II ");
134 else
135 printf("NONE ");
137 printf(" %s %s",dos_to_unix(fname,False),
138 asctime(LocalTime((time_t *)&e->time.tv_sec)));
142 static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid,
143 enum brl_type lock_type,
144 br_off start, br_off size)
146 static int count;
147 if (count==0) {
148 printf("Byte range locks:\n");
149 printf(" Pid dev:inode R/W start size\n");
150 printf("------------------------------------------------\n");
152 count++;
154 printf("%6d %05x:%05x %s %9.0f %9.0f\n",
155 (int)pid, (int)dev, (int)ino,
156 lock_type==READ_LOCK?"R":"W",
157 (double)start, (double)size);
161 /*******************************************************************
162 dump the elements of the profile structure
163 ******************************************************************/
164 static int profile_dump(void)
166 if (!profile_setup(True)) {
167 fprintf(stderr,"Failed to initialise profile memory\n");
168 return -1;
171 printf("smb_count: %u\n", profile_p->smb_count);
172 printf("uid_changes: %u\n", profile_p->uid_changes);
173 printf("************************ System Calls ****************************\n");
174 printf("opendir_count: %u\n", profile_p->syscall_opendir_count);
175 printf("opendir_time: %u\n", profile_p->syscall_opendir_time);
176 printf("readdir_count: %u\n", profile_p->syscall_readdir_count);
177 printf("readdir_time: %u\n", profile_p->syscall_readdir_time);
178 printf("mkdir_count: %u\n", profile_p->syscall_mkdir_count);
179 printf("mkdir_time: %u\n", profile_p->syscall_mkdir_time);
180 printf("rmdir_count: %u\n", profile_p->syscall_rmdir_count);
181 printf("rmdir_time: %u\n", profile_p->syscall_rmdir_time);
182 printf("closedir_count: %u\n", profile_p->syscall_closedir_count);
183 printf("closedir_time: %u\n", profile_p->syscall_closedir_time);
184 printf("open_count: %u\n", profile_p->syscall_open_count);
185 printf("open_time: %u\n", profile_p->syscall_open_time);
186 printf("close_count: %u\n", profile_p->syscall_close_count);
187 printf("close_time: %u\n", profile_p->syscall_close_time);
188 printf("read_count: %u\n", profile_p->syscall_read_count);
189 printf("read_time: %u\n", profile_p->syscall_read_time);
190 printf("read_bytes: %u\n", profile_p->syscall_read_bytes);
191 printf("write_count: %u\n", profile_p->syscall_write_count);
192 printf("write_time: %u\n", profile_p->syscall_write_time);
193 printf("write_bytes: %u\n", profile_p->syscall_write_bytes);
194 printf("lseek_count: %u\n", profile_p->syscall_lseek_count);
195 printf("lseek_time: %u\n", profile_p->syscall_lseek_time);
196 printf("rename_count: %u\n", profile_p->syscall_rename_count);
197 printf("rename_time: %u\n", profile_p->syscall_rename_time);
198 printf("fsync_count: %u\n", profile_p->syscall_fsync_count);
199 printf("fsync_time: %u\n", profile_p->syscall_fsync_time);
200 printf("stat_count: %u\n", profile_p->syscall_stat_count);
201 printf("stat_time: %u\n", profile_p->syscall_stat_time);
202 printf("fstat_count: %u\n", profile_p->syscall_fstat_count);
203 printf("fstat_time: %u\n", profile_p->syscall_fstat_time);
204 printf("lstat_count: %u\n", profile_p->syscall_lstat_count);
205 printf("lstat_time: %u\n", profile_p->syscall_lstat_time);
206 printf("unlink_count: %u\n", profile_p->syscall_unlink_count);
207 printf("unlink_time: %u\n", profile_p->syscall_unlink_time);
208 printf("chmod_count: %u\n", profile_p->syscall_chmod_count);
209 printf("chmod_time: %u\n", profile_p->syscall_chmod_time);
210 printf("fchmod_count: %u\n", profile_p->syscall_fchmod_count);
211 printf("fchmod_time: %u\n", profile_p->syscall_fchmod_time);
212 printf("chown_count: %u\n", profile_p->syscall_chown_count);
213 printf("chown_time: %u\n", profile_p->syscall_chown_time);
214 printf("fchown_count: %u\n", profile_p->syscall_fchown_count);
215 printf("fchown_time: %u\n", profile_p->syscall_fchown_time);
216 printf("chdir_count: %u\n", profile_p->syscall_chdir_count);
217 printf("chdir_time: %u\n", profile_p->syscall_chdir_time);
218 printf("getwd_count: %u\n", profile_p->syscall_getwd_count);
219 printf("getwd_time: %u\n", profile_p->syscall_getwd_time);
220 printf("utime_count: %u\n", profile_p->syscall_utime_count);
221 printf("utime_time: %u\n", profile_p->syscall_utime_time);
222 printf("ftruncate_count: %u\n", profile_p->syscall_ftruncate_count);
223 printf("ftruncate_time: %u\n", profile_p->syscall_ftruncate_time);
224 printf("fcntl_lock_count: %u\n", profile_p->syscall_fcntl_lock_count);
225 printf("fcntl_lock_time: %u\n", profile_p->syscall_fcntl_lock_time);
226 printf("readlink_count: %u\n", profile_p->syscall_readlink_count);
227 printf("readlink_time: %u\n", profile_p->syscall_readlink_time);
228 printf("symlink_count: %u\n", profile_p->syscall_symlink_count);
229 printf("symlink_time: %u\n", profile_p->syscall_symlink_time);
230 printf("************************ Statcache *******************************\n");
231 printf("lookups: %u\n", profile_p->statcache_lookups);
232 printf("misses: %u\n", profile_p->statcache_misses);
233 printf("hits: %u\n", profile_p->statcache_hits);
234 printf("************************ Writecache ******************************\n");
235 printf("read_hits: %u\n", profile_p->writecache_read_hits);
236 printf("abutted_writes: %u\n", profile_p->writecache_abutted_writes);
237 printf("total_writes: %u\n", profile_p->writecache_total_writes);
238 printf("non_oplock_writes: %u\n", profile_p->writecache_non_oplock_writes);
239 printf("direct_writes: %u\n", profile_p->writecache_direct_writes);
240 printf("init_writes: %u\n", profile_p->writecache_init_writes);
241 printf("flushed_writes[SEEK]: %u\n", profile_p->writecache_flushed_writes[SEEK_FLUSH]);
242 printf("flushed_writes[READ]: %u\n", profile_p->writecache_flushed_writes[READ_FLUSH]);
243 printf("flushed_writes[WRITE]: %u\n", profile_p->writecache_flushed_writes[WRITE_FLUSH]);
244 printf("flushed_writes[READRAW]: %u\n", profile_p->writecache_flushed_writes[READRAW_FLUSH]);
245 printf("flushed_writes[OPLOCK_RELEASE]: %u\n", profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH]);
246 printf("flushed_writes[CLOSE]: %u\n", profile_p->writecache_flushed_writes[CLOSE_FLUSH]);
247 printf("flushed_writes[SYNC]: %u\n", profile_p->writecache_flushed_writes[SYNC_FLUSH]);
248 printf("flushed_writes[SIZECHANGE]: %u\n", profile_p->writecache_flushed_writes[SIZECHANGE_FLUSH]);
249 printf("num_perfect_writes: %u\n", profile_p->writecache_num_perfect_writes);
250 printf("num_write_caches: %u\n", profile_p->writecache_num_write_caches);
251 printf("allocated_write_caches: %u\n", profile_p->writecache_allocated_write_caches);
252 printf("************************ SMB Calls *******************************\n");
253 printf("mkdir_count: %u\n", profile_p->SMBmkdir_count);
254 printf("mkdir_time: %u\n", profile_p->SMBmkdir_time);
255 printf("rmdir_count: %u\n", profile_p->SMBrmdir_count);
256 printf("rmdir_time: %u\n", profile_p->SMBrmdir_time);
257 printf("open_count: %u\n", profile_p->SMBopen_count);
258 printf("open_time: %u\n", profile_p->SMBopen_time);
259 printf("create_count: %u\n", profile_p->SMBcreate_count);
260 printf("create_time: %u\n", profile_p->SMBcreate_time);
261 printf("close_count: %u\n", profile_p->SMBclose_count);
262 printf("close_time: %u\n", profile_p->SMBclose_time);
263 printf("flush_count: %u\n", profile_p->SMBflush_count);
264 printf("flush_time: %u\n", profile_p->SMBflush_time);
265 printf("unlink_count: %u\n", profile_p->SMBunlink_count);
266 printf("unlink_time: %u\n", profile_p->SMBunlink_time);
267 printf("mv_count: %u\n", profile_p->SMBmv_count);
268 printf("mv_time: %u\n", profile_p->SMBmv_time);
269 printf("getatr_count: %u\n", profile_p->SMBgetatr_count);
270 printf("getatr_time: %u\n", profile_p->SMBgetatr_time);
271 printf("setatr_count: %u\n", profile_p->SMBsetatr_count);
272 printf("setatr_time: %u\n", profile_p->SMBsetatr_time);
273 printf("read_count: %u\n", profile_p->SMBread_count);
274 printf("read_time: %u\n", profile_p->SMBread_time);
275 printf("write_count: %u\n", profile_p->SMBwrite_count);
276 printf("write_time: %u\n", profile_p->SMBwrite_time);
277 printf("lock_count: %u\n", profile_p->SMBlock_count);
278 printf("lock_time: %u\n", profile_p->SMBlock_time);
279 printf("unlock_count: %u\n", profile_p->SMBunlock_count);
280 printf("unlock_time: %u\n", profile_p->SMBunlock_time);
281 printf("ctemp_count: %u\n", profile_p->SMBctemp_count);
282 printf("ctemp_time: %u\n", profile_p->SMBctemp_time);
283 printf("mknew_count: %u\n", profile_p->SMBmknew_count);
284 printf("mknew_time: %u\n", profile_p->SMBmknew_time);
285 printf("chkpth_count: %u\n", profile_p->SMBchkpth_count);
286 printf("chkpth_time: %u\n", profile_p->SMBchkpth_time);
287 printf("exit_count: %u\n", profile_p->SMBexit_count);
288 printf("exit_time: %u\n", profile_p->SMBexit_time);
289 printf("lseek_count: %u\n", profile_p->SMBlseek_count);
290 printf("lseek_time: %u\n", profile_p->SMBlseek_time);
291 printf("lockread_count: %u\n", profile_p->SMBlockread_count);
292 printf("lockread_time: %u\n", profile_p->SMBlockread_time);
293 printf("writeunlock_count: %u\n", profile_p->SMBwriteunlock_count);
294 printf("writeunlock_time: %u\n", profile_p->SMBwriteunlock_time);
295 printf("readbraw_count: %u\n", profile_p->SMBreadbraw_count);
296 printf("readbraw_time: %u\n", profile_p->SMBreadbraw_time);
297 printf("readBmpx_count: %u\n", profile_p->SMBreadBmpx_count);
298 printf("readBmpx_time: %u\n", profile_p->SMBreadBmpx_time);
299 printf("readBs_count: %u\n", profile_p->SMBreadBs_count);
300 printf("readBs_time: %u\n", profile_p->SMBreadBs_time);
301 printf("writebraw_count: %u\n", profile_p->SMBwritebraw_count);
302 printf("writebraw_time: %u\n", profile_p->SMBwritebraw_time);
303 printf("writeBmpx_count: %u\n", profile_p->SMBwriteBmpx_count);
304 printf("writeBmpx_time: %u\n", profile_p->SMBwriteBmpx_time);
305 printf("writeBs_count: %u\n", profile_p->SMBwriteBs_count);
306 printf("writeBs_time: %u\n", profile_p->SMBwriteBs_time);
307 printf("writec_count: %u\n", profile_p->SMBwritec_count);
308 printf("writec_time: %u\n", profile_p->SMBwritec_time);
309 printf("setattrE_count: %u\n", profile_p->SMBsetattrE_count);
310 printf("setattrE_time: %u\n", profile_p->SMBsetattrE_time);
311 printf("getattrE_count: %u\n", profile_p->SMBgetattrE_count);
312 printf("getattrE_time: %u\n", profile_p->SMBgetattrE_time);
313 printf("lockingX_count: %u\n", profile_p->SMBlockingX_count);
314 printf("lockingX_time: %u\n", profile_p->SMBlockingX_time);
315 printf("trans_count: %u\n", profile_p->SMBtrans_count);
316 printf("trans_time: %u\n", profile_p->SMBtrans_time);
317 printf("transs_count: %u\n", profile_p->SMBtranss_count);
318 printf("transs_time: %u\n", profile_p->SMBtranss_time);
319 printf("ioctl_count: %u\n", profile_p->SMBioctl_count);
320 printf("ioctl_time: %u\n", profile_p->SMBioctl_time);
321 printf("ioctls_count: %u\n", profile_p->SMBioctls_count);
322 printf("ioctls_time: %u\n", profile_p->SMBioctls_time);
323 printf("copy_count: %u\n", profile_p->SMBcopy_count);
324 printf("copy_time: %u\n", profile_p->SMBcopy_time);
325 printf("move_count: %u\n", profile_p->SMBmove_count);
326 printf("move_time: %u\n", profile_p->SMBmove_time);
327 printf("echo_count: %u\n", profile_p->SMBecho_count);
328 printf("echo_time: %u\n", profile_p->SMBecho_time);
329 printf("writeclose_count: %u\n", profile_p->SMBwriteclose_count);
330 printf("writeclose_time: %u\n", profile_p->SMBwriteclose_time);
331 printf("openX_count: %u\n", profile_p->SMBopenX_count);
332 printf("openX_time: %u\n", profile_p->SMBopenX_time);
333 printf("readX_count: %u\n", profile_p->SMBreadX_count);
334 printf("readX_time: %u\n", profile_p->SMBreadX_time);
335 printf("writeX_count: %u\n", profile_p->SMBwriteX_count);
336 printf("writeX_time: %u\n", profile_p->SMBwriteX_time);
337 printf("trans2_count: %u\n", profile_p->SMBtrans2_count);
338 printf("trans2_time: %u\n", profile_p->SMBtrans2_time);
339 printf("transs2_count: %u\n", profile_p->SMBtranss2_count);
340 printf("transs2_time: %u\n", profile_p->SMBtranss2_time);
341 printf("findclose_count: %u\n", profile_p->SMBfindclose_count);
342 printf("findclose_time: %u\n", profile_p->SMBfindclose_time);
343 printf("findnclose_count: %u\n", profile_p->SMBfindnclose_count);
344 printf("findnclose_time: %u\n", profile_p->SMBfindnclose_time);
345 printf("tcon_count: %u\n", profile_p->SMBtcon_count);
346 printf("tcon_time: %u\n", profile_p->SMBtcon_time);
347 printf("tdis_count: %u\n", profile_p->SMBtdis_count);
348 printf("tdis_time: %u\n", profile_p->SMBtdis_time);
349 printf("negprot_count: %u\n", profile_p->SMBnegprot_count);
350 printf("negprot_time: %u\n", profile_p->SMBnegprot_time);
351 printf("sesssetupX_count: %u\n", profile_p->SMBsesssetupX_count);
352 printf("sesssetupX_time: %u\n", profile_p->SMBsesssetupX_time);
353 printf("ulogoffX_count: %u\n", profile_p->SMBulogoffX_count);
354 printf("ulogoffX_time: %u\n", profile_p->SMBulogoffX_time);
355 printf("tconX_count: %u\n", profile_p->SMBtconX_count);
356 printf("tconX_time: %u\n", profile_p->SMBtconX_time);
357 printf("dskattr_count: %u\n", profile_p->SMBdskattr_count);
358 printf("dskattr_time: %u\n", profile_p->SMBdskattr_time);
359 printf("search_count: %u\n", profile_p->SMBsearch_count);
360 printf("search_time: %u\n", profile_p->SMBsearch_time);
361 printf("ffirst_count: %u\n", profile_p->SMBffirst_count);
362 printf("ffirst_time: %u\n", profile_p->SMBffirst_time);
363 printf("funique_count: %u\n", profile_p->SMBfunique_count);
364 printf("funique_time: %u\n", profile_p->SMBfunique_time);
365 printf("fclose_count: %u\n", profile_p->SMBfclose_count);
366 printf("fclose_time: %u\n", profile_p->SMBfclose_time);
367 printf("nttrans_count: %u\n", profile_p->SMBnttrans_count);
368 printf("nttrans_time: %u\n", profile_p->SMBnttrans_time);
369 printf("nttranss_count: %u\n", profile_p->SMBnttranss_count);
370 printf("nttranss_time: %u\n", profile_p->SMBnttranss_time);
371 printf("ntcreateX_count: %u\n", profile_p->SMBntcreateX_count);
372 printf("ntcreateX_time: %u\n", profile_p->SMBntcreateX_time);
373 printf("ntcancel_count: %u\n", profile_p->SMBntcancel_count);
374 printf("ntcancel_time: %u\n", profile_p->SMBntcancel_time);
375 printf("splopen_count: %u\n", profile_p->SMBsplopen_count);
376 printf("splopen_time: %u\n", profile_p->SMBsplopen_time);
377 printf("splwr_count: %u\n", profile_p->SMBsplwr_count);
378 printf("splwr_time: %u\n", profile_p->SMBsplwr_time);
379 printf("splclose_count: %u\n", profile_p->SMBsplclose_count);
380 printf("splclose_time: %u\n", profile_p->SMBsplclose_time);
381 printf("splretq_count: %u\n", profile_p->SMBsplretq_count);
382 printf("splretq_time: %u\n", profile_p->SMBsplretq_time);
383 printf("sends_count: %u\n", profile_p->SMBsends_count);
384 printf("sends_time: %u\n", profile_p->SMBsends_time);
385 printf("sendb_count: %u\n", profile_p->SMBsendb_count);
386 printf("sendb_time: %u\n", profile_p->SMBsendb_time);
387 printf("fwdname_count: %u\n", profile_p->SMBfwdname_count);
388 printf("fwdname_time: %u\n", profile_p->SMBfwdname_time);
389 printf("cancelf_count: %u\n", profile_p->SMBcancelf_count);
390 printf("cancelf_time: %u\n", profile_p->SMBcancelf_time);
391 printf("getmac_count: %u\n", profile_p->SMBgetmac_count);
392 printf("getmac_time: %u\n", profile_p->SMBgetmac_time);
393 printf("sendstrt_count: %u\n", profile_p->SMBsendstrt_count);
394 printf("sendstrt_time: %u\n", profile_p->SMBsendstrt_time);
395 printf("sendend_count: %u\n", profile_p->SMBsendend_count);
396 printf("sendend_time: %u\n", profile_p->SMBsendend_time);
397 printf("sendtxt_count: %u\n", profile_p->SMBsendtxt_count);
398 printf("sendtxt_time: %u\n", profile_p->SMBsendtxt_time);
399 printf("invalid_count: %u\n", profile_p->SMBinvalid_count);
400 printf("invalid_time: %u\n", profile_p->SMBinvalid_time);
401 printf("************************ Pathworks Calls *************************\n");
402 printf("setdir_count: %u\n", profile_p->pathworks_setdir_count);
403 printf("setdir_time: %u\n", profile_p->pathworks_setdir_time);
404 printf("************************ Trans2 Calls ****************************\n");
405 printf("open_count: %u\n", profile_p->Trans2_open_count);
406 printf("open_time: %u\n", profile_p->Trans2_open_time);
407 printf("findfirst_count: %u\n", profile_p->Trans2_findfirst_count);
408 printf("findfirst_time: %u\n", profile_p->Trans2_findfirst_time);
409 printf("findnext_count: %u\n", profile_p->Trans2_findnext_count);
410 printf("findnext_time: %u\n", profile_p->Trans2_findnext_time);
411 printf("qfsinfo_count: %u\n", profile_p->Trans2_qfsinfo_count);
412 printf("qfsinfo_time: %u\n", profile_p->Trans2_qfsinfo_time);
413 printf("setfsinfo_count: %u\n", profile_p->Trans2_setfsinfo_count);
414 printf("setfsinfo_time: %u\n", profile_p->Trans2_setfsinfo_time);
415 printf("qpathinfo_count: %u\n", profile_p->Trans2_qpathinfo_count);
416 printf("qpathinfo_time: %u\n", profile_p->Trans2_qpathinfo_time);
417 printf("setpathinfo_count: %u\n", profile_p->Trans2_setpathinfo_count);
418 printf("setpathinfo_time: %u\n", profile_p->Trans2_setpathinfo_time);
419 printf("qfileinfo_count: %u\n", profile_p->Trans2_qfileinfo_count);
420 printf("qfileinfo_time: %u\n", profile_p->Trans2_qfileinfo_time);
421 printf("setfileinfo_count: %u\n", profile_p->Trans2_setfileinfo_count);
422 printf("setfileinfo_time: %u\n", profile_p->Trans2_setfileinfo_time);
423 printf("fsctl_count: %u\n", profile_p->Trans2_fsctl_count);
424 printf("fsctl_time: %u\n", profile_p->Trans2_fsctl_time);
425 printf("ioctl_count: %u\n", profile_p->Trans2_ioctl_count);
426 printf("ioctl_time: %u\n", profile_p->Trans2_ioctl_time);
427 printf("findnotifyfirst_count: %u\n", profile_p->Trans2_findnotifyfirst_count);
428 printf("findnotifyfirst_time: %u\n", profile_p->Trans2_findnotifyfirst_time);
429 printf("findnotifynext_count: %u\n", profile_p->Trans2_findnotifynext_count);
430 printf("findnotifynext_time: %u\n", profile_p->Trans2_findnotifynext_time);
431 printf("mkdir_count: %u\n", profile_p->Trans2_mkdir_count);
432 printf("mkdir_time: %u\n", profile_p->Trans2_mkdir_time);
433 printf("session_setup_count: %u\n", profile_p->Trans2_session_setup_count);
434 printf("session_setup_time: %u\n", profile_p->Trans2_session_setup_time);
435 printf("get_dfs_referral_count: %u\n", profile_p->Trans2_get_dfs_referral_count);
436 printf("get_dfs_referral_time: %u\n", profile_p->Trans2_get_dfs_referral_time);
437 printf("report_dfs_inconsistancy_count: %u\n", profile_p->Trans2_report_dfs_inconsistancy_count);
438 printf("report_dfs_inconsistancy_time: %u\n", profile_p->Trans2_report_dfs_inconsistancy_time);
439 printf("************************ NT Transact Calls ***********************\n");
440 printf("create_count: %u\n", profile_p->NT_transact_create_count);
441 printf("create_time: %u\n", profile_p->NT_transact_create_time);
442 printf("ioctl_count: %u\n", profile_p->NT_transact_ioctl_count);
443 printf("ioctl_time: %u\n", profile_p->NT_transact_ioctl_time);
444 printf("set_security_desc_count: %u\n", profile_p->NT_transact_set_security_desc_count);
445 printf("set_security_desc_time: %u\n", profile_p->NT_transact_set_security_desc_time);
446 printf("notify_change_count: %u\n", profile_p->NT_transact_notify_change_count);
447 printf("notify_change_time: %u\n", profile_p->NT_transact_notify_change_time);
448 printf("rename_count: %u\n", profile_p->NT_transact_rename_count);
449 printf("rename_time: %u\n", profile_p->NT_transact_rename_time);
450 printf("query_security_desc_count: %u\n", profile_p->NT_transact_query_security_desc_count);
451 printf("query_security_desc_time: %u\n", profile_p->NT_transact_query_security_desc_time);
452 printf("************************ ACL Calls *******************************\n");
453 printf("get_nt_acl_count: %u\n", profile_p->get_nt_acl_count);
454 printf("get_nt_acl_time: %u\n", profile_p->get_nt_acl_time);
455 printf("fget_nt_acl_count: %u\n", profile_p->fget_nt_acl_count);
456 printf("fget_nt_acl_time: %u\n", profile_p->fget_nt_acl_time);
457 printf("set_nt_acl_count: %u\n", profile_p->set_nt_acl_count);
458 printf("set_nt_acl_time: %u\n", profile_p->set_nt_acl_time);
459 printf("fset_nt_acl_count: %u\n", profile_p->fset_nt_acl_count);
460 printf("fset_nt_acl_time: %u\n", profile_p->fset_nt_acl_time);
461 printf("chmod_acl_count: %u\n", profile_p->chmod_acl_count);
462 printf("chmod_acl_time: %u\n", profile_p->chmod_acl_time);
463 printf("fchmod_acl_count: %u\n", profile_p->fchmod_acl_count);
464 printf("fchmod_acl_time: %u\n", profile_p->fchmod_acl_time);
465 printf("************************ NMBD Calls ****************************\n");
466 printf("name_release_count: %u\n", profile_p->name_release_count);
467 printf("name_release_time: %u\n", profile_p->name_release_time);
468 printf("name_refresh_count: %u\n", profile_p->name_refresh_count);
469 printf("name_refresh_time: %u\n", profile_p->name_refresh_time);
470 printf("name_registration_count: %u\n", profile_p->name_registration_count);
471 printf("name_registration_time: %u\n", profile_p->name_registration_time);
472 printf("node_status_count: %u\n", profile_p->node_status_count);
473 printf("node_status_time: %u\n", profile_p->node_status_time);
474 printf("name_query_count: %u\n", profile_p->name_query_count);
475 printf("name_query_time: %u\n", profile_p->name_query_time);
476 printf("host_announce_count: %u\n", profile_p->host_announce_count);
477 printf("host_announce_time: %u\n", profile_p->host_announce_time);
478 printf("workgroup_announce_count: %u\n", profile_p->workgroup_announce_count);
479 printf("workgroup_announce_time: %u\n", profile_p->workgroup_announce_time);
480 printf("local_master_announce_count: %u\n", profile_p->local_master_announce_count);
481 printf("local_master_announce_time: %u\n", profile_p->local_master_announce_time);
482 printf("master_browser_announce_count: %u\n", profile_p->master_browser_announce_count);
483 printf("master_browser_announce_time: %u\n", profile_p->master_browser_announce_time);
484 printf("lm_host_announce_count: %u\n", profile_p->lm_host_announce_count);
485 printf("lm_host_announce_time: %u\n", profile_p->lm_host_announce_time);
486 printf("get_backup_list_count: %u\n", profile_p->get_backup_list_count);
487 printf("get_backup_list_time: %u\n", profile_p->get_backup_list_time);
488 printf("reset_browser_count: %u\n", profile_p->reset_browser_count);
489 printf("reset_browser_time: %u\n", profile_p->reset_browser_time);
490 printf("announce_request_count: %u\n", profile_p->announce_request_count);
491 printf("announce_request_time: %u\n", profile_p->announce_request_time);
492 printf("lm_announce_request_count: %u\n", profile_p->lm_announce_request_count);
493 printf("lm_announce_request_time: %u\n", profile_p->lm_announce_request_time);
494 printf("domain_logon_count: %u\n", profile_p->domain_logon_count);
495 printf("domain_logon_time: %u\n", profile_p->domain_logon_time);
496 printf("sync_browse_lists_count: %u\n", profile_p->sync_browse_lists_count);
497 printf("sync_browse_lists_time: %u\n", profile_p->sync_browse_lists_time);
498 printf("run_elections_count: %u\n", profile_p->run_elections_count);
499 printf("run_elections_time: %u\n", profile_p->run_elections_time);
500 printf("election_count: %u\n", profile_p->election_count);
501 printf("election_time: %u\n", profile_p->election_time);
503 return 0;
507 static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
509 static pid_t last_pid;
510 struct session_record *ptr;
511 struct connections_data crec;
513 if (dbuf.dsize != sizeof(crec))
514 return 0;
516 memcpy(&crec, dbuf.dptr, sizeof(crec));
518 if (crec.cnum == -1)
519 return 0;
521 if (!process_exists(crec.pid) || !Ucrit_checkUsername(uidtoname(crec.uid))) {
522 return 0;
525 if (brief) {
526 ptr=srecs;
527 while (ptr!=NULL) {
528 if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) {
529 if (ptr->start > crec.start)
530 ptr->start=crec.start;
531 break;
533 ptr=ptr->next;
535 if (ptr==NULL) {
536 ptr=(struct session_record *) malloc(sizeof(struct session_record));
537 ptr->uid=crec.uid;
538 ptr->pid=crec.pid;
539 ptr->start=crec.start;
540 strncpy(ptr->machine,crec.machine,30);
541 ptr->machine[30]='\0';
542 ptr->next=srecs;
543 srecs=ptr;
545 } else {
546 Ucrit_addPid(crec.pid);
547 if (processes_only) {
548 if (last_pid != crec.pid)
549 printf("%d\n",(int)crec.pid);
550 last_pid = crec.pid; /* XXXX we can still get repeats, have to
551 add a sort at some time */
552 } else {
553 printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s",
554 crec.name,uidtoname(crec.uid),gidtoname(crec.gid),(int)crec.pid,
555 crec.machine,crec.addr,
556 asctime(LocalTime(&crec.start)));
560 return 0;
566 int main(int argc, char *argv[])
568 pstring fname;
569 int c;
570 static pstring servicesf = CONFIGFILE;
571 extern char *optarg;
572 int profile_only = 0;
573 TDB_CONTEXT *tdb;
574 struct session_record *ptr;
576 TimeInit();
577 setup_logging(argv[0],True);
579 charset_initialise();
581 DEBUGLEVEL = 0;
582 dbf = stderr;
584 if (getuid() != geteuid()) {
585 printf("smbstatus should not be run setuid\n");
586 return(1);
589 while ((c = getopt(argc, argv, "pdLSs:u:bPB")) != EOF) {
590 switch (c) {
591 case 'b':
592 brief = 1;
593 break;
594 case 'B':
595 show_brl = 1;
596 break;
597 case 'd':
598 verbose = 1;
599 break;
600 case 'L':
601 locks_only = 1;
602 break;
603 case 'p':
604 processes_only = 1;
605 break;
606 case 'P':
607 profile_only = 1;
608 break;
609 case 'S':
610 shares_only = 1;
611 break;
612 case 's':
613 pstrcpy(servicesf, optarg);
614 break;
615 case 'u':
616 Ucrit_addUsername(optarg);
617 break;
618 default:
619 fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv);
620 return (-1);
624 if (!lp_load(servicesf,False,False,False)) {
625 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
626 return (-1);
629 if (verbose) {
630 printf("using configfile = %s\n", servicesf);
633 if (profile_only) {
634 return profile_dump();
637 tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
638 if (!tdb) {
639 printf("connections.tdb not initialised\n");
640 if (!lp_status(-1))
641 printf("You need to have status=yes in your smb config file\n");
642 return(0);
643 } else if (verbose) {
644 printf("Opened status file %s\n", fname);
647 if (locks_only) goto locks;
649 printf("\nSamba version %s\n",VERSION);
650 if (brief) {
651 printf("PID Username Machine Time logged in\n");
652 printf("-------------------------------------------------------------------\n");
653 } else {
654 printf("Service uid gid pid machine\n");
655 printf("----------------------------------------------\n");
657 tdb_traverse(tdb, traverse_fn1, NULL);
659 locks:
660 if (processes_only) exit(0);
662 if (brief) {
663 ptr=srecs;
664 while (ptr!=NULL) {
665 printf("%-8d%-10.10s%-30.30s%s",
666 (int)ptr->pid,uidtoname(ptr->uid),
667 ptr->machine,
668 asctime(LocalTime(&(ptr->start))));
669 ptr=ptr->next;
671 printf("\n");
672 exit(0);
675 printf("\n");
677 if (!shares_only) {
678 int ret;
680 if (!locking_init(1)) {
681 printf("Can't initialise locking module - exiting\n");
682 exit(1);
685 ret = share_mode_forall(print_share_mode);
687 if (ret == 0) {
688 printf("No locked files\n");
689 } else if (ret == -1) {
690 printf("locked file list truncated\n");
693 printf("\n");
695 if (show_brl) {
696 brl_forall(print_brl);
699 locking_end();
702 return (0);