1 | /********************************************************************* |
2 | * |
3 | * This is based on code created by Peter Harvey, |
4 | * (pharvey@codebydesign.com). |
5 | * |
6 | * Modified and extended by Nick Gorham |
7 | * (nick@lurcher.org). |
8 | * |
9 | * Any bugs or problems should be considered the fault of Nick and not |
10 | * Peter. |
11 | * |
12 | * copyright (c) 1999 Nick Gorham |
13 | * |
14 | * This library is free software; you can redistribute it and/or |
15 | * modify it under the terms of the GNU Lesser General Public |
16 | * License as published by the Free Software Foundation; either |
17 | * version 2 of the License, or (at your option) any later version. |
18 | * |
19 | * This library is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 | * Lesser General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Lesser General Public |
25 | * License along with this library; if not, write to the Free Software |
26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
27 | * |
28 | ********************************************************************** |
29 | * |
30 | * $Id: SQLTablePrivilegesW.c,v 1.10 2009/02/18 17:59:08 lurcher Exp $ |
31 | * |
32 | * $Log: SQLTablePrivilegesW.c,v $ |
33 | * Revision 1.10 2009/02/18 17:59:08 lurcher |
34 | * Shift to using config.h, the compile lines were making it hard to spot warnings |
35 | * |
36 | * Revision 1.9 2008/08/29 08:01:39 lurcher |
37 | * Alter the way W functions are passed to the driver |
38 | * |
39 | * Revision 1.8 2007/02/28 15:37:49 lurcher |
40 | * deal with drivers that call internal W functions and end up in the driver manager. controlled by the --enable-handlemap configure arg |
41 | * |
42 | * Revision 1.7 2004/01/12 09:54:39 lurcher |
43 | * |
44 | * Fix problem where STATE_S5 stops metadata calls |
45 | * |
46 | * Revision 1.6 2003/10/30 18:20:46 lurcher |
47 | * |
48 | * Fix broken thread protection |
49 | * Remove SQLNumResultCols after execute, lease S4/S% to driver |
50 | * Fix string overrun in SQLDriverConnect |
51 | * Add initial support for Interix |
52 | * |
53 | * Revision 1.5 2002/12/05 17:44:31 lurcher |
54 | * |
55 | * Display unknown return values in return logging |
56 | * |
57 | * Revision 1.4 2002/11/11 17:10:18 lurcher |
58 | * |
59 | * VMS changes |
60 | * |
61 | * Revision 1.3 2002/08/23 09:42:37 lurcher |
62 | * |
63 | * Fix some build warnings with casts, and a AIX linker mod, to include |
64 | * deplib's on the link line, but not the libtool generated ones |
65 | * |
66 | * Revision 1.2 2002/07/24 08:49:52 lurcher |
67 | * |
68 | * Alter UNICODE support to use iconv for UNICODE-ANSI conversion |
69 | * |
70 | * Revision 1.1.1.1 2001/10/17 16:40:07 lurcher |
71 | * |
72 | * First upload to SourceForge |
73 | * |
74 | * Revision 1.3 2001/07/03 09:30:41 nick |
75 | * |
76 | * Add ability to alter size of displayed message in the log |
77 | * |
78 | * Revision 1.2 2001/04/12 17:43:36 nick |
79 | * |
80 | * Change logging and added autotest to odbctest |
81 | * |
82 | * Revision 1.1 2000/12/31 20:30:54 nick |
83 | * |
84 | * Add UNICODE support |
85 | * |
86 | * |
87 | **********************************************************************/ |
88 | |
89 | #include <config.h> |
90 | #include "drivermanager.h" |
91 | |
92 | static char const rcsid[]= "$RCSfile: SQLTablePrivilegesW.c,v $" ; |
93 | |
94 | SQLRETURN SQLTablePrivilegesW( |
95 | SQLHSTMT statement_handle, |
96 | SQLWCHAR *sz_catalog_name, |
97 | SQLSMALLINT cb_catalog_name, |
98 | SQLWCHAR *sz_schema_name, |
99 | SQLSMALLINT cb_schema_name, |
100 | SQLWCHAR *sz_table_name, |
101 | SQLSMALLINT cb_table_name ) |
102 | { |
103 | DMHSTMT statement = (DMHSTMT) statement_handle; |
104 | SQLRETURN ret; |
105 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ], s2[ 100 + LOG_MESSAGE_LEN ], s3[ 100 + LOG_MESSAGE_LEN ]; |
106 | |
107 | /* |
108 | * check statement |
109 | */ |
110 | |
111 | if ( !__validate_stmt( statement )) |
112 | { |
113 | dm_log_write( __FILE__, |
114 | __LINE__, |
115 | LOG_INFO, |
116 | LOG_INFO, |
117 | "Error: SQL_INVALID_HANDLE" ); |
118 | |
119 | #ifdef WITH_HANDLE_REDIRECT |
120 | { |
121 | DMHSTMT parent_statement; |
122 | |
123 | parent_statement = find_parent_handle( statement, SQL_HANDLE_STMT ); |
124 | |
125 | if ( parent_statement ) { |
126 | dm_log_write( __FILE__, |
127 | __LINE__, |
128 | LOG_INFO, |
129 | LOG_INFO, |
130 | "Info: found parent handle" ); |
131 | |
132 | if ( CHECK_SQLTABLEPRIVILEGESW( parent_statement -> connection )) |
133 | { |
134 | dm_log_write( __FILE__, |
135 | __LINE__, |
136 | LOG_INFO, |
137 | LOG_INFO, |
138 | "Info: calling redirected driver function" ); |
139 | |
140 | return SQLTABLEPRIVILEGESW( parent_statement -> connection, |
141 | statement_handle, |
142 | sz_catalog_name, |
143 | cb_catalog_name, |
144 | sz_schema_name, |
145 | cb_schema_name, |
146 | sz_table_name, |
147 | cb_table_name ); |
148 | } |
149 | } |
150 | } |
151 | #endif |
152 | return SQL_INVALID_HANDLE; |
153 | } |
154 | |
155 | function_entry( statement ); |
156 | |
157 | if ( log_info.log_flag ) |
158 | { |
159 | sprintf( statement -> msg, "\n\t\tEntry:\ |
160 | \n\t\t\tStatement = %p\ |
161 | \n\t\t\tCatalog Name = %s\ |
162 | \n\t\t\tSchema Name = %s\ |
163 | \n\t\t\tTable Name = %s" , |
164 | statement, |
165 | __wstring_with_length( s1, sz_catalog_name, cb_catalog_name ), |
166 | __wstring_with_length( s2, sz_schema_name, cb_schema_name ), |
167 | __wstring_with_length( s3, sz_table_name, cb_table_name )); |
168 | |
169 | dm_log_write( __FILE__, |
170 | __LINE__, |
171 | LOG_INFO, |
172 | LOG_INFO, |
173 | statement -> msg ); |
174 | } |
175 | |
176 | thread_protect( SQL_HANDLE_STMT, statement ); |
177 | |
178 | if (( sz_catalog_name && cb_catalog_name < 0 && cb_catalog_name != SQL_NTS ) || |
179 | ( sz_schema_name && cb_schema_name < 0 && cb_schema_name != SQL_NTS ) || |
180 | ( sz_table_name && cb_table_name < 0 && cb_table_name != SQL_NTS )) |
181 | { |
182 | dm_log_write( __FILE__, |
183 | __LINE__, |
184 | LOG_INFO, |
185 | LOG_INFO, |
186 | "Error: HY090" ); |
187 | |
188 | __post_internal_error( &statement -> error, |
189 | ERROR_HY090, NULL, |
190 | statement -> connection -> environment -> requested_version ); |
191 | |
192 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
193 | } |
194 | |
195 | /* |
196 | * check states |
197 | */ |
198 | |
199 | #ifdef NR_PROBE |
200 | if ( statement -> state == STATE_S5 || |
201 | statement -> state == STATE_S6 || |
202 | statement -> state == STATE_S7 ) |
203 | #else |
204 | if (( statement -> state == STATE_S6 && statement -> eod == 0 ) || |
205 | statement -> state == STATE_S7 ) |
206 | #endif |
207 | { |
208 | dm_log_write( __FILE__, |
209 | __LINE__, |
210 | LOG_INFO, |
211 | LOG_INFO, |
212 | "Error: 24000" ); |
213 | |
214 | __post_internal_error( &statement -> error, |
215 | ERROR_24000, NULL, |
216 | statement -> connection -> environment -> requested_version ); |
217 | |
218 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
219 | } |
220 | else if ( statement -> state == STATE_S8 || |
221 | statement -> state == STATE_S9 || |
222 | statement -> state == STATE_S10 || |
223 | statement -> state == STATE_S13 || |
224 | statement -> state == STATE_S14 || |
225 | statement -> state == STATE_S15 ) |
226 | { |
227 | dm_log_write( __FILE__, |
228 | __LINE__, |
229 | LOG_INFO, |
230 | LOG_INFO, |
231 | "Error: HY010" ); |
232 | |
233 | __post_internal_error( &statement -> error, |
234 | ERROR_HY010, NULL, |
235 | statement -> connection -> environment -> requested_version ); |
236 | |
237 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
238 | } |
239 | |
240 | if ( statement -> state == STATE_S11 || |
241 | statement -> state == STATE_S12 ) |
242 | { |
243 | if ( statement -> interupted_func != SQL_API_SQLTABLEPRIVILEGES ) |
244 | { |
245 | dm_log_write( __FILE__, |
246 | __LINE__, |
247 | LOG_INFO, |
248 | LOG_INFO, |
249 | "Error: HY010" ); |
250 | |
251 | __post_internal_error( &statement -> error, |
252 | ERROR_HY010, NULL, |
253 | statement -> connection -> environment -> requested_version ); |
254 | |
255 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
256 | } |
257 | } |
258 | |
259 | /* |
260 | * TO_DO Check the SQL_ATTR_METADATA_ID settings |
261 | */ |
262 | |
263 | if ( statement -> connection -> unicode_driver || |
264 | CHECK_SQLTABLEPRIVILEGESW( statement -> connection )) |
265 | { |
266 | if ( !CHECK_SQLTABLEPRIVILEGESW( statement -> connection )) |
267 | { |
268 | dm_log_write( __FILE__, |
269 | __LINE__, |
270 | LOG_INFO, |
271 | LOG_INFO, |
272 | "Error: IM001" ); |
273 | |
274 | __post_internal_error( &statement -> error, |
275 | ERROR_IM001, NULL, |
276 | statement -> connection -> environment -> requested_version ); |
277 | |
278 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
279 | } |
280 | |
281 | ret = SQLTABLEPRIVILEGESW( statement -> connection , |
282 | statement -> driver_stmt, |
283 | sz_catalog_name, |
284 | cb_catalog_name, |
285 | sz_schema_name, |
286 | cb_schema_name, |
287 | sz_table_name, |
288 | cb_table_name ); |
289 | } |
290 | else |
291 | { |
292 | SQLCHAR *as1, *as2, *as3; |
293 | int clen; |
294 | |
295 | if ( !CHECK_SQLTABLEPRIVILEGES( statement -> connection )) |
296 | { |
297 | dm_log_write( __FILE__, |
298 | __LINE__, |
299 | LOG_INFO, |
300 | LOG_INFO, |
301 | "Error: IM001" ); |
302 | |
303 | __post_internal_error( &statement -> error, |
304 | ERROR_IM001, NULL, |
305 | statement -> connection -> environment -> requested_version ); |
306 | |
307 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
308 | } |
309 | |
310 | as1 = (SQLCHAR*) unicode_to_ansi_alloc( sz_catalog_name, cb_catalog_name, statement -> connection, &clen ); |
311 | cb_catalog_name = clen; |
312 | as2 = (SQLCHAR*) unicode_to_ansi_alloc( sz_schema_name, cb_schema_name, statement -> connection, &clen ); |
313 | cb_schema_name = clen; |
314 | as3 = (SQLCHAR*) unicode_to_ansi_alloc( sz_table_name, cb_table_name, statement -> connection, &clen ); |
315 | cb_table_name = clen; |
316 | |
317 | ret = SQLTABLEPRIVILEGES( statement -> connection , |
318 | statement -> driver_stmt, |
319 | as1, |
320 | cb_catalog_name, |
321 | as2, |
322 | cb_schema_name, |
323 | as3, |
324 | cb_table_name ); |
325 | |
326 | if ( as1 ) free( as1 ); |
327 | if ( as2 ) free( as2 ); |
328 | if ( as3 ) free( as3 ); |
329 | } |
330 | |
331 | if ( SQL_SUCCEEDED( ret )) |
332 | { |
333 | statement -> state = STATE_S5; |
334 | statement -> prepared = 0; |
335 | } |
336 | else if ( ret == SQL_STILL_EXECUTING ) |
337 | { |
338 | statement -> interupted_func = SQL_API_SQLTABLEPRIVILEGES; |
339 | if ( statement -> state != STATE_S11 && |
340 | statement -> state != STATE_S12 ) |
341 | statement -> state = STATE_S11; |
342 | } |
343 | else |
344 | { |
345 | statement -> state = STATE_S1; |
346 | } |
347 | |
348 | if ( log_info.log_flag ) |
349 | { |
350 | sprintf( statement -> msg, |
351 | "\n\t\tExit:[%s]" , |
352 | __get_return_status( ret, s1 )); |
353 | |
354 | dm_log_write( __FILE__, |
355 | __LINE__, |
356 | LOG_INFO, |
357 | LOG_INFO, |
358 | statement -> msg ); |
359 | } |
360 | |
361 | return function_return( SQL_HANDLE_STMT, statement, ret ); |
362 | } |
363 | |