~ubuntu-branches/debian/stretch/screen/stretch

« back to all changes in this revision

Viewing changes to teln.c

  • Committer: Package Import Robot
  • Author(s): Axel Beckert
  • Date: 2015-06-17 21:57:18 UTC
  • mfrom: (7.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20150617215718-mmj4dpghyl5a0ipy
Tags: 4.3.0-2
* Upload to unstable again.
* Re-add debian/dirs with /etc/tmpfiles.d/ and add a comment why screen
  ships an empty directory.
  + Fixes regression introduced in 4.2.1-4: If systemd is not installed
    and screen is either setuid or neither setuid nor setgid,
    /var/lib/dpkg/info/screen.postinst bailed out with "16:
    /var/lib/dpkg/info/screen.postinst: cannot create
    /etc/tmpfiles.d/screen-cleanup.conf: Directory nonexistent".
  + See comment in debian/dirs for more detailed reasoning.
* No more ship /lib/systemd/system/screen-cleanup.service in the package
  but link it to /dev/null in postinst and remove the link again in
  postrm. (LP: #1462692)
* Add fixed bugs reported in Ubuntu to previous changelog entry.
* Apply wrap-and-sort.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
static void TelReply __P((struct win *, char *, int));
49
49
static void TelDocmd __P((struct win *, int, int));
50
50
static void TelDosub __P((struct win *));
 
51
 
51
52
// why TEL_DEFPORT has "
52
 
#define TEL_DEFPORT     "23"
 
53
#define TEL_DEFPORT     "23"
53
54
#define TEL_CONNECTING  (-2)
54
55
 
55
56
#define TC_IAC          255
108
109
 
109
110
int
110
111
TelOpenAndConnect(struct win *p) {
111
 
  int fd, on = 1;
112
 
  char buf[256];
113
 
 
114
 
  struct addrinfo hints, *res0, *res;
115
 
 
116
 
  if (!(p->w_cmdargs[1])) {
117
 
    Msg(0, "Usage: screen //telnet host [port]");
118
 
    return -1;
119
 
  }
120
 
 
121
 
  memset(&hints, 0, sizeof(hints));
122
 
  hints.ai_family = af;
123
 
  hints.ai_socktype = SOCK_STREAM;
124
 
  hints.ai_protocol = IPPROTO_TCP;
125
 
  if(getaddrinfo(p->w_cmdargs[1], p->w_cmdargs[2] ? p->w_cmdargs[2] : TEL_DEFPORT,
126
 
                 &hints, &res0)) {
127
 
     Msg(0, "unknown host: %s", p->w_cmdargs[1]);
128
 
     return -1;
129
 
  }
130
 
 
131
 
  for(res = res0; res; res = res->ai_next) {
132
 
    if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
133
 
      if(res->ai_next)
134
 
        continue;
135
 
      else {
136
 
        Msg(errno, "TelOpenAndConnect: socket");
137
 
        freeaddrinfo(res0);
138
 
        return -1;
139
 
      }
140
 
    }
141
 
 
142
 
    if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
143
 
      Msg(errno, "TelOpenAndConnect: setsockopt SO_OOBINLINE");
144
 
 
145
 
    if (p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT))
146
 
      snprintf(buf, 256, "Trying %s %s...", p->w_cmdargs[1], p->w_cmdargs[2]);
147
 
    else
148
 
      snprintf(buf, 256, "Trying %s...", p->w_cmdargs[1]);
149
 
    WriteString(p, buf, strlen(buf));
150
 
    if (connect(fd, res->ai_addr, res->ai_addrlen)) {
151
 
      if (errno == EINPROGRESS) {
152
 
       p->w_telstate = TEL_CONNECTING;
153
 
       p->w_telconnev.fd = fd;
154
 
       p->w_telconnev.handler = tel_connev_fn;
155
 
       p->w_telconnev.data = (char *)p;
156
 
       p->w_telconnev.type = EV_WRITE;
157
 
       p->w_telconnev.pri = 1;
158
 
       debug("telnet connect in progress...\n");
159
 
       evenq(&p->w_telconnev);
160
 
      }
161
 
      else {
162
 
        close(fd);
163
 
       if(res->ai_next)
164
 
         continue;
165
 
       else {
166
 
          Msg(errno, "TelOpenAndConnect: connect");
167
 
          freeaddrinfo(res0);
168
 
          return -1;
169
 
       }
170
 
      }
171
 
    }
172
 
    else
173
 
      WriteString(p, "connected.\r\n", 12);
174
 
    if (!(p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT)))
175
 
      TelReply(p, (char *)tn_init, sizeof(tn_init));
176
 
    p->w_ptyfd = fd;
177
 
    memcpy(&p->w_telsa, &res->ai_addr, sizeof(res->ai_addr));
178
 
    freeaddrinfo(res0);
179
 
    return 0;
180
 
  }
