Ejemplo n.º 1
0
rtl_TextEncoding osl_getTextEncodingFromLocale( rtl_Locale * pLocale )
{
    const _pair *language = 0;
    char locale_buf[64] = "";
    char *cp;

    /* default to process locale if pLocale == NULL */
    if( NULL == pLocale )
        osl_getProcessLocale( &pLocale );

    /* convert rtl_Locale to locale string */
    if( _compose_locale( pLocale, locale_buf, 64 ) )
    {
        /* check special handling list (EUC) first */
        language = _pair_search( locale_buf, _full_locale_list, SAL_N_ELEMENTS( _full_locale_list ) );

        if( NULL == language )
        {
            /*
             *  check if there is a charset qualifier at the end of the given locale string
             *  e.g. de.ISO8859-15 or de.ISO8859-15@euro which strongly indicates what
             *  charset to use
             */
            cp = strrchr( locale_buf, '.' );

            if( NULL != cp )
            {
                language = _pair_search( cp + 1, _locale_extension_list, SAL_N_ELEMENTS( _locale_extension_list ) );
            }
        }

        /* use iso language code to determine the charset */
        if( NULL == language )
        {
            /* iso lang codes have 2 charaters */
            locale_buf[2] = '\0';

            language = _pair_search( locale_buf, _iso_language_list, SAL_N_ELEMENTS( _iso_language_list ) );
        }
    }

    /* a matching item in our list provides a mapping from codeset to
     * rtl-codeset */
    if ( language != NULL )
        return language->value;

    return RTL_TEXTENCODING_DONTKNOW;
}
Ejemplo n.º 2
0
STDMETHODIMP SOComWindowPeer::InterfaceSupportsErrorInfo(REFIID riid)
{
    static const IID* arr[] =
    {
        &IID_ISOComWindowPeer,
    };

    for (int i=0;i<SAL_N_ELEMENTS(arr);i++)
    {
        if (InlineIsEqualGUID(*arr[i],riid))
            return S_OK;
    }
    return S_FALSE;
}
Ejemplo n.º 3
0
void cabLogErr(PERF erf, char * msg)
{
    if (!erf)
    {
        cabLog(CABLOG_ERR, "%s: An unknown problem occurred");
        return;
    }

    if (erf->erfOper >= 0)
    {
        if (erf->erfOper < SAL_N_ELEMENTS(FCI_ERRS))
            cabLog(CABLOG_ERR, "%s: %s", msg, FCI_ERRS[erf->erfOper]);
        else
            cabLog(CABLOG_ERR, "%s: Unknown error", msg);
    }
}
Ejemplo n.º 4
0
rtl_TextEncoding osl_getTextEncodingFromLocale( rtl_Locale * pLocale )
{
    const _pair *language=0;

    char  locale_buf[64] = "";
    char  codeset_buf[64];

    char *ctype_locale = 0;
    char *codeset      = 0;

    /* default to process locale if pLocale == NULL */
    if( NULL == pLocale )
        osl_getProcessLocale( &pLocale );

    /* convert rtl_Locale to locale string */
    _compose_locale( pLocale, locale_buf, 64 );

    /* basic thread safeness */
    pthread_mutex_lock( &aLocalMutex );

    /* remember the charset as indicated by the LC_CTYPE locale */
    ctype_locale = setlocale( LC_CTYPE, NULL );

    /* set the desired LC_CTYPE locale */
    if( NULL == setlocale( LC_CTYPE, locale_buf ) )
    {
        pthread_mutex_unlock(&aLocalMutex);
        return RTL_TEXTENCODING_DONTKNOW;
    }

    /* get the charset as indicated by the LC_CTYPE locale */
#if defined(NETBSD) && !defined(CODESET)
    codeset = NULL;
#else
    codeset = nl_langinfo( CODESET );
#endif

    if ( codeset != NULL )
    {
        /* get codeset into mt save memory */
        strncpy( codeset_buf, codeset, sizeof(codeset_buf) );
        codeset_buf[sizeof(codeset_buf) - 1] = 0;
        codeset = codeset_buf;
    }

    /* restore the original value of locale */
    if ( ctype_locale != NULL )
        setlocale( LC_CTYPE, ctype_locale );

    pthread_mutex_unlock( &aLocalMutex );

    /* search the codeset in our language list */
    if ( codeset != NULL )
    {
        language = _pair_search (codeset, _nl_language_list, SAL_N_ELEMENTS( _nl_language_list ) );
    }

    OSL_ASSERT( language && ( RTL_TEXTENCODING_DONTKNOW != language->value ) );

    /* a matching item in our list provides a mapping from codeset to
     * rtl-codeset */
    if ( language != NULL )
        return language->value;

    return RTL_TEXTENCODING_DONTKNOW;
}
Ejemplo n.º 5
0
static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder)
{
    sal_Bool bRet = sal_False;
    HINSTANCE hLibrary;
    sal_Char PathA[_MAX_PATH];
    sal_Unicode PathW[_MAX_PATH];

    if ((hLibrary = LoadLibrary("shell32.dll")) != NULL)
    {
        BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
        BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);

        pSHGetSpecialFolderPathA = (BOOL (WINAPI *)(HWND, LPSTR, int, BOOL))GetProcAddress(hLibrary, "SHGetSpecialFolderPathA");
        pSHGetSpecialFolderPathW = (BOOL (WINAPI *)(HWND, LPWSTR, int, BOOL))GetProcAddress(hLibrary, "SHGetSpecialFolderPathW");

        if (pSHGetSpecialFolderPathA)
        {
            if (pSHGetSpecialFolderPathA(GetActiveWindow(), PathA, nFolder, TRUE))
            {
                rtl_string2UString( strPath, PathA, (sal_Int32) strlen(PathA), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS);
                OSL_ASSERT(*strPath != NULL);
                bRet = sal_True;
            }
        }
        else if (pSHGetSpecialFolderPathW)
        {
            if (pSHGetSpecialFolderPathW(GetActiveWindow(), PathW, nFolder, TRUE))
            {
                rtl_uString_newFromStr( strPath, PathW);
                bRet = sal_True;
            }
        }
        else
        {
            HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *) = (HRESULT (WINAPI *)(HWND, int, LPITEMIDLIST *))GetProcAddress(hLibrary, "SHGetSpecialFolderLocation");
            BOOL (WINAPI *pSHGetPathFromIDListA)(LPCITEMIDLIST, LPSTR) = (BOOL (WINAPI *)(LPCITEMIDLIST, LPSTR))GetProcAddress(hLibrary, "SHGetPathFromIDListA");
            BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST, LPWSTR) = (BOOL (WINAPI *)(LPCITEMIDLIST, LPWSTR))GetProcAddress(hLibrary, "SHGetPathFromIDListW");
             HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *) = (HRESULT (WINAPI *)(LPMALLOC *))GetProcAddress(hLibrary, "SHGetMalloc");

            if (pSHGetSpecialFolderLocation && (pSHGetPathFromIDListA || pSHGetPathFromIDListW ) && pSHGetMalloc )
            {
                   LPITEMIDLIST pidl;
                LPMALLOC pMalloc;
                   HRESULT  hr;

                   hr = pSHGetSpecialFolderLocation(GetActiveWindow(), nFolder, &pidl);

                /* Get SHGetSpecialFolderLocation fails if directory does not exists. */
                /* If it fails we try to create the directory and redo the call */
                if (! SUCCEEDED(hr))
                {
                    HKEY hRegKey;

                    if (RegOpenKey(HKEY_CURRENT_USER,
                                   "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
                                   &hRegKey) == ERROR_SUCCESS)
                    {
                        LONG lRet;
                        DWORD lSize = SAL_N_ELEMENTS(PathA);
                        DWORD Type = REG_SZ;

                        switch (nFolder)
                        {
                            case CSIDL_APPDATA:
                                lRet = RegQueryValueEx(hRegKey, "AppData", NULL, &Type, (LPBYTE)PathA, &lSize);
                                  break;

                            case CSIDL_PERSONAL:
                                lRet = RegQueryValueEx(hRegKey, "Personal", NULL, &Type, (LPBYTE)PathA, &lSize);
                                break;

                            default:
                                lRet = -1l;
                        }

                        if ((lRet == ERROR_SUCCESS) && (Type == REG_SZ))
                        {
                            if (_access(PathA, 0) < 0)
                                CreateDirectory(PathA, NULL);

                               hr = pSHGetSpecialFolderLocation(GetActiveWindow(), nFolder, &pidl);
                        }

                        RegCloseKey(hRegKey);
                    }
                }

                if (SUCCEEDED(hr))
                {
                    if (pSHGetPathFromIDListW && pSHGetPathFromIDListW(pidl, PathW))
                       {
                        /* if directory does not exist, create it */
                        if (_waccess(PathW, 0) < 0)
                            CreateDirectoryW(PathW, NULL);

                        rtl_uString_newFromStr( strPath, PathW);
                        bRet = sal_True;
                       }
                    else if (pSHGetPathFromIDListA && pSHGetPathFromIDListA(pidl, PathA))
                    {
                        /* if directory does not exist, create it */
                        if (_access(PathA, 0) < 0)
                            CreateDirectoryA(PathA, NULL);

                        rtl_string2UString( strPath, PathA, (sal_Int32) strlen(PathA), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS);
                        OSL_ASSERT(*strPath != NULL);
                        bRet = sal_True;
                    }
                   }

                   if (SUCCEEDED(pSHGetMalloc(&pMalloc)))
                {
                       pMalloc->lpVtbl->Free(pMalloc, pidl);
                    pMalloc->lpVtbl->Release(pMalloc);
                }
            }
        }
    }

    FreeLibrary(hLibrary);

    return bRet;
}
Ejemplo n.º 6
0
Archivo: start.c Proyecto: TrTLE/core
SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv )
{
    sal_Bool bSentArgs = sal_False;
    const char* pUsePlugin;
    rtl_uString *pPipePath = NULL;
    Args *args;
    int status = 0;
    struct splash* splash = NULL;
    struct sigaction sigpipe_action;
    struct sigaction sigterm_action;

    /* turn SIGPIPE into an error */
    memset(&sigpipe_action, 0, sizeof(struct sigaction));
    sigpipe_action.sa_handler = SIG_IGN;
    sigemptyset(&sigpipe_action.sa_mask);
    sigaction(SIGPIPE, &sigpipe_action, NULL);
    memset(&sigterm_action, 0, sizeof(struct sigaction));
    sigterm_action.sa_handler = &sigterm_handler;
    sigemptyset(&sigterm_action.sa_mask);
    sigaction(SIGTERM, &sigterm_action, NULL);

    args = args_parse ();
    args->pAppPath = get_app_path( argv[0] );
    if ( !args->pAppPath )
    {
        fprintf( stderr, "ERROR: Can't read app link\n" );
        exit( 1 );
    }

#ifndef ENABLE_QUICKSTART_LIBPNG
    /* we can't load and render it anyway */
    args->bInhibitSplash = sal_True;
#endif

    pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" );
    if ( pUsePlugin && !strcmp(pUsePlugin, "svp") )
        args->bInhibitSplash = sal_True;

    if ( !args->bInhibitPipe && getenv("LIBO_XDGAPP") == NULL )
    {
        int fd = 0;
        pPipePath = get_pipe_path( args->pAppPath );

        if ( ( fd = connect_pipe( pPipePath ) ) >= 0 )
        {
            // Wait for answer
            char resp[ strlen( "InternalIPC::SendArguments" ) + 1];
            ssize_t n = read( fd, resp, SAL_N_ELEMENTS( resp ) );
            if (n == (ssize_t) SAL_N_ELEMENTS( resp )
                && (memcmp(
                resp, "InternalIPC::SendArguments",
                SAL_N_ELEMENTS( resp ) - 1) == 0)) {
                rtl_uString *pCwdPath = NULL;
                osl_getProcessWorkingDir( &pCwdPath );

                // Then send args
                bSentArgs = send_args( fd, pCwdPath );
           }

            close( fd );
        }
    }

    if ( !bSentArgs )
    {
        /* we have to prepare for, and exec the binary */
        int nPercent = 0;
        ChildInfo *info;
        sal_Bool bAllArgs = sal_True;
        sal_Bool bShortWait, bRestart;

        /* sanity check pieces */
        system_checks();

        /* load splash image and create window */
        if ( !args->bInhibitSplash )
        {
            splash = splash_create(args->pAppPath, argc, argv);
        }

        /* pagein */
        if (!args->bInhibitPagein)
            exec_pagein (args);

        /* javaldx */
#if HAVE_FEATURE_JAVA
        if (!args->bInhibitJavaLdx)
            exec_javaldx (args);
#endif

        do
        {
            bRestart = sal_False;

            /* fast updates if we have somewhere to update it to */
            bShortWait = splash ? sal_True : sal_False;

            /* Periodically update the splash & the percent according
               to what status_fd says, poll quickly only while starting */
            info = child_spawn (args, bAllArgs, bShortWait);
            g_pProcess = info->child;
            while (!child_exited_wait (info, bShortWait))
            {
                ProgressStatus eResult;

                splash_draw_progress( splash, nPercent );
                eResult = read_percent( info, &nPercent );
                if (eResult != ProgressContinue)
                {
                    splash_destroy(splash);
                    splash = NULL;
                    bShortWait = sal_False;
                }

            }


            status = child_get_exit_code(info);
            g_pProcess = NULL; // reset
            switch (status) {
            case EXITHELPER_CRASH_WITH_RESTART: // re-start with just -env: parameters
                bRestart = sal_True;
                bAllArgs = sal_False;
                break;
            case EXITHELPER_NORMAL_RESTART: // re-start with all arguments
                bRestart = sal_True;
                bAllArgs = sal_True;
                break;
            default:
                break;
            }

            child_info_destroy (info);
        } while (bRestart);
    }

    /* cleanup */
    if ( pPipePath )
        rtl_uString_release( pPipePath );
    args_free (args);

    return status;
}
Ejemplo n.º 7
0
Archivo: start.c Proyecto: TrTLE/core
static void
exec_javaldx (Args *args)
{
    char newpath[4096];
    sal_uInt32 nArgs;
    rtl_uString *pApp;
    rtl_uString **ppArgs;
    rtl_uString *pTmp, *pTmp2;

    oslProcess javaldx = NULL;
    oslFileHandle fileOut= NULL;
    oslProcessError err;

    ppArgs = (rtl_uString **)calloc( args->nArgsEnv + 2, sizeof( rtl_uString* ) );

    for ( nArgs = 0; nArgs < args->nArgsEnv; ++nArgs )
        ppArgs[nArgs] = args->ppArgs[nArgs];

    /* Use absolute path to redirectrc */
    pTmp = NULL;
    rtl_uString_newFromAscii( &pTmp, "-env:INIFILENAME=vnd.sun.star.pathname:" );
    rtl_uString_newConcat( &pTmp, pTmp, args->pAppPath );
    pTmp2 = NULL;
    rtl_uString_newFromAscii( &pTmp2, "redirectrc" );
    rtl_uString_newConcat( &pTmp, pTmp, pTmp2 );
    ppArgs[nArgs] = pTmp;
    rtl_uString_release (pTmp2);
    nArgs++;

    /* And also to javaldx */
    pApp = NULL;
    rtl_uString_newFromAscii( &pApp, "file://" );
    rtl_uString_newConcat( &pApp, pApp, args->pAppPath );
    pTmp = NULL;
    rtl_uString_newFromAscii( &pTmp, "javaldx" );
    rtl_uString_newConcat( &pApp, pApp, pTmp );
    rtl_uString_release( pTmp );

    err = osl_executeProcess_WithRedirectedIO( pApp, ppArgs, nArgs,
                                               osl_Process_NORMAL,
                                               NULL, // security
                                               NULL, // work dir
                                               NULL, 0,
                                               &javaldx, // process handle
                                               NULL,
                                               &fileOut,
                                               NULL);

    rtl_uString_release( ppArgs[nArgs-1] );
    rtl_uString_release( pApp );
    free( ppArgs );

    if( err != osl_Process_E_None)
    {
        fprintf (stderr, "Warning: failed to launch javaldx - java may not function correctly\n");
        if (javaldx)
            osl_freeProcessHandle(javaldx);
        if (fileOut)
            osl_closeFile(fileOut);
        return;
    } else {
        char *chomp;
        sal_uInt64 bytes_read;

        /* Magically osl_readLine doesn't work with pipes with E_SPIPE - so be this lame instead: */
        while (osl_readFile (fileOut, newpath, SAL_N_ELEMENTS (newpath), &bytes_read) == osl_File_E_INTR);

        if (bytes_read <= 0) {
            fprintf (stderr, "Warning: failed to read path from javaldx\n");
            if (javaldx)
                osl_freeProcessHandle(javaldx);
            if (fileOut)
                osl_closeFile(fileOut);
            return;
        }
        newpath[bytes_read] = '\0';

        if ((chomp = strstr (newpath, "\n")))
            *chomp = '\0';
    }

    extend_library_path (newpath);

    if (javaldx)
        osl_freeProcessHandle(javaldx);
    if (fileOut)
        osl_closeFile(fileOut);
}
Ejemplo n.º 8
0
Archivo: start.c Proyecto: TrTLE/core
/* Send args to the OOo instance (using the 'fd' file descriptor) */
static sal_Bool
send_args( int fd, rtl_uString *pCwdPath )
{
    rtl_uString *pBuffer = NULL, *pTmp = NULL;
    sal_Int32 nCapacity = 1000;
    rtl_String *pOut = NULL;
    sal_Bool bResult;
    size_t nLen;
    rtl_uString *pEscapedCwdPath = escape_path( pCwdPath );
    sal_uInt32 nArg = 0;
    sal_uInt32 nArgCount = rtl_getAppCommandArgCount();

    rtl_uString_new_WithLength( &pBuffer, nCapacity );
    rtl_uString_new( &pTmp );

    rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
            rtl_uString_getLength( pBuffer ),
            RTL_CONSTASCII_STRINGPARAM( "InternalIPC::Arguments" ) );

    if ( rtl_uString_getLength( pEscapedCwdPath ) )
    {
        rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
            rtl_uString_getLength( pBuffer ),
            RTL_CONSTASCII_STRINGPARAM( "1" ) );
        rtl_uStringbuffer_insert( &pBuffer, &nCapacity,
                    rtl_uString_getLength( pBuffer ),
                    rtl_uString_getStr( pEscapedCwdPath ),
                    rtl_uString_getLength( pEscapedCwdPath ) );
    }
    else
    {
        rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
            rtl_uString_getLength( pBuffer ),
            RTL_CONSTASCII_STRINGPARAM( "0" ) );
    }

    for ( nArg = 0; nArg < nArgCount; ++nArg )
    {
        rtl_uString *pEscapedTmp = NULL;
        rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
                rtl_uString_getLength( pBuffer ),
                ",", 1 );

        rtl_getAppCommandArg( nArg, &pTmp );

        pEscapedTmp = escape_path( pTmp );

        rtl_uStringbuffer_insert( &pBuffer, &nCapacity,
                rtl_uString_getLength( pBuffer ),
                rtl_uString_getStr( pEscapedTmp ),
                rtl_uString_getLength( pEscapedTmp ) );

        rtl_uString_release( pEscapedTmp );
    }

    if ( !rtl_convertUStringToString(
             &pOut, rtl_uString_getStr( pBuffer ),
             rtl_uString_getLength( pBuffer ), RTL_TEXTENCODING_UTF8,
             ( RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
               | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR ) ) )
    {
        fprintf( stderr, "ERROR: cannot convert arguments to UTF-8\n" );
        exit( 1 );
    }

    nLen = rtl_string_getLength( pOut ) + 1;
    bResult = ( write( fd, rtl_string_getStr( pOut ), nLen ) == (ssize_t) nLen );

    if ( bResult )
    {
        char resp[ strlen( "InternalIPC::ProcessingDone" ) ];
        ssize_t n = read( fd, resp, SAL_N_ELEMENTS( resp ) );
        bResult = n == (ssize_t) SAL_N_ELEMENTS( resp )
            && (memcmp(
                    resp, "InternalIPC::ProcessingDone",
                    SAL_N_ELEMENTS( resp ) )
                == 0);
    }

    /* cleanup */
    rtl_uString_release( pEscapedCwdPath );
    rtl_uString_release( pBuffer );
    rtl_uString_release( pTmp );
    rtl_string_release( pOut );

    return bResult;
}
Ejemplo n.º 9
0
int SAL_CALL main (void)
{
    rtlCipher cipher;

    /* ECB */
    cipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
    OSL_ASSERT(cipher != 0);
    if (cipher != 0)
    {
        rtlCipherError result;
        sal_uInt8      ecb_in[40], ecb_out[40];
        sal_uInt32     length = strlen(cbc_data) + 1;

        result = rtl_cipher_init (
            cipher, rtl_Cipher_DirectionBoth,
            cbc_key, sizeof(cbc_key), NULL, 0);
        OSL_ASSERT(result == rtl_Cipher_E_None);

        memset (ecb_out, 0, sizeof(ecb_out));
        result = rtl_cipher_encode (
            cipher, cbc_data, length, ecb_out, sizeof(ecb_out));
        OSL_ASSERT(result == rtl_Cipher_E_None);
        OSL_ASSERT(memcmp (ecb_out, ecb_ok, sizeof(ecb_ok)) == 0);

        memset (ecb_in,  0, sizeof(ecb_in));
        result = rtl_cipher_decode (
            cipher, ecb_out, length, ecb_in, sizeof(ecb_in));
        OSL_ASSERT(result == rtl_Cipher_E_None);
        OSL_ASSERT(memcmp (ecb_in, cbc_data, length) == 0);

        rtl_cipher_destroy (cipher);
    }

    /* CBC */
    cipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
    OSL_ASSERT(cipher != 0);
    if (cipher != 0)
    {
        rtlCipherError result;
        sal_uInt8      cbc_in[40], cbc_out[40];
        sal_uInt32     length = strlen(cbc_data) + 1;

        result = rtl_cipher_init (
            cipher, rtl_Cipher_DirectionEncode,
            cbc_key, sizeof(cbc_key), cbc_iv, sizeof(cbc_iv));
        OSL_ASSERT(result == rtl_Cipher_E_None);

        memset (cbc_out, 0, sizeof(cbc_out));
        result = rtl_cipher_encode (
            cipher, cbc_data, length, cbc_out, sizeof(cbc_out));
        OSL_ASSERT(result == rtl_Cipher_E_None);
        OSL_ASSERT(memcmp (cbc_out, cbc_ok, sizeof(cbc_ok)) == 0);

        result = rtl_cipher_init (
            cipher, rtl_Cipher_DirectionDecode,
            cbc_key, sizeof(cbc_key), cbc_iv, sizeof(cbc_iv));
        OSL_ASSERT(result == rtl_Cipher_E_None);

        memset (cbc_in,  0, sizeof(cbc_in));
        result = rtl_cipher_decode (
            cipher, cbc_out, length, cbc_in, sizeof(cbc_in));
        OSL_ASSERT(result == rtl_Cipher_E_None);
        OSL_ASSERT(memcmp (cbc_in, cbc_data, length) == 0);

        rtl_cipher_destroy (cipher);
     }

    /* CFB */
    cipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
    OSL_ASSERT(cipher != 0);
    if (cipher != 0)
    {
        rtlCipherError result;
        sal_uInt8      cfb_in[40], cfb_out[40];
        sal_uInt32     length = strlen(cbc_data) + 1;

        result = rtl_cipher_init (
            cipher, rtl_Cipher_DirectionEncode,
            cbc_key, sizeof(cbc_key), cbc_iv, sizeof(cbc_iv));
        OSL_ASSERT(result == rtl_Cipher_E_None);

        memset (cfb_out, 0, sizeof(cfb_out));
        result = rtl_cipher_encode (
            cipher, cbc_data, length, cfb_out, sizeof(cfb_out));
        OSL_ASSERT(result == rtl_Cipher_E_None);
        OSL_ASSERT(memcmp (cfb_out, cfb_ok, sizeof(cfb_ok)) == 0);

        result = rtl_cipher_init (
            cipher, rtl_Cipher_DirectionDecode,
            cbc_key, sizeof(cbc_key), cbc_iv, sizeof(cbc_iv));
        OSL_ASSERT(result == rtl_Cipher_E_None);

        memset (cfb_in,  0, sizeof(cfb_in));
        result = rtl_cipher_decode (
            cipher, cfb_out, length, cfb_in, sizeof(cfb_in));
        OSL_ASSERT(result == rtl_Cipher_E_None);
        OSL_ASSERT(memcmp (cfb_in, cbc_data, length) == 0);

        rtl_cipher_destroy (cipher);
    }

    /* ARCFOUR */
    cipher = rtl_cipher_create (rtl_Cipher_AlgorithmARCFOUR, rtl_Cipher_ModeStream);
    OSL_ASSERT(cipher != 0);
    if (cipher != 0)
    {
        rtlCipherError result;
        sal_uInt8      arcfour_out[40];
        sal_Size       length;
        int            i, n;

        n = SAL_N_ELEMENTS(arcfour_data_len);
        for (i = 0; i < n; i++)
        {
            length = arcfour_data_len[i];

            result = rtl_cipher_init (
                cipher, rtl_Cipher_DirectionBoth,
                &(arcfour_key[i][1]), arcfour_key[i][0], 0, 0);
            OSL_ASSERT(result == rtl_Cipher_E_None);

            memset (arcfour_out, 0, sizeof(arcfour_out));
            result = rtl_cipher_encode (
                cipher, &(arcfour_data[i][0]), length,
                arcfour_out, sizeof(arcfour_out));
            OSL_ASSERT(result == rtl_Cipher_E_None);
            OSL_ASSERT(memcmp (arcfour_out, arcfour_ok[i], length) == 0);
        }

        n = arcfour_data_len[3];
        for (i = 1; i < n; i++)
        {
            length = i;

            result = rtl_cipher_init (
                cipher, rtl_Cipher_DirectionBoth,
                &(arcfour_key[3][1]), arcfour_key[3][0], 0, 0);
            OSL_ASSERT(result == rtl_Cipher_E_None);

            memset (arcfour_out, 0, sizeof(arcfour_out));
            result = rtl_cipher_encode (
                cipher, &(arcfour_data[3][0]), length,
                arcfour_out, sizeof(arcfour_out));
            OSL_ASSERT(result == rtl_Cipher_E_None);
            OSL_ASSERT(memcmp (arcfour_out, arcfour_ok[3], length) == 0);
            OSL_ASSERT(arcfour_out[length] == 0);
        }

        n = arcfour_data_len[3];
        for (i = 1; i < n; i++)
        {
            length = i;

            result = rtl_cipher_init (
                cipher, rtl_Cipher_DirectionBoth,
                &(arcfour_key[3][1]), arcfour_key[3][0], 0, 0);
            OSL_ASSERT(result == rtl_Cipher_E_None);

            memset (arcfour_out, 0, sizeof(arcfour_out));
            result = rtl_cipher_encode (
                cipher, &(arcfour_data[3][0]), length,
                &(arcfour_out[0]), sizeof(arcfour_out));
            OSL_ASSERT(result == rtl_Cipher_E_None);

            result = rtl_cipher_encode (
                cipher, &(arcfour_data[3][length]), n - length,
                &(arcfour_out[length]), sizeof(arcfour_out) - length);
            OSL_ASSERT(result == rtl_Cipher_E_None);

            OSL_ASSERT(memcmp (arcfour_out, arcfour_ok[3], length) == 0);
        }

        rtl_cipher_destroy (cipher);
    }

    /* Done */
    return 0;
}
Ejemplo n.º 10
0
    rtl_uString_release( ustrTempPath );

    return error;
}

/******************************************************************
 * Generates a random unique file name. We're using the scheme
 * from the standard c-lib function mkstemp to generate a more
 * or less random unique file name
 *
 * @param rand_name
 *        receives the random name
 ******************************************************************/

static const char LETTERS[]        = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
static const int  COUNT_OF_LETTERS = SAL_N_ELEMENTS(LETTERS) - 1;

#define RAND_NAME_LENGTH 6

static void osl_gen_random_name_impl_(rtl_uString** rand_name)
{
    static uint64_t value;

    char     buffer[RAND_NAME_LENGTH];
    struct   timeval tv;
    uint64_t v;
    int      i;

    gettimeofday(&tv, NULL);

    value += ((uint64_t)tv.tv_usec << 16) ^ tv.tv_sec ^ getpid();
Ejemplo n.º 11
0
Archivo: msidb.c Proyecto: NadithM/core
/***********************************************************************
 * msidbExportTables
 *
 * Takes a list of tables or '*' (for all) to export to text archive
 * files in specified folder
 *
 * For each table, a file called <tablename>.idt is exported containing
 * tab separated ASCII.
 *
 * Examples (note wildcard escape for *nix/bash):
 * msidb -d <pathtomsi>.msi -f <workdir> -e \*
 * msidb -d <pathtomsi>.msi -f <workdir> -e File Directory Binary
 **********************************************************************/
static BOOL msidbExportTables(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR tables[])
{
    static const WCHAR ext[] = {'.', 'i', 'd', 't', 0};
    static const WCHAR all[] = {'*', 0};
    UINT r, len;
    MSIHANDLE dbhandle, tableListView, rec;
    LPWSTR tableFile = 0;
    WCHAR tableName[MAX_TABLE_NAME];
    DWORD size = SAL_N_ELEMENTS(tableName);
    int i = 0;

    r = MsiOpenDatabaseW(dbfile, (LPCWSTR) MSIDBOPEN_READONLY, &dbhandle);

    if (r != ERROR_SUCCESS) return FALSE;

    if (strcmpW(tables[0], all) == 0)
    {
        r = MsiDatabaseOpenView(dbhandle, "SELECT Name FROM _Tables", &tableListView);
        r = MsiViewExecute(tableListView, 0);
        r = MsiViewFetch(tableListView, &rec);

        while (r == ERROR_SUCCESS)
        {
            size = SAL_N_ELEMENTS(tableName);
            r = MsiRecordGetStringW(rec, 1, tableName, &size);
            if (r == ERROR_SUCCESS)
            {
                len = lstrlenW(tableName) + 5;
                tableFile = malloc(len * sizeof (WCHAR));
                if (tableFile == NULL) return FALSE;

                lstrcpyW(tableFile, tableName);
                lstrcatW(tableFile, ext);

                r = MsiDatabaseExportW(dbhandle, tableName, wdir, tableFile);

                free(tableFile);
                MsiCloseHandle(rec);
            }

            r = MsiViewFetch(tableListView, &rec);
        }

        MsiViewClose(tableListView);
        MsiCloseHandle(tableListView);
    }
    else
    {
        for (i = 0; i < MAX_TABLES && tables[i] != 0; ++i)
        {
            len = lstrlenW(tables[i]) + 5;
            tableFile = malloc(len * sizeof (WCHAR));
            if (tableFile == NULL) return FALSE;

            lstrcpyW(tableFile, tables[i]);
            lstrcatW(tableFile, ext);
            r = MsiDatabaseExportW(dbhandle, tables[i], wdir, tableFile);

            free(tableFile);
        }
    }

    MsiCloseHandle(dbhandle);
    return TRUE;
}