File: _odbcinst_UserINI.c

package info (click to toggle)
unixodbc 2.2.14p2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 14,628 kB
  • ctags: 12,533
  • sloc: ansic: 104,243; cpp: 38,571; sh: 15,958; makefile: 2,727; sql: 1
file content (122 lines) | stat: -rw-r--r-- 2,826 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**************************************************
 *
 **************************************************
 * This code was created by Peter Harvey @ CodeByDesign.
 * Released under LGPL 28.JAN.99
 *
 * Contributions from...
 * -----------------------------------------------
 * Peter Harvey		- pharvey@codebydesign.com
 **************************************************/
#ifdef HAVE_PWD_H
    #include <pwd.h>
#endif

#include <odbcinstext.h>

#ifdef VMS

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;
}

#else

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

    pHomeDir    = "/home";                              
    pPasswd     = (struct passwd *)getpwuid(nUserID);   

    pszFileName[0] = '\0';

    if ( pPasswd != NULL )
        if ( ( char *)pPasswd->pw_dir != NULL )
            pHomeDir    = pPasswd->pw_dir;

    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;
}

#endif

BOOL _odbcinst_FileINI( char *pszPath )
{
	char b1[ 256 ];

    /* we need a viable buffer (with space for FILENAME_MAX chars)... */
    if ( !pszPath )
        return FALSE;

    /* system configured to use a special location... */
    *pszPath = '\0';
    SQLGetPrivateProfileString( "ODBC", "FileDSNPath", "", pszPath, FILENAME_MAX - 2, "odbcinst.ini" );
    if ( *pszPath )
        return TRUE;

    /* default location... */
    sprintf( pszPath, "%s/ODBCDataSources", odbcinst_system_file_path( b1 ));

    return TRUE;
}