chiark / gitweb /
lib/client.[ch]: Delete `disorder_client_af' which is no longer used.
[disorder] / lib / client.c
index 52c5b6851180005a804ee5cf520f0087918c8bd2..fb1b1ccbf6923880ee5ce55fc5573c64bfdba3c2 100644 (file)
@@ -41,9 +41,6 @@
 #if HAVE_NETDB_H
 # include <netdb.h>
 #endif
-#if HAVE_PCRE_H
-# include <pcre.h>
-#endif
 
 #include "log.h"
 #include "mem.h"
@@ -85,6 +82,8 @@ struct disorder_client {
   int open;
   /** @brief Socket I/O context */
   struct socketio sio;
+  /** @brief Whether to try to open a privileged connection */
+  int trypriv;
 };
 
 /** @brief Create a new client
@@ -100,12 +99,37 @@ disorder_client *disorder_new(int verbose) {
 
   c->verbose = verbose;
   c->family = -1;
+  c->trypriv = 1;
   return c;
 }
 
-/** @brief Return the address family used by this client */
-int disorder_client_af(disorder_client *c) {
-  return c->family;
+/** @brief Don't try to make a privileged connection
+ * @param c Client
+ *
+ * You must call this before any of the connection functions (e.g.,
+ * disorder_connect(), disorder_connect_user()), if at all.
+ */
+void disorder_force_unpriv(disorder_client *c) {
+  assert(!c->open);
+  c->trypriv = 0;
+}
+
+/** @brief Determine the local socket address of this client */
+int disorder_client_sockname(disorder_client *c,
+                            struct sockaddr *sa, socklen_t *len_inout) {
+  int rc;
+  if((rc = getsockname(c->sio.sd, sa, len_inout)))
+    disorder_error(errno, "failed to read client socket name");
+  return rc;
+}
+
+/** @brief Determine the remote peer address for this client */
+int disorder_client_peername(disorder_client *c,
+                            struct sockaddr *sa, socklen_t *len_inout) {
+  int rc;
+  if((rc = getpeername(c->sio.sd, sa, len_inout)))
+    disorder_error(errno, "failed to read client socket name");
+  return rc;
 }
 
 /** @brief Read a response line
@@ -432,7 +456,9 @@ int disorder_connect_generic(struct config *conf,
   socklen_t salen;
   char errbuf[1024];
 
-  if((salen = find_server(conf, &sa, &c->ident)) == (socklen_t)-1)
+  if((salen = disorder_find_server(conf,
+                                  (c->trypriv ? 0 : DISORDER_FS_NOTPRIV),
+                                  &sa, &c->ident)) == (socklen_t)-1)
     return -1;
   c->input = 0;
   c->output = 0;