home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / src / amilock / source / talkto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-03  |  2.4 KB  |  97 lines

  1. #include <stdlib.h>
  2. #include <exec/types.h>
  3. #include <exec/ports.h>
  4. #include <exec/memory.h>
  5. #include <dos/dos.h>
  6. #include <clib/exec_protos.h>
  7. #include <clib/alib_protos.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <intuition/intuition.h>
  11. #include <proto/all.h>
  12. #include <clib/dos_protos.h>
  13.  
  14. #include "headers/talkto_proto.h"
  15. #include "headers/deamon.h"
  16. #include "headers/Error_proto.h"
  17. #include "headers/global.h"
  18.  
  19. BOOL Error(char *);
  20.  
  21. int CXBRK(void) { return(0); }
  22. int chkabort(void) {return(0);}
  23.  
  24. struct CurrentUser    *ID;
  25.  
  26. BOOL SafePutToPort(struct Message *, STRPTR);
  27.  
  28. unsigned long TalkTo(User,Pass,Pass1,contr)
  29. char        *User,*Pass,*Pass1;
  30. unsigned long     contr;
  31. {
  32.        struct MsgPort         *SecReplyPort;
  33.         struct SecMessage     *Secmsg, *reply;
  34.     unsigned long        sys;
  35.  
  36. #if (DEBUG)
  37. fprintf(stderr,"talking to \n");
  38. #endif
  39.     if (!FindPort(DEAMON)) {
  40.         if (!system(BOOTDEAM)) {
  41.             Error("cannot open Deamon");
  42.             exit(1);
  43.         }
  44.     }
  45.         if (SecReplyPort = CreatePort(0,0)) {
  46.             if (Secmsg = (struct SecMessage *) AllocMem(sizeof(struct SecMessage), MEMF_PUBLIC | MEMF_CLEAR)){
  47.                     Secmsg->LoginMsg.mn_Node.ln_Type = NT_MESSAGE;             
  48.                     Secmsg->LoginMsg.mn_Length = sizeof(struct SecMessage);    
  49.                     Secmsg->LoginMsg.mn_ReplyPort = SecReplyPort;
  50.                     strcpy(Secmsg->User,User);
  51.                     strcpy(Secmsg->Password,Pass);
  52.             Secmsg->Control = contr;
  53.  
  54.                     if (SafePutToPort((struct Message *)Secmsg,DEAMON)) {
  55. #if (DEBUG)
  56.     fprintf(stderr,"waiting\n");
  57. #endif
  58.                         WaitPort(SecReplyPort);
  59. #if (DEBUG)
  60.     fprintf(stderr,"got the\n");
  61. #endif
  62.                         if (reply = (struct SecMessage *)GetMsg(SecReplyPort)) {
  63.                     sys = Secmsg->Access;
  64.                 }
  65.                 if (contr == WHOAMI) {
  66.                     ID = Secmsg->UserData;
  67.                 }
  68.                     
  69.                   }
  70.                     else {
  71.                 Error("Can't find 'Secport'");
  72.                         FreeMem(Secmsg, sizeof(struct SecMessage));
  73.                 return FALSE;
  74.             }
  75.             }
  76.             else Error("Couldn't get memory");
  77.             DeletePort(SecReplyPort);
  78.         }
  79.         else Error("Couldn't create SecReplyPort");
  80. #if (DEBUG)
  81. fprintf(stderr,"finished talking\n");
  82. #endif
  83.     if (sys) return OK;
  84.     else return -1;
  85. }
  86.  
  87.  
  88. BOOL SafePutToPort(struct Message *message, STRPTR portname)
  89. {
  90.     struct MsgPort *port;
  91.  
  92.     Forbid();
  93.     port = FindPort(portname);
  94.     if (port) PutMsg(port, message);
  95.     Permit();
  96.     return (BOOL)(port ? TRUE : FALSE);
  97. }