Пример #1
0
int main( int argc, char **argv )
{
    char key;

#ifndef __WATCOMC__
    _argc = argc;
    _argv = argv;
#endif

    Initialize();
    OpeningStatement();
    for( ;; ) {
        Output( TRP_MSG_press_q );
        Output( "\r\n" );
        for( ;; ) {
            if( RemoteConnect() ) break;
            NothingToDo();
            if( KeyPress() ) {
                key = KeyGet();
                if( key == 'q' || key == 'Q' ) {
                    KillTrap();
                    RemoteUnLink();
                    SayGNiteGracey( 0 );
                }
            }
        }
        Output( TRP_MSG_session_started );
        Output( "\r\n\r\n" );
        Session();
#ifndef NETWARE
        /* flush keyboard input */
        while( KeyPress() )
            KeyGet();
#endif
        Output( "\r\n\r\n" );
        Output( TRP_MSG_session_ended );
        Output( "\r\n\r\n" );
        RemoteDisco();
        if( OneShot ) {
            KillTrap();
            RemoteUnLink();
            SayGNiteGracey( 0 );
        }
    }
    return( 0 );
}
Пример #2
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char                trpfile[CCHMAXPATH];
    unsigned            len;
    const char          *ptr;
    APIRET              rc;
    char                trpname[CCHMAXPATH] = "";
    char                trppath[CCHMAXPATH] = "";
    trap_init_func      *init_func;

    if( parms == NULL || *parms == '\0' )
        parms = "std";
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr )
        ;
    len = ptr - parms;
    memcpy( trpfile, parms, len );
    trpfile[len] = '\0';

    /* To prevent conflicts with the 16-bit DIP DLLs, the 32-bit versions have the "D32"
     * extension. We will search for them along the PATH (not in LIBPATH);
     */
    strcpy( trpname, trpfile );
    strcat( trpname, ".D32" );
    _searchenv( trpname, "PATH", trppath );
    if( trppath[0] == '\0' ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trpname );
        return( buff );
    }
    rc = DosLoadModule( NULL, 0, trppath, &TrapFile );
    if( rc != 0 ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trppath );
        return( buff );
    }
    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    if( DosQueryProcAddr( TrapFile, 1, NULL, (PFN*)&init_func ) == 0
      && DosQueryProcAddr( TrapFile, 2, NULL, (PFN*)&FiniFunc ) == 0
      && DosQueryProcAddr( TrapFile, 3, NULL, (PFN*)&ReqFunc ) == 0 ) {
        if( DosQueryProcAddr( TrapFile, 4, NULL, (PFN*)&InfoFunc ) != 0 ) {
            InfoFunc = NULL;
        }
        if( DosQueryProcAddr( TrapFile, 5, NULL, (PFN*)&HardFunc ) != 0 ) {
            HardFunc = NULL;
        }
        parms = ptr;
        if( *parms != '\0' )
            ++parms;
        *trap_ver = init_func( parms, buff, trap_ver->remote );
        if( buff[0] == '\0' ) {
            if( TrapVersionOK( *trap_ver ) ) {
                TrapVer = *trap_ver;
                return( NULL );
            }
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        }
    }
    KillTrap();
    return( buff );
}
Пример #3
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    FILE                *fp;
    trap_file_header    __far *head;
    char                filename[256];
    char                *p;
    char                chr;

    if( parms == NULL || *parms == '\0' )
        parms = DEFAULT_TRP_NAME;
    p = filename;
    for( ; (chr = *parms) != '\0'; parms++ ) {
        if( chr == TRAP_PARM_SEPARATOR ) {
            parms++;
            break;
        }
        *p++ = chr;
    }
#ifdef USE_FILENAME_VERSION
    *p++ = ( USE_FILENAME_VERSION / 10 ) + '0';
    *p++ = ( USE_FILENAME_VERSION % 10 ) + '0';
