chiark / gitweb /
disorder setup-guest enforces mail_sender requirement
[disorder] / clients / authorize.c
index e38aed48a15ef0479f09a5ae1c20eb8f164db7aa..c442d23730b55f4b3b28a4bc103fce00e2aff982 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
 /*
  * This file is part of DisOrder
- * Copyright (C) 2005 Richard Kettlewell
+ * Copyright (C) 2005, 2007 Richard Kettlewell
  *
  * 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
  *
  * 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
 #include <fcntl.h>
 #include <stdio.h>
 
 #include <fcntl.h>
 #include <stdio.h>
 
+#include "client.h"
 #include "authorize.h"
 #include "log.h"
 #include "configuration.h"
 #include "printf.h"
 #include "hex.h"
 
 #include "authorize.h"
 #include "log.h"
 #include "configuration.h"
 #include "printf.h"
 #include "hex.h"
 
-int authorize(const char *user) {
+/** @brief Create a DisOrder login for the calling user, called @p user
+ * @param client DisOrder client
+ * @param user Username to create (UTF-8)
+ * @param rights Initial rights or NULL for default
+ * @return 0 on success, non-0 on error
+ */
+int authorize(disorder_client *client, const char *user, const char *rights) {
   uint8_t pwbin[10];
   const struct passwd *pw, *jbpw;
   gid_t jbgid;
   uint8_t pwbin[10];
   const struct passwd *pw, *jbpw;
   gid_t jbgid;
@@ -60,7 +67,7 @@ int authorize(const char *user) {
   gcry_randomize(pwbin, sizeof pwbin, GCRY_STRONG_RANDOM);
   pwhex = hex(pwbin, sizeof pwbin);
 
   gcry_randomize(pwbin, sizeof pwbin, GCRY_STRONG_RANDOM);
   pwhex = hex(pwbin, sizeof pwbin);
 
-  /* create config.USER, to end up with mode 440 user:jukebox */
+  /* create config.USER, to end up with mode 400 user:<anything> */
   if((fd = open(t, O_WRONLY|O_CREAT|O_EXCL, 0600)) < 0)
     fatal(errno, "error creating %s", t);
   if(fchown(fd, pw->pw_uid, -1) < 0)
   if((fd = open(t, O_WRONLY|O_CREAT|O_EXCL, 0600)) < 0)
     fatal(errno, "error creating %s", t);
   if(fchown(fd, pw->pw_uid, -1) < 0)
@@ -75,21 +82,10 @@ int authorize(const char *user) {
   if(rename(t, c) < 0)
     fatal(errno, "error renaming %s to %s", t, c);
 
   if(rename(t, c) < 0)
     fatal(errno, "error renaming %s to %s", t, c);
 
-  /* append to config.private.  We might create it along the way (though this
-   * is unlikely) in which case it had better be 640 root:jukebox */
-  if(!(c = config_private()))
-    fatal(0, "cannot determine private config file");
-  if((fd = open(c, O_WRONLY|O_APPEND|O_CREAT, 0600)) < 0)
-    fatal(errno, "error opening %s", c);
-  if(fchown(fd, 0, jbgid) < 0)
-    fatal(errno, "error chowning %s", c);
-  if(fchmod(fd, 0640) < 0)
-    fatal(errno, "error chmoding %s", t);
-  if(!(fp = fdopen(fd, "a")))
-    fatal(errno, "error calling fdopen");
-  if(fprintf(fp, "allow %s %s\n", user, pwhex) < 0
-     || fclose(fp) < 0)
-    fatal(errno, "error appending to %s", c);
+  /* create the user on the server */
+  if(disorder_adduser(client, user, pwhex, rights))
+    return -1;
+
   return 0;
 }
 
   return 0;
 }
 
@@ -101,4 +97,3 @@ fill-column:79
 indent-tabs-mode:nil
 End:
 */
 indent-tabs-mode:nil
 End:
 */
-/* arch-tag:BHATzWNN/1ccK/g2pbA63Q */