Skip to content

Commit 1d49a3d

Browse files
committed
Initial commit
1 parent 2fea48f commit 1d49a3d

20 files changed

+1451
-0
lines changed

CHANGES

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
db2-hash-routines 1.1
2+
3+
- renamed package to db2-hash-routines
4+
- changed man pages
5+
6+
db2-auth-routines 1.1
7+
8+
- renamed package to db2-auth-routines
9+
- added man pages
10+
- added stored procedures
11+
- renamed several files (see README)
12+
- changed makertn script to optionally compile with xlc on AIX
13+
14+
db2-auth-udfs 1.3
15+
16+
- allow empty input parameters (empty strings)
17+
- changed reg_udfs.ddl to register the functions as NOT FENCED
18+
19+
db2-auth-udfs 1.2
20+
21+
- changed the code to use the APR library
22+
- renamed the files
23+
- changed makeudf.bat to compile with MS compiler
24+
- added maketest[.bat] to compile test program
25+
26+
db2-auth-udfs 1.1.1
27+
28+
- changed the makemod script to use it on AIX as well
29+
30+
db2-auth-udfs 1.1
31+
32+
- added script for compiling the library on Windows
33+
- rewrote the README file for better understanding
34+
35+
db2-auth-udfs 1.0
36+
37+
- initial release
38+
39+
http://mod-auth-ibmdb2.sourceforge.net/

README

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
written by Helmut K. C. Tessarek
2+
3+
Last Update: 2012-04-13
4+
5+
http://mod-auth-ibmdb2.sourceforge.net/
6+
7+
Contents:
8+
---------
9+
10+
1) Description of the library
11+
2) File Description
12+
13+
1) Description of the library
14+
-----------------------------
15+
16+
This library delivers the following functions as UDFs and SPs:
17+
18+
function in library UDF / SP
19+
20+
md5 md5
21+
aprmd5 apr_md5
22+
aprcrypt apr_crypt
23+
aprsha1 apr_sha1
24+
validate validate_pw
25+
26+
The md5 function is compatible to the PHP md5 function.
27+
The aprmd5, aprcrypt and aprsha1 functions are compatible to the Apache
28+
functions that are used in the htpasswd utility.
29+
The validate function validates a password against a hash.
30+
31+
In win32 environments apr_crypt returns the output of apr_md5.
32+
33+
2) File Description
34+
-------------------
35+
36+
hash.c the SQL API stuff
37+
hash.h the c code for the functions
38+
register.ddl script to register the UDFs and SPs
39+
drop.ddl script to drop the UDFs and SPs
40+
makertn bash script to compile the library (Linux/AIX)
41+
test_hash.c test program for the functions
42+
hash.exp function export file for AIX
43+
hash.def definition file for Windows
44+
makertn.bat script to compile the library (win32)
45+
maketest.bat script to compile test program
46+
INSTALL compiling and installing instructions
47+
CHANGES change log
48+
README this file

drop.ddl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
DROP FUNCTION md5;
2+
DROP FUNCTION apr_md5;
3+
DROP FUNCTION apr_crypt;
4+
DROP FUNCTION apr_sha1;
5+
DROP FUNCTION validate_pw;
6+
7+
DROP PROCEDURE md5;
8+
DROP PROCEDURE apr_md5;
9+
DROP PROCEDURE apr_crypt;
10+
DROP PROCEDURE apr_sha1;
11+
DROP PROCEDURE validate_pw;