#endif
    *p = '\0';
    fp = DIGLoader( Open )( filename, p - filename, DEFAULT_TRP_EXT, NULL, 0 );
    if( fp == NULL ) {
        sprintf( buff, "%s '%s'", TC_ERR_CANT_LOAD_TRAP, filename );
        return( buff );
    }
    p = ReadInTrap( fp );
    DIGLoader( Close )( fp );
    sprintf( buff, "%s '%s'", TC_ERR_CANT_LOAD_TRAP, filename );
    if( p == NULL ) {
        if( (p = SetTrapHandler()) != NULL || (p = CopyEnv()) != NULL ) {
            strcpy( buff, p );
        } else {
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            head = EXTENDER_RM2PM( TrapMem.rm, 0 );
            if( head->sig == TRAP_SIGNATURE ) {
                PMData->initfunc.s.offset = head->init;
                PMData->reqfunc.s.offset  = head->req;
                PMData->finifunc.s.offset = head->fini;
                PMData->initfunc.s.segment = TrapMem.rm;
                PMData->reqfunc.s.segment  = TrapMem.rm;
                PMData->finifunc.s.segment = TrapMem.rm;
                if( CallTrapInit( parms, buff, trap_ver ) ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = DoTrapAccess;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
                }
            }
        }
    }
    KillTrap();
    return( buff );
}
Пример #4
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    dig_fhandle     filehndl;
    const char      *ptr;
    trap_init_func  *init_func;
#ifdef USE_FILENAME_VERSION
    char            filename[256];
    char            *p;
#endif

    if( parms == NULL || *parms == '\0' )
        parms = "std";
#ifdef USE_FILENAME_VERSION
    for( ptr = parms, p = filename; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        *p++ = *ptr;
    }
    *p++ = ( USE_FILENAME_VERSION / 10 ) + '0';
    *p++ = ( USE_FILENAME_VERSION % 10 ) + '0';
    *p = '\0';
    filehndl = DIGPathOpen( filename, p - filename, "trp", NULL, 0 );
#else
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        ;
    }
    filehndl = DIGPathOpen( parms, ptr - parms, "trp", NULL, 0 );
#endif
    if( filehndl == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
        return( buff );
    }
    parms = ptr;
    ptr = ReadInTrap( DIGGetSystemHandle( filehndl ) );
    DIGPathClose( filehndl );
    if( ptr != NULL ) {
        strcpy( buff, ptr );
    } else {
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        if( TrapCode->signature == TRAP_SIGNATURE ) {
            init_func = MK_FP( FP_SEG( TrapCode ), TrapCode->init_off );
            if( *parms != '\0' )
                ++parms;
            *trap_ver = init_func( parms, buff, trap_ver->remote );
            if( buff[0] == '\0' ) {
                if( TrapVersionOK( *trap_ver ) ) {
                    TrapVer = *trap_ver;
                    FiniFunc = MK_FP( FP_SEG( TrapCode ), TrapCode->fini_off );
                    ReqFunc = MK_FP( FP_SEG( TrapCode ), TrapCode->req_off );
                    return( NULL );
                }
                strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            }
        }
    }
    KillTrap();
    return( buff );
}
Пример #5
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    dig_fhandle         filehndl;
    const char          *ptr;
    const trap_requests *(*ld_func)( const trap_callbacks * );
    char                trap_name[_MAX_PATH];
    const trap_requests *trap_funcs;

    if( parms == NULL || *parms == '\0' )
        parms = "std";
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr )
        ;
#if !defined( BUILTIN_TRAP_FILE )
    filehndl = DIGPathOpen( parms, ptr - parms, "so", trap_name, sizeof( trap_name ) );
    if( filehndl == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
        return( buff );
    }
    TrapFile = dlopen( trap_name, RTLD_NOW );
    DIGPathClose( filehndl );
    if( TrapFile == NULL ) {
        puts( dlerror() );
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trap_name );
        return( buff );
    }
    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    ld_func = dlsym( TrapFile, "TrapLoad" );
    if( ld_func != NULL ) {
#else
    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    ld_func = TrapLoad;
#endif
        trap_funcs = ld_func( &TrapCallbacks );
        if( trap_funcs != NULL ) {
            parms = ptr;
            if( *parms != '\0' )
                ++parms;
            *trap_ver = trap_funcs->init_func( parms, buff, trap_ver->remote );
            FiniFunc = trap_funcs->fini_func;
            if( buff[0] == '\0' ) {
                if( TrapVersionOK( *trap_ver ) ) {
                    TrapVer = *trap_ver;
                    ReqFunc = trap_funcs->req_func;
                    return( NULL );
                }
                strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            }
        }
#if !defined( BUILTIN_TRAP_FILE )
    }
