Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
505d9037
Commit
505d9037
authored
23 years ago
by
D'Arcy J.M. Cain
Browse files
Options
Downloads
Patches
Plain Diff
Upgraded code to use the current version 1 calling conventions.
parent
2ba48262
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/chkpass/chkpass.c
+47
-32
47 additions, 32 deletions
contrib/chkpass/chkpass.c
with
47 additions
and
32 deletions
contrib/chkpass/chkpass.c
+
47
−
32
View file @
505d9037
...
...
@@ -4,7 +4,7 @@
* darcy@druid.net
* http://www.druid.net/darcy/
*
* $
Header: /cvsroot/pgsql/contrib/chkpass/
chkpass.c,v 1.
2
2001/05/2
7
1
9:06
:2
0
darcy Exp $
* $
Id:
chkpass.c,v 1.
3
2001/05/2
8
1
5:34
:2
7
darcy Exp $
* best viewed with tabs set to 4
*/
...
...
@@ -14,7 +14,7 @@
#include
<unistd.h>
#include
<postgres.h>
#include
<
utils/palloc
.h>
#include
<
fmgr
.h>
/*
* This type encrypts it's input unless the first character is a colon.
...
...
@@ -38,13 +38,14 @@ typedef struct chkpass
* Various forward declarations:
*/
chkpass
*
chkpass_in
(
char
*
str
);
char
*
chkpass_out
(
chkpass
*
addr
);
text
*
chkpass_rout
(
chkpass
*
addr
);
Datum
chkpass_in
(
PG_FUNCTION_ARGS
);
Datum
chkpass_out
(
PG_FUNCTION_ARGS
);
Datum
chkpass_rout
(
PG_FUNCTION_ARGS
);
/* Only equal or not equal make sense */
bool
chkpass_eq
(
chkpass
*
a1
,
text
*
a2
);
bool
chkpass_ne
(
chkpass
*
a1
,
text
*
a2
);
Datum
chkpass_eq
(
PG_FUNCTION_ARGS
);
Datum
chkpass_ne
(
PG_FUNCTION_ARGS
);
/* This function checks that the password is a good one
* It's just a placeholder for now */
...
...
@@ -57,9 +58,11 @@ verify_pass(const char *str)
/*
* CHKPASS reader.
*/
chkpass
*
chkpass_in
(
char
*
str
)
PG_FUNCTION_INFO_V1
(
chkpass_in
)
Datum
chkpass_in
(
PG_FUNCTION_ARGS
)
{
char
*
str
=
PG_GETARG_CSTRING
(
0
);
chkpass
*
result
;
char
mysalt
[
4
];
static
bool
random_initialized
=
false
;
...
...
@@ -72,14 +75,14 @@ chkpass_in(char *str)
result
=
(
chkpass
*
)
palloc
(
sizeof
(
chkpass
));
strncpy
(
result
->
password
,
str
+
1
,
13
);
result
->
password
[
13
]
=
0
;
return
(
result
);
return
PointerGetDatum
(
result
);
}
if
(
verify_pass
(
str
)
!=
0
)
{
elog
(
ERROR
,
"chkpass_in: purported CHKPASS
\"
%s
\"
is a weak password"
,
str
);
return
NULL
;
return
PointerGetDatum
(
NULL
)
;
}
result
=
(
chkpass
*
)
palloc
(
sizeof
(
chkpass
));
...
...
@@ -95,7 +98,7 @@ chkpass_in(char *str)
mysalt
[
2
]
=
0
;
/* technically the terminator is not
* necessary but I like to play safe */
strcpy
(
result
->
password
,
crypt
(
str
,
mysalt
));
return
(
result
);
return
PointerGetDatum
(
result
);
}
/*
...
...
@@ -103,13 +106,15 @@ chkpass_in(char *str)
* Just like any string but we know it is max 15 (13 plus colon and terminator.)
*/
char
*
chkpass_out
(
chkpass
*
password
)
PG_FUNCTION_INFO_V1
(
chkpass_out
)
Datum
chkpass_out
(
PG_FUNCTION_ARGS
)
{
chkpass
*
password
=
(
chkpass
*
)
PG_GETARG_POINTER
(
0
);
char
*
result
;
if
(
password
==
NULL
)
return
(
NULL
);
return
PointerGetDatum
(
NULL
);
if
((
result
=
(
char
*
)
palloc
(
16
))
!=
NULL
)
{
...
...
@@ -117,7 +122,7 @@ chkpass_out(chkpass * password)
strcpy
(
result
+
1
,
password
->
password
);
}
return
(
result
);
PG_RETURN_CSTRING
(
result
);
}
...
...
@@ -125,21 +130,23 @@ chkpass_out(chkpass * password)
* special output function that doesn't output the colon
*/
text
*
chkpass_rout
(
chkpass
*
password
)
PG_FUNCTION_INFO_V1
(
chkpass_rout
)
Datum
chkpass_rout
(
PG_FUNCTION_ARGS
)
{
chkpass
*
password
=
(
chkpass
*
)
PG_GETARG_POINTER
(
0
);
text
*
result
=
NULL
;
if
(
password
==
NULL
)
return
(
NULL
);
return
PointerGetDatum
(
NULL
);
if
((
result
=
(
text
*
)
palloc
(
VARHDRSZ
+
16
))
!=
NULL
)
{
result
->
vl_len
=
VARHDRSZ
+
strlen
(
password
->
password
);
memcpy
(
result
->
vl_dat
,
password
->
password
,
strlen
(
password
->
pass
memcpy
(
result
->
vl_dat
,
password
->
password
,
strlen
(
password
->
pass
word
));
}
return
(
result
);
PG_RETURN_CSTRING
(
result
);
}
...
...
@@ -147,29 +154,37 @@ chkpass_rout(chkpass *password)
* Boolean tests
*/
bool
chkpass_eq
(
chkpass
*
a1
,
text
*
a2
)
PG_FUNCTION_INFO_V1
(
chkpass_eq
)
Datum
chkpass_eq
(
PG_FUNCTION_ARGS
)
{
char
str
[
10
];
int
sz
=
8
;
chkpass
*
a1
=
(
chkpass
*
)
PG_GETARG_POINTER
(
0
);
text
*
a2
=
(
text
*
)
PG_GETARG_TEXT_P
(
1
);
char
str
[
10
];
int
sz
=
8
;
if
(
!
a1
||
!
a2
)
PG_RETURN_BOOL
(
0
);
if
(
!
a1
||
!
a2
)
return
0
;
if
(
a2
->
vl_len
<
12
)
sz
=
a2
->
vl_len
-
4
;
strncpy
(
str
,
a2
->
vl_dat
,
sz
);
str
[
sz
]
=
0
;
return
(
strcmp
(
a1
->
password
,
crypt
(
str
,
a1
->
password
))
==
0
);
PG_RETURN_BOOL
(
strcmp
(
a1
->
password
,
crypt
(
str
,
a1
->
password
))
==
0
);
}
bool
chkpass_ne
(
chkpass
*
a1
,
text
*
a2
)
PG_FUNCTION_INFO_V1
(
chkpass_ne
)
Datum
chkpass_ne
(
PG_FUNCTION_ARGS
)
{
char
str
[
10
];
int
sz
=
8
;
chkpass
*
a1
=
(
chkpass
*
)
PG_GETARG_POINTER
(
0
);
text
*
a2
=
(
text
*
)
PG_GETARG_TEXT_P
(
1
);
char
str
[
10
];
int
sz
=
8
;
if
(
!
a1
||
!
a2
)
return
0
;
if
(
a2
->
vl_len
<
12
)
sz
=
a2
->
vl_len
-
4
;
strncpy
(
str
,
a2
->
vl_dat
,
sz
);
str
[
sz
]
=
0
;
return
(
strcmp
(
a1
->
password
,
crypt
(
str
,
a1
->
password
))
!=
0
);
PG_RETURN_BOOL
(
strcmp
(
a1
->
password
,
crypt
(
str
,
a1
->
password
))
!=
0
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment