2 Unix SMB/Netbios implementation.
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.
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
39 struct session_record
{
44 struct session_record
*next
;
48 extern BOOL AllowDebugChange
;
50 static pstring Ucrit_username
= ""; /* added by OH */
51 static pid_t Ucrit_pid
[100]; /* Ugly !!! */ /* added by OH */
52 static int Ucrit_MaxPid
=0; /* added by OH */
53 static unsigned int Ucrit_IsActive
= 0; /* added by OH */
54 static int verbose
, brief
;
55 static int shares_only
= 0; /* Added by RJS */
56 static int locks_only
= 0; /* Added by RJS */
57 static BOOL processes_only
=False
;
60 /* we need these because we link to locking*.o */
61 void become_root(void) {}
62 void unbecome_root(void) {}
66 static void Ucrit_addUsername(char *username
)
68 pstrcpy(Ucrit_username
, username
);
69 if(strlen(Ucrit_username
) > 0)
73 static unsigned int Ucrit_checkUsername(char *username
)
75 if ( !Ucrit_IsActive
) return 1;
76 if (strcmp(Ucrit_username
,username
) ==0) return 1;
80 static void Ucrit_addPid(pid_t pid
)
83 if ( !Ucrit_IsActive
) return;
84 for (i
=0;i
<Ucrit_MaxPid
;i
++)
85 if( pid
== Ucrit_pid
[i
] ) return;
86 Ucrit_pid
[Ucrit_MaxPid
++] = pid
;
89 static unsigned int Ucrit_checkPid(pid_t pid
)
92 if ( !Ucrit_IsActive
) return 1;
93 for (i
=0;i
<Ucrit_MaxPid
;i
++)
94 if( pid
== Ucrit_pid
[i
] ) return 1;
99 static void print_share_mode(share_mode_entry
*e
, char *fname
)
103 printf("Locked files:\n");
104 printf("Pid DenyMode Access R/W Oplock Name\n");
105 printf("--------------------------------------------------------------\n");
109 if (Ucrit_checkPid(e
->pid
)) {
110 printf("%-5d ",(int)e
->pid
);
111 switch (GET_DENY_MODE(e
->share_mode
)) {
112 case DENY_NONE
: printf("DENY_NONE "); break;
113 case DENY_ALL
: printf("DENY_ALL "); break;
114 case DENY_DOS
: printf("DENY_DOS "); break;
115 case DENY_READ
: printf("DENY_READ "); break;
116 case DENY_WRITE
:printf("DENY_WRITE "); break;
117 case DENY_FCB
: printf("DENY_FCB "); break;
119 printf("0x%-8x ",(unsigned int)e
->desired_access
);
120 switch (e
->share_mode
&0xF) {
121 case 0: printf("RDONLY "); break;
122 case 1: printf("WRONLY "); break;
123 case 2: printf("RDWR "); break;
127 (EXCLUSIVE_OPLOCK
|BATCH_OPLOCK
)) ==
128 (EXCLUSIVE_OPLOCK
|BATCH_OPLOCK
))
129 printf("EXCLUSIVE+BATCH ");
130 else if (e
->op_type
& EXCLUSIVE_OPLOCK
)
131 printf("EXCLUSIVE ");
132 else if (e
->op_type
& BATCH_OPLOCK
)
134 else if (e
->op_type
& LEVEL_II_OPLOCK
)
139 printf(" %s %s",dos_to_unix_static(fname
),
140 asctime(LocalTime((time_t *)&e
->time
.tv_sec
)));
144 static void print_brl(SMB_DEV_T dev
, SMB_INO_T ino
, int pid
,
145 enum brl_type lock_type
,
146 br_off start
, br_off size
)
150 printf("Byte range locks:\n");
151 printf(" Pid dev:inode R/W start size\n");
152 printf("------------------------------------------------\n");
156 printf("%6d %05x:%05x %s %9.0f %9.0f\n",
157 (int)pid
, (int)dev
, (int)ino
,
158 lock_type
==READ_LOCK
?"R":"W",
159 (double)start
, (double)size
);
163 /*******************************************************************
164 dump the elements of the profile structure
165 ******************************************************************/
166 static int profile_dump(void)
169 if (!profile_setup(True
)) {
170 fprintf(stderr
,"Failed to initialise profile memory\n");
174 printf("smb_count: %u\n", profile_p
->smb_count
);
175 printf("uid_changes: %u\n", profile_p
->uid_changes
);
176 printf("************************ System Calls ****************************\n");
177 printf("opendir_count: %u\n", profile_p
->syscall_opendir_count
);
178 printf("opendir_time: %u\n", profile_p
->syscall_opendir_time
);
179 printf("readdir_count: %u\n", profile_p
->syscall_readdir_count
);
180 printf("readdir_time: %u\n", profile_p
->syscall_readdir_time
);
181 printf("mkdir_count: %u\n", profile_p
->syscall_mkdir_count
);
182 printf("mkdir_time: %u\n", profile_p
->syscall_mkdir_time
);
183 printf("rmdir_count: %u\n", profile_p
->syscall_rmdir_count
);
184 printf("rmdir_time: %u\n", profile_p
->syscall_rmdir_time
);
185 printf("closedir_count: %u\n", profile_p
->syscall_closedir_count
);
186 printf("closedir_time: %u\n", profile_p
->syscall_closedir_time
);
187 printf("open_count: %u\n", profile_p
->syscall_open_count
);
188 printf("open_time: %u\n", profile_p
->syscall_open_time
);
189 printf("close_count: %u\n", profile_p
->syscall_close_count
);
190 printf("close_time: %u\n", profile_p
->syscall_close_time
);
191 printf("read_count: %u\n", profile_p
->syscall_read_count
);
192 printf("read_time: %u\n", profile_p
->syscall_read_time
);
193 printf("read_bytes: %u\n", profile_p
->syscall_read_bytes
);
194 printf("write_count: %u\n", profile_p
->syscall_write_count
);
195 printf("write_time: %u\n", profile_p
->syscall_write_time
);
196 printf("write_bytes: %u\n", profile_p
->syscall_write_bytes
);
198 printf("sendfile_count: %u\n", profile_p
->syscall_sendfile_count
);
199 printf("sendfile_time: %u\n", profile_p
->syscall_sendfile_time
);
200 printf("sendfile_bytes: %u\n", profile_p
->syscall_sendfile_bytes
);
202 printf("lseek_count: %u\n", profile_p
->syscall_lseek_count
);
203 printf("lseek_time: %u\n", profile_p
->syscall_lseek_time
);
204 printf("rename_count: %u\n", profile_p
->syscall_rename_count
);
205 printf("rename_time: %u\n", profile_p
->syscall_rename_time
);
206 printf("fsync_count: %u\n", profile_p
->syscall_fsync_count
);
207 printf("fsync_time: %u\n", profile_p
->syscall_fsync_time
);
208 printf("stat_count: %u\n", profile_p
->syscall_stat_count
);
209 printf("stat_time: %u\n", profile_p
->syscall_stat_time
);
210 printf("fstat_count: %u\n", profile_p
->syscall_fstat_count
);
211 printf("fstat_time: %u\n", profile_p
->syscall_fstat_time
);
212 printf("lstat_count: %u\n", profile_p
->syscall_lstat_count
);
213 printf("lstat_time: %u\n", profile_p
->syscall_lstat_time
);
214 printf("unlink_count: %u\n", profile_p
->syscall_unlink_count
);
215 printf("unlink_time: %u\n", profile_p
->syscall_unlink_time
);
216 printf("chmod_count: %u\n", profile_p
->syscall_chmod_count
);
217 printf("chmod_time: %u\n", profile_p
->syscall_chmod_time
);
218 printf("fchmod_count: %u\n", profile_p
->syscall_fchmod_count
);
219 printf("fchmod_time: %u\n", profile_p
->syscall_fchmod_time
);
220 printf("chown_count: %u\n", profile_p
->syscall_chown_count
);
221 printf("chown_time: %u\n", profile_p
->syscall_chown_time
);
222 printf("fchown_count: %u\n", profile_p
->syscall_fchown_count
);
223 printf("fchown_time: %u\n", profile_p
->syscall_fchown_time
);
224 printf("chdir_count: %u\n", profile_p
->syscall_chdir_count
);
225 printf("chdir_time: %u\n", profile_p
->syscall_chdir_time
);
226 printf("getwd_count: %u\n", profile_p
->syscall_getwd_count
);
227 printf("getwd_time: %u\n", profile_p
->syscall_getwd_time
);
228 printf("utime_count: %u\n", profile_p
->syscall_utime_count
);
229 printf("utime_time: %u\n", profile_p
->syscall_utime_time
);
230 printf("ftruncate_count: %u\n", profile_p
->syscall_ftruncate_count
);
231 printf("ftruncate_time: %u\n", profile_p
->syscall_ftruncate_time
);
232 printf("fcntl_lock_count: %u\n", profile_p
->syscall_fcntl_lock_count
);
233 printf("fcntl_lock_time: %u\n", profile_p
->syscall_fcntl_lock_time
);
234 printf("readlink_count: %u\n", profile_p
->syscall_readlink_count
);
235 printf("readlink_time: %u\n", profile_p
->syscall_readlink_time
);
236 printf("symlink_count: %u\n", profile_p
->syscall_symlink_count
);
237 printf("symlink_time: %u\n", profile_p
->syscall_symlink_time
);
238 printf("************************ Statcache *******************************\n");
239 printf("lookups: %u\n", profile_p
->statcache_lookups
);
240 printf("misses: %u\n", profile_p
->statcache_misses
);
241 printf("hits: %u\n", profile_p
->statcache_hits
);
242 printf("************************ Writecache ******************************\n");
243 printf("read_hits: %u\n", profile_p
->writecache_read_hits
);
244 printf("abutted_writes: %u\n", profile_p
->writecache_abutted_writes
);
245 printf("total_writes: %u\n", profile_p
->writecache_total_writes
);
246 printf("non_oplock_writes: %u\n", profile_p
->writecache_non_oplock_writes
);
247 printf("direct_writes: %u\n", profile_p
->writecache_direct_writes
);
248 printf("init_writes: %u\n", profile_p
->writecache_init_writes
);
249 printf("flushed_writes[SEEK]: %u\n", profile_p
->writecache_flushed_writes
[SEEK_FLUSH
]);
250 printf("flushed_writes[READ]: %u\n", profile_p
->writecache_flushed_writes
[READ_FLUSH
]);
251 printf("flushed_writes[WRITE]: %u\n", profile_p
->writecache_flushed_writes
[WRITE_FLUSH
]);
252 printf("flushed_writes[READRAW]: %u\n", profile_p
->writecache_flushed_writes
[READRAW_FLUSH
]);
253 printf("flushed_writes[OPLOCK_RELEASE]: %u\n", profile_p
->writecache_flushed_writes
[OPLOCK_RELEASE_FLUSH
]);
254 printf("flushed_writes[CLOSE]: %u\n", profile_p
->writecache_flushed_writes
[CLOSE_FLUSH
]);
255 printf("flushed_writes[SYNC]: %u\n", profile_p
->writecache_flushed_writes
[SYNC_FLUSH
]);
256 printf("flushed_writes[SIZECHANGE]: %u\n", profile_p
->writecache_flushed_writes
[SIZECHANGE_FLUSH
]);
257 printf("num_perfect_writes: %u\n", profile_p
->writecache_num_perfect_writes
);
258 printf("num_write_caches: %u\n", profile_p
->writecache_num_write_caches
);
259 printf("allocated_write_caches: %u\n", profile_p
->writecache_allocated_write_caches
);
260 printf("************************ SMB Calls *******************************\n");
261 printf("mkdir_count: %u\n", profile_p
->SMBmkdir_count
);
262 printf("mkdir_time: %u\n", profile_p
->SMBmkdir_time
);
263 printf("rmdir_count: %u\n", profile_p
->SMBrmdir_count
);
264 printf("rmdir_time: %u\n", profile_p
->SMBrmdir_time
);
265 printf("open_count: %u\n", profile_p
->SMBopen_count
);
266 printf("open_time: %u\n", profile_p
->SMBopen_time
);
267 printf("create_count: %u\n", profile_p
->SMBcreate_count
);
268 printf("create_time: %u\n", profile_p
->SMBcreate_time
);
269 printf("close_count: %u\n", profile_p
->SMBclose_count
);
270 printf("close_time: %u\n", profile_p
->SMBclose_time
);
271 printf("flush_count: %u\n", profile_p
->SMBflush_count
);
272 printf("flush_time: %u\n", profile_p
->SMBflush_time
);
273 printf("unlink_count: %u\n", profile_p
->SMBunlink_count
);
274 printf("unlink_time: %u\n", profile_p
->SMBunlink_time
);
275 printf("mv_count: %u\n", profile_p
->SMBmv_count
);
276 printf("mv_time: %u\n", profile_p
->SMBmv_time
);
277 printf("getatr_count: %u\n", profile_p
->SMBgetatr_count
);
278 printf("getatr_time: %u\n", profile_p
->SMBgetatr_time
);
279 printf("setatr_count: %u\n", profile_p
->SMBsetatr_count
);
280 printf("setatr_time: %u\n", profile_p
->SMBsetatr_time
);
281 printf("read_count: %u\n", profile_p
->SMBread_count
);
282 printf("read_time: %u\n", profile_p
->SMBread_time
);
283 printf("write_count: %u\n", profile_p
->SMBwrite_count
);
284 printf("write_time: %u\n", profile_p
->SMBwrite_time
);
285 printf("lock_count: %u\n", profile_p
->SMBlock_count
);
286 printf("lock_time: %u\n", profile_p
->SMBlock_time
);
287 printf("unlock_count: %u\n", profile_p
->SMBunlock_count
);
288 printf("unlock_time: %u\n", profile_p
->SMBunlock_time
);
289 printf("ctemp_count: %u\n", profile_p
->SMBctemp_count
);
290 printf("ctemp_time: %u\n", profile_p
->SMBctemp_time
);
291 printf("mknew_count: %u\n", profile_p
->SMBmknew_count
);
292 printf("mknew_time: %u\n", profile_p
->SMBmknew_time
);
293 printf("chkpth_count: %u\n", profile_p
->SMBchkpth_count
);
294 printf("chkpth_time: %u\n", profile_p
->SMBchkpth_time
);
295 printf("exit_count: %u\n", profile_p
->SMBexit_count
);
296 printf("exit_time: %u\n", profile_p
->SMBexit_time
);
297 printf("lseek_count: %u\n", profile_p
->SMBlseek_count
);
298 printf("lseek_time: %u\n", profile_p
->SMBlseek_time
);
299 printf("lockread_count: %u\n", profile_p
->SMBlockread_count
);
300 printf("lockread_time: %u\n", profile_p
->SMBlockread_time
);
301 printf("writeunlock_count: %u\n", profile_p
->SMBwriteunlock_count
);
302 printf("writeunlock_time: %u\n", profile_p
->SMBwriteunlock_time
);
303 printf("readbraw_count: %u\n", profile_p
->SMBreadbraw_count
);
304 printf("readbraw_time: %u\n", profile_p
->SMBreadbraw_time
);
305 printf("readBmpx_count: %u\n", profile_p
->SMBreadBmpx_count
);
306 printf("readBmpx_time: %u\n", profile_p
->SMBreadBmpx_time
);
307 printf("readBs_count: %u\n", profile_p
->SMBreadBs_count
);
308 printf("readBs_time: %u\n", profile_p
->SMBreadBs_time
);
309 printf("writebraw_count: %u\n", profile_p
->SMBwritebraw_count
);
310 printf("writebraw_time: %u\n", profile_p
->SMBwritebraw_time
);
311 printf("writeBmpx_count: %u\n", profile_p
->SMBwriteBmpx_count
);
312 printf("writeBmpx_time: %u\n", profile_p
->SMBwriteBmpx_time
);
313 printf("writeBs_count: %u\n", profile_p
->SMBwriteBs_count
);
314 printf("writeBs_time: %u\n", profile_p
->SMBwriteBs_time
);
315 printf("writec_count: %u\n", profile_p
->SMBwritec_count
);
316 printf("writec_time: %u\n", profile_p
->SMBwritec_time
);
317 printf("setattrE_count: %u\n", profile_p
->SMBsetattrE_count
);
318 printf("setattrE_time: %u\n", profile_p
->SMBsetattrE_time
);
319 printf("getattrE_count: %u\n", profile_p
->SMBgetattrE_count
);
320 printf("getattrE_time: %u\n", profile_p
->SMBgetattrE_time
);
321 printf("lockingX_count: %u\n", profile_p
->SMBlockingX_count
);
322 printf("lockingX_time: %u\n", profile_p
->SMBlockingX_time
);
323 printf("trans_count: %u\n", profile_p
->SMBtrans_count
);
324 printf("trans_time: %u\n", profile_p
->SMBtrans_time
);
325 printf("transs_count: %u\n", profile_p
->SMBtranss_count
);
326 printf("transs_time: %u\n", profile_p
->SMBtranss_time
);
327 printf("ioctl_count: %u\n", profile_p
->SMBioctl_count
);
328 printf("ioctl_time: %u\n", profile_p
->SMBioctl_time
);
329 printf("ioctls_count: %u\n", profile_p
->SMBioctls_count
);
330 printf("ioctls_time: %u\n", profile_p
->SMBioctls_time
);
331 printf("copy_count: %u\n", profile_p
->SMBcopy_count
);
332 printf("copy_time: %u\n", profile_p
->SMBcopy_time
);
333 printf("move_count: %u\n", profile_p
->SMBmove_count
);
334 printf("move_time: %u\n", profile_p
->SMBmove_time
);
335 printf("echo_count: %u\n", profile_p
->SMBecho_count
);
336 printf("echo_time: %u\n", profile_p
->SMBecho_time
);
337 printf("writeclose_count: %u\n", profile_p
->SMBwriteclose_count
);
338 printf("writeclose_time: %u\n", profile_p
->SMBwriteclose_time
);
339 printf("openX_count: %u\n", profile_p
->SMBopenX_count
);
340 printf("openX_time: %u\n", profile_p
->SMBopenX_time
);
341 printf("readX_count: %u\n", profile_p
->SMBreadX_count
);
342 printf("readX_time: %u\n", profile_p
->SMBreadX_time
);
343 printf("writeX_count: %u\n", profile_p
->SMBwriteX_count
);
344 printf("writeX_time: %u\n", profile_p
->SMBwriteX_time
);
345 printf("trans2_count: %u\n", profile_p
->SMBtrans2_count
);
346 printf("trans2_time: %u\n", profile_p
->SMBtrans2_time
);
347 printf("transs2_count: %u\n", profile_p
->SMBtranss2_count
);
348 printf("transs2_time: %u\n", profile_p
->SMBtranss2_time
);
349 printf("findclose_count: %u\n", profile_p
->SMBfindclose_count
);
350 printf("findclose_time: %u\n", profile_p
->SMBfindclose_time
);
351 printf("findnclose_count: %u\n", profile_p
->SMBfindnclose_count
);
352 printf("findnclose_time: %u\n", profile_p
->SMBfindnclose_time
);
353 printf("tcon_count: %u\n", profile_p
->SMBtcon_count
);
354 printf("tcon_time: %u\n", profile_p
->SMBtcon_time
);
355 printf("tdis_count: %u\n", profile_p
->SMBtdis_count
);
356 printf("tdis_time: %u\n", profile_p
->SMBtdis_time
);
357 printf("negprot_count: %u\n", profile_p
->SMBnegprot_count
);
358 printf("negprot_time: %u\n", profile_p
->SMBnegprot_time
);
359 printf("sesssetupX_count: %u\n", profile_p
->SMBsesssetupX_count
);
360 printf("sesssetupX_time: %u\n", profile_p
->SMBsesssetupX_time
);
361 printf("ulogoffX_count: %u\n", profile_p
->SMBulogoffX_count
);
362 printf("ulogoffX_time: %u\n", profile_p
->SMBulogoffX_time
);
363 printf("tconX_count: %u\n", profile_p
->SMBtconX_count
);
364 printf("tconX_time: %u\n", profile_p
->SMBtconX_time
);
365 printf("dskattr_count: %u\n", profile_p
->SMBdskattr_count
);
366 printf("dskattr_time: %u\n", profile_p
->SMBdskattr_time
);
367 printf("search_count: %u\n", profile_p
->SMBsearch_count
);
368 printf("search_time: %u\n", profile_p
->SMBsearch_time
);
369 printf("ffirst_count: %u\n", profile_p
->SMBffirst_count
);
370 printf("ffirst_time: %u\n", profile_p
->SMBffirst_time
);
371 printf("funique_count: %u\n", profile_p
->SMBfunique_count
);
372 printf("funique_time: %u\n", profile_p
->SMBfunique_time
);
373 printf("fclose_count: %u\n", profile_p
->SMBfclose_count
);
374 printf("fclose_time: %u\n", profile_p
->SMBfclose_time
);
375 printf("nttrans_count: %u\n", profile_p
->SMBnttrans_count
);
376 printf("nttrans_time: %u\n", profile_p
->SMBnttrans_time
);
377 printf("nttranss_count: %u\n", profile_p
->SMBnttranss_count
);
378 printf("nttranss_time: %u\n", profile_p
->SMBnttranss_time
);
379 printf("ntcreateX_count: %u\n", profile_p
->SMBntcreateX_count
);
380 printf("ntcreateX_time: %u\n", profile_p
->SMBntcreateX_time
);
381 printf("ntcancel_count: %u\n", profile_p
->SMBntcancel_count
);
382 printf("ntcancel_time: %u\n", profile_p
->SMBntcancel_time
);
383 printf("splopen_count: %u\n", profile_p
->SMBsplopen_count
);
384 printf("splopen_time: %u\n", profile_p
->SMBsplopen_time
);
385 printf("splwr_count: %u\n", profile_p
->SMBsplwr_count
);
386 printf("splwr_time: %u\n", profile_p
->SMBsplwr_time
);
387 printf("splclose_count: %u\n", profile_p
->SMBsplclose_count
);
388 printf("splclose_time: %u\n", profile_p
->SMBsplclose_time
);
389 printf("splretq_count: %u\n", profile_p
->SMBsplretq_count
);
390 printf("splretq_time: %u\n", profile_p
->SMBsplretq_time
);
391 printf("sends_count: %u\n", profile_p
->SMBsends_count
);
392 printf("sends_time: %u\n", profile_p
->SMBsends_time
);
393 printf("sendb_count: %u\n", profile_p
->SMBsendb_count
);
394 printf("sendb_time: %u\n", profile_p
->SMBsendb_time
);
395 printf("fwdname_count: %u\n", profile_p
->SMBfwdname_count
);
396 printf("fwdname_time: %u\n", profile_p
->SMBfwdname_time
);
397 printf("cancelf_count: %u\n", profile_p
->SMBcancelf_count
);
398 printf("cancelf_time: %u\n", profile_p
->SMBcancelf_time
);
399 printf("getmac_count: %u\n", profile_p
->SMBgetmac_count
);
400 printf("getmac_time: %u\n", profile_p
->SMBgetmac_time
);
401 printf("sendstrt_count: %u\n", profile_p
->SMBsendstrt_count
);
402 printf("sendstrt_time: %u\n", profile_p
->SMBsendstrt_time
);
403 printf("sendend_count: %u\n", profile_p
->SMBsendend_count
);
404 printf("sendend_time: %u\n", profile_p
->SMBsendend_time
);
405 printf("sendtxt_count: %u\n", profile_p
->SMBsendtxt_count
);
406 printf("sendtxt_time: %u\n", profile_p
->SMBsendtxt_time
);
407 printf("invalid_count: %u\n", profile_p
->SMBinvalid_count
);
408 printf("invalid_time: %u\n", profile_p
->SMBinvalid_time
);
409 printf("************************ Pathworks Calls *************************\n");
410 printf("setdir_count: %u\n", profile_p
->pathworks_setdir_count
);
411 printf("setdir_time: %u\n", profile_p
->pathworks_setdir_time
);
412 printf("************************ Trans2 Calls ****************************\n");
413 printf("open_count: %u\n", profile_p
->Trans2_open_count
);
414 printf("open_time: %u\n", profile_p
->Trans2_open_time
);
415 printf("findfirst_count: %u\n", profile_p
->Trans2_findfirst_count
);
416 printf("findfirst_time: %u\n", profile_p
->Trans2_findfirst_time
);
417 printf("findnext_count: %u\n", profile_p
->Trans2_findnext_count
);
418 printf("findnext_time: %u\n", profile_p
->Trans2_findnext_time
);
419 printf("qfsinfo_count: %u\n", profile_p
->Trans2_qfsinfo_count
);
420 printf("qfsinfo_time: %u\n", profile_p
->Trans2_qfsinfo_time
);
421 printf("setfsinfo_count: %u\n", profile_p
->Trans2_setfsinfo_count
);
422 printf("setfsinfo_time: %u\n", profile_p
->Trans2_setfsinfo_time
);
423 printf("qpathinfo_count: %u\n", profile_p
->Trans2_qpathinfo_count
);
424 printf("qpathinfo_time: %u\n", profile_p
->Trans2_qpathinfo_time
);
425 printf("setpathinfo_count: %u\n", profile_p
->Trans2_setpathinfo_count
);
426 printf("setpathinfo_time: %u\n", profile_p
->Trans2_setpathinfo_time
);
427 printf("qfileinfo_count: %u\n", profile_p
->Trans2_qfileinfo_count
);
428 printf("qfileinfo_time: %u\n", profile_p
->Trans2_qfileinfo_time
);
429 printf("setfileinfo_count: %u\n", profile_p
->Trans2_setfileinfo_count
);
430 printf("setfileinfo_time: %u\n", profile_p
->Trans2_setfileinfo_time
);
431 printf("fsctl_count: %u\n", profile_p
->Trans2_fsctl_count
);
432 printf("fsctl_time: %u\n", profile_p
->Trans2_fsctl_time
);
433 printf("ioctl_count: %u\n", profile_p
->Trans2_ioctl_count
);
434 printf("ioctl_time: %u\n", profile_p
->Trans2_ioctl_time
);
435 printf("findnotifyfirst_count: %u\n", profile_p
->Trans2_findnotifyfirst_count
);
436 printf("findnotifyfirst_time: %u\n", profile_p
->Trans2_findnotifyfirst_time
);
437 printf("findnotifynext_count: %u\n", profile_p
->Trans2_findnotifynext_count
);
438 printf("findnotifynext_time: %u\n", profile_p
->Trans2_findnotifynext_time
);
439 printf("mkdir_count: %u\n", profile_p
->Trans2_mkdir_count
);
440 printf("mkdir_time: %u\n", profile_p
->Trans2_mkdir_time
);
441 printf("session_setup_count: %u\n", profile_p
->Trans2_session_setup_count
);
442 printf("session_setup_time: %u\n", profile_p
->Trans2_session_setup_time
);
443 printf("get_dfs_referral_count: %u\n", profile_p
->Trans2_get_dfs_referral_count
);
444 printf("get_dfs_referral_time: %u\n", profile_p
->Trans2_get_dfs_referral_time
);
445 printf("report_dfs_inconsistancy_count: %u\n", profile_p
->Trans2_report_dfs_inconsistancy_count
);
446 printf("report_dfs_inconsistancy_time: %u\n", profile_p
->Trans2_report_dfs_inconsistancy_time
);
447 printf("************************ NT Transact Calls ***********************\n");
448 printf("create_count: %u\n", profile_p
->NT_transact_create_count
);
449 printf("create_time: %u\n", profile_p
->NT_transact_create_time
);
450 printf("ioctl_count: %u\n", profile_p
->NT_transact_ioctl_count
);
451 printf("ioctl_time: %u\n", profile_p
->NT_transact_ioctl_time
);
452 printf("set_security_desc_count: %u\n", profile_p
->NT_transact_set_security_desc_count
);
453 printf("set_security_desc_time: %u\n", profile_p
->NT_transact_set_security_desc_time
);
454 printf("notify_change_count: %u\n", profile_p
->NT_transact_notify_change_count
);
455 printf("notify_change_time: %u\n", profile_p
->NT_transact_notify_change_time
);
456 printf("rename_count: %u\n", profile_p
->NT_transact_rename_count
);
457 printf("rename_time: %u\n", profile_p
->NT_transact_rename_time
);
458 printf("query_security_desc_count: %u\n", profile_p
->NT_transact_query_security_desc_count
);
459 printf("query_security_desc_time: %u\n", profile_p
->NT_transact_query_security_desc_time
);
460 printf("************************ ACL Calls *******************************\n");
461 printf("get_nt_acl_count: %u\n", profile_p
->get_nt_acl_count
);
462 printf("get_nt_acl_time: %u\n", profile_p
->get_nt_acl_time
);
463 printf("fget_nt_acl_count: %u\n", profile_p
->fget_nt_acl_count
);
464 printf("fget_nt_acl_time: %u\n", profile_p
->fget_nt_acl_time
);
465 printf("set_nt_acl_count: %u\n", profile_p
->set_nt_acl_count
);
466 printf("set_nt_acl_time: %u\n", profile_p
->set_nt_acl_time
);
467 printf("fset_nt_acl_count: %u\n", profile_p
->fset_nt_acl_count
);
468 printf("fset_nt_acl_time: %u\n", profile_p
->fset_nt_acl_time
);
469 printf("chmod_acl_count: %u\n", profile_p
->chmod_acl_count
);
470 printf("chmod_acl_time: %u\n", profile_p
->chmod_acl_time
);
471 printf("fchmod_acl_count: %u\n", profile_p
->fchmod_acl_count
);
472 printf("fchmod_acl_time: %u\n", profile_p
->fchmod_acl_time
);
473 printf("************************ NMBD Calls ****************************\n");
474 printf("name_release_count: %u\n", profile_p
->name_release_count
);
475 printf("name_release_time: %u\n", profile_p
->name_release_time
);
476 printf("name_refresh_count: %u\n", profile_p
->name_refresh_count
);
477 printf("name_refresh_time: %u\n", profile_p
->name_refresh_time
);
478 printf("name_registration_count: %u\n", profile_p
->name_registration_count
);
479 printf("name_registration_time: %u\n", profile_p
->name_registration_time
);
480 printf("node_status_count: %u\n", profile_p
->node_status_count
);
481 printf("node_status_time: %u\n", profile_p
->node_status_time
);
482 printf("name_query_count: %u\n", profile_p
->name_query_count
);
483 printf("name_query_time: %u\n", profile_p
->name_query_time
);
484 printf("host_announce_count: %u\n", profile_p
->host_announce_count
);
485 printf("host_announce_time: %u\n", profile_p
->host_announce_time
);
486 printf("workgroup_announce_count: %u\n", profile_p
->workgroup_announce_count
);
487 printf("workgroup_announce_time: %u\n", profile_p
->workgroup_announce_time
);
488 printf("local_master_announce_count: %u\n", profile_p
->local_master_announce_count
);
489 printf("local_master_announce_time: %u\n", profile_p
->local_master_announce_time
);
490 printf("master_browser_announce_count: %u\n", profile_p
->master_browser_announce_count
);
491 printf("master_browser_announce_time: %u\n", profile_p
->master_browser_announce_time
);
492 printf("lm_host_announce_count: %u\n", profile_p
->lm_host_announce_count
);
493 printf("lm_host_announce_time: %u\n", profile_p
->lm_host_announce_time
);
494 printf("get_backup_list_count: %u\n", profile_p
->get_backup_list_count
);
495 printf("get_backup_list_time: %u\n", profile_p
->get_backup_list_time
);
496 printf("reset_browser_count: %u\n", profile_p
->reset_browser_count
);
497 printf("reset_browser_time: %u\n", profile_p
->reset_browser_time
);
498 printf("announce_request_count: %u\n", profile_p
->announce_request_count
);
499 printf("announce_request_time: %u\n", profile_p
->announce_request_time
);
500 printf("lm_announce_request_count: %u\n", profile_p
->lm_announce_request_count
);
501 printf("lm_announce_request_time: %u\n", profile_p
->lm_announce_request_time
);
502 printf("domain_logon_count: %u\n", profile_p
->domain_logon_count
);
503 printf("domain_logon_time: %u\n", profile_p
->domain_logon_time
);
504 printf("sync_browse_lists_count: %u\n", profile_p
->sync_browse_lists_count
);
505 printf("sync_browse_lists_time: %u\n", profile_p
->sync_browse_lists_time
);
506 printf("run_elections_count: %u\n", profile_p
->run_elections_count
);
507 printf("run_elections_time: %u\n", profile_p
->run_elections_time
);
508 printf("election_count: %u\n", profile_p
->election_count
);
509 printf("election_time: %u\n", profile_p
->election_time
);
511 #else /* ndef WITH_PROFILE */
512 fprintf(stderr
,"Profile data unavailable\n");
513 #endif /* WITH_PROFILE */
518 static int traverse_fn1(TDB_CONTEXT
*tdb
, TDB_DATA kbuf
, TDB_DATA dbuf
, void *state
)
520 static pid_t last_pid
;
521 struct session_record
*ptr
;
522 struct connections_data crec
;
524 if (dbuf
.dsize
!= sizeof(crec
))
527 memcpy(&crec
, dbuf
.dptr
, sizeof(crec
));
532 if (!process_exists(crec
.pid
) || !Ucrit_checkUsername(uidtoname(crec
.uid
))) {
539 if ((ptr
->pid
==crec
.pid
)&&(strncmp(ptr
->machine
,crec
.machine
,30)==0)) {
540 if (ptr
->start
> crec
.start
)
541 ptr
->start
=crec
.start
;
547 ptr
=(struct session_record
*) malloc(sizeof(struct session_record
));
552 ptr
->start
=crec
.start
;
553 strncpy(ptr
->machine
,crec
.machine
,30);
554 ptr
->machine
[30]='\0';
559 Ucrit_addPid(crec
.pid
);
560 if (processes_only
) {
561 if (last_pid
!= crec
.pid
)
562 printf("%d\n",(int)crec
.pid
);
563 last_pid
= crec
.pid
; /* XXXX we can still get repeats, have to
564 add a sort at some time */
566 printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s",
567 crec
.name
,uidtoname(crec
.uid
),gidtoname(crec
.gid
),(int)crec
.pid
,
568 crec
.machine
,crec
.addr
,
569 asctime(LocalTime(&crec
.start
)));
579 int main(int argc
, char *argv
[])
583 static pstring servicesf
= CONFIGFILE
;
585 int profile_only
= 0;
587 struct session_record
*ptr
;
590 setup_logging(argv
[0],True
);
592 charset_initialise();
594 AllowDebugChange
= False
;
598 if (getuid() != geteuid()) {
599 printf("smbstatus should not be run setuid\n");
603 while ((c
= getopt(argc
, argv
, "pdLSs:u:bPB")) != EOF
) {
627 pstrcpy(servicesf
, optarg
);
630 Ucrit_addUsername(optarg
);
633 fprintf(stderr
, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv
);
638 if (!lp_load(servicesf
,False
,False
,False
)) {
639 fprintf(stderr
, "Can't load %s - run testparm to debug it\n", servicesf
);
644 printf("using configfile = %s\n", servicesf
);
648 return profile_dump();
651 tdb
= tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT
, O_RDONLY
, 0);
653 printf("%s not initialized.\n", lock_path("connections.tdb"));
654 printf("This is normal if an SMB client has never connected to your server.\n");
655 if (!lp_status(-1)) {
656 printf("You need to have status=yes in your smb config file\n");
659 } else if (verbose
) {
660 slprintf (fname
, sizeof(fname
)-1, "%s/%s", lp_lockdir(), "connections.tdb");
661 printf("Opened %s\n", fname
);
664 if (locks_only
) goto locks
;
666 printf("\nSamba version %s\n",VERSION
);
668 printf("PID Username Machine Time logged in\n");
669 printf("-------------------------------------------------------------------\n");
671 printf("Service uid gid pid machine\n");
672 printf("----------------------------------------------\n");
674 tdb_traverse(tdb
, traverse_fn1
, NULL
);
678 if (processes_only
) exit(0);
683 printf("%-8d%-10.10s%-30.30s%s",
684 (int)ptr
->pid
,uidtoname(ptr
->uid
),
686 asctime(LocalTime(&(ptr
->start
))));
698 if (!locking_init(1)) {
699 printf("Can't initialise locking module - exiting\n");
703 ret
= share_mode_forall(print_share_mode
);
706 printf("No locked files\n");
707 } else if (ret
== -1) {
708 printf("locked file list truncated\n");
714 brl_forall(print_brl
);