home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0905.lha / MultiUser / C.src / MakeKeyfiles.c < prev    next >
C/C++ Source or Header  |  1993-08-26  |  4KB  |  132 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Make the .MultiUser.keyfiles                                        *
  5. * ---------------------------------------------------------    *
  6. * ⌐ Copyright 1993 by Geert Uytterhoeven                            *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include <dos/dos.h>
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <proto/intuition.h>
  16. #include <libraries/multiuser.h>
  17. #include <stdlib.h>
  18.  
  19. #include "MakeKeyfiles_rev.h"
  20.  
  21.  
  22. char __VersTag__[] = VERSTAG;
  23.  
  24.  
  25. int __saveds Start(char *arg)
  26. {
  27.     struct ExecBase *SysBase;
  28.     struct DosLibrary *DOSBase;
  29.     struct IntuitionBase *IntuitionBase;
  30.     struct RDArgs *args;
  31.     LONG argarray[] = {
  32.         NULL, NULL, NULL
  33.     };
  34.     int rc = RETURN_ERROR;
  35.     int error;
  36.     BPTR passwddirlock, configdirlock, fl, fh;
  37.     struct DevProc *passwddirdp, *configdirdp, *devproc;
  38.     STRPTR *volume;
  39.     char key[64];
  40.     char buffer1[1024];
  41.     char buffer2[1024];
  42.     int i, j;
  43.     BOOL passwddirok = FALSE, configdirok = FALSE, ok = TRUE;
  44.     LONG stream[3];
  45.     ULONG seconds, micros;
  46.  
  47.     SysBase = *(struct ExecBase **)4;
  48.  
  49.     if ((!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) ||
  50.          (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)))) {
  51.         rc = RETURN_FAIL;
  52.         goto Exit;
  53.     }
  54.  
  55.     args = ReadArgs("PASSWDDIR/A,CONFIGDIR/A,VOLUME/A/M", argarray, NULL);
  56.     if (!args)
  57.         PrintFault(IoErr(), NULL);
  58.     else {
  59.         if (passwddirlock = Lock((STRPTR)argarray[0], ACCESS_READ)) {
  60.             if (configdirlock = Lock((STRPTR)argarray[1], ACCESS_READ)) {
  61.                 passwddirdp = GetDeviceProc((STRPTR)argarray[0], NULL);
  62.                 configdirdp = GetDeviceProc((STRPTR)argarray[1], NULL);
  63.                 CurrentTime(&seconds, µs);
  64.                 srand(micros);
  65.                 for (i = 0; i < 64; i++)
  66.                     key[i] = (char)(((ULONG)rand()>>25)+32);
  67.                 stream[0] = (LONG)key;
  68.                 volume = (STRPTR *)argarray[2];
  69.                 for (i = 0; volume[i] && ok; i++) {
  70.                     if (fl = Lock(volume[i], ACCESS_READ)) {
  71.                         devproc = GetDeviceProc(volume[i], NULL);
  72.                         if (passwddirdp->dvp_Port == devproc->dvp_Port) {
  73.                             NameFromLock(passwddirlock, buffer1, 1024);
  74.                             passwddirok = TRUE;
  75.                         } else
  76.                             buffer1[0] = '\0';
  77.                         for (j = 0; buffer1[j] && (buffer1[j] != ':'); j++);
  78.                         stream[1] = (LONG)&buffer1[j];
  79.                         if (configdirdp->dvp_Port == devproc->dvp_Port) {
  80.                             NameFromLock(configdirlock, buffer2, 1024);
  81.                             configdirok = TRUE;
  82.                         } else
  83.                             buffer2[0] = '\0';
  84.                         for (j = 0; buffer2[j] && (buffer2[j] != ':'); j++);
  85.                         stream[2] = (LONG)&buffer2[j];
  86.                         fl = CurrentDir(fl);
  87.                         error = 0;
  88.                         if (fh = Open(muKey_FileName, MODE_NEWFILE)) {
  89.                             if (VFPrintf(fh, "%s\n%s\n%s\n", stream) == -1)
  90.                                 error = IoErr();
  91.                             Close(fh);
  92.                         } else
  93.                             error = IoErr();
  94.                         if (error) {
  95.                             VPrintf("Couldn't create keyfile on volume %s", (LONG *)&volume[i]);
  96.                             PrintFault(error, " ");
  97.                         }
  98.                         UnLock(CurrentDir(fl));
  99.                         FreeDeviceProc(devproc);
  100.                     } else {
  101.                         PrintFault(IoErr(), NULL);
  102.                         ok = FALSE;
  103.                     }
  104.                 }
  105.                 if (ok)
  106.                     if (passwddirok)
  107.                         if (configdirok)
  108.                             rc = RETURN_OK;
  109.                         else
  110.                             PutStr("The configuration directory must be on a"
  111.                                      "partition using the MultiUserFileSystem\n");
  112.                     else
  113.                         PutStr("The password directory must be on a"
  114.                                  "partition using the MultiUserFileSystem\n");
  115.                 FreeDeviceProc(configdirdp);
  116.                 FreeDeviceProc(passwddirdp);
  117.                 UnLock(configdirlock);
  118.             } else
  119.                 PrintFault(IoErr(), NULL);
  120.             UnLock(passwddirlock);
  121.         } else
  122.             PrintFault(IoErr(), NULL);
  123.     }
  124.     FreeArgs(args);
  125.  
  126. Exit:
  127.     CloseLibrary((struct Library *)IntuitionBase);
  128.     CloseLibrary((struct Library *)DOSBase);
  129.  
  130.     return(rc);
  131. }
  132.