taskrambler  0.1.9
Web server and task management solution.
application.h File Reference
#include <sys/types.h>
#include "class.h"
#include "session.h"
#include "hash.h"
#include "auth.h"
#include "auth/credential.h"
#include "storage/storage.h"
#include "user.h"
#include "uuid.h"
+ Include dependency graph for application.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  randval
 

Functions

 CLASS (Application)
 
int applicationLogin (Application, Credential, Session)
 
void applicationLogout (Application, Session)
 
Uuid applicationCreateUser (Application, Credential, User)
 
Uuid applicationUpdateUser (Application, User)
 
User applicationGetUser (Application, Uuid)
 
int applicationUpdatePassword (Application, Credential, User)
 
Session applicationSessionStart (Application)
 
Session applicationSessionGet (Application, const char *)
 
void applicationSessionStop (Application, Session)
 
void applicationSessionCleanup (Application, time_t)
 

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 application.h.


Data Structure Documentation

struct randval

Definition at line 40 of file application.h.

+ Collaboration diagram for randval:
Data Fields
time_t timestamp
int value

Function Documentation

Uuid applicationCreateUser ( Application  ,
Credential  ,
User   
)
Todo:
error handling is missing here

Definition at line 43 of file create_user.c.

References applicationUpdatePassword(), indexUuid(), MEM_FREE, serialize(), SPR_OK, storageDelete(), storagePut(), and uuidZero.

Referenced by controllerSignupCreate(), and controllerUserCreate().

47 {
48  char * user_serialized;
49  size_t nuser_serialized;
50  Uuid index;
51 
52  index = indexUuid(user, this->user_namespace);
53  serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
54 
55  if (SPR_OK != storagePut(
56  this->users,
57  (char *)(index->uuid).value,
58  sizeof((index->uuid).value),
59  user_serialized,
60  nuser_serialized))
61  {
62  return uuidZero;
63  }
64 
65  MEM_FREE(user_serialized);
66 
67  if (! applicationUpdatePassword(this, cred, user)) {
68  /**
69  * \todo
70  * error handling is missing here
71  */
73  this->users,
74  (char *)(index->uuid).value,
75  sizeof((index->uuid).value));
76 
77  return uuidZero;
78  }
79 
80  return index;
81 }
#define MEM_FREE(seg)
Definition: memory.h:28
int storageDelete(Storage, char *, size_t)
int applicationUpdatePassword(Application, Credential, User)
StoragePutResult storagePut(Storage, char *, size_t, char *, size_t)
Definition: storage/put.c:34
Uuid uuidZero
void serialize(void *, unsigned char **, size_t *)
Definition: serializable.c:32
Uuid indexUuid(void *, Uuid)
Definition: indexable.c:33

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

User applicationGetUser ( Application  ,
Uuid   
)

Definition at line 41 of file get_user.c.

References MEM_FREE, storageGet(), and unserialize().

Referenced by controllerUserRead().

42 {
43  char * user_serialized;
44  size_t nuser_serialized;
45  User user = NULL;
46 
47  storageGet(
48  this->users,
49  (char *)(uuid->uuid).value,
50  sizeof((uuid->uuid).value),
51  &user_serialized,
52  &nuser_serialized);
53 
54  if (NULL != user_serialized) {
56  user,
57  (unsigned char *)user_serialized,
58  nuser_serialized);
59  MEM_FREE(user_serialized);
60  }
61 
62  return user;
63 }
#define MEM_FREE(seg)
Definition: memory.h:28
void storageGet(Storage, char *, size_t, char **, size_t *)
Definition: storage/get.c:34
void unserialize(void *, const unsigned char *, size_t)
Definition: serializable.c:41

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int applicationLogin ( Application  ,
Credential  ,
Session   
)

this is a user authenticated via another method than the password database and has not yet logged in. NOTE: first we have to remove the search user and as username is initialized with something that we will free later here we must set it to NULL so that the delete will not free it.

Todo:
Handle error...if this fails we have most likely a collision.

Definition at line 42 of file login.c.

References authenticate(), CRED_PASSWORD, CRED_PWD, CSTRA, FALSE, indexUuid(), MEM_FREE, serialize(), storageGet(), storagePut(), TRUE, and unserialize().

Referenced by controllerAuthenticateCreate(), and controllerSignupCreate().

