chiark / gitweb /
server/tripe.h: Allow `break' from FOREACH_PEER.
[tripe] / server / admin.c
index a339167c6374c0a649e37e6d654c21789247e4a1..8eb5ec3ca5a16d3565739ffdea48ff553c75e13f 100644 (file)
@@ -1793,7 +1793,7 @@ static void acmd_peerinfo(admin *a, unsigned ac, char *av[])
   if ((p = a_findpeer(a, av[0])) != 0) {
     ps = p_spec(p);
     a_info(a, "tunnel=%s", ps->tops->name, A_END);
-    a_info(a, "key=%s", ps->tag, A_END);
+    a_info(a, "key=%s", p_tag(p), A_END);
     a_info(a, "keepalive=%lu", ps->t_ka, A_END);
     a_ok(a);
   }
@@ -2213,19 +2213,21 @@ void a_daemon(void) { flags |= F_DAEMON; }
  * Arguments:  @const char *name@ = socket name to create
  *             @uid_t u@ = user to own the socket
  *             @gid_t g@ = group to own the socket
+ *             @mode_t m@ = permissions to set on the socket
  *
  * Returns:    ---
  *
  * Use:                Creates the admin listening socket.
  */
 
-void a_init(const char *name, uid_t u, gid_t g)
+void a_init(const char *name, uid_t u, gid_t g, mode_t m)
 {
   int fd;
   int n = 5;
   struct sockaddr_un sun;
   struct sigaction sa;
   size_t sz;
+  mode_t omask;
 
   /* --- Create services table --- */
 
@@ -2243,7 +2245,7 @@ void a_init(const char *name, uid_t u, gid_t g)
 
   /* --- Attempt to bind to the socket --- */
 
-  umask(0077);
+  omask = umask(0077);
 again:
   if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
     die(EXIT_FAILURE, "couldn't create socket: %s", strerror(errno));
@@ -2274,12 +2276,15 @@ again:
     close(fd);
     goto again;
   }
-  chmod(sun.sun_path, 0600);
   if (chown(sun.sun_path, u, g)) {
-    T( trace(T_ADMIN,
-            "admin: failed to give away socket: %s",
-            strerror(errno)); )
+    die(EXIT_FAILURE, "failed to set socket owner: %s",
+       strerror(errno));
   }
+  if (chmod(sun.sun_path, m)) {
+    die(EXIT_FAILURE, "failed to set socket permissions: %s",
+       strerror(errno));
+  }
+  umask(omask);
   fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
   if (listen(fd, 5))
     die(EXIT_FAILURE, "couldn't listen on socket: %s", strerror(errno));