taskrambler  0.1.9
Web server and task management solution.
auth/storage/storage.c File Reference
#include "class.h"
#include "storage/storage.h"
#include "auth.h"
#include "uuid.h"
#include "user.h"
#include "commons.h"
#include "utils/memory.h"
+ Include dependency graph for auth/storage/storage.c:

Go to the source code of this file.

Functions

static int authStorageCtor (void *_this, va_list *params)
 
static void authStorageDtor (void *_this)
 
static int authStorageAuthenticate (void *_this, Credential cred, Uuid user_index)
 
 INIT_IFACE (Class, authStorageCtor, authStorageDtor, NULL)
 
 INIT_IFACE (Auth, authStorageAuthenticate)
 
 CREATE_CLASS (AuthStorage, NULL, IFACE(Class), IFACE(Auth))
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file auth/storage/storage.c.

Function Documentation

static int authStorageAuthenticate ( void *  _this,
Credential  cred,
Uuid  user_index 
)
static

Definition at line 50 of file auth/storage/storage.c.

References CRED_PASSWORD, CRED_PWD, FALSE, hash_pw(), HASH_SIZE, MEM_FREE, SALT_SIZE, storageGet(), and TRUE.

51 {
52  AuthStorage this = _this;
53 
54  unsigned char current_hash[HASH_SIZE];
55  unsigned char * found_hash = NULL;
56  size_t nfound_hash = 0;
57 
58  if (CRED_PASSWORD != cred->type) {
59  return FALSE;
60  }
61 
62  storageGet(
63  this->store,
64  (char *)(user_index->uuid).value,
65  sizeof((user_index->uuid).value),
66  (char **)&found_hash,
67  &nfound_hash);
68 
69  if (NULL == found_hash || (SALT_SIZE + HASH_SIZE) != nfound_hash) {
70  /* user not found or found hash is invalid */
71  return FALSE;
72  }
73 
74  /* found_hash <=> salt+hash */
75  if (FALSE == hash_pw(
76  CRED_PWD(cred).pass,
77  CRED_PWD(cred).npass,
78  current_hash,
79  &found_hash)) {
80  MEM_FREE(found_hash);
81  return FALSE;
82  }
83 
84  if (0 != memcmp(current_hash, found_hash+SALT_SIZE, HASH_SIZE)) {
85  MEM_FREE(found_hash);
86  return FALSE;
87  }
88 
89  MEM_FREE(found_hash);
90  return TRUE;
91 }
#define MEM_FREE(seg)
Definition: memory.h:28
#define SALT_SIZE
Definition: auth/storage.h:34
void storageGet(Storage, char *, size_t, char **, size_t *)
Definition: storage/get.c:34
#define FALSE
Definition: commons.h:28
#define TRUE
Definition: commons.h:27
int hash_pw(const char *, const size_t, unsigned char *, unsigned char **)
Definition: hash_pw.c:74
#define HASH_SIZE
Definition: auth/storage.h:35
#define CRED_PWD(c)
Definition: credential.h:30

+ Here is the call graph for this function:

static int authStorageCtor ( void *  _this,
va_list *  params 
)
static

Definition at line 33 of file auth/storage/storage.c.

34 {
35  AuthStorage this = _this;
36 
37  this->store = va_arg(*params, Storage);
38 
39  return 0;
40 }
static void authStorageDtor ( void *  _this)
static

Definition at line 44 of file auth/storage/storage.c.

45 {
46 }
CREATE_CLASS ( AuthStorage  ,
NULL  ,
IFACE(Class)  ,
IFACE(Auth)   
)
INIT_IFACE ( Class  ,
authStorageCtor  ,
authStorageDtor  ,
NULL   
)
INIT_IFACE ( Auth  ,
authStorageAuthenticate   
)