Greenbone Security Assistant  8.0.0
gsad_session.h File Reference

GSAD user session handling. More...

#include "gsad_user.h"
#include <glib.h>
Include dependency graph for gsad_session.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void session_add_user (const gchar *id, user_t *user)
 Add user to the session "database". More...
 
void session_remove_user (const gchar *id)
 Remove a user from the session "database". More...
 
user_t * session_get_user_by_id (const gchar *id)
 
user_t * session_get_user_by_username (const gchar *username)
 
void session_remove_other_sessions (const gchar *id, user_t *user)
 Removes all session of the user, except the one with the passed id. More...
 
void session_init ()
 

Detailed Description

GSAD user session handling.

Definition in file gsad_session.h.

Function Documentation

◆ session_add_user()

void session_add_user ( const gchar *  id,
user_t *  user 
)

Add user to the session "database".

Parameters
[in]idUnique identifier.
[in]userUser.

Definition at line 147 of file gsad_session.c.

148 {
149  g_mutex_lock (mutex);
150 
152 
154 
155  g_mutex_unlock (mutex);
156 }
static GMutex * mutex
Mutex to prevent concurrent access to the session.
Definition: gsad_session.c:44
void session_add_user_internal(user_t *user)
Definition: gsad_session.c:78
void session_remove_user_internal(const gchar *id)
Definition: gsad_session.c:65
User information structure, for sessions.
Definition: gsad_user.c:42

References mutex, session_add_user_internal(), and session_remove_user_internal().

Referenced by renew_session_gmp(), save_my_settings_gmp(), user_add(), and user_find().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_get_user_by_id()

user_t* session_get_user_by_id ( const gchar *  id)

Find a user by a session identifier

Returns
Return a copy of the user or NULL if not found

Definition at line 97 of file gsad_session.c.

98 {
99  user_t *user;
100 
101  g_mutex_lock (mutex);
102 
104 
105  g_mutex_unlock (mutex);
106 
107  return user;
108 }
user_t * user_copy(user_t *user)
Definition: gsad_user.c:124
static GMutex * mutex
Mutex to prevent concurrent access to the session.
Definition: gsad_session.c:44
user_t * session_get_user_by_id_internal(const gchar *id)
Definition: gsad_session.c:47
User information structure, for sessions.
Definition: gsad_user.c:42

References mutex, session_get_user_by_id_internal(), and user_copy().

Referenced by user_find(), and user_logout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_get_user_by_username()

user_t* session_get_user_by_username ( const gchar *  username)

Find the first user with the username

Returns
Return a copy of the user or NULL if not found

Definition at line 116 of file gsad_session.c.

117 {
118  int index;
119  user_t *user = NULL;
120 
121  g_mutex_lock (mutex);
122 
123  for (index = 0; index < users->len; index++)
124  {
125  user_t *item = (user_t *) g_ptr_array_index (users, index);
126  const gchar *name = user_get_username (item);
127 
128  if (str_equal (name, username))
129  {
130  user = user_copy (item);
131  break;
132  }
133  }
134 
135  g_mutex_unlock (mutex);
136 
137  return user;
138 }
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:157
user_t * user_copy(user_t *user)
Definition: gsad_user.c:124
static GMutex * mutex
Mutex to prevent concurrent access to the session.
Definition: gsad_session.c:44
GPtrArray * users
User session data.
Definition: gsad_session.c:39
User information structure, for sessions.
Definition: gsad_user.c:42

References mutex, str_equal(), user_copy(), user_get_username(), and users.

Referenced by save_user_gmp(), and user_add().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_init()

void session_init ( )

Definition at line 84 of file gsad_session.c.

85 {
86  mutex = g_malloc (sizeof (GMutex));
87  g_mutex_init (mutex);
88  users = g_ptr_array_new ();
89 }
static GMutex * mutex
Mutex to prevent concurrent access to the session.
Definition: gsad_session.c:44
GPtrArray * users
User session data.
Definition: gsad_session.c:39

References mutex, and users.

◆ session_remove_other_sessions()

void session_remove_other_sessions ( const gchar *  id,
user_t *  user 
)

Removes all session of the user, except the one with the passed id.

Parameters
[in]idID of the session to keep
[in]userThe user to logout.

Definition at line 181 of file gsad_session.c.

182 {
183  int index;
184 
185  g_mutex_lock (mutex);
186 
187  for (index = 0; index < users->len; index++)
188  {
189  user_t *item = (user_t *) g_ptr_array_index (users, index);
190 
191  const gchar *itemtoken = user_get_token (item);
192  const gchar *itemname = user_get_username (item);
193  const gchar *username = user_get_username (user);
194 
195  if (str_equal (itemname, username) && !str_equal (id, itemtoken))
196  {
197  g_debug ("%s: logging out user '%s', token '%s'", __FUNCTION__,
198  itemname, itemtoken);
199  g_ptr_array_remove (users, (gpointer) item);
200 
201  user_free (item);
202 
203  index--;
204  }
205  }
206 
207  g_mutex_unlock (mutex);
208 }
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
void user_free(user_t *user)
Definition: gsad_user.c:102
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:157
static GMutex * mutex
Mutex to prevent concurrent access to the session.
Definition: gsad_session.c:44
const gchar * user_get_token(user_t *user)
Definition: gsad_user.c:175
GPtrArray * users
User session data.
Definition: gsad_session.c:39
User information structure, for sessions.
Definition: gsad_user.c:42

References mutex, str_equal(), user_free(), user_get_token(), user_get_username(), and users.

Referenced by save_my_settings_gmp(), and save_user_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_remove_user()

void session_remove_user ( const gchar *  id)

Remove a user from the session "database".

Parameters
[in]idUnique identifier.

Definition at line 164 of file gsad_session.c.

165 {
166  g_mutex_lock (mutex);
167 
169 
170  g_mutex_unlock (mutex);
171 }
static GMutex * mutex
Mutex to prevent concurrent access to the session.
Definition: gsad_session.c:44
void session_remove_user_internal(const gchar *id)
Definition: gsad_session.c:65

References mutex, and session_remove_user_internal().

Referenced by user_add(), user_find(), and user_logout().

Here is the call graph for this function:
Here is the caller graph for this function: