home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /* File: FLIST.C - Copyright (C) Adrian M. Cunnelly 1993 */
- /* */
- /* Function: For all connected workstations list all files that */
- /* are open on the current server. */
- /* */
- /* This has been tested with Netware 2.15 and 3.11 */
- /* */
- /* Usage: flist */
- /* */
- /* Functions Called: CheckConsolePrivileges */
- /* GetBinderyObjectID */
- /* GetConnectionInformation */
- /* GetConnectionNumber */
- /* GetConnectionsOpenFiles */
- /* GetFileServerInformation */
- /* GetObjectConnectionNumbers */
- /* GetPathFromDirectoryEntry */
- /* GetPreferredConnectionID */
- /* GetDefaultConnectionID */
- /* GetPrimaryConnectionID */
- /* SetPreferredConnectionID */
- /* ISShellLoaded */
- /* */
- /***************************************************************************/
-
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <io.h>
- #include <errno.h>
- #include <conio.h>
- #include <dos.h>
-
- #ifndef TURBOC
- #include <search.h>
- #endif
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <fcntl.h>
- #include <ctype.h>
-
- #include "netware.h"
-
- void show_usage( void );
- int get_max_connections( void );
- void do_connection( int station );
- int do_it( int argc, char *argv[]);
-
- static int this_con,max_con;
- static OPEN_FILES_INFO openfiles[64];
-
- int main(int argc,char *argv[])
- {
- int thisserver,prefserver;
- int rcode;
-
- printf("\nFLIST (v2.0) - Copyright (C) Adrian M. Cunnelly 1993\n\n");
-
- if (IsShellLoaded() != SUCCESS)
- {
- printf("*** No netware shell loaded ***\n");
- exit(255);
- }
-
- if ((prefserver = GetPreferredConnectionID()) == 0)
- {
- if ((thisserver = GetDefaultConnectionID()) == 0)
- thisserver = GetPrimaryConnectionID();
- SetPreferredConnectionID( thisserver );
- }
- else
- thisserver = prefserver;
-
- if ((this_con = GetConnectionNumber()) == 0)
- {
- printf("*** No current connection ***\n");
- if (thisserver != prefserver) /* reset preferred server */
- SetPreferredConnectionID( prefserver );
- exit(255);
- }
- if (CheckConsolePrivileges() != 0)
- {
- printf("FLIST requires user to have Console Operator rights");
- printf("... aborted\n");
- if (thisserver != prefserver) /* reset preferred server */
- SetPreferredConnectionID( prefserver );
- exit(255);
- }
- if ((max_con = get_max_connections()) == 0)
- {
- if (thisserver != prefserver) /* reset preferred server */
- SetPreferredConnectionID( prefserver );
- exit(255);
- }
-
- rcode = do_it( argc, argv );
- if (thisserver != prefserver) /* reset preferred server */
- SetPreferredConnectionID( prefserver );
- return( rcode );
- }
-
- int do_it( int argc, char *argv[])
- {
- unsigned int station;
- char *this_param;
- int param=1;
- int req_connection = -1;
- long req_user = 0L;
- char req_uname[OBJECT_LENGTH];
- word conn_count;
- byte connections[100];
- int r;
-
- while(--argc)
- {
- this_param = argv[param++];
-
- if(*this_param == '-' || *this_param == '/')
- {
- switch(toupper(*(++this_param)))
- {
- case 'C':
- if (req_user > 0L)
- {
- printf("Connection number cannot be specified if");
- printf(" username is used\n\n");
- show_usage();
- return(255);
- }
- if ((req_connection = atoi(this_param+1)) < 1)
- {
- printf("Connection number [%d] is invalid\n\n",
- req_connection);
- show_usage();
- return(255);
- }
- break;
- case 'U':
- if (req_connection > 0)
- {
- printf("Username cannot be specified if connection");
- printf(" number is used\n\n");
- show_usage();
- return(255);
- }
- if ( GetBinderyObjectID( USER ,
- this_param+1 ,
- &req_user ) != SUCCESS)
- {
- printf("Invalid username specified: %s\n\n",
- this_param+1);
- show_usage();
- return(255);
- }
- else
- strcpy(req_uname,this_param+1);
- break;
- case '?':
- show_usage();
- return(0);
-
- default:
- printf("Invalid option specified\n\n");
- show_usage();
- return(255);
- }
- }
- else
- {
- printf("Invalid parameter specified\n\n");
- show_usage();
- return(255);
- }
- }
-
- if (req_connection > max_con)
- {
- printf("Connection number [%d] out of range, max allowed is %d\n",
- req_connection,max_con);
- return(255);
- }
-
- if (req_connection > 0)
- do_connection(req_connection);
- else
- if (req_user > 0L)
- {
- if ( ( r = GetObjectConnectionNumbers( USER , req_uname , &conn_count ,
- connections ) ) != SUCCESS )
- {
- printf("GetObjectConnectionNumbers returned: %03d--%#02x\n",
- r,r);
- return(255);
- }
- for (station=0; station < conn_count; station++)
- do_connection( connections[ station ] );
- }
- else
- for (station=1; station<=max_con; station++)
- do_connection(station);
-
- return(0);
- }
-
- int get_max_connections( void )
- {
- FILE_SERVER_INFO sinfo;
- int r;
-
- if ((r=GetFileServerInformation( &sinfo )) != SUCCESS)
- {
- printf("GetFileServerInformation returned: %03d--%#02x\n",r,r);
- return (0);
- }
-
- return( sinfo.connections_supported );
- }
-
- void do_connection( int station )
- {
- long object_id;
- int object_type;
- char object_name[OBJECT_LENGTH];
- byte logintime[7];
- int r,r1,i;
- char path[256];
- int fcount;
-
- if((r1=GetConnectionInformation( (word)station , object_name,
- &object_type,&object_id,
- logintime)) != SUCCESS)
- {
- printf("GetConnectionInformation returned: %03d--%#02x\n",r1,r1);
- return;
- }
- else
- if ( (object_id == 0) || (object_name[0] == '\0') )
- return;
- else
- {
- if (station != this_con)
- printf(" %2u-%-16s\n",station , object_name );
- else
- printf(" \376 %2u-%-16s\n",station , object_name );
-
- r=GetConnectionsOpenFiles(station,64,&openfiles[0],
- &fcount);
- if (r == NOT_ENOUGH_ITEMS)
- {
- printf("Warning: more than 64 files open\n");
- fcount=64;
- r = SUCCESS;
- }
-
- if (r != SUCCESS)
- printf("GetConnectionsOpenFiles returned: %03d--%#02x\n",
- r,r);
- else
- {
- for (i=0;i<fcount;i++)
- {
- if (openfiles[i].directory_entry != 0)
- { /* Must be on Netware 3.11 */
- if ((r1=GetPathFromDirectoryEntry(openfiles[i].name_space,
- openfiles[i].volume_number,
- openfiles[i].directory_entry,path)) == SUCCESS)
- printf(" %s\n",path);
- }
- else
- { /* Must be Netware 2.15 */
- if ((r1=GetPathFromDirectoryEntry(openfiles[i].name_space,
- openfiles[i].volume_number,
- openfiles[i].parent_dir_entry,path)) == SUCCESS)
- printf(" %s/%s\n",path,
- openfiles[i].file_name);
- }
- if (r1 != SUCCESS)
- printf("GetPathFromDirectoryEntry returned: %03d--%#02x\n",
- r1,r1);
- }
- }
-
- if (fcount == 0)
- printf(" ** No Open Files **\n");
- }
- }
-
- void show_usage( void )
- {
- printf("Usage: Flist <options>\n\n");
- printf(" Options:\n");
- printf(" -cn - Show open files for connection number 'n'\n");
- printf(" [ default: all connections ]\n");
- printf(" -uxx - Show open files for all connections logged in");
- printf(" as user xx\n");
- printf(" -? - This screen of information\n");
- printf("\n");
- }
-