46 {
47  Uuid search;
48  AuthModule auth_module;
49 
50  User user = new(User, NULL);
51 
52  user->username = CRED_PWD(credential).user;
53  user->nusername = &CRED_PWD(credential).nuser;
54  search = indexUuid(user, this->user_namespace);
55 
56  auth_module = authenticate(this->auth, credential, search);
57 
58  if (0 != auth_module) {
59  char * user_serialized;
60  size_t nuser_serialized;
61 
62  session->user = user;
63 
64  switch (credential->type) {
65  case CRED_PASSWORD:
66  storageGet(
67  this->users,
68  (char *)(search->uuid).value,
69  sizeof((search->uuid).value),
70  &user_serialized,
71  &nuser_serialized);
72 
73  if (NULL != user_serialized) {
75  session->user,
76  (unsigned char *)user_serialized,
77  nuser_serialized);
78  MEM_FREE(user_serialized);
79  } else {
80  /**
81  * this is a user authenticated via another method
82  * than the password database and has not yet
83  * logged in.
84  * NOTE: first we have to remove the search user and
85  * as username is initialized with something that we
86  * will free later here we must set it to NULL so that
87  * the delete will not free it.
88  */
89  session->user->username = NULL;
90  delete(session->user);
91  session->user = new(User,
92  CRED_PWD(credential).user,
93  CRED_PWD(credential).nuser,
94  CSTRA(""),
95  CSTRA(""),
96  CSTRA(""));
97 
98  serialize(
99  session->user,
100  (unsigned char **)&user_serialized,
101  &nuser_serialized);
102  /**
103  * \todo
104  * Handle error...if this fails we have most likely
105  * a collision.
106  */
107  storagePut(
108  this->users,
109  (char *)(search->uuid).value,
110  sizeof((search->uuid).value),
111  user_serialized,
112  nuser_serialized);
113  MEM_FREE(user_serialized);
114  }
115 
116  session->user->auth_type = auth_module;
117  break;
118 
119  default:
120  break;
121  }
122 
123  delete(search);
124  return TRUE;
125  }
126 
127  delete(search);
128 
129  return FALSE;
130 }
#define MEM_FREE(seg)
Definition: memory.h:28
StoragePutResult storagePut(Storage, char *, size_t, char *, size_t)
Definition: storage/put.c:34
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
int authenticate(void *, Credential, Uuid)
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
void serialize(void *, unsigned char **, size_t *)
Definition: serializable.c:32
Uuid indexUuid(void *, Uuid)
Definition: indexable.c:33
void unserialize(void *, const unsigned char *, size_t)
Definition: serializable.c:41
AuthModule
Definition: auth/auth.h:51
#define CRED_PWD(c)
Definition: credential.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void applicationLogout ( Application  ,
Session   
)

Definition at line 33 of file logout.c.

Referenced by controllerAuthenticateDelete().

34 {
35  delete(session->user);
36 }

+ Here is the caller graph for this function:

void applicationSessionCleanup ( Application  ,
time_t   
)

Definition at line 36 of file session_cleanup.c.

References hashCleanup(), MEM_FREE, memCalloc(), and SESSION_LIVETIME.

Referenced by applicationAdapterHttpUpdate().

37 {
38  unsigned int expired = now - this->session_time_ofs;
39  unsigned int i = 0;
40 
41  if (SESSION_LIVETIME <= expired) {
42  expired = SESSION_LIVETIME;
43  }
44 
45  if (0 < expired && SESSION_LIVETIME > expired) {
46  Hash * tmp_buf = memCalloc(SESSION_LIVETIME, sizeof(Hash));
47 
48  memcpy(
49  &(tmp_buf[expired]),
50  this->active_sessions,
51  (SESSION_LIVETIME - expired) * sizeof(Hash));
52  memcpy(
53  tmp_buf,
54  &(this->active_sessions[SESSION_LIVETIME - expired]),
55  expired * sizeof(Hash));
56 
57  MEM_FREE(this->active_sessions);
58  this->active_sessions = tmp_buf;
59  }
60 
61  for (i=0; i<expired; i++) {
62  hashCleanup(this->active_sessions[i]);
63  }
64 
65  this->session_time_ofs = now;
66 }
#define MEM_FREE(seg)
Definition: memory.h:28
void * memCalloc(size_t, size_t)
Definition: memory.c:818
#define SESSION_LIVETIME
Definition: session.h:33
void hashCleanup(Hash)
Definition: cleanup.c:35

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Session applicationSessionGet ( Application  ,
const char *   
)

now get the session if not expired

update livetime of session if found

Definition at line 36 of file session_get.c.

References hashAdd(), hashDelete(), and SESSION_LIVETIME.

Referenced by applicationAdapterHttpUpdate().

