Newsgroups: vmsnet.networks.desktop.pathworks
Subject: Pathworks login program
From: "Peter Ruwhof - Leiden Univ." <RUWHOF@RULBUR.LEIDENUNIV.NL>
Date: Tue, 28 Jul 1992 12:19:00 MET

I got several requests for my login program, as well as suggestions to upload
it to a FTP-server. I am not able to do uploads form here, maybe someone on
the list can upload my program.
 
Here is the C source code (written for Borland C) and an example of the
'database' file that is being used: SERVICE.DAT.
 
Peter Ruwhof
 
system/network manager
University Bureau of the Leiden University
Netherlands
internet:     ruwhof@rulbur.leidenuniv.nl
bitnet/earn:  ruwhof@hlerul5b.bitnet
telephone:    +31 71 273122
telefax:      +31 71 273118
mail:         PO Box 9500, 2300 RA Leiden, Netherlands
 
 
 
 
--------------------------- CONNECT.C --------------------------------
 
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <process.h>
#include <string.h>
#include <ctype.h>
 
capture_ctrlbrk (void interrupt (*func) ())
 {
  setvect(0x23,func);
 }
 
void interrupt get_out()
 {
  return;
 }
 
 
main(int argc, char *argv[])
{
 char username[32], service[80], regel[80], drive[6];
 char *password;
 char c;
 int j, i = 1;
 FILE *infofile;
 
 /* disable Ctrl-Break */
 capture_ctrlbrk(get_out);
 
 password = (char *) malloc(32);
 if (password == NULL) {
    printf ("%s: Memory allocation error. Program terminated\n", argv[0]);
    exit (2);
 }
 
 if (argc < 4) {
   printf ("Network connection manager for Pathworks networks.\n");
   printf ("Copyright (C) P. Ruwhof, RUL AZ/AO&S, 1991, 1992\n");
   printf ("\nSupply personal_drive_letter, node and username as\
 arguments.\n");
   printf ("Example: CONNECT m: RULBR1 password\n");
   exit (2);
 }
 strcpy (username, argv[3]);
 
 
 while (i != 0) {
   i = 0;
   cputs("Password: ");
   j = wherex();
   while (((c = getch()) != 13) && (i < 31)) {
     password[i++] = c;
     if (c == '\b') {
       if (wherex() > j) {
         gotoxy (wherex() - 1, wherey());
         putch (' ');
         gotoxy (wherex() - 1, wherey());
         i -= 2;
       }
       else
         i--;
     }
     else
       putch ('*');
   }
   password[i] = '\0';
   cputs("\x0D\n");
 
   /* connect personal drive */
 
   strcpy (drive, argv[1]);
   printf ("\nConnection to drive %s is being made...\n", drive);
   sprintf (service, " \\\\%s\\%s%%%s ", argv[2], username, username);
   i = spawnlp (P_WAIT, "USE.EXE", "USE.EXE",
                drive, service, password, " /NET", NULL);
 
   if (i != 0)
     if (i == 1) {
       printf ("\nWrong Username/Password!\n");
       strset (password, ' ');
       free (password);
       exit (3);
     }
     else {
       printf ("\n%s: Spawn error. Program terminated. Exit code %d.\n",
               argv[0], i);
       strset (password, ' ');
       free (password);
       exit (2);
     }
 }
 printf ("..OK\n");
 
 clrscr();
 
 /* check for new mail, default: do not maintain mail connection */
 
  printf ("\nThe mailbox is being checked...\n");
  i = spawnlp (P_WAIT, "MAILCHK.EXE", "MAILCHK.EXE",
                "/start", argv[2], username, password, NULL);
  if (i > 1) {
     printf ("%s: Spawn error. Program terminated. Exit code %d\n",
             argv[0], i);
     strset (password, ' ');
     free (password);
     exit (2);
  }
  else {
     if (i == 1) {
       printf ("Do you want more information about your new mail? (Y/N)");
       if (toupper(getch()) == 'Y') {
         printf ("\n");
         i = spawnlp (P_WAIT, "MAILCHK.EXE", "MAILCHK.EXE", "/v", NULL);
         if (i > 1) {
           printf ("%s: Spawn error. Program terminated. Exit code %d\n",
                   argv[0], i);
           strset (password, ' ');
           free (password);
           exit (2);
         }
         printf ("\nPress any key to continue.\n");
         getch();
       }
       else
         printf ("\n");
     }
     if (argc != 5) {
       i = spawnlp (P_WAIT, "MAILCHK.EXE", "MAILCHK.EXE",
                    "/stop", NULL);
       if (i != 0) {
          printf ("%s: Spawn error. Program terminated. Exit code %d\n",
                  argv[0], i);
          strset (password, ' ');
          free (password);
          exit (2);
       }
     }
  }
 
 
 
 /* check service.dat for other connections desired */
 
 printf ("\nConnections to other drives are being made...\n");
 
 sprintf (service, "%s\\service.dat", argv[1]);
 if ((infofile = fopen (service,"rt")) == NULL) {
    printf("CONNECT: %s \SERVICE.DAT not found. Only\n", drive);
    printf("         drive %s is connected.\n", drive);
    strset (password, ' ');
    free (password);
    exit (1);
 }
 
 
 // skip first two (comment) lines of service.dat
 fgets (regel, 80, infofile);
 fgets (regel, 80, infofile);
 
 while (fgets (regel, 80, infofile) != NULL) {
    strncpy (drive, regel + 3, 5);
    drive[5] = '\0';
    strcpy (service, regel + 9);
    i = strlen (service);
    service[i - 1] = '\0';
    if (toupper(regel[1]) != 'P')
      if (toupper(regel[0]) == 'N')
        i = spawnlp (P_WAIT, "USE.EXE", "USE.EXE",
                     drive, service, "/NET", "/LOG", NULL);
      else
        i = spawnlp (P_WAIT, "USE.EXE", "USE.EXE",
                     drive, service, "/V", "/LOG", NULL);
    else {
      if (toupper(regel[0]) == 'N') {
        strcat (service, "%");
        strcat (service, username);
        i = spawnlp (P_WAIT, "USE.EXE", "USE.EXE",
                     drive, service, password, "/NET", "/LOG", NULL);
      }
      else
        i = spawnlp (P_WAIT, "USE.EXE", "USE.EXE",
                     drive, service, password, "/V", "/LOG", NULL);
    }
    if (i != 0)
      if (i > 0) {
        printf ("%s: Service %s unknown or not available.\n",
                 argv[0], service);
        printf ("Press any key to continue.\n");
        getch ();
      }
      else {
        printf ("%s: Spawn error. Program terminated. Exit code %d\n",
                argv[0], i);
        strset (password, ' ');
        free (password);
        exit (2);
      }
 }
 
 fclose(infofile);
 strset (password, ' ');
 free (password);
}
 
 
-------------------------------------------------------------------------
 
Attention: service.dat should contain two lines before the first line
with connection information. I use the first line as a 'help'-line, the
second is empty.
Service.dat should be located in the root directory of the user's personal
file-service.
 
 
------------------------- SERVICE.DAT -----------------------------------
N=netwerk, P=password, V=virtual. Driveletter at pos 4, service at pos 10.
 
NP L:    \\RULBR1\SHAREDSERV
N  N:    \\RULBR1\PCCOMMON
N  P:    \\RULBR1\TEST%TEST password
NP LPT1: \\RULBR1\HP_LASER
N  LPT3: \\RULBR1\HP_DESKJET
------------------------------------------------------------------------