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
28 * This program reports current SMB connections
37 struct connect_record crec;
39 struct session_record{
44 struct session_record *next;
47 extern int DEBUGLEVEL;
49 extern pstring myhostname;
51 static pstring Ucrit_username = ""; /* added by OH */
52 int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */
53 int Ucrit_MaxPid=0; /* added by OH */
54 unsigned int Ucrit_IsActive = 0; /* added by OH */
56 /* we need these because we link to locking*.o */
57 void become_root(BOOL save_dir) {}
58 void unbecome_root(BOOL restore_dir) {}
59 connection_struct Connections[MAX_CONNECTIONS];
60 files_struct Files[MAX_OPEN_FILES];
61 struct current_user current_user;
64 static void print_share_mode(share_mode_entry *e, char *fname)
68 printf("Locked files:\n");
69 printf("Pid DenyMode R/W Oplock Name\n");
70 printf("--------------------------------------------------\n");
74 printf("%-5d ",e->pid);
75 switch ((e->share_mode>>4)&0xF) {
76 case DENY_NONE: printf("DENY_NONE "); break;
77 case DENY_ALL: printf("DENY_ALL "); break;
78 case DENY_DOS: printf("DENY_DOS "); break;
79 case DENY_READ: printf("DENY_READ "); break;
80 case DENY_WRITE:printf("DENY_WRITE "); break;
82 switch (e->share_mode&0xF) {
83 case 0: printf("RDONLY "); break;
84 case 1: printf("WRONLY "); break;
85 case 2: printf("RDWR "); break;
89 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
90 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
91 printf("EXCLUSIVE+BATCH ");
92 else if (e->op_type & EXCLUSIVE_OPLOCK)
94 else if (e->op_type & BATCH_OPLOCK)
99 printf(" %s %s",fname,asctime(LocalTime((time_t *)&e->time.tv_sec)));
104 int main(int argc, char *argv[])
109 static pstring servicesf = CONFIGFILE;
111 int verbose = 0, brief =0;
112 BOOL processes_only=False;
114 struct session_record *ptr;
118 setup_logging(argv[0],True);
120 charset_initialise();
125 if (getuid() != geteuid()) {
126 printf("smbstatus should not be run setuid\n");
130 while ((c = getopt(argc, argv, "pds:u:b")) != EOF) {
142 strcpy(servicesf, optarg);
144 case 'u': /* added by OH */
145 Ucrit_addUsername(optarg); /* added by OH */
148 fprintf(stderr, "Usage: %s [-d] [-p] [-s configfile] [-u username]\n", *argv); /* changed by OH */
153 get_myname(myhostname, NULL);
155 if (!lp_load(servicesf,False,False,False)) {
156 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
161 printf("using configfile = %s\n", servicesf);
162 printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL");
165 strcpy(fname,lp_lockdir());
166 standard_sub_basic(fname);
167 trim_string(fname,"","/");
168 strcat(fname,"/STATUS..LCK");
170 f = fopen(fname,"r");
172 printf("Couldn't open status file %s\n",fname);
174 printf("You need to have status=yes in your smb config file\n");
178 printf("Opened status file %s\n", fname);
183 if (!processes_only) {
184 printf("\nSamba version %s\n",VERSION);
188 printf("PID Username Machine Time logged in\n");
189 printf("-------------------------------------------------------------------\n");
193 printf("Service uid gid pid machine\n");
194 printf("----------------------------------------------\n");
200 if (fread(&crec,sizeof(crec),1,f) != 1)
202 if (crec.cnum == -1) continue;
203 if ( crec.magic == 0x280267 && process_exists(crec.pid)
204 && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */
212 if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0))
214 if (ptr->start > crec.start)
215 ptr->start=crec.start;
222 ptr=(struct session_record *) malloc(sizeof(struct session_record));
225 ptr->start=crec.start;
226 strncpy(ptr->machine,crec.machine,30);
227 ptr->machine[30]='\0';
234 Ucrit_addPid(crec.pid); /* added by OH */
235 if (processes_only) {
236 if (last_pid != crec.pid)
237 printf("%d\n",crec.pid);
238 last_pid = crec.pid; /* XXXX we can still get repeats, have to
239 add a sort at some time */
242 printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s",
243 crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid,
244 crec.machine,crec.addr,
245 asctime(LocalTime(&crec.start)));
251 if (processes_only) exit(0);
258 printf("%-8d%-10.10s%-30.30s%s",ptr->pid,uidtoname(ptr->uid),ptr->machine,asctime(LocalTime(&(ptr->start))));
269 if (share_mode_forall(print_share_mode) <= 0)
270 printf("No locked files\n");
274 share_status(stdout);
282 void Ucrit_addUsername(pstring username)
284 strcpy(Ucrit_username, username);
285 if(strlen(Ucrit_username) > 0)
289 unsigned int Ucrit_checkUsername(pstring username)
291 if ( !Ucrit_IsActive) return 1;
292 if (strcmp(Ucrit_username,username) ==0) return 1;
296 void Ucrit_addPid(int pid)
299 if ( !Ucrit_IsActive) return;
300 for (i=0;i<Ucrit_MaxPid;i++)
301 if( pid == Ucrit_pid[i] ) return;
302 Ucrit_pid[Ucrit_MaxPid++] = pid;
305 unsigned int Ucrit_checkPid(int pid)
308 if ( !Ucrit_IsActive) return 1;
309 for (i=0;i<Ucrit_MaxPid;i++)
310 if( pid == Ucrit_pid[i] ) return 1;