]> asedeno.scripts.mit.edu Git - PuTTY_svn.git/commitdiff
Get rid of the error-return mechanism from x11_init.
authorSimon Tatham <anakin@pobox.com>
Sun, 17 Nov 2013 14:05:23 +0000 (14:05 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 17 Nov 2013 14:05:23 +0000 (14:05 +0000)
Now that it doesn't actually make a network connection because that's
deferred until after the X authorisation exchange, there's no point in
having it return an error message and write the real output through a
pointer argument. Instead, we can just have it return xconn directly
and simplify the call sites.

git-svn-id: http://svn.tartarus.org/sgt/putty@10081 cda61777-01e9-0310-a592-d414129be87e

ssh.c
ssh.h
x11fwd.c

diff --git a/ssh.c b/ssh.c
index ec05f0ac82b372ef40546881b808ff81f3057a88..ee7fb44e33f36cf4c23de1dcf9beaae8ab9cf48e 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -4887,34 +4887,22 @@ static void ssh1_smsg_x11_open(Ssh ssh, struct Packet *pktin)
                    PKT_INT, remoteid, PKT_END);
        logevent("Rejected X11 connect request");
     } else {
-        char *err;
-
        c = snew(struct ssh_channel);
        c->ssh = ssh;
 
-       if ((err = x11_init(&c->u.x11.xconn, ssh->x11authtree, c,
-                            NULL, -1)) != NULL) {
-           logeventf(ssh, "Opening X11 forward connection failed: %s", err);
-            sfree(err);
-           sfree(c);
-           send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
-                       PKT_INT, remoteid, PKT_END);
-       } else {
-           logevent
-               ("Opening X11 forward connection succeeded");
-           c->remoteid = remoteid;
-           c->halfopen = FALSE;
-           c->localid = alloc_channel_id(ssh);
-           c->closes = 0;
-           c->pending_eof = FALSE;
-           c->throttling_conn = 0;
-           c->type = CHAN_X11; /* identify channel type */
-           add234(ssh->channels, c);
-           send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_CONFIRMATION,
-                       PKT_INT, c->remoteid, PKT_INT,
-                       c->localid, PKT_END);
-           logevent("Opened X11 forward channel");
-       }
+       c->u.x11.xconn = x11_init(ssh->x11authtree, c, NULL, -1);
+        c->remoteid = remoteid;
+        c->halfopen = FALSE;
+        c->localid = alloc_channel_id(ssh);
+        c->closes = 0;
+        c->pending_eof = FALSE;
+        c->throttling_conn = 0;
+        c->type = CHAN_X11;    /* identify channel type */
+        add234(ssh->channels, c);
+        send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_CONFIRMATION,
+                    PKT_INT, c->remoteid, PKT_INT,
+                    c->localid, PKT_END);
+        logevent("Opened X11 forward channel");
     }
 }
 
@@ -7563,7 +7551,6 @@ static void ssh2_msg_channel_open(Ssh ssh, struct Packet *pktin)
 
     if (typelen == 3 && !memcmp(type, "x11", 3)) {
        char *addrstr;
-       char *x11err;
 
        ssh_pkt_getstring(pktin, &peeraddr, &peeraddrlen);
        addrstr = snewn(peeraddrlen+1, char);
@@ -7576,14 +7563,12 @@ static void ssh2_msg_channel_open(Ssh ssh, struct Packet *pktin)
 
        if (!ssh->X11_fwd_enabled)
            error = "X11 forwarding is not enabled";
-       else if ((x11err = x11_init(&c->u.x11.xconn, ssh->x11authtree, c,
-                                   addrstr, peerport)) != NULL) {
-           logeventf(ssh, "Local X11 connection failed: %s", x11err);
-            sfree(x11err);
-           error = "Unable to open an X11 connection";
-       } else {
-           logevent("Opening X11 forward connection succeeded");
+       else {
+            c->u.x11.xconn = x11_init(ssh->x11authtree, c,
+                                      addrstr, peerport);
            c->type = CHAN_X11;
+
+            logevent("Opened X11 forward channel");
        }
 
        sfree(addrstr);
diff --git a/ssh.h b/ssh.h
index f73a3738ca85d41a9cbc1dd903e1550089c34893..675a509ed97aff36f3a720d22aff2fc8cb9b33c3 100644 (file)
--- a/ssh.h
+++ b/ssh.h
@@ -418,8 +418,7 @@ void x11_free_display(struct X11Display *disp);
 struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype);
 void x11_free_fake_auth(struct X11FakeAuth *auth);
 struct X11Connection;                  /* opaque outside x11fwd.c */
-extern char *x11_init(struct X11Connection **, tree234 *authtree,
-                      void *, const char *, int);
+struct X11Connection *x11_init(tree234 *authtree, void *, const char *, int);
 extern void x11_close(struct X11Connection *);
 extern int x11_send(struct X11Connection *, char *, int);
 extern void x11_send_eof(struct X11Connection *s);
index ea9a157a194be18e54908a22dc1b062eb8cdf74b..54656f3a457e4091d3a66298b1e8e654de414717 100644 (file)
--- a/x11fwd.c
+++ b/x11fwd.c
@@ -649,14 +649,11 @@ int x11_get_screen_number(char *display)
 }
 
 /*
- * Called to set up the raw connection.
- * 
- * On success, returns NULL and fills in *xconnret. On error, returns
- * a dynamically allocated error message string.
+ * Called to set up the X11Connection structure, though this does not
+ * yet connect to an actual server.
  */
-extern char *x11_init(struct X11Connection **xconnret,
-                      tree234 *authtree, void *c,
-                      const char *peeraddr, int peerport)
+struct X11Connection *x11_init(tree234 *authtree, void *c,
+                               const char *peeraddr, int peerport)
 {
     static const struct plug_function_table fn_table = {
        x11_log,
@@ -671,7 +668,7 @@ extern char *x11_init(struct X11Connection **xconnret,
     /*
      * Open socket.
      */
-    xconn = *xconnret = snew(struct X11Connection);
+    xconn = snew(struct X11Connection);
     xconn->fn = &fn_table;
     xconn->auth_protocol = NULL;
     xconn->authtree = authtree;
@@ -698,7 +695,7 @@ extern char *x11_init(struct X11Connection **xconnret,
     xconn->peer_addr = peeraddr ? dupstr(peeraddr) : NULL;
     xconn->peer_port = peerport;
 
-    return NULL;
+    return xconn;
 }
 
 void x11_close(struct X11Connection *xconn)