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 | #include <odbcinstext.h> |
13 | |
14 | #define SQL_MAX_DSN_LENGTH 32 |
15 | |
16 | BOOL SQLValidDSN( LPCSTR pszDSN ) |
17 | { |
18 | inst_logClear(); |
19 | |
20 | if ( pszDSN == NULL ) |
21 | return FALSE; |
22 | |
23 | if ( strlen( pszDSN ) < 1 || strlen( pszDSN ) > SQL_MAX_DSN_LENGTH ) |
24 | return FALSE; |
25 | |
26 | if ( strstr( pszDSN, "[" ) != NULL ) |
27 | return FALSE; |
28 | |
29 | if ( strstr( pszDSN, "]" ) != NULL ) |
30 | return FALSE; |
31 | |
32 | if ( strstr( pszDSN, "{" ) != NULL ) |
33 | return FALSE; |
34 | |
35 | if ( strstr( pszDSN, "}" ) != NULL ) |
36 | return FALSE; |
37 | |
38 | if ( strstr( pszDSN, "(" ) != NULL ) |
39 | return FALSE; |
40 | |
41 | if ( strstr( pszDSN, ")" ) != NULL ) |
42 | return FALSE; |
43 | |
44 | if ( strstr( pszDSN, "," ) != NULL ) |
45 | return FALSE; |
46 | |
47 | if ( strstr( pszDSN, ";" ) != NULL ) |
48 | return FALSE; |
49 | |
50 | if ( strstr( pszDSN, "?" ) != NULL ) |
51 | return FALSE; |
52 | |
53 | if ( strstr( pszDSN, "*" ) != NULL ) |
54 | return FALSE; |
55 | |
56 | if ( strstr( pszDSN, "=" ) != NULL ) |
57 | return FALSE; |
58 | |
59 | if ( strstr( pszDSN, "!" ) != NULL ) |
60 | return FALSE; |
61 | |
62 | if ( strstr( pszDSN, "@" ) != NULL ) |
63 | return FALSE; |
64 | |
65 | if ( strstr( pszDSN, "\\" ) != NULL ) |
66 | return FALSE; |
67 | |
68 | |
69 | return TRUE; |
70 | } |
71 | |
72 | BOOL INSTAPI SQLValidDSNW(LPCWSTR lpszDSN) |
73 | { |
74 | char *dsn; |
75 | BOOL ret; |
76 | |
77 | inst_logClear(); |
78 | |
79 | dsn = _single_string_alloc_and_copy( lpszDSN ); |
80 | |
81 | ret = SQLValidDSN( dsn ); |
82 | |
83 | free( dsn ); |
84 | |
85 | return ret; |
86 | } |
87 | |