1 /**************************************************
2  *
3  **************************************************
4  * This code was created by Peter Harvey @ CodeByDesign.
5  * Released under LGPL 28.JAN.99
6  *
7  * Contributions from...
8  * -----------------------------------------------
9  * Peter Harvey		- pharvey@codebydesign.com
10  **************************************************/
11 #include <config.h>
12 #ifdef HAVE_PWD_H
13     #include <pwd.h>
14 #endif
15 
16 #include <odbcinstext.h>
17 
18 #ifdef VMS
19 
_odbcinst_UserINI(char * pszFileName,BOOL bVerify)20 BOOL _odbcinst_UserINI( char *pszFileName, BOOL bVerify )
21 {
22     FILE            *hFile;
23     char            *szEnv_INIUSER              = getvmsenv("ODBCINI");
24     struct passwd   *pPasswd                    = NULL;
25     char            *pHomeDir                   = NULL;
26 
27     pszFileName[0] = '\0';
28 
29     if ( szEnv_INIUSER )
30     {
31         strncpy( pszFileName, szEnv_INIUSER, ODBC_FILENAME_MAX );
32     }
33     else
34     {
35         sprintf( pszFileName, "SYS$LOGIN:ODBC.INI" );
36     }
37 
38     if ( bVerify )
39     {
40         hFile = uo_fopen( pszFileName, "r" );
41         if ( hFile )
42             uo_fclose( hFile );
43         else
44             return FALSE;
45     }
46 
47     return TRUE;
48 }
49 
50 #else
51 
_odbcinst_UserINI(char * pszFileName,BOOL bVerify)52 BOOL _odbcinst_UserINI( char *pszFileName, BOOL bVerify )
53 {
54     FILE            *hFile;
55     char            *szEnv_INIUSER              = getenv("ODBCINI");
56 #ifdef HAVE_GETUID
57     uid_t           nUserID                     = getuid();
58 #else
59     uid_t           nUserID                     = 0;
60 #endif
61     struct passwd   *pPasswd                    = NULL;
62     char            *pHomeDir                   = NULL;
63 
64     pHomeDir    = "/home";
65 #ifdef HAVE_GETPWUID
66     pPasswd     = (struct passwd *)getpwuid(nUserID);
67 #endif
68 
69     pszFileName[0] = '\0';
70 
71 #ifdef HAVE_PWD_H
72     if ( pPasswd != NULL )
73         if ( ( char *)pPasswd->pw_dir != NULL )
74             pHomeDir    = pPasswd->pw_dir;
75 #else
76     pHomeDir = getenv("HOME");
77 #endif
78 
79     if ( szEnv_INIUSER )
80     {
81         strncpy( pszFileName, szEnv_INIUSER, ODBC_FILENAME_MAX );
82     }
83     if ( pszFileName[0] == '\0' )
84     {
85         sprintf( pszFileName, "%s%s", pHomeDir, "/.odbc.ini" );
86     }
87 
88 #ifdef DHAVE_ENDPWENT
89     /*
90      * close the password file
91      */
92     endpwent();
93 #endif
94 
95     if ( bVerify )
96     {
97         /*
98          * create it of it doesn't exist
99          */
100 
101         hFile = uo_fopen( pszFileName, "a" );
102         if ( hFile )
103             uo_fclose( hFile );
104         else
105             return FALSE;
106     }
107 
108     return TRUE;
109 }
110 
111 #endif
112 
_odbcinst_FileINI(char * pszPath)113 BOOL _odbcinst_FileINI( char *pszPath )
114 {
115 	char b1[ ODBC_FILENAME_MAX + 1 ];
116 
117     /* we need a viable buffer (with space for FILENAME_MAX chars)... */
118     if ( !pszPath )
119         return FALSE;
120 
121     /* system configured to use a special location... */
122     *pszPath = '\0';
123     SQLGetPrivateProfileString( "ODBC", "FileDSNPath", "", pszPath, FILENAME_MAX - 2, "odbcinst.ini" );
124     if ( *pszPath )
125         return TRUE;
126 
127     /* default location... */
128     sprintf( pszPath, "%s/ODBCDataSources", odbcinst_system_file_path( b1 ));
129 
130     return TRUE;
131 }
132 
133 
134