181
 
  return -1;
 
112
        int fd, on = 1;
 
113
        char buf[256];
 
114
 
 
115
        struct addrinfo hints, *res0, *res;
 
116
 
 
117
        if (!(p->w_cmdargs[1])) {
 
118
                Msg(0, "Usage: screen //telnet host [port]");
 
119
                return -1;
 
120
        }
 
121
 
 
122
        memset(&hints, 0, sizeof(hints));
 
123
        hints.ai_family = af;
 
124
        hints.ai_socktype = SOCK_STREAM;
 
125
        hints.ai_protocol = IPPROTO_TCP;
 
126
 
 
127
        if(getaddrinfo(p->w_cmdargs[1], p->w_cmdargs[2] ? p->w_cmdargs[2] : TEL_DEFPORT, &hints, &res0)) {
 
128
                Msg(0, "unknown host: %s", p->w_cmdargs[1]);
 
129
                return -1;
 
130
        }
 
131
 
 
132
        for(res = res0; res; res = res->ai_next) {
 
133
                if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
 
134
                        if(res->ai_next)
 
135
                                continue;
 
136
                        else {
 
137
                                Msg(errno, "TelOpenAndConnect: socket");
 
138
                                freeaddrinfo(res0);
 
139
                                return -1;
 
140
                        }
 
141
                }
 
142
 
 
143
                if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
 
144
                        Msg(errno, "TelOpenAndConnect: setsockopt SO_OOBINLINE");
 
145
 
 
146
                if (p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT))
 
147
                        snprintf(buf, 256, "Trying %s %s...", p->w_cmdargs[1], p->w_cmdargs[2]);
 
148
                else
 
149
                        snprintf(buf, 256, "Trying %s...", p->w_cmdargs[1]);
 
150
 
 
151
                WriteString(p, buf, strlen(buf));
 
152
                if (connect(fd, res->ai_addr, res->ai_addrlen)) {
 
153
                        if (errno == EINPROGRESS) {
 
154
                                p->w_telstate = TEL_CONNECTING;
 
155
                                p->w_telconnev.fd = fd;
 
156
                                p->w_telconnev.handler = tel_connev_fn;
 
157
                                p->w_telconnev.data = (char *)p;
 
158
                                p->w_telconnev.type = EV_WRITE;
 
159
                                p->w_telconnev.pri = 1;
 
160
                                debug("telnet connect in progress...\n");
 
161
                                evenq(&p->w_telconnev);
 
162
                        }
 
163
                        else {
 
164
                                close(fd);
 
165
                                if(res->ai_next)
 
166
                                        continue;
 
167
                                else {
 
168
                                        Msg(errno, "TelOpenAndConnect: connect");
 
169
                                        freeaddrinfo(res0);
 
170
                                        return -1;
 
171
                                }
 
172
                        }
 
173
                }
 
174
                else
 
175
                        WriteString(p, "connected.\r\n", 12);
 
176
 
 
177
                if (!(p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT)))
 
178
                        TelReply(p, (char *)tn_init, sizeof(tn_init));
 
179
 
 
180
                p->w_ptyfd = fd;
 
181
                memcpy(&p->w_telsa, &res->ai_addr, sizeof(res->ai_addr));
 
182
                freeaddrinfo(res0);
 
183
                return 0;
 
184
        }
 
185
        return -1;
182
186
}
183
187
 
184
188
int