summaryrefslogtreecommitdiffstats
path: root/src/util/authtok.c
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2013-03-14 09:10:39 +0100
committerJakub Hrozek <jhrozek@redhat.com>2013-04-02 17:01:08 +0200
commit9acfb09f7969a69f58bd45c856b01700541853ca (patch)
tree51b08598dde631e49910dc3c5865460208a6a9f5 /src/util/authtok.c
parent53b58615fbc13eddcd6e2f28066b67cb5f16b6d3 (diff)
downloadsssd-9acfb09f7969a69f58bd45c856b01700541853ca.tar.gz
sssd-9acfb09f7969a69f58bd45c856b01700541853ca.tar.xz
sssd-9acfb09f7969a69f58bd45c856b01700541853ca.zip
Making the authtok structure really opaque.
Definition of structure sss_auth_token was removed from header file authtok.h and there left only declaration of this structure. Therefore only way how to use this structure is to use accessory function from same header file. To creating new empty authotok can only be used newly created function sss_authtok_new(). TALLOC context was removed from copy and setter functions, because pointer to stuct sss_auth_token is used as a memory context. All declaration of struct sss_auth_token variables was replaced with pointer to this structure and related changes was made in source code. Function copy_pam_data can copy from argument src which was dynamically allocated with function create_pam_data() or zero initialized struct pam_data allocated on stack. https://fedorahosted.org/sssd/ticket/1830
Diffstat (limited to 'src/util/authtok.c')
-rw-r--r--src/util/authtok.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/util/authtok.c b/src/util/authtok.c
index 1c54d04cc..83e6a1c94 100644
--- a/src/util/authtok.c
+++ b/src/util/authtok.c
@@ -19,6 +19,12 @@
#include "authtok.h"
+struct sss_auth_token {
+ enum sss_authtok_type type;
+ uint8_t *data;
+ size_t length;
+};
+
enum sss_authtok_type sss_authtok_get_type(struct sss_auth_token *tok)
{
return tok->type;
@@ -80,8 +86,7 @@ errno_t sss_authtok_get_ccfile(struct sss_auth_token *tok,
return EINVAL;
}
-static errno_t sss_authtok_set_string(TALLOC_CTX *mem_ctx,
- struct sss_auth_token *tok,
+static errno_t sss_authtok_set_string(struct sss_auth_token *tok,
enum sss_authtok_type type,
const char *context_name,
const char *str, size_t len)
@@ -101,7 +106,7 @@ static errno_t sss_authtok_set_string(TALLOC_CTX *mem_ctx,
size = len + 1;
- tok->data = talloc_named(mem_ctx, size, "%s", context_name);
+ tok->data = talloc_named(tok, size, "%s", context_name);
if (!tok->data) {
return ENOMEM;
}
@@ -131,38 +136,33 @@ void sss_authtok_set_empty(struct sss_auth_token *tok)
tok->length = 0;
}
-errno_t sss_authtok_set_password(TALLOC_CTX *mem_ctx,
- struct sss_auth_token *tok,
+errno_t sss_authtok_set_password(struct sss_auth_token *tok,
const char *password, size_t len)
{
sss_authtok_set_empty(tok);
- return sss_authtok_set_string(mem_ctx, tok,
- SSS_AUTHTOK_TYPE_PASSWORD,
+ return sss_authtok_set_string(tok, SSS_AUTHTOK_TYPE_PASSWORD,
"password", password, len);
}
-errno_t sss_authtok_set_ccfile(TALLOC_CTX *mem_ctx,
- struct sss_auth_token *tok,
+errno_t sss_authtok_set_ccfile(struct sss_auth_token *tok,
const char *ccfile, size_t len)
{
sss_authtok_set_empty(tok);
- return sss_authtok_set_string(mem_ctx, tok,
- SSS_AUTHTOK_TYPE_CCFILE,
+ return sss_authtok_set_string(tok, SSS_AUTHTOK_TYPE_CCFILE,
"ccfile", ccfile, len);
}
-errno_t sss_authtok_set(TALLOC_CTX *mem_ctx,
- struct sss_auth_token *tok,
+errno_t sss_authtok_set(struct sss_auth_token *tok,
enum sss_authtok_type type,
uint8_t *data, size_t len)
{
switch (type) {
case SSS_AUTHTOK_TYPE_PASSWORD:
- return sss_authtok_set_password(mem_ctx, tok, (const char *)data, len);
+ return sss_authtok_set_password(tok, (const char *)data, len);
case SSS_AUTHTOK_TYPE_CCFILE:
- return sss_authtok_set_ccfile(mem_ctx, tok, (const char *)data, len);
+ return sss_authtok_set_ccfile(tok, (const char *)data, len);
case SSS_AUTHTOK_TYPE_EMPTY:
sss_authtok_set_empty(tok);
return EOK;
@@ -171,8 +171,7 @@ errno_t sss_authtok_set(TALLOC_CTX *mem_ctx,
return EINVAL;
}
-errno_t sss_authtok_copy(TALLOC_CTX *mem_ctx,
- struct sss_auth_token *src,
+errno_t sss_authtok_copy(struct sss_auth_token *src,
struct sss_auth_token *dst)
{
sss_authtok_set_empty(dst);
@@ -181,7 +180,7 @@ errno_t sss_authtok_copy(TALLOC_CTX *mem_ctx,
return EOK;
}
- dst->data = talloc_memdup(mem_ctx, src->data, src->length);
+ dst->data = talloc_memdup(dst, src->data, src->length);
if (!dst->data) {
return ENOMEM;
}
@@ -191,6 +190,19 @@ errno_t sss_authtok_copy(TALLOC_CTX *mem_ctx,
return EOK;
}
+struct sss_auth_token *sss_authtok_new(TALLOC_CTX *mem_ctx)
+{
+ struct sss_auth_token *token;
+
+ token = talloc_zero(mem_ctx, struct sss_auth_token);
+ if (token == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_zero failed.\n"));
+ }
+
+ return token;
+}
+
+
void sss_authtok_wipe_password(struct sss_auth_token *tok)
{
if (tok->type != SSS_AUTHTOK_TYPE_PASSWORD) {