From 1d3da6d18ffefaf4cac0292a4f081801f912a842 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Mon, 24 Jun 2013 14:39:34 +0200 Subject: [PATCH] Addition of users_update Fixed warning in service_alloc Correct comment in gateway.c --- core/depend.mk | 3 ++- core/gateway.c | 2 +- core/service.c | 1 + core/users.c | 17 +++++++++++++++++ include/users.h | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/depend.mk b/core/depend.mk index b8d8841f6..8c19ccd8e 100644 --- a/core/depend.mk +++ b/core/depend.mk @@ -334,7 +334,8 @@ service.o: service.c /usr/include/stdio.h /usr/include/features.h \ ../include/service.h ../include/spinlock.h ../include/thread.h \ /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ /usr/include/bits/setjmp.h ../include/dcb.h ../include/buffer.h \ - ../include/server.h ../include/router.h ../include/modules.h + ../include/server.h ../include/router.h ../include/modules.h \ + ../include/users.h ../include/hashtable.h ../include/atomic.h server.o: server.c /usr/include/stdio.h /usr/include/features.h \ /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \ diff --git a/core/gateway.c b/core/gateway.c index 897b0b644..827aab5ac 100644 --- a/core/gateway.c +++ b/core/gateway.c @@ -242,7 +242,7 @@ char buf[1024], *home, *cnf_file = NULL; poll_init(); /* - * Start the service that was created above + * Start the services that were created above */ printf("Started %d services\n", serviceStartAll()); diff --git a/core/service.c b/core/service.c index 93352b5e6..36c9ffbe7 100644 --- a/core/service.c +++ b/core/service.c @@ -37,6 +37,7 @@ #include #include #include +#include static SPINLOCK service_spin = SPINLOCK_INIT; static SERVICE *allServices = NULL; diff --git a/core/users.c b/core/users.c index fa5f265e3..c30ceb955 100644 --- a/core/users.c +++ b/core/users.c @@ -130,3 +130,20 @@ char atomic_add(&users->stats.n_fetches, 1); return hashtable_fetch(users->data, user); } + +/** + * Change the password data associated with a user in the users + * table. + * + * @param users The users table + * @param user The user name + * @param auth The new authentication details + * @return Number of users updated + */ +int +users_update(USERS *users, char *user, char *auth) +{ + if (hashtable_delete(users->data, user) == 0) + return 0; + return hashtable_add(users->data, user, auth); +} diff --git a/include/users.h b/include/users.h index 4f209ba4a..441091090 100644 --- a/include/users.h +++ b/include/users.h @@ -56,4 +56,5 @@ extern void users_free(USERS *); /**< Free a users table */ extern int users_add(USERS *, char *, char *); /**< Add a user to the users table */ extern int users_delete(USERS *, char *); /**< Delete a user from the users table */ extern char *users_fetch(USERS *, char *); /**< Fetch the authentication data for a user */ +extern int users_update(USERS *, char *, char *); /**< Change the password data for a user in the users table */ #endif