#endif
    KillTrap();
    return( buff );
}
Пример #6
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    char                *err;
    char                *parm;
    char                *end;
    dig_fhandle         dh;
    trap_file_header    __far *head;


    if( trapbuff == NULL ) {
        trapbuff = DEFAULT_TRP_NAME;
    }
    end = strchr( trapbuff, PARM_SEPARATOR );
    if( end == NULL ) {
        end = &trapbuff[strlen( trapbuff )];
        parm = end;
    } else {
        parm = end + 1;
    }
    dh = DIGPathOpen( trapbuff, end - trapbuff, DEFAULT_TRP_EXT, NULL, 0 );
    if( dh == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        return( buff );
    }
    err = ReadInTrap( DIGGetSystemHandle( dh ) );
    DIGPathClose( dh );
    sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
    if( err == NULL ) {
        if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) {
            strcpy( buff, err );
        } else {
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            head = MK_PM( TrapMem.segm.rm, 0 );
            if( head->sig == TRAP_SIGNATURE ) {
                PMData->initfunc.s.offset = head->init;
                PMData->reqfunc.s.offset  = head->req;
                PMData->finifunc.s.offset = head->fini;
                PMData->initfunc.s.segment = TrapMem.segm.rm;
                PMData->reqfunc.s.segment  = TrapMem.segm.rm;
                PMData->finifunc.s.segment = TrapMem.segm.rm;
                if( CallTrapInit( parm, buff, trap_ver ) ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = DoTrapAccess;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
                }
            }
        }
    }
    KillTrap();
    return( buff );
}
Пример #7
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char                *err;
    const char          *end;
    dig_fhandle         dh;
    trap_file_header    __far *head;


    if( parms == NULL || *parms == '\0' ) {
        parms = DEFAULT_TRP_NAME;
    }
    for( end = parms; *end != '\0' && *end != TRAP_PARM_SEPARATOR; ++end )
        ;
    dh = DIGPathOpen( parms, end - parms, DEFAULT_TRP_EXT, NULL, 0 );
    if( dh == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
        return( buff );
    }
    err = ReadInTrap( DIGGetSystemHandle( dh ) );
    DIGPathClose( dh );
    sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
    if( err == NULL ) {
        if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) {
            strcpy( buff, err );
        } else {
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            head = MK_PM( TrapMem.segm.rm, 0 );
            if( head->sig == TRAP_SIGNATURE ) {
                PMData->initfunc.s.offset = head->init;
                PMData->reqfunc.s.offset  = head->req;
                PMData->finifunc.s.offset = head->fini;
                PMData->initfunc.s.segment = TrapMem.segm.rm;
                PMData->reqfunc.s.segment  = TrapMem.segm.rm;
                PMData->finifunc.s.segment = TrapMem.segm.rm;
                parms = end;
                if( *parms != '\0' )
                    ++parms;
                if( CallTrapInit( parms, buff, trap_ver ) ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = DoTrapAccess;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
                }
            }
        }
    }
    KillTrap();
    return( buff );
}
Пример #8
0
void FiniTrap( void )
{
    disconnect_req      in_mx;

    in_mx.req = REQ_DISCONNECT;
    TrapSimpAccess( sizeof( in_mx ), &in_mx, 0, NULL );
    RestoreHandlers();
    KillTrap();
    GrabHandlers();
#if !defined( BUILD_RFX )
    FiniSuppServices();
#endif
#ifdef ENABLE_TRAP_LOGGING
    CloseTrapTraceFile();
#endif
}
Пример #9
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    dig_fhandle         filehndl;
    char                *ptr;
    char                *parm;
    const trap_requests *(*ld_func)( const trap_callbacks * );
    const trap_requests *trap_funcs;

    if( trapbuff == NULL )
        trapbuff = "std";
    for( ptr = trapbuff; *ptr != '\0' && *ptr != ';'; ++ptr )
        ;
    parm = (*ptr != '\0') ? ptr + 1 : ptr;
    filehndl = DIGPathOpen( trapbuff, ptr - trapbuff, "trp", NULL, 0 );
    if( filehndl == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        return( buff );
    }
    TrapCode = ReadInImp( filehndl );
    DIGPathClose( filehndl );
    sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
    if( TrapCode != NULL ) {
#ifdef __WATCOMC__
        if( TrapCode->sig == TRAPSIG ) {
#endif
            strcpy( buff, TC_ERR_BAD_TRAP_FILE );
            ld_func = (void *)TrapCode->init_rtn;
            trap_funcs = ld_func( &TrapCallbacks );
            if( trap_funcs != NULL ) {
                *trap_ver = trap_funcs->init_func( parm, buff, trap_ver->remote );
                FiniFunc = trap_funcs->fini_func;
                if( buff[0] == '\0' ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = trap_funcs->req_func;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_BAD_TRAP_FILE );
                }
            }
#ifdef __WATCOMC__
        }
#endif
        KillTrap();
    }
    return( buff );
}
Пример #10
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    char        *ptr;

    if( trapbuff == NULL ) trapbuff = "std";
    for( ptr = trapbuff; *ptr != '\0' && *ptr != ';'; ++ptr ) ;
    ptr = (*ptr != '\0') ? ptr + 1 : ptr;
    *trap_ver = TrapInit( ptr, buff, trap_ver->remote );
    if( buff[0] != '\0' ) {
        return( buff );
    }
    if( !TrapVersionOK( *trap_ver ) ) {
        KillTrap();
        return( TC_ERR_WRONG_TRAP_VERSION );
    }
    TrapVer = *trap_ver;
    ReqFunc = TrapRequest;
    return( NULL );
}
Пример #11
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    dig_fhandle     filehndl;
    char            *ptr;
    char            *parm;
    trap_init_func  *init_func;

    if( trapbuff == NULL )
        trapbuff = "std";
    for( ptr = trapbuff; *ptr != '\0' && *ptr != ';'; ++ptr )
        ;
    parm = (*ptr != '\0') ? ptr + 1 : ptr;
    filehndl = DIGPathOpen( trapbuff, ptr - trapbuff, "trp", NULL, 0 );
    if( filehndl == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        return( buff );
    }
    ptr = ReadInTrap( DIGGetSystemHandle( filehndl ) );
    DIGPathClose( filehndl );
    if( ptr != NULL ) {
        strcpy( buff, ptr );
    } else {
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        if( TrapCode->signature == TRAP_SIGNATURE ) {
            init_func = MK_FP( FP_SEG( TrapCode ), TrapCode->init_off );
            *trap_ver = init_func( parm, buff, trap_ver->remote );
            if( buff[0] == '\0' ) {
                if( TrapVersionOK( *trap_ver ) ) {
                    TrapVer = *trap_ver;
                    FiniFunc = MK_FP( FP_SEG( TrapCode ), TrapCode->fini_off );
                    ReqFunc = MK_FP( FP_SEG( TrapCode ), TrapCode->req_off );
                    return( NULL );
                }
                strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            }
        }
    }
    KillTrap();
    return( buff );
}
Пример #12
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char    chr;

    if( parms == NULL || *parms == '\0' )
        parms = DEFAULT_TRP_NAME;
    for( ; (chr = *parms) != '\0'; parms++ ) {
        if( chr == TRAP_PARM_SEPARATOR ) {
            parms++;
            break;
        }
    }
    *trap_ver = TrapInit( parms, buff, trap_ver->remote );
    if( buff[0] == '\0' ) {
        if( TrapVersionOK( *trap_ver ) ) {
            TrapVer = *trap_ver;
            ReqFunc = TrapRequest;
            return( NULL );
        }
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    }
    KillTrap();
    return( buff );
}
Пример #13
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char                *err;
    const char          *ptr;
    dig_ldhandle        ldfh;
    trap_file_header    __far *head;
#ifdef USE_FILENAME_VERSION
    char                filename[256];
    char                *p;
#endif

    if( parms == NULL || *parms == '\0' ) {
        parms = DEFAULT_TRP_NAME;
    }
#ifdef USE_FILENAME_VERSION
    for( ptr = parms, p = filename; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        *p++ = *ptr;
    }
    *p++ = ( USE_FILENAME_VERSION / 10 ) + '0';
    *p++ = ( USE_FILENAME_VERSION % 10 ) + '0';
    *p = '\0';
    ldfh = DIGLoader( Open )( filename, p - filename, DEFAULT_TRP_EXT, NULL, 0 );