hash.c

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| hash: hashing library for IBM DB2 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 2007-2012 Helmut K. C. Tessarek |
6+
+----------------------------------------------------------------------+
7+
| Licensed under the Apache License, Version 2.0 (the "License"); you |
8+
| may not use this file except in compliance with the License. You may |
9+
| obtain a copy of the License at |
10+
| http://www.apache.org/licenses/LICENSE-2.0 |
11+
| |
12+
| Unless required by applicable law or agreed to in writing, software |
13+
| distributed under the License is distributed on an "AS IS" BASIS, |
14+
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
15+
| implied. See the License for the specific language governing |
16+
| permissions and limitations under the License. |
17+
+----------------------------------------------------------------------+
18+
| Author: Helmut K. C. Tessarek |
19+
+----------------------------------------------------------------------+
20+
| Website: http://mod-auth-ibmdb2.sourceforge.net |
21+
+----------------------------------------------------------------------+
22+
*/
23+
24+
/* $Id: hash.c,v 1.2 2012/11/25 07:59:12 tessus Exp $ */
25+
26+
#include <stdio.h>
27+
#include <sqludf.h>
28+
#include <sqlca.h>
29+
#include <sqlda.h>
30+
#include "hash.h"
31+
32+
/*--------------------------------------------------*/
33+
/* function md5: MD5 Hashing */
34+
/* */
35+
/* input : varchar */
36+
/* output: varchar */
37+
/*--------------------------------------------------*/
38+
39+
#ifdef __cplusplus
40+
extern "C"
41+
#endif
42+
void SQL_API_FN md5( SQLUDF_CHAR *in,
43+
SQLUDF_CHAR out[33],
44+
SQLUDF_SMALLINT *innull,
45+
SQLUDF_SMALLINT *outnull,
46+
SQLUDF_TRAIL_ARGS)
47+
{
48+
char *t;
49+
50+
if( *innull != 0 )
51+
{
52+
*outnull = -1;
53+
return;
54+
}
55+
56+
t = mk_hash( in, ALG_MD5 );
57+
strcpy( out, t );
58+
free( t );
59+
60+
*outnull = 0;
61+
return;
62+
}
63+
64+
/*--------------------------------------------------*/
65+
/* function apr_md5: MD5 Hashing as in the htpasswd */
66+
/* program from Apache */
67+
/* */
68+
/* input : varchar */
69+
/* output: varchar */
70+
/*--------------------------------------------------*/
71+
72+
#ifdef __cplusplus
73+
extern "C"
74+
#endif
75+
void SQL_API_FN aprmd5( SQLUDF_CHAR *in,
76+
SQLUDF_CHAR out[38],
77+
SQLUDF_SMALLINT *innull,
78+
SQLUDF_SMALLINT *outnull,
79+
SQLUDF_TRAIL_ARGS)
80+
{
81+
char *t;
82+
83+
if( *innull != 0 )
84+
{
85+
*outnull = -1;
86+
return;
87+
}
88+
89+
t = mk_hash( in, ALG_APMD5 );
90+
strcpy( out, t );
91+
free( t );
92+
93+
*outnull = 0;
94+
return;
95+
}
96+
97+
/*--------------------------------------------------*/
98+
/* function apr_crypt: Crypt fuction as in the */
99+
/* htpasswd program from Apache */
100+
/* */
101+
/* input : varchar */
102+
/* output: varchar */
103+
/*--------------------------------------------------*/
104+
105+
#ifdef __cplusplus
106+
extern "C"
107+
#endif
108+
void SQL_API_FN aprcrypt( SQLUDF_CHAR *in,
109+
SQLUDF_CHAR out[14],
110+
SQLUDF_SMALLINT *innull,
111+
SQLUDF_SMALLINT *outnull,
112+
SQLUDF_TRAIL_ARGS)
113+
{
114+
char *t;
115+
116+
if( *innull != 0 )
117+
{
118+
*outnull = -1;
119+
return;
120+
}
121+
122+
t = mk_hash( in, ALG_CRYPT );
123+
strcpy( out, t );
124+
free( t );
125+
126+
*outnull = 0;
127+
return;
128+
}
129+
130+
/*--------------------------------------------------*/
131+
/* function apr_sha1: SHA1 fuction as in the */
132+
/* htpasswd program from Apache */
133+
/* */
134+
/* input : varchar */
135+
/* output: varchar */
136+
/*--------------------------------------------------*/
137+
138+
#ifdef __cplusplus
139+
extern "C"
140+
#endif
141+
void SQL_API_FN aprsha1( SQLUDF_CHAR *in,
142+
SQLUDF_CHAR out[34],
143+
SQLUDF_SMALLINT *innull,
144+
SQLUDF_SMALLINT *outnull,
145+
SQLUDF_TRAIL_ARGS)
146+
{
147+
char *t;
148+
149+
if( *innull != 0 )
150+
{
151+
*outnull = -1;
152+
return;
153+
}
154+
155+
t = mk_hash( in, ALG_APSHA );
156+
strcpy( out, t );
157+
free( t );
158+
159+
*outnull = 0;
160+
return;
161+
}
162+
163+
/*--------------------------------------------------*/
164+
/* function validate : validates the hash */
165+
/* */
166+
/* input1: varchar */
167+
/* input2: varchar */
168+
/* output: integer */
169+
/*--------------------------------------------------*/
170+
171+
#ifdef __cplusplus
172+
extern "C"
173+
#endif
174+
SQL_API_RC SQL_API_FN validate( SQLUDF_CHAR *password,
175+
SQLUDF_CHAR *hash,
176+
SQLUDF_INTEGER *out,
177+
SQLUDF_SMALLINT *passwordNullInd,
178+
SQLUDF_SMALLINT *hashNullInd,
179+
SQLUDF_SMALLINT *outNullInd,
180+
SQLUDF_TRAIL_ARGS)
181+
{
182+
apr_status_t status;
183+
char *md5, *result;
184+
185+
*out = -1;
186+
*outNullInd = -1;
187+
188+
if( *passwordNullInd != 0 || *hashNullInd != 0 )
189+
{
190+
*outNullInd = -1;
191+
return(0);
192+
}
193+
194+
if( strlen(hash) == 0 )
195+
{
196+
strcpy(SQLUDF_STATE, "39701");
197+
strcpy(SQLUDF_MSGTX, "The second parameter (hash) must not be empty.");
198+
*outNullInd = 0;
199+
return(0);
200+
}
201+
202+
if( strlen(hash) == 32 )
203+
{
204+
md5 = mk_hash( password, ALG_MD5 );
205+
206+
if( apr_strnatcmp( hash, md5 ) == 0 )
207+
{
208+
*out = 1;
209+
}
210+
else
211+
{
212+
*out = 0;
213+
}
214+
215+
free(md5);
216+
217+
*outNullInd = 0;
218+
return(0);
219+
}
220+
221+
status = apr_password_validate( password, hash );
222+
223+
if( status == APR_SUCCESS )
224+
{
225+
*out = 1;
226+
}
227+
else
228+
{
229+
// maybe a different encrypted password (glibc2 crypt)?
230+
result = crypt( password, hash );
231+
if( strcmp( hash, result ) == 0 )
232+
{
233+
*out = 1;
234+
}
235+
else
236+
{
237+
*out = 0;
238+
}
239+
}
240+
241+
*outNullInd = 0;
242+
return(0);
243+
}

hash.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
LIBRARY HASH
2+
EXPORTS
3+
md5
4+
aprmd5
5+
aprcrypt
6+
aprsha1
7+
validate

hash.exp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
md5
2+
aprmd5
3+
aprcrypt
4+
aprsha1
5+
validate

0 commit comments

Comments
 (0)