home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / dec93 / os20 / util / multiuser.lha / MultiUser / C.src / Passwd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  4.4 KB  |  178 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Change Password                                                            *
  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 <utility/tagitem.h>
  16. #include <proto/reqtools.h>
  17. #include <libraries/reqtools.h>
  18. #include <string.h>
  19. #include <libraries/multiuser.h>
  20. #include <proto/multiuser.h>
  21.  
  22. #include "Passwd_rev.h"
  23.  
  24.  
  25. char __VersTag__[] = VERSTAG;
  26.  
  27.  
  28. static void __regargs myputs(char *str, struct DosLibrary *DOSBase);
  29. static void __regargs mygets(char *str, struct DosLibrary *DOSBase);
  30.  
  31.  
  32. int __saveds Start(char *arg)
  33. {
  34.     struct ExecBase *SysBase;
  35.     struct DosLibrary *DOSBase;
  36.     struct muBase *muBase = NULL;
  37.     struct ReqToolsBase *ReqToolsBase = NULL;
  38.     char oldpwd[muPASSWORDSIZE];
  39.     char newpwd1[muPASSWORDSIZE];
  40.     char newpwd2[muPASSWORDSIZE];
  41.     struct RDArgs *args;
  42.     LONG argarray[] = {
  43.         NULL
  44.     };
  45.     static struct TagItem allwaystags[] = {
  46.         RT_ReqPos, REQPOS_CENTERSCR,
  47.         RT_LockWindow, TRUE,
  48.         TAG_DONE
  49.     };
  50.     struct TagItem infotags[] = {
  51.         RTEZ_Flags, EZREQF_CENTERTEXT,
  52.         TAG_MORE, (LONG)allwaystags
  53.     };
  54.     struct TagItem pwdtags[] = {
  55.         RTGS_TextFmt, NULL,
  56.         RTGS_Invisible, TRUE,
  57.         RTGS_AllowEmpty, TRUE,
  58.         RTGS_Flags, GSREQF_CENTERTEXT,
  59.         RTGS_GadFmt, (LONG)"OK",
  60.         TAG_MORE, (LONG)allwaystags
  61.     };
  62.     int rc = RETURN_ERROR;
  63.  
  64.  
  65.     SysBase = *(struct ExecBase **)4;
  66.     
  67.     if ((!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) ||
  68.          (!(muBase = (struct muBase *)OpenLibrary("multiuser.library", 39))) ||
  69.          (!(ReqToolsBase = (struct ReqToolsBase *)OpenLibrary("reqtools.library", 38)))) {
  70.         rc = RETURN_FAIL;
  71.         goto Exit;
  72.     }
  73.  
  74.     args = ReadArgs("GUI/S", argarray, NULL);
  75.     if (!args)
  76.         PrintFault(IoErr(), NULL);
  77.     else {
  78.         if (argarray[0]) {
  79.             memset(oldpwd, '\0', sizeof(oldpwd));
  80.             memset(newpwd1, '\0', sizeof(newpwd1));
  81.             memset(newpwd2, '\0', sizeof(newpwd2));
  82.             pwdtags[0].ti_Data = (LONG)"Enter your old password";
  83.             rtGetStringA(oldpwd, muPASSWORDSIZE-1, "MultiUser Passwd Request",
  84.                              NULL, pwdtags);
  85.             pwdtags[0].ti_Data = (LONG)"Enter your new password";
  86.             rtGetStringA(newpwd1, muPASSWORDSIZE-1, "MultiUser Passwd Request",
  87.                              NULL, pwdtags);
  88.             pwdtags[0].ti_Data = (LONG)"Retype your new password";
  89.             rtGetStringA(newpwd2, muPASSWORDSIZE-1, "MultiUser Passwd Request",
  90.                              NULL, pwdtags);
  91.         } else {
  92.             myputs("\nOld password        : ", DOSBase);
  93.             mygets(oldpwd, DOSBase);
  94.             myputs("\n\nNew password        : ", DOSBase);
  95.             mygets(newpwd1, DOSBase);
  96.             myputs("\n\nRetype new password : ", DOSBase);
  97.             mygets(newpwd2, DOSBase);
  98.             myputs("\n\n", DOSBase);
  99.         };
  100.  
  101.         if (strcmp(newpwd1, newpwd2))
  102.             if (argarray[0])
  103.                 rtEZRequestA("Error retyping new password", "OK", NULL, NULL, infotags);
  104.             else
  105.                 myputs("Error retyping new password\n", DOSBase);
  106.         else
  107.             if (muPasswd(oldpwd, newpwd1)) {
  108.                 if (argarray[0])
  109.                     rtEZRequestA("Password successfully changed", "OK", NULL, NULL, infotags);
  110.                 else
  111.                     myputs("Password successfully changed\n", DOSBase);
  112.                 rc = RETURN_OK;
  113.             } else
  114.                 if (argarray[0])
  115.                     rtEZRequestA("Changing password failed", "OK", NULL, NULL, infotags);
  116.                 else
  117.                     myputs("Changing password failed\n", DOSBase);
  118.     }
  119.     FreeArgs(args);
  120.  
  121. Exit:
  122.     CloseLibrary((struct Library *)ReqToolsBase);
  123.     CloseLibrary((struct Library *)muBase);
  124.     CloseLibrary((struct Library *)DOSBase);
  125.  
  126.     return(rc);
  127. }    
  128.  
  129.  
  130. static void __regargs myputs(char *str, struct DosLibrary *DOSBase)
  131. {
  132.     Write(Output(), str, strlen(str));
  133. }
  134.  
  135.  
  136. static void __regargs mygets(char *str, struct DosLibrary *DOSBase)
  137. {
  138.     LONG len = 0;
  139.     char buf;
  140.     BOOL done = FALSE;
  141.     BPTR in, out;
  142.  
  143.     in = Input();
  144.     out = Output();
  145.     SetMode(in, 1);
  146.     do {
  147.         Read(in, &buf, 1);
  148.         switch(buf) {
  149.             case    '\b':
  150.                 if (len) {
  151.                     FPutC(out, '\b');
  152.                     Flush(out);
  153.                     len--;
  154.                 }
  155.                 break;
  156.     
  157.             case    '\n':
  158.             case    '\r':
  159.                 done = TRUE;
  160.                 break;
  161.     
  162.             default:
  163.                 if ((len < muPASSWORDSIZE-1) && ((buf & 0x7f) > 31)
  164.                      && (buf != 127)) {
  165.                     FPutC(out, ' ');
  166.                     str[len++] = buf;
  167.                 } else
  168.                     FPutC(out, 7);
  169.                 Flush(out);
  170.                 break;
  171.         }
  172.     } while (!done);
  173.     str[len] = 0;
  174.     SetMode(in, 0);
  175.     FPutC(out, '\r');
  176.     Flush(out);
  177. }
  178.