#else
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        ;
    }
    ldfh = DIGLoader( Open )( parms, ptr - parms, DEFAULT_TRP_EXT, NULL, 0 );
#endif
    if( ldfh == DIGLD_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
        return( buff );
    }
    err = ReadInTrap( ldfh );
    DIGLoader( Close )( ldfh );
    sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
    if( err == NULL ) {
        if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) {
            strcpy( buff, err );
        } else {
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            head = MK_PM( TrapMem.segm.rm, 0 );
            if( head->sig == TRAP_SIGNATURE ) {
                PMData->initfunc.s.offset = head->init;
                PMData->reqfunc.s.offset  = head->req;
                PMData->finifunc.s.offset = head->fini;
                PMData->initfunc.s.segment = TrapMem.segm.rm;
                PMData->reqfunc.s.segment  = TrapMem.segm.rm;
                PMData->finifunc.s.segment = TrapMem.segm.rm;
                parms = ptr;
                if( *parms != '\0' )
                    ++parms;
                if( CallTrapInit( parms, buff, trap_ver ) ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = DoTrapAccess;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
                }
            }
        }
    }
    KillTrap();
    return( buff );
}
Пример #14
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char                trpfile[256];
    char                *p;
    bool                have_ext;
    char                chr;
    trap_init_func      *init_func;

    if( parms == NULL || *parms == '\0' )
        parms = DEFAULT_TRP_NAME;
    have_ext = false;
    p = trpfile;
    for( ; (chr = *parms) != '\0'; parms++ ) {
        if( chr == TRAP_PARM_SEPARATOR ) {
            parms++;
            break;
        }
        switch( chr ) {
        case ':':
        case '/':
        case '\\':
            have_ext = false;
            break;
        case '.':
#ifdef USE_FILENAME_VERSION
            *p++ = ( USE_FILENAME_VERSION / 10 ) + '0';
            *p++ = ( USE_FILENAME_VERSION % 10 ) + '0';
#endif
            have_ext = true;
            break;
        }
        *p++ = chr;
    }
    if( !have_ext ) {
#ifdef USE_FILENAME_VERSION
        *p++ = ( USE_FILENAME_VERSION / 10 ) + '0';
        *p++ = ( USE_FILENAME_VERSION % 10 ) + '0';
#endif
        *p++ = '.';
        *p++ = 'd';
        *p++ = 'l';
        *p++ = 'l';
    }
    *p = '\0';
    TrapFile = LoadLibrary( trpfile );
    if( TrapFile == NULL ) {
        sprintf( buff, "%s '%s'", TC_ERR_CANT_LOAD_TRAP, trpfile );
        return( buff );
    }
    init_func = (trap_init_func *)GetProcAddress( TrapFile, (LPSTR)1 );
    FiniFunc = (trap_fini_func *)GetProcAddress( TrapFile, (LPSTR)2 );
    ReqFunc = (trap_req_func *)GetProcAddress( TrapFile, (LPSTR)3 );
    TRAPENTRY_PTR_NAME( InfoFunction ) = TRAPENTRY_PTR_CAST( InfoFunction )GetProcAddress( TrapFile, (LPSTR)4 );
    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    if( init_func != NULL && FiniFunc != NULL && ReqFunc != NULL
      && TRAPENTRY_PTR_NAME( InfoFunction ) != NULL ) {
        *trap_ver = init_func( parms, buff, trap_ver->remote );
        if( buff[0] == '\0' ) {
            if( TrapVersionOK( *trap_ver ) ) {
                TrapVer = *trap_ver;
                return( NULL );
            }
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        }
    }
    KillTrap();
    return( buff );
}
Пример #15
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char                trpfile[256];
    const char          *ptr;
    char                *dst;
    char                have_ext;
    char                chr;
    trap_init_func      *init_func;

    if( parms == NULL || *parms == '\0' )
        parms = "std";
    have_ext = FALSE;
    dst = trpfile;
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        chr = *ptr;
        switch( chr ) {
        case ':':
        case '/':
        case '\\':
            have_ext = 0;
            break;
        case '.':
            have_ext = 1;
            break;
        }
        *dst++ = chr;
    }
    if( !have_ext ) {
        *dst++ = '.';
        *dst++ = 'd';
        *dst++ = 'l';
        *dst++ = 'l';
    }
    *dst = '\0';
    TrapFile = LoadLibrary( trpfile );
    if( TrapFile == NULL ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trpfile );
        return( buff );
    }
    init_func = (trap_init_func *)GetProcAddress( TrapFile, (LPSTR)1 );
    FiniFunc = (trap_fini_func *)GetProcAddress( TrapFile, (LPSTR)2 );
    ReqFunc = (trap_req_func *)GetProcAddress( TrapFile, (LPSTR)3 );
    InfoFunction = (INFO_FUNC *)GetProcAddress( TrapFile, (LPSTR)4 );
