home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / contrib / samba / samba-1.8 / samba-1 / samba-1.8.05 / status.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-27  |  2.3 KB  |  91 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.8.
  4.    Copyright (C) Andrew Tridgell 1994
  5.    
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.    
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.    
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. /*
  22.  * This program reports current SMB connections
  23.  */
  24.  
  25. #include "includes.h"
  26. #include "smb.h"
  27.  
  28. struct connect_record crec;
  29.  
  30. int main(int argc, char *argv[])
  31. {
  32.   FILE *f;
  33.   pstring fname;
  34.   int uid;
  35.  
  36.   strcpy(fname,LOCKDIR);
  37.   trim_string(fname,"","/");
  38.   strcat(fname,"/STATUS..LCK");
  39.  
  40.   /* if we're running suid then don't allow them to specify the lock 
  41.      file */
  42.   if (argc > 1)
  43.     {
  44.       if (getuid() == geteuid())
  45.     strcpy(fname,argv[1]);
  46.       else
  47.     printf("ignoring filename %s as process is suid\n",argv[1]);
  48.     }
  49.   
  50.  
  51.   f = fopen(fname,"r");
  52.   if (!f)
  53.     {
  54.       printf("Couldn't open status file %s\n",fname);
  55.       printf("Perhaps you don't have status=yes in [globals] ?\n");
  56.       printf("or maybe you need to give this program the name of your status file\n");
  57.       return(0);
  58.     }
  59.  
  60.   if (getuid() != 0)
  61.     setuid(0);
  62.  
  63.   uid = getuid();
  64.  
  65.   printf("\nSamba version %s\n",VERSION);
  66.   if (uid != 0)
  67.     {
  68.       printf("This program needs to be run as root (or suid root) to run correctly\n");
  69.       printf("when not running as root it may report some connections that are gone\n\n");
  70.     }
  71.  
  72.   printf("Service      uid   gid   pid   machine\n");
  73.   printf("--------------------------------------\n");
  74.  
  75.   while (!feof(f))
  76.     {
  77.       if (fread(&crec,sizeof(crec),1,f) != 1)
  78.     break;
  79.       if (crec.magic == 0x280267 && (uid!=0 || process_exists(crec.pid)))
  80.     printf("%-10.10s %5d %5d %5d   %s (%s) %s",
  81.            crec.name,crec.uid,crec.gid,crec.pid,
  82.            crec.machine,crec.addr,asctime(LocalTime(&crec.start,0)));
  83.     }
  84.  
  85.   printf("\n");
  86.  
  87.   fclose(f);
  88.   return (0);
  89. }
  90.  
  91.