37 {
38  Session sess = NULL;
39  int index;
40 
41  if (NULL != sid) {
42  /**
43  * now get the session if not expired
44  */
45  for (index=0; index<SESSION_LIVETIME; index++) {
46  sess = (Session)hashDelete(
47  (this->active_sessions)[index], sid, 36);
48  if (NULL != sess) {
49  break;
50  }
51  }
52 
53  /**
54  * update livetime of session if found
55  */
56  if (NULL != sess) {
57  sess->livetime = this->session_time_ofs + SESSION_LIVETIME;
58  hashAdd((this->active_sessions)[0], sess);
59  }
60  }
61 
62  return sess;
63 }
void * hashDelete(Hash, const char *, size_t)
Definition: hash/delete.c:48
#define SESSION_LIVETIME
Definition: session.h:33
void * hashAdd(Hash, void *)
Definition: add.c:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Session applicationSessionStart ( Application  )

Definition at line 36 of file session_start.c.

References hashAdd().

Referenced by applicationAdapterHttpUpdate().

37 {
38  Session sess = new(Session);
39 
40  hashAdd((this->active_sessions)[0], sess);
41 
42  return sess;
43 }
void * hashAdd(Hash, void *)
Definition: add.c:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void applicationSessionStop ( Application  ,
Session   
)

Definition at line 35 of file session_stop.c.

References hashDeleteByVal(), and SESSION_LIVETIME.

36 {
37  int index = SESSION_LIVETIME -
38  (session->livetime - this->session_time_ofs);
39 
40  if (SESSION_LIVETIME > index) {
41  hashDeleteByVal((this->active_sessions)[index], session->hash);
42  }
43 }
void * hashDeleteByVal(Hash, unsigned long)
Definition: hash/delete.c:59
#define SESSION_LIVETIME
Definition: session.h:33

+ Here is the call graph for this function:

int applicationUpdatePassword ( Application  ,
Credential  ,
User   
)

Definition at line 41 of file update_password.c.

References CRED_PWD, FALSE, hash_pw(), HASH_SIZE, indexUuid(), MEM_FREE, SALT_SIZE, storageUpdate(), and TRUE.

Referenced by applicationCreateUser().

45 {
46  unsigned char hash_data[SALT_SIZE+HASH_SIZE];
47  unsigned char * salt = NULL;
48  unsigned char * hash = hash_data+SALT_SIZE;
49  Uuid index;
50 
51  if (FALSE == hash_pw(
52  CRED_PWD(cred).pass,
53  CRED_PWD(cred).npass,
54  hash,
55  &salt)) {
56  return FALSE;
57  }
58 
59  memcpy(hash_data, salt, SALT_SIZE);
60  MEM_FREE(salt);
61 
62  index = indexUuid(user, this->user_namespace);
64  this->passwords,
65  (char *)(index->uuid).value,
66  sizeof((index->uuid).value),
67  (char *)hash_data,
68  SALT_SIZE + HASH_SIZE);
69  delete(index);
70 
71  return TRUE;
72 }
#define MEM_FREE(seg)
Definition: memory.h:28
StoragePutResult storageUpdate(Storage, char *, size_t, char *, size_t)
#define SALT_SIZE
Definition: auth/storage.h: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
Uuid indexUuid(void *, Uuid)
Definition: indexable.c:33
#define CRED_PWD(c)
Definition: credential.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Uuid applicationUpdateUser ( Application  ,
User   
)

Definition at line 43 of file update_user.c.

References indexUuid(), MEM_FREE, serialize(), SPR_OK, storageUpdate(), and uuidZero.

Referenced by controllerUserUpdate().

46 {
47  char * user_serialized;
48  size_t nuser_serialized;
49  Uuid index;
50 
51  index = indexUuid(user, this->user_namespace);
52  serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
53 
54  if (SPR_OK != storageUpdate(
55  this->users,
56  (char *)(index->uuid).value,
57  sizeof((index->uuid).value),
58  user_serialized,
59  nuser_serialized))
60  {
61  return uuidZero;
62  }
63 
64  MEM_FREE(user_serialized);
65 
66  return index;
67 }
#define MEM_FREE(seg)
Definition: memory.h:28
StoragePutResult storageUpdate(Storage, char *, size_t, char *, size_t)
Uuid uuidZero
void serialize(void *, unsigned char **, size_t *)
Definition: serializable.c:32
Uuid indexUuid(void *, Uuid)
Definition: indexable.c:33

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CLASS ( Application  )

Definition at line 45 of file application.h.

45  {
46  Hash * active_sessions;
47  time_t session_time_ofs;
48 
49  Auth auth;
50 
51  struct randval * val;
52 
53  Storage users;
54  Storage passwords;
55  Storage roles;
56 
57  Uuid user_namespace;
58 
59  Hash roles_user_index;
60  Hash roles_resource_index;
61 
62  const char * version;
63  const char * loc;
64 };