taskrambler  0.1.9
Web server and task management solution.
login.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "auth.h"
#include "uuid.h"
#include "storage/storage.h"
#include "interface/serializable.h"
#include "interface/indexable.h"
#include "utils/memory.h"
#include "application/application.h"
+ Include dependency graph for login.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

int applicationLogin (Application this, Credential credential, Session session)
 

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 login.c.

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 23 of file login.c.

Function Documentation

int applicationLogin ( Application  this,
Credential  credential,
Session  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: