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
;
37 static pstring Ucrit_username
= ""; /* added by OH */
38 int Ucrit_pid
[100]; /* Ugly !!! */ /* added by OH */
39 int Ucrit_MaxPid
=0; /* added by OH */
40 unsigned int Ucrit_IsActive
= 0; /* added by OH */
41 void Ucrit_addUsername(pstring username
); /* added by OH */
42 unsigned int Ucrit_checkUsername(pstring username
); /* added by OH */
43 void Ucrit_addPid(int pid
); /* added by OH */
44 unsigned int Ucrit_checkPid(int pid
); /* added by OH */
46 int main(int argc
, char *argv
[])
51 static pstring servicesf
= CONFIGFILE
;
57 BOOL processes_only
=False
;
60 setup_logging(argv
[0],True
);
65 dbf
= fopen("/dev/null","w");
67 if (getuid() != geteuid()) {
68 printf("smbstatus should not be run setuid\n");
72 while ((c
= getopt(argc
, argv
, "pdsu:")) != EOF
) {
81 strcpy(servicesf
, optarg
);
83 case 'u': /* added by OH */
84 Ucrit_addUsername(optarg
); /* added by OH */
87 fprintf(stderr
, "Usage: %s [-d] [-p] [-s configfile] [-u username]\n", *argv
); /* changed by OH */
94 if (!lp_load(servicesf
,False
)) {
95 fprintf(stderr
, "Can't load %s - run testparm to debug it\n", servicesf
);
100 printf("using configfile = %s\n", servicesf
);
101 printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL");
104 strcpy(fname
,lp_lockdir());
105 standard_sub_basic(fname
);
106 trim_string(fname
,"","/");
107 strcat(fname
,"/STATUS..LCK");
109 f
= fopen(fname
,"r");
111 printf("Couldn't open status file %s\n",fname
);
113 printf("You need to have status=yes in your smb config file\n");
119 if (!processes_only
) {
120 printf("\nSamba version %s\n",VERSION
);
122 printf("Service uid gid pid machine\n");
123 printf("----------------------------------------------\n");
128 if (fread(&crec
,sizeof(crec
),1,f
) != 1)
130 if ( crec
.magic
== 0x280267 && process_exists(crec
.pid
)
131 && Ucrit_checkUsername(uidtoname(crec
.uid
)) /* added by OH */
134 Ucrit_addPid(crec
.pid
); /* added by OH */
135 if (processes_only
) {
136 if (last_pid
!= crec
.pid
)
137 printf("%d\n",crec
.pid
);
138 last_pid
= crec
.pid
; /* XXXX we can still get repeats, have to
139 add a sort at some time */
142 printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s",
143 crec
.name
,uidtoname(crec
.uid
),gidtoname(crec
.gid
),crec
.pid
,
144 crec
.machine
,crec
.addr
,
145 asctime(LocalTime(&crec
.start
,GMT_TO_LOCAL
)));
150 if (processes_only
) exit(0);
154 dir
= opendir(lp_lockdir());
156 while ((s
=readdirname(dir
))) {
164 if (sscanf(s
,"share.%d.%d",&dev
,&inode
)!=2) continue;
166 strcpy(lname
,lp_lockdir());
167 trim_string(lname
,NULL
,"/");
171 fd
= open(lname
,O_RDONLY
,0);
172 if (fd
< 0) continue;
173 if (read(fd
,buf
,16) != 16) continue;
174 n
= read(fd
,fname
,sizeof(fname
));
182 if ( !Ucrit_checkPid(pid
) ) /* added by OH */
185 if (IVAL(buf
,12) != LOCKING_VERSION
|| !process_exists(pid
)) {
186 if (unlink(lname
)==0)
187 printf("Deleted stale share file %s\n",s
);
191 fname
[sizeof(fname
)-1] = 0;
195 printf("Locked files:\n");
196 printf("Pid DenyMode R/W Name\n");
197 printf("------------------------------\n");
202 switch ((mode
>>4)&0xF)
204 case DENY_NONE
: printf("DENY_NONE "); break;
205 case DENY_ALL
: printf("DENY_ALL "); break;
206 case DENY_DOS
: printf("DENY_DOS "); break;
207 case DENY_READ
: printf("DENY_READ "); break;
208 case DENY_WRITE
:printf("DENY_WRITE "); break;
212 case 0: printf("RDONLY "); break;
213 case 1: printf("WRONLY "); break;
214 case 2: printf("RDWR "); break;
216 printf(" %s %s",fname
,asctime(LocalTime(&t
,GMT_TO_LOCAL
)));
221 printf("No locked files\n");
227 void Ucrit_addUsername(pstring username
)
229 strcpy(Ucrit_username
, username
);
230 if(strlen(Ucrit_username
) > 0)
234 unsigned int Ucrit_checkUsername(pstring username
)
236 if ( !Ucrit_IsActive
) return 1;
237 if (strcmp(Ucrit_username
,username
) ==0) return 1;
241 void Ucrit_addPid(int pid
)
244 if ( !Ucrit_IsActive
) return;
245 for (i
=0;i
<Ucrit_MaxPid
;i
++)
246 if( pid
== Ucrit_pid
[i
] ) return;
247 Ucrit_pid
[Ucrit_MaxPid
++] = pid
;
250 unsigned int Ucrit_checkPid(int pid
)
253 if ( !Ucrit_IsActive
) return 1;
254 for (i
=0;i
<Ucrit_MaxPid
;i
++)
255 if( pid
== Ucrit_pid
[i
] ) return 1;