home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / NETWORK / 3LOG.ZIP / 3LOG.C next >
Encoding:
C/C++ Source or Header  |  1990-11-01  |  5.1 KB  |  185 lines

  1. /*---------------------------------------------------------------------------*/
  2. /* 3LOG.C - Copyright (c) 3Com Corporation, 1989-1990.  All rights reserved.
  3.    By:  Michel Degive:CSO:3COM
  4.    This program logs 3+ login user name in a file
  5.    Uses 3+ Developer's Library    /*
  6. /*---------------------------------------------------------------------------*/
  7.  
  8. #include "stdio.h"
  9. #include "string.h"
  10. #include "ctype.h"
  11. #include "dos.h"
  12. #include "malloc.h"
  13. #include "time.h"
  14. #include "fcntl.h"
  15. #include "sys\types.h"
  16. #include "sys\stat.h"
  17. #include "share.h"
  18. #include "io.h"
  19. #include "process.h"
  20. #include "stdlib.h"
  21.  
  22. #include "d3l.h"
  23.  
  24.  
  25. /****************************************************************************/
  26. void main (argc, argv, envp)
  27. int argc;
  28. char *argv[];
  29. char *envp[];
  30. /****************************************************************************/
  31. {
  32. int i=0, file;
  33. char legal_name[80],log_file[80],log_action[80],log_program[80];
  34.  
  35. memset(legal_name,'\0',80);
  36. memset(log_file,'\0',80);
  37. memset(log_action,'\0',80);
  38. memset(log_program,'\0',80);
  39.  
  40. /* process command line arguments */
  41. if (argc<3)
  42.        {
  43.        printf ("ERROR: To start 3LOG TYPE:");
  44.        printf ("\n          3LOG ARG1 ARG2 ARG3");
  45.        printf ("\n            where ARG1 = ON    to register name");
  46.        printf ("\n                         OFF   to un-register name");
  47.        printf ("\n                         LIST  to list log names");
  48.        printf ("\n                  ARG2 = LogFileName   EG: 3LOG.DAT");
  49.        printf ("\n                  ARG3 = ProgramName(optional)  EG: PETS.EXE");
  50.        exit (1);
  51.        }
  52. strcpy(log_action,argv[1]);
  53. strcpy(log_file,argv[2]);
  54. if (argc>3)
  55.        strcpy(log_program,argv[3]);
  56. else
  57.        log_program[0]='\0';
  58.  
  59. /* Get legal name */
  60. if (D3LGetLoginName(legal_name)) /* get Login User Name */
  61.         {
  62.         printf("\n ERROR: Could not get Login User Name, Login first\n");
  63.         exit(1);
  64.         }
  65.  
  66. for (i=strlen(legal_name);i<40;i++)
  67.         legal_name[i]=' ';
  68. legal_name[40]='\0';
  69.  
  70. if(-1==(file=sopen(log_file,O_CREAT|O_RDWR,SH_DENYNO,S_IREAD|S_IWRITE)))
  71.         {
  72.         printf(" ERROR Cannot Open Log file: %d",errno);
  73.         exit(1);
  74.         }
  75.  
  76. /* Process Log commands */
  77. if  (stricmp(log_action,"OFF")==0)
  78.         log_name_off(file,legal_name);
  79. if  (stricmp(log_action,"ON")==0)
  80.         log_name_on(file,legal_name,log_program);
  81. if  (stricmp(log_action,"LIST")==0)
  82.         log_name_list(file);
  83.  
  84.  
  85. close(file);
  86. exit(0);
  87.  
  88. } /* end of main */
  89.  
  90. /***************************************************************************/
  91. log_name_on(file,name,prog)  /* Add name to log file */
  92. int file;
  93. char name[];
  94. char prog[];
  95. /***************************************************************************/
  96. {
  97. char buffer[100],lname[60],ltime[30];
  98. long rec=0L;
  99. time_t dt;
  100. memset(buffer,'\0',100);
  101. memset(lname,'\0',60);
  102. memset(ltime,'\0',30);
  103.  
  104. time(&dt);
  105. strcpy(ltime,ctime(&dt));
  106.  
  107.  
  108. while (!strlen(prog) && !eof(file))   /* Check if name already there */
  109.         {
  110.         read(file, buffer, 72);
  111.         strncpy(lname,buffer,40);
  112.         lname[40]='\0';
  113.         if (stricmp(lname,name)==0)
  114.                 return;
  115.         }
  116. lseek(file,0L,0);
  117. while (!eof(file)) /* position to blank record or eof if no blank record */
  118.         {
  119.         read(file, buffer, 72);
  120.         if (buffer[0]==' ')
  121.                 {
  122.                 rec=tell(file)-72L;
  123.                 break;
  124.                 }
  125.         else
  126.                 rec=tell(file);
  127.         }
  128.  
  129. lseek(file,rec,0);
  130. sprintf(buffer,"%-40.40s%-12.12s%-20.20s",name,prog,ltime+4);
  131. write(file, buffer,72);
  132. }
  133. /* end of log_name_on */
  134.  
  135. /***************************************************************************/
  136. log_name_off(file,name) /* remove name from log file */
  137. int file;
  138. char name[];
  139. /***************************************************************************/
  140. {
  141. char buffer[100],temp[72],lname[60];
  142. long rec=0L;
  143.  
  144. memset(buffer,'\0',100);
  145. memset(lname,'\0',60);
  146. memset(temp,' ',72);
  147. temp[91]='\0';
  148.  
  149. while (!eof(file))
  150.         {
  151.         rec=tell(file);
  152.         read(file, buffer, 72);
  153.         strncpy(lname,buffer,40);
  154.         lname[40]='\0';
  155.         if (stricmp(lname,name)==0)
  156.                 {
  157.                 lseek(file,rec,0);
  158.                 write(file, temp, 72);
  159.                 return;
  160.                 }
  161.         }
  162.  
  163. } /* end of log_name_off */
  164.  
  165.  
  166. /***************************************************************************/
  167. log_name_list(file)    /* List names in Log file */
  168. int file;
  169. /***************************************************************************/
  170. {
  171. char buffer[100];
  172.  
  173. memset(buffer,'\0',100);
  174. printf("\nUser Name                                Program      Date/Time           ");
  175. printf("\n──────────────────────────────────────── ──────────── ────────────────────\n");
  176. while (!eof(file))
  177.         {
  178.         read(file, buffer, 72);
  179.         if (buffer[0]!=' ')
  180.                 printf("%-40.40s %-12.12s %-20.20s\n",
  181.                                 buffer,buffer+40,buffer+52);
  182.         }
  183. } /* end of log_name_list */
  184.  
  185.