chiark / gitweb /
'confirm' now logs the user in (and sends back their username so the
[disorder] / lib / trackdb.c
index dc4cd4eda49009de2a41cd90426e5dd56bdcc309..8239a698ec89bea05f8eae3141291b37618fd689 100644 (file)
@@ -17,7 +17,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
  */
-/** @file server/trackdb.c
+/** @file lib/trackdb.c
  * @brief Track database
  *
  * This file is getting in desparate need of splitting up...
@@ -64,7 +64,7 @@
 #include "hash.h"
 #include "unicode.h"
 #include "unidata.h"
-#include "mime.h"
+#include "base64.h"
 
 #define RESCAN "disorder-rescan"
 #define DEADLOCK "disorder-deadlock"
@@ -113,7 +113,7 @@ DB *trackdb_prefsdb;
  * - Values are UTF-8(NFC(unicode(path name)))
  * - There can be more than one value per key
  * - Presence of key,value means that path matches the search terms
- * - Only tracks fond in @ref tracks_tracksdb are represented here
+ * - Only tracks fond in @ref trackdb_tracksdb are represented here
  * - This database can be reconstructed, it contains no user data
  */
 DB *trackdb_searchdb;
@@ -349,7 +349,7 @@ static DB *open_db(const char *path,
 }
 
 /** @brief Open track databases
- * @param Flags flags word
+ * @param flags Flags flags word
  *
  * @p flags should have one of:
  * - @p TRACKDB_NO_UPGRADE, if no upgrade should be attempted
@@ -2493,7 +2493,7 @@ static int one_old_user(const char *user, const char *password,
     rights_type r;
 
     parse_rights(config->default_rights, &r, 1);
-    r &= (RIGHT_SCRATCH__MASK|RIGHT_MOVE__MASK|RIGHT_REMOVE__MASK);
+    r &= ~(rights_type)(RIGHT_SCRATCH__MASK|RIGHT_MOVE__MASK|RIGHT_REMOVE__MASK);
     r |= (RIGHT_ADMIN|RIGHT_RESCAN
           |RIGHT_SCRATCH_ANY|RIGHT_MOVE_ANY|RIGHT_REMOVE_ANY);
     rights = rights_string(r);
@@ -2574,7 +2574,8 @@ const char *trackdb_get_password(const char *user) {
  * @param user Username
  * @param password Password or NULL
  * @param rights Initial rights
- * @param email Email address
+ * @param email Email address or NULL
+ * @param confirmation Confirmation string or NULL
  * @return 0 on success, non-0 on error
  */
 int trackdb_adduser(const char *user,
@@ -2601,7 +2602,7 @@ int trackdb_adduser(const char *user,
 
 /** @brief Delete a user
  * @param user User to delete
- * @param 0 on success, non-0 if the user didn't exist anyway
+ * @return 0 on success, non-0 if the user didn't exist anyway
  */
 int trackdb_deluser(const char *user) {
   int e;
@@ -2704,11 +2705,20 @@ char **trackdb_listusers(void) {
   return v->vec;
 }
 
+/** @brief Confirm a user registration
+ * @param user Username
+ * @param confirmation Confirmation string
+ * @param rightsp Where to put user rights
+ * @param tid Transaction ID
+ * @return 0 on success, non-0 on error
+ */
 static int trackdb_confirm_tid(const char *user, const char *confirmation,
+                               rights_type *rightsp,
                                DB_TXN *tid) {
   const char *stored_confirmation;
   struct kvp *k;
   int e;
+  const char *rights;
   
   if((e = trackdb_getdata(trackdb_usersdb, user, &k, tid)))
     return e;
@@ -2717,6 +2727,12 @@ static int trackdb_confirm_tid(const char *user, const char *confirmation,
     /* DB claims -30,800 to -30,999 so -1 should be a safe bet */
     return -1;
   }
+  if(!(rights = kvp_get(k, "rights"))) {
+    error(0, "no rights for unconfirmed user '%s'", user);
+    return -1;
+  }
+  if(parse_rights(rights, rightsp, 1))
+    return -1;
   if(strcmp(confirmation, stored_confirmation)) {
     error(0, "wrong confirmation string for user '%s'", user);
     return -1;
@@ -2729,12 +2745,14 @@ static int trackdb_confirm_tid(const char *user, const char *confirmation,
 /** @brief Confirm a user registration
  * @param user Username
  * @param confirmation Confirmation string
+ * @param rightsp Where to put user rights
  * @return 0 on success, non-0 on error
  */
-int trackdb_confirm(const char *user, const char *confirmation) {
+int trackdb_confirm(const char *user, const char *confirmation,
+                    rights_type *rightsp) {
   int e;
 
-  WITH_TRANSACTION(trackdb_confirm_tid(user, confirmation, tid));
+  WITH_TRANSACTION(trackdb_confirm_tid(user, confirmation, rightsp, tid));
   switch(e) {
   case 0:
     info("registration confirmed for user '%s'", user);