BOOL _odbcinst_UserINI( char *pszFileName, BOOL bVerify )
{
    FILE            *hFile;
    char            *szEnv_INIUSER              = getvmsenv("ODBCINI");
    struct passwd   *pPasswd                    = NULL;
    char            *pHomeDir                   = NULL;

    pszFileName[0] = '\0';

    if ( szEnv_INIUSER )
    {
        strncpy( pszFileName, szEnv_INIUSER, ODBC_FILENAME_MAX );
    }
    else
    {
        sprintf( pszFileName, "SYS$LOGIN:ODBC.INI" );
    }

    if ( bVerify )
    {
        hFile = uo_fopen( pszFileName, "r" );
        if ( hFile )
            uo_fclose( hFile );
        else
            return FALSE;
    }

    return TRUE;
}
Exemple #2
0
int logPushMsg( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessage )
{
    HLOGMSG     hMsg;
    FILE        *hFile;

    if ( !hLog ) return LOG_ERROR;
    if ( !hLog->hMessages ) return LOG_ERROR;
    if ( !hLog->bOn ) return LOG_SUCCESS;

    if ( !pszModule ) return LOG_ERROR;
    if ( !pszFunctionName ) return LOG_ERROR;
    if ( !pszMessage ) return LOG_ERROR;


    /* check for, and handle, max msg */
    if ( hLog->nMaxMsgs && hLog->hMessages->nItems >= hLog->nMaxMsgs )
        logPopMsg( hLog );

    hMsg                    = malloc( sizeof(LOGMSG) );
    if (!hMsg) goto error_abort0;

    hMsg->pszModuleName     = (char *)strdup( pszModule );
    if (!hMsg->pszModuleName) goto error_abort1;

    hMsg->pszFunctionName   = (char *)strdup( pszFunctionName );
    if (!hMsg->pszFunctionName) goto error_abort2;

    hMsg->pszMessage        = (char *)strdup( pszMessage );
    if (!hMsg->pszMessage) goto error_abort3;

    hMsg->nLine             = nLine;
    hMsg->nSeverity         = nSeverity;
    hMsg->nCode             = nCode;

    /* append to  list */
    lstAppend( hLog->hMessages, hMsg );

    /* append to file */
    if ( hLog->pszLogFile )
    {
        hFile = uo_fopen( hLog->pszLogFile, "a" );
        if ( !hFile ) return LOG_ERROR;

        uo_fprintf( hFile, "[%s][%s][%s][%d]%s\n", hLog->pszProgramName, pszModule, pszFunctionName, nLine, pszMessage );

        uo_fclose( hFile );
    }

    return LOG_SUCCESS;

    error_abort3:
    free(hMsg->pszFunctionName);
    error_abort2:
    free(hMsg->pszModuleName);
    error_abort1:
    free(hMsg);
    error_abort0:
    return LOG_ERROR;
}
BOOL _odbcinst_UserINI( char *pszFileName, BOOL bVerify )
{
    FILE            *hFile;
    char            *szEnv_INIUSER              = getenv("ODBCINI");
#ifdef HAVE_GETUID
    uid_t           nUserID                     = getuid();
#else
    uid_t           nUserID                     = 0;
#endif
    struct passwd   *pPasswd                    = NULL;
    char            *pHomeDir                   = NULL;

    pHomeDir    = "/home";                              
#ifdef HAVE_GETPWUID
    pPasswd     = (struct passwd *)getpwuid(nUserID);   
#endif

    pszFileName[0] = '\0';

#ifdef HAVE_PWD_H
    if ( pPasswd != NULL )
        if ( ( char *)pPasswd->pw_dir != NULL )
            pHomeDir    = pPasswd->pw_dir;
#else
    pHomeDir = getenv("HOME");
#endif

    if ( szEnv_INIUSER )
    {
        strncpy( pszFileName, szEnv_INIUSER, ODBC_FILENAME_MAX );
    }
    if ( pszFileName[0] == '\0' )
    {
        sprintf( pszFileName, "%s%s", pHomeDir, "/.odbc.ini" );
    }

#ifdef DHAVE_ENDPWENT
    /*
     * close the password file
     */
    endpwent();
#endif

    if ( bVerify )
    {
        /*
         * create it of it doesn't exist
         */

        hFile = uo_fopen( pszFileName, "a" );
        if ( hFile )
            uo_fclose( hFile );
        else
            return FALSE;
    }

    return TRUE;
}
Exemple #4
0
int iniCommit( HINI hIni )
{
    FILE    *hFile;

    /* SANITY CHECK */
    if ( hIni == NULL )
        return INI_ERROR;

    if ( hIni->bReadOnly )
        return INI_ERROR;

    /* OPEN FILE */

#ifdef __OS2__
    if (hIni->iniFileType == 0)
    {
#endif
        hFile = uo_fopen( hIni->szFileName, "w" );
#ifdef __OS2__
    }
    else
    {
        hFile = (FILE *)iniOS2Open (hIni->szFileName);
    }
#endif
    if ( !hFile )
        return INI_ERROR;

	_iniDump( hIni, hFile );

    /* CLEANUP */
    if ( hFile != NULL )
    {
#ifdef __OS2__
        if (hIni->iniFileType == 0)
#endif
		    uo_fclose( hFile );
#ifdef __OS2__
        else
            iniOS2Close( hFile);
#endif
     }

    return INI_SUCCESS;
}
Exemple #5
0
int iniAppend( HINI hIni, char *pszFileName )
{
    FILE    *hFile;
	char    szLine[INI_MAX_LINE+1];
	char	szObjectName[INI_MAX_OBJECT_NAME+1];
	char	szPropertyName[INI_MAX_PROPERTY_NAME+1];
	char	szPropertyValue[INI_MAX_PROPERTY_VALUE+1];

    /* SANITY CHECK */
    if ( strlen( pszFileName ) > ODBC_FILENAME_MAX )
        return INI_ERROR;

    /* OPEN FILE */
    hFile = uo_fopen( pszFileName, "r" );
	if ( !hFile )
		return INI_ERROR;

	iniObjectLast( hIni );
	iniPropertyLast( hIni );

	/* SCAN UNTIL WE GET TO AN OBJECT NAME OR EOF */
	szLine[0] = '\0';
	if ( _iniScanUntilObject( hIni, hFile, szLine ) == INI_SUCCESS )
	{
		do
		{
			if ( szLine[0] == hIni->cLeftBracket )
			{
				_iniObjectRead( hIni, szLine, szObjectName );
				if ( iniObjectSeek( hIni, szObjectName ) == INI_SUCCESS )
				{
					iniObjectLast( hIni );
					iniPropertyLast( hIni );
					if ( _iniScanUntilNextObject( hIni, hFile, szLine ) != INI_SUCCESS)
						break;
				}
				else
				{
					iniObjectInsert( hIni, szObjectName );
					if ( uo_fgets( szLine, INI_MAX_LINE, hFile ) == NULL )
						break;
				}
			}
			else if ( (strchr( hIni->cComment, szLine[0] ) == NULL ) && isalnum(szLine[0]) )
			{
				_iniPropertyRead( hIni, szLine, szPropertyName, szPropertyValue );
				iniPropertyInsert( hIni, szPropertyName, szPropertyValue );
				if ( uo_fgets( szLine, INI_MAX_LINE, hFile ) == NULL )
					break;
			}
			else
			{
				if ( uo_fgets( szLine, INI_MAX_LINE, hFile ) == NULL )
					break;
			}
		} while( 1 );
	}

	/* WE ARE NOT GOING TO TRY TO BE SMART ENOUGH TO SAVE THIS STUFF */
	hIni->bReadOnly			= 1;

    /* CLEANUP */
    if ( hFile != NULL )
		uo_fclose( hFile );

    return INI_SUCCESS;
}
Exemple #6
0
int logvPushMsgf( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessageFormat, va_list args )
{
    HLOGMSG     hMsg=NULL;
    FILE        *hFile;
    int             mlen=0;

    if ( !hLog ) return LOG_ERROR;
    if ( !hLog->hMessages ) return LOG_ERROR;
    if ( !hLog->bOn ) return LOG_SUCCESS;

    if ( !pszModule ) return LOG_ERROR;
    if ( !pszFunctionName ) return LOG_ERROR;
    if ( !pszMessageFormat ) return LOG_ERROR;

    /* check for, and handle, max msg */
    if ( hLog->nMaxMsgs && hLog->hMessages->nItems == hLog->nMaxMsgs )
        logPopMsg( hLog );

    hMsg                    = malloc( sizeof(LOGMSG) );
    if (!hMsg) goto error_abort0;

    hMsg->pszModuleName     = (char *)strdup( pszModule );
    if (!hMsg->pszModuleName) goto error_abort1;

    hMsg->pszFunctionName   = (char *)strdup( pszFunctionName );
    if (!hMsg->pszFunctionName) goto error_abort2;

#if defined( HAVE_VSNPRINTF )
    mlen=vsnprintf(NULL,0,pszMessageFormat,args);
#else
    mlen=uodbc_vsnprintf(NULL,0,pszMessageFormat,args);
#endif
    mlen++;
    hMsg->pszMessage        = malloc(mlen);
    if (!hMsg->pszMessage) goto error_abort3;

#if defined( HAVE_VSNPRINTF )
    vsnprintf(hMsg->pszMessage,mlen,pszMessageFormat,args);
#else
    uodbc_vsnprintf(hMsg->pszMessage,mlen,pszMessageFormat,args);
#endif

    hMsg->nLine             = nLine;
    hMsg->nSeverity         = nSeverity;
    hMsg->nCode             = nCode;

    /* append to  list */
    lstAppend( hLog->hMessages, hMsg );

    /* append to file */
    if ( hLog->pszLogFile )
    {
        hFile = uo_fopen( hLog->pszLogFile, "a" );
        if ( !hFile ) return LOG_ERROR;

        if (hMsg)
        {
            uo_fprintf( hFile, "[%s][%s][%s][%d]%s\n", hLog->pszProgramName, pszModule, pszFunctionName, nLine, hMsg->pszMessage );
        }
        else
        {
            uo_fprintf( hFile, "[%s][%s][%s][%d]", hLog->pszProgramName, pszModule, pszFunctionName, nLine );
            uo_vfprintf( hFile, pszMessageFormat, args );
            uo_fprintf( hFile, "\n" );
        }

        uo_fclose( hFile );
    }

    return LOG_SUCCESS;

    error_abort3:
    free(hMsg->pszFunctionName);
    error_abort2:
    free(hMsg->pszModuleName);
    error_abort1:
    free(hMsg);
    error_abort0:
    return LOG_ERROR;
}