//    LibListFunc = (INFO_FUNC *)GetProcAddress( TrapFile, (LPSTR)5 );
    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    if( init_func != NULL && FiniFunc != NULL && ReqFunc != NULL
            && InfoFunction != NULL /* && LibListFunc != NULL */ ) {
        parms = ptr;
        if( *parms != '\0' )
            ++parms;
        *trap_ver = init_func( parms, buff, trap_ver->remote );
        if( buff[0] == '\0' ) {
            if( TrapVersionOK( *trap_ver ) ) {
                TrapVer = *trap_ver;
                return( NULL );
            }
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        }
    }
    KillTrap();
    return( buff );
}
Пример #16
0
void InitTrap( char *trap_file )
{
    mx_entry            in[1];
    mx_entry            out[2];
    connect_req         in_mx;
    connect_ret         out_mx;
    char                *error;
    trap_version        ver;
    char                buff[ TXT_LEN ];

#ifdef ENABLE_TRAP_LOGGING
    if( TrpDebugFile )
        OpenTrapTraceFile( TrpDebugFile, TrpDebugFileFlush );
#endif

/* Don't use TxtBuff except for error -- it may have a Finger message in it */

#if !defined( BUILD_RFX )
    TrapSetFailCallBack( TrapFailed );
#endif
    InitTrapError = FALSE;
    RestoreHandlers();
    ver.remote = FALSE;
#if !defined( BUILD_RFX )
    if( stricmp( trap_file, "dumb" ) == 0 ) {
        error = LoadDumbTrap( &ver );
    } else {
#endif
        error = LoadTrap( trap_file, buff, &ver );
#if !defined( BUILD_RFX )
    }
#endif
    GrabHandlers();
    if( error != NULL ) {
        strcpy( buff, error );
        InitTrapError = TRUE;
        StartupErr( buff );
    }
    in_mx.req = REQ_CONNECT;
    in_mx.ver.major = TRAP_MAJOR_VERSION;
    in_mx.ver.minor = TRAP_MINOR_VERSION;
    in_mx.ver.remote = FALSE;
    in[0].ptr = &in_mx;
    in[0].len = sizeof( in_mx );
    out[0].ptr = &out_mx;
    out[0].len = sizeof( out_mx );
    buff[0] = '\0';
    out[1].ptr = buff;
    out[1].len = MAX_ERR_MSG_SIZE;
    TrapAccess( 1, in, 2, out );
    MaxPacketLen = out_mx.max_msg_size;
    if( buff[0] != '\0' ) {
        KillTrap();
        InitTrapError = TRUE;
        StartupErr( buff );
    }
#if !defined( BUILD_RFX )
    if( !InitTrapError ) {
        InitSuppServices();
    }
#endif
    if( ver.remote ) {
        _SwitchOn( SW_REMOTE_LINK );
    } else {
        _SwitchOff( SW_REMOTE_LINK );
    }
}
Пример #17
0
static void TrapFailed( void )
{
    KillTrap();
    StartupErr( LIT( ERR_REMOTE_LINK_BROKEN ) );
}
Пример #18
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char                trpfile[256];
    const char          *ptr;
    char                *dst;
    bool                have_ext;
    char                chr;
    UINT                prev;
    trap_init_func      *init_func;

    if( parms == NULL || *parms == '\0' )
        parms = "std";
    have_ext = FALSE;
    dst = trpfile;
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        chr = *ptr;
        switch( chr ) {
        case ':':
        case '/':
        case '\\':
            have_ext = FALSE;
            break;
        case '.':
            have_ext = TRUE;
            break;
        }
        *dst++ = chr;
    }
    if( !have_ext ) {
        *dst++ = '.';
        *dst++ = 'd';
        *dst++ = 'l';
        *dst++ = 'l';
    }
    *dst = '\0';
    /*
     * load toolhelp since windows can't seem to handle having a static
     * reference to a dll inside a dynamically loaded dll
     */
    toolhelp = LoadLibrary( "toolhelp.dll" );
    if( (UINT)toolhelp < 32 ) {
        toolhelp = 0;
    }
    prev = SetErrorMode( SEM_NOOPENFILEERRORBOX );
    TrapFile = LoadLibrary( trpfile );
    SetErrorMode( prev );
    if( (UINT)TrapFile < 32 ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trpfile );
        TrapFile = 0;
        return( buff );
    }
    init_func = (trap_init_func *)GetProcAddress( TrapFile, (LPSTR)2 );
    FiniFunc = (trap_fini_func *)GetProcAddress( TrapFile, (LPSTR)3 );
    ReqFunc  = (trap_req_func *)GetProcAddress( TrapFile, (LPSTR)4 );
    HookFunc = (void(TRAPENTRY*)(LPVOID)) GetProcAddress( TrapFile, (LPSTR)5 );
    InfoFunction = (void(TRAPENTRY*)(HWND)) GetProcAddress( TrapFile, (LPSTR)6 );
    HardModeCheck = (int(TRAPENTRY*)(void)) GetProcAddress( TrapFile, (LPSTR)7 );
    SetHardMode = (void(TRAPENTRY*)(char)) GetProcAddress( TrapFile, (LPSTR)12 );
    UnLockInput = (void(TRAPENTRY*)(void)) GetProcAddress( TrapFile, (LPSTR)13 );
    GetHwndFunc = (int(TRAPENTRY*)(void)) GetProcAddress( TrapFile, (LPSTR)8 );
    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    if( init_func != NULL && FiniFunc != NULL && ReqFunc != NULL
      && HookFunc != NULL && InfoFunction != NULL && HardModeCheck != NULL
      && GetHwndFunc != NULL && SetHardMode != NULL && UnLockInput != NULL ) {
        parms = ptr;
        if( *parms != '\0' )
            ++parms;
        *trap_ver = init_func( parms, buff, trap_ver->remote );
        if( buff[0] == '\0' ) {
            if( TrapVersionOK( *trap_ver ) ) {
                TrapVer = *trap_ver;
                return( NULL );
            }
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        }
    }
    KillTrap();
    return( buff );
}
Пример #19
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    char                *err;
    char                *parm;
    char                *end;
    handle              dh;
    trap_file_header    __far *head;
    char                init_error[256];


    if( trapbuff == NULL ) {
        trapbuff = DEFAULT_TRP_NAME;
    }
    end = strchr( trapbuff, PARM_SEPARATOR );
    if( end == NULL ) {
        end = &trapbuff[ strlen( trapbuff ) ];
        parm = end;
    } else {
        parm = end + 1;
    }
    dh = PathOpen( trapbuff, end - trapbuff, DEFAULT_TRP_EXT );
    if( dh == NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        return( buff );
    }
    err = ReadInTrap( GetSystemHandle( dh ) );
    FileClose( dh );
    if( err != NULL ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        KillTrap();
        return( buff );
    }
    err = SetTrapHandler();
    if( err != NULL ) {
        KillTrap();
        return( err );
    }
    err = CopyEnv();
    if( err != NULL ) {
        KillTrap();
        return( err );
    }
    head = MK_PM( TrapMem.s.rm, 0 );
    if( head->sig != TRAP_SIGNATURE ) {
        KillTrap();
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        return( buff );
    }
    PMData->initfunc.s.offset = head->init;
    PMData->reqfunc.s.offset  = head->req;
    PMData->finifunc.s.offset = head->fini;
    PMData->initfunc.s.segment = TrapMem.s.rm;
    PMData->reqfunc.s.segment  = TrapMem.s.rm;
    PMData->finifunc.s.segment = TrapMem.s.rm;
    if( !CallTrapInit( parm, init_error, trap_ver ) ) {
        KillTrap();
        strcpy( buff, init_error );
        return( buff );
    }
    if( !TrapVersionOK( *trap_ver ) ) {
        KillTrap();
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        return( buff );
    }
    TrapVer = *trap_ver;
    ReqFunc = DoTrapAccess;
    return( NULL );
}