#include "postgres.h"#include <time.h>#include <unistd.h>#include "fmgr.h"#include "utils/builtins.h"
Go to the source code of this file.
Data Structures | |
| struct | chkpass |
Typedefs | |
| typedef struct chkpass | chkpass |
Functions | |
| Datum | chkpass_in (PG_FUNCTION_ARGS) |
| Datum | chkpass_out (PG_FUNCTION_ARGS) |
| Datum | chkpass_rout (PG_FUNCTION_ARGS) |
| Datum | chkpass_eq (PG_FUNCTION_ARGS) |
| Datum | chkpass_ne (PG_FUNCTION_ARGS) |
| static int | verify_pass (const char *str) |
| PG_FUNCTION_INFO_V1 (chkpass_in) | |
| PG_FUNCTION_INFO_V1 (chkpass_out) | |
| PG_FUNCTION_INFO_V1 (chkpass_rout) | |
| PG_FUNCTION_INFO_V1 (chkpass_eq) | |
| PG_FUNCTION_INFO_V1 (chkpass_ne) | |
Variables | |
| PG_MODULE_MAGIC | |
| Datum chkpass_eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 139 of file chkpass.c.
References a1, a2, crypt(), chkpass::password, PG_GETARG_POINTER, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and text_to_cstring_buffer().
{
chkpass *a1 = (chkpass *) PG_GETARG_POINTER(0);
text *a2 = PG_GETARG_TEXT_PP(1);
char str[9];
text_to_cstring_buffer(a2, str, sizeof(str));
PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) == 0);
}
| Datum chkpass_in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 68 of file chkpass.c.
References crypt(), ereport, errcode(), errmsg(), ERROR, palloc(), chkpass::password, PG_GETARG_CSTRING, PG_RETURN_POINTER, random(), strlcpy(), and verify_pass().
{
char *str = PG_GETARG_CSTRING(0);
chkpass *result;
char mysalt[4];
static char salt_chars[] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/* special case to let us enter encrypted passwords */
if (*str == ':')
{
result = (chkpass *) palloc(sizeof(chkpass));
strlcpy(result->password, str + 1, 13 + 1);
PG_RETURN_POINTER(result);
}
if (verify_pass(str) != 0)
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("password \"%s\" is weak", str)));
result = (chkpass *) palloc(sizeof(chkpass));
mysalt[0] = salt_chars[random() & 0x3f];
mysalt[1] = salt_chars[random() & 0x3f];
mysalt[2] = 0; /* technically the terminator is not necessary
* but I like to play safe */
strcpy(result->password, crypt(str, mysalt));
PG_RETURN_POINTER(result);
}
| Datum chkpass_ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 151 of file chkpass.c.
References a1, a2, crypt(), chkpass::password, PG_GETARG_POINTER, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and text_to_cstring_buffer().
{
chkpass *a1 = (chkpass *) PG_GETARG_POINTER(0);
text *a2 = PG_GETARG_TEXT_PP(1);
char str[9];
text_to_cstring_buffer(a2, str, sizeof(str));
PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) != 0);
}
| Datum chkpass_out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 106 of file chkpass.c.
References palloc(), chkpass::password, PG_GETARG_POINTER, and PG_RETURN_CSTRING.
{
chkpass *password = (chkpass *) PG_GETARG_POINTER(0);
char *result;
result = (char *) palloc(16);
result[0] = ':';
strcpy(result + 1, password->password);
PG_RETURN_CSTRING(result);
}
| Datum chkpass_rout | ( | PG_FUNCTION_ARGS | ) |
Definition at line 125 of file chkpass.c.
References cstring_to_text(), chkpass::password, PG_GETARG_POINTER, and PG_RETURN_TEXT_P.
{
chkpass *password = (chkpass *) PG_GETARG_POINTER(0);
PG_RETURN_TEXT_P(cstring_to_text(password->password));
}
| PG_FUNCTION_INFO_V1 | ( | chkpass_in | ) |
| PG_FUNCTION_INFO_V1 | ( | chkpass_rout | ) |
| PG_FUNCTION_INFO_V1 | ( | chkpass_ne | ) |
| PG_FUNCTION_INFO_V1 | ( | chkpass_eq | ) |
| PG_FUNCTION_INFO_V1 | ( | chkpass_out | ) |
| static int verify_pass | ( | const char * | str | ) | [static] |
1.7.1