2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1994-1995
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 * This program reports current SMB connections
33 struct connect_record crec;
34 extern int DEBUGLEVEL;
36 extern pstring myhostname;
38 static pstring Ucrit_username = ""; /* added by OH */
39 int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */
40 int Ucrit_MaxPid=0; /* added by OH */
41 unsigned int Ucrit_IsActive = 0; /* added by OH */
42 void Ucrit_addUsername(pstring username); /* added by OH */
43 unsigned int Ucrit_checkUsername(pstring username); /* added by OH */
44 void Ucrit_addPid(int pid); /* added by OH */
45 unsigned int Ucrit_checkPid(int pid); /* added by OH */
47 int main(int argc, char *argv[])
52 static pstring servicesf = CONFIGFILE;
58 BOOL processes_only=False;
61 setup_logging(argv[0],True);
66 dbf = fopen("/dev/null","w");
68 if (getuid() != geteuid()) {
69 printf("smbstatus should not be run setuid\n");
73 while ((c = getopt(argc, argv, "pds:u:")) != EOF) {
82 strcpy(servicesf, optarg);
84 case 'u': /* added by OH */
85 Ucrit_addUsername(optarg); /* added by OH */
88 fprintf(stderr, "Usage: %s [-d] [-p] [-s configfile] [-u username]\n", *argv); /* changed by OH */
93 if (!lp_load(servicesf,False)) {
94 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
98 get_myname(myhostname, NULL);
101 printf("using configfile = %s\n", servicesf);
102 printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL");
105 strcpy(fname,lp_lockdir());
106 standard_sub_basic(fname);
107 trim_string(fname,"","/");
108 strcat(fname,"/STATUS..LCK");
110 f = fopen(fname,"r");
112 printf("Couldn't open status file %s\n",fname);
114 printf("You need to have status=yes in your smb config file\n");
118 printf("Opened status file %s\n", fname);
123 if (!processes_only) {
124 printf("\nSamba version %s\n",VERSION);
126 printf("Service uid gid pid machine\n");
127 printf("----------------------------------------------\n");
132 if (fread(&crec,sizeof(crec),1,f) != 1)
134 if ( crec.magic == 0x280267 && process_exists(crec.pid)
135 && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */
138 Ucrit_addPid(crec.pid); /* added by OH */
139 if (processes_only) {
140 if (last_pid != crec.pid)
141 printf("%d\n",crec.pid);
142 last_pid = crec.pid; /* XXXX we can still get repeats, have to
143 add a sort at some time */
146 printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s",
147 crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid,
148 crec.machine,crec.addr,
149 asctime(LocalTime(&crec.start,GMT_TO_LOCAL)));
154 if (processes_only) exit(0);
158 dir = opendir(lp_lockdir());
160 while ((s=readdirname(dir))) {
168 if (sscanf(s,"share.%d.%d",&dev,&inode)!=2) continue;
170 strcpy(lname,lp_lockdir());
171 trim_string(lname,NULL,"/");
175 fd = open(lname,O_RDONLY,0);
176 if (fd < 0) continue;
177 if (read(fd,buf,16) != 16) continue;
178 n = read(fd,fname,sizeof(fname));
186 if ( !Ucrit_checkPid(pid) ) /* added by OH */
189 if (IVAL(buf,12) != LOCKING_VERSION || !process_exists(pid)) {
190 if (unlink(lname)==0)
191 printf("Deleted stale share file %s\n",s);
195 fname[sizeof(fname)-1] = 0;
199 printf("Locked files:\n");
200 printf("Pid DenyMode R/W Name\n");
201 printf("------------------------------\n");
206 switch ((mode>>4)&0xF)
208 case DENY_NONE: printf("DENY_NONE "); break;
209 case DENY_ALL: printf("DENY_ALL "); break;
210 case DENY_DOS: printf("DENY_DOS "); break;
211 case DENY_READ: printf("DENY_READ "); break;
212 case DENY_WRITE:printf("DENY_WRITE "); break;
216 case 0: printf("RDONLY "); break;
217 case 1: printf("WRONLY "); break;
218 case 2: printf("RDWR "); break;
220 printf(" %s %s",fname,asctime(LocalTime(&t,GMT_TO_LOCAL)));
225 printf("No locked files\n");
231 void Ucrit_addUsername(pstring username)
233 strcpy(Ucrit_username, username);
234 if(strlen(Ucrit_username) > 0)
238 unsigned int Ucrit_checkUsername(pstring username)
240 if ( !Ucrit_IsActive) return 1;
241 if (strcmp(Ucrit_username,username) ==0) return 1;
245 void Ucrit_addPid(int pid)
248 if ( !Ucrit_IsActive) return;
249 for (i=0;i<Ucrit_MaxPid;i++)
250 if( pid == Ucrit_pid[i] ) return;
251 Ucrit_pid[Ucrit_MaxPid++] = pid;
254 unsigned int Ucrit_checkPid(int pid)
257 if ( !Ucrit_IsActive) return 1;
258 for (i=0;i<Ucrit_MaxPid;i++)
259 if( pid == Ucrit_pid[i] ) return 1;