home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*/
- /* 3LOG.C - Copyright (c) 3Com Corporation, 1989-1990. All rights reserved.
- By: Michel Degive:CSO:3COM
- This program logs 3+ login user name in a file
- Uses 3+ Developer's Library /*
- /*---------------------------------------------------------------------------*/
-
- #include "stdio.h"
- #include "string.h"
- #include "ctype.h"
- #include "dos.h"
- #include "malloc.h"
- #include "time.h"
- #include "fcntl.h"
- #include "sys\types.h"
- #include "sys\stat.h"
- #include "share.h"
- #include "io.h"
- #include "process.h"
- #include "stdlib.h"
-
- #include "d3l.h"
-
-
- /****************************************************************************/
- void main (argc, argv, envp)
- int argc;
- char *argv[];
- char *envp[];
- /****************************************************************************/
- {
- int i=0, file;
- char legal_name[80],log_file[80],log_action[80],log_program[80];
-
- memset(legal_name,'\0',80);
- memset(log_file,'\0',80);
- memset(log_action,'\0',80);
- memset(log_program,'\0',80);
-
- /* process command line arguments */
- if (argc<3)
- {
- printf ("ERROR: To start 3LOG TYPE:");
- printf ("\n 3LOG ARG1 ARG2 ARG3");
- printf ("\n where ARG1 = ON to register name");
- printf ("\n OFF to un-register name");
- printf ("\n LIST to list log names");
- printf ("\n ARG2 = LogFileName EG: 3LOG.DAT");
- printf ("\n ARG3 = ProgramName(optional) EG: PETS.EXE");
- exit (1);
- }
- strcpy(log_action,argv[1]);
- strcpy(log_file,argv[2]);
- if (argc>3)
- strcpy(log_program,argv[3]);
- else
- log_program[0]='\0';
-
- /* Get legal name */
- if (D3LGetLoginName(legal_name)) /* get Login User Name */
- {
- printf("\n ERROR: Could not get Login User Name, Login first\n");
- exit(1);
- }
-
- for (i=strlen(legal_name);i<40;i++)
- legal_name[i]=' ';
- legal_name[40]='\0';
-
- if(-1==(file=sopen(log_file,O_CREAT|O_RDWR,SH_DENYNO,S_IREAD|S_IWRITE)))
- {
- printf(" ERROR Cannot Open Log file: %d",errno);
- exit(1);
- }
-
- /* Process Log commands */
- if (stricmp(log_action,"OFF")==0)
- log_name_off(file,legal_name);
- if (stricmp(log_action,"ON")==0)
- log_name_on(file,legal_name,log_program);
- if (stricmp(log_action,"LIST")==0)
- log_name_list(file);
-
-
- close(file);
- exit(0);
-
- } /* end of main */
-
- /***************************************************************************/
- log_name_on(file,name,prog) /* Add name to log file */
- int file;
- char name[];
- char prog[];
- /***************************************************************************/
- {
- char buffer[100],lname[60],ltime[30];
- long rec=0L;
- time_t dt;
- memset(buffer,'\0',100);
- memset(lname,'\0',60);
- memset(ltime,'\0',30);
-
- time(&dt);
- strcpy(ltime,ctime(&dt));
-
-
- while (!strlen(prog) && !eof(file)) /* Check if name already there */
- {
- read(file, buffer, 72);
- strncpy(lname,buffer,40);
- lname[40]='\0';
- if (stricmp(lname,name)==0)
- return;
- }
- lseek(file,0L,0);
- while (!eof(file)) /* position to blank record or eof if no blank record */
- {
- read(file, buffer, 72);
- if (buffer[0]==' ')
- {
- rec=tell(file)-72L;
- break;
- }
- else
- rec=tell(file);
- }
-
- lseek(file,rec,0);
- sprintf(buffer,"%-40.40s%-12.12s%-20.20s",name,prog,ltime+4);
- write(file, buffer,72);
- }
- /* end of log_name_on */
-
- /***************************************************************************/
- log_name_off(file,name) /* remove name from log file */
- int file;
- char name[];
- /***************************************************************************/
- {
- char buffer[100],temp[72],lname[60];
- long rec=0L;
-
- memset(buffer,'\0',100);
- memset(lname,'\0',60);
- memset(temp,' ',72);
- temp[91]='\0';
-
- while (!eof(file))
- {
- rec=tell(file);
- read(file, buffer, 72);
- strncpy(lname,buffer,40);
- lname[40]='\0';
- if (stricmp(lname,name)==0)
- {
- lseek(file,rec,0);
- write(file, temp, 72);
- return;
- }
- }
-
- } /* end of log_name_off */
-
-
- /***************************************************************************/
- log_name_list(file) /* List names in Log file */
- int file;
- /***************************************************************************/
- {
- char buffer[100];
-
- memset(buffer,'\0',100);
- printf("\nUser Name Program Date/Time ");
- printf("\n──────────────────────────────────────── ──────────── ────────────────────\n");
- while (!eof(file))
- {
- read(file, buffer, 72);
- if (buffer[0]!=' ')
- printf("%-40.40s %-12.12s %-20.20s\n",
- buffer,buffer+40,buffer+52);
- }
- } /* end of log_name_list */
-