home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / kernex32.zip / mwdd_src.zip / 32bits / ext2-os2 / skeleton / ses / sec32_init_base.c < prev    next >
C/C++ Source or Header  |  1997-03-16  |  8KB  |  223 lines

  1. //
  2. // $Header: d:\\32bits\\ext2-os2\\skeleton\\ses\\rcs\\sec32_init_base.c,v 1.2 1997/03/16 13:13:43 Willm Exp $
  3. //
  4.  
  5. // 32 bits OS/2 device driver and IFS support. Provides 32 bits kernel 
  6. // services (DevHelp) and utility functions to 32 bits OS/2 ring 0 code 
  7. // (device drivers and installable file system drivers).
  8. // Copyright (C) 1995, 1996, 1997  Matthieu WILLM (willm@ibm.net)
  9. //
  10. // This program is free software; you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation; either version 2 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program; if not, write to the Free Software
  22. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. #define INCL_DOSERRORS
  25. #define INCL_NOPMAPI
  26. #include <os2.h>
  27. #include <secure.h>
  28.  
  29. #include <string.h>
  30.  
  31. #include <os2/types.h>
  32. #include <os2/StackToFlat.h>
  33. #include <os2/DevHlp32.h>
  34. #include <os2/reqpkt32.h>
  35. #include <os2/SecHlp.h>
  36.  
  37. #include "sec32.h"
  38.  
  39. extern unsigned short codeend;
  40. extern unsigned short dataend;
  41. extern PTR16          DevHelp2;
  42.  
  43. extern int _System sec32_pre_init_base(PTR16 reqpkt);
  44.  
  45. extern char code32_end;
  46. extern char data32_end;
  47.  
  48. extern void begin_code32(void);
  49. extern int  begin_data32;
  50.  
  51. int LockSegments(void) {
  52.     APIRET rc;
  53.     ULONG  PgCount;
  54.     char   lock[12];
  55.  
  56.     /*
  57.      * Locks DGROUP into physical memory
  58.      */
  59.     if ((rc = DevHlp32_VMLock(
  60.                         VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
  61.                         &begin_data32,
  62.                         (ULONG)(&data32_end) - (ULONG)(&begin_data32),
  63.                         (void *)-1,
  64.                         __StackToFlat(lock),
  65.                         __StackToFlat(&PgCount))) == NO_ERROR) {
  66.         /*
  67.          * Locks CODE32 into physical memory
  68.          */
  69.         if ((rc = DevHlp32_VMLock(
  70.                             VMDHL_LONG | VMDHL_VERIFY,
  71.                             (void *)begin_code32,
  72.                             (ULONG)(&code32_end) - (ULONG)begin_code32,
  73.                             (void *)-1,
  74.                             __StackToFlat(lock),
  75.                             __StackToFlat(&PgCount))) == NO_ERROR) {
  76.             /*
  77.              * Nothing else to do ...
  78.              */
  79.         }
  80.     }
  81.     return rc;
  82. }
  83.  
  84.  
  85. extern char banner[];
  86.  
  87. #pragma pack(1)
  88. struct ddd32_parm_list {
  89.   unsigned short cache_parm_list;        /* addr of InitCache_Parameter List  */
  90.   unsigned short disk_config_table;      /* addr of disk_configuration table  */
  91.   unsigned short init_req_vec_table;     /* addr of IRQ_Vector_Table          */
  92.   unsigned short cmd_line_args;          /* addr of Command Line Args         */
  93.   unsigned short machine_config_table;   /* addr of Machine Config Info       */
  94. };
  95. #pragma pack()
  96.  
  97.  
  98. /*
  99.  * Pointer to kernel _TKSSBase value.
  100.  */
  101. void *TKSSBase;
  102.  
  103. /*
  104.  * mwdd32.sys DevHlp32 entry points
  105.  */
  106. struct DevHelp32 DevHelp32 = {DEVHELP32_MAGIC, DEVHELP32_VERSION, };
  107.  
  108. /*
  109.  * SecHlp kernel entry points
  110.  */
  111. struct SecExp_s SecurityExports = {SEC_EXPORT_MAJOR_VERSION , SEC_EXPORT_MINOR_VERSION , };
  112.  
  113. /*
  114.  * SecHlp sesdd32.sys entry points
  115.  */
  116. struct SecurityHelpers SecHlp = {0, };
  117.  
  118. int sec32_init_base(PTR16 reqpkt) {
  119.     int                 quiet = 0;
  120.     int                 status;
  121.     int                 rc;
  122.     struct reqpkt_init     *request;
  123.     struct ddd32_parm_list *cmd;
  124.     char               *tmp;
  125.     char               *szParm;
  126.     unsigned short      tmpsel;
  127.     PTR16               tmpparm;
  128.  
  129.     /*
  130.      * Initialize request status
  131.      */
  132.     status = 0;
  133.  
  134.     /*
  135.      * We first do preliminaty init code so that DevHelp32 functions and
  136.      * __StackToFlat() can be called.
  137.      */
  138.     if ((rc = sec32_pre_init_base(reqpkt)) == NO_ERROR) {
  139.         /*
  140.          * Now we convert the 16:16 request packet pointer to FLAT
  141.          */
  142.         if ((rc = DevHlp32_VirtToLin(reqpkt, __StackToFlat(&request))) == NO_ERROR) {
  143.             /*
  144.              * Now we convert the 16:16 command line pointer to FLAT
  145.              */
  146.             if ((rc = DevHlp32_VirtToLin(request->u.input.initarg, __StackToFlat(&cmd))) == NO_ERROR) {
  147.         tmpparm.seg = request->u.input.initarg.seg;
  148.         tmpparm.ofs = cmd->cmd_line_args;
  149.                 if ((rc = DevHlp32_VirtToLin(tmpparm, __StackToFlat(&szParm))) == NO_ERROR) {
  150.                     strupr(szParm);
  151.                     for (tmp = strpbrk(szParm, "-/"); tmp; tmp = strpbrk(tmp, "-/")) {
  152.                   tmp ++;
  153.                         //
  154.                         // Quiet initialization.
  155.                         //
  156.                         if (strncmp(tmp, "Q", sizeof("Q") - 1) == 0) {
  157.                             quiet = 1;
  158.                             continue;
  159.                         }
  160.                     }
  161.  
  162.                     if ((rc = LockSegments()) == NO_ERROR) {
  163.                       if ((rc = DevHlp32_Security(DHSEC_SETIMPORT, &SecurityImports)) == NO_ERROR) {
  164. //                             if ((rc = sec32_attach_ses((void *)&SecHlp)) == NO_ERROR) {
  165.                                   if ((rc = DevHlp32_Security(DHSEC_GETEXPORT, &SecurityExports)) == NO_ERROR) {
  166.                             if (!quiet)
  167.                                   DevHlp32_SaveMessage(banner, strlen(banner) + 1);
  168.                                     request->u.output.codeend = codeend;
  169.                                     request->u.output.dataend = dataend;
  170.                                 } else {
  171.                                     /*
  172.                                      * couldn't retrieve security helpers from kernel
  173.                                      */
  174.                                     status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  175.                                 }
  176. //                          } else {
  177.                                 /*
  178.                                  * couldn't retrieve security helpers from sesdd32.sys
  179.                                  */
  180. //                DevHlp32_SaveMessage("SEC32 : failure while attaching to SESDD32.SYS", sizeof("SEC32 : failure while attaching to SESDD32.SYS"));
  181. //                              status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  182. //                          }
  183.                         } else {
  184.                             /*
  185.                              * couldn't import security callbacks
  186.                              */
  187.                             status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  188.                         }
  189.                     } else {
  190.                         /*
  191.                          * couldn't lock 32 bits segments
  192.                          */
  193.                         status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  194.                     }
  195.                 } else {
  196.                     /*
  197.                      * Error while thunking command line pointer
  198.                      */
  199.                     status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  200.                 }
  201.             } else {
  202.                 /*
  203.                  * Error while thunking command line pointer
  204.                  */
  205.                 status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  206.             }
  207.         } else {
  208.             /*
  209.              * Error while thunking reqpkt
  210.              */
  211.             status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  212.         }
  213.     } else {
  214.         status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  215.         /*
  216.          * error in drv32_pre_init
  217.          */
  218.     }
  219.  
  220.     return (status | STDON);
  221. }
  222.  
  223.