~ubuntu-branches/ubuntu/karmic/libfs/karmic

« back to all changes in this revision

Viewing changes to src/FSOpenServ.c

  • Committer: Bazaar Package Importer
  • Author(s): Brice Goglin
  • Date: 2009-07-27 17:21:16 UTC
  • mfrom: (1.1.3 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090727172116-jeovucf7k0k0smp2
Tags: 2:1.0.2-1
* New upstream release.
* Add a link to www.X.org and a reference to the upstream module
  in the long description.
* Add README.source, bump Standards-Version to 3.8.2.
* Move the -dbg package to section debug.
* Add myself to Uploaders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Xorg: FSOpenServ.c,v 1.4 2001/02/09 02:03:25 xorgcvs Exp $ */
2
 
 
3
 
/* @(#)FSOpenServ.c     4.1     91/05/02
 
1
/*
4
2
 * Copyright 1990 Network Computing Devices;
5
3
 * Portions Copyright 1987 by Digital Equipment Corporation
6
4
 *
24
22
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 
25
23
 * SOFTWARE.
26
24
 */
27
 
/* $XFree86: xc/lib/FS/FSOpenServ.c,v 1.8tsi Exp $ */
28
25
 
29
26
/*
30
27
 
63
60
#include        "FSlibint.h"
64
61
#include        <X11/Xtrans/Xtrans.h>
65
62
 
66
 
int         _FSdebug = 0;
 
63
static int _FSdebug = 0;
67
64
 
68
65
static fsReq _dummy_request = {
69
66
    0, 0, 0
91
88
    FSServer    *svr,
92
89
    char        *setup)
93
90
{
94
 
 
95
 
    _FSDisconnectServer(svr->trans_conn);
 
91
    if (svr->trans_conn)
 
92
        _FSDisconnectServer(svr->trans_conn);
96
93
    _FSFreeServerStructure(svr);
97
94
    FSfree(setup);
98
95
    errno = ENOMEM;
111
108
    int         endian;
112
109
    fsConnClientPrefix client;
113
110
    fsConnSetup prefix;
114
 
    char       *setup;
 
111
    char       *setup = NULL;
115
112
    fsConnSetupAccept conn;
116
 
    char       *auth_data;
117
 
    char       *alt_data,
 
113
    char       *auth_data = NULL;
 
114
    char       *alt_data = NULL,
118
115
               *ad;
119
 
    AlternateServer *alts;
 
116
    AlternateServer *alts = NULL;
120
117
    int         altlen;
121
118
    char       *vendor_string;
122
119
    unsigned long        setuplength;
131
128
        errno = ENOMEM;
132
129
        return (FSServer *) NULL;
133
130
    }
 
131
 
 
132
    if ((svr->server_name = FSmalloc((unsigned) (strlen(server) + 1)))
 
133
            == NULL) {
 
134
        goto fail;
 
135
    }
 
136
    (void) strcpy(svr->server_name, server);
 
137
 
134
138
    if ((svr->trans_conn = _FSConnectServer(server)) == NULL) {
135
 
        FSfree((char *) svr);
136
 
        return (FSServer *) NULL;
 
139
        goto fail;
137
140
    }
138
141
 
139
142
    svr->fd = _FSTransGetConnectionNumber (svr->trans_conn);
157
160
    if (setuplength > (SIZE_MAX>>2)
158
161
        || (alt_data = (char *)
159
162
         (setup = FSmalloc((unsigned) setuplength))) == NULL) {
160
 
        errno = ENOMEM;
161
 
        FSfree((char *) svr);
162
 
        return (FSServer *) NULL;
 
163
        goto fail;
163
164
    }
164
165
    _FSRead(svr, (char *) alt_data, setuplength);
165
166
    ad = alt_data;
166
167
 
167
168
#if SIZE_MAX <= UINT_MAX
168
169
    if (prefix.num_alternates > SIZE_MAX / sizeof(AlternateServer)) {
169
 
        errno = ENOMEM;
170
 
        FSfree((char *) alt_data);
171
 
        FSfree((char *) svr);
172
 
        return (FSServer *) 0;
 
170
        goto fail;
173
171
    }
174
172
#endif
175
173
 
176
174
    alts = (AlternateServer *)
177
175
        FSmalloc(sizeof(AlternateServer) * prefix.num_alternates);
178
176
    if (!alts) {
179
 
        errno = ENOMEM;
180
 
        FSfree((char *) alt_data);
181
 
        FSfree((char *) svr);
182
 
        return (FSServer *) 0;
 
177
        goto fail;
183
178
    }
184
179
    for (i = 0; i < prefix.num_alternates; i++) {
185
180
        alts[i].subset = (Bool) *ad++;
189
184
            while (--i) {
190
185
                FSfree((char *) alts[i].name);
191
186
            }
192
 
            FSfree((char *) alts);
193
 
            FSfree((char *) alt_data);
194
 
            FSfree((char *) svr);
195
 
            errno = ENOMEM;
196
 
            return (FSServer *) 0;
 
187
            goto fail;
197
188
        }
198
 
        bcopy(ad, alts[i].name, altlen);
 
189
        memmove(alts[i].name, ad, altlen);
199
190
        alts[i].name[altlen] = '\0';
200
191
        ad += altlen + ((4 - (altlen + 2)) & 3);
201
192
    }
202
193
    FSfree((char *) alt_data);
 
194
    alt_data = NULL;
203
195
 
204
196
    svr->alternate_servers = alts;
205
197
    svr->num_alternates = prefix.num_alternates;
208
200
    if (setuplength > (SIZE_MAX>>2) 
209
201
        || (auth_data = (char *)
210
202
         (setup = FSmalloc((unsigned) setuplength))) == NULL) {
211
 
        errno = ENOMEM;
212
 
        FSfree((char *) alts);
213
 
        FSfree((char *) svr);
214
 
        return (FSServer *) NULL;
 
203
        goto fail;
215
204
    }
216
205
    _FSRead(svr, (char *) auth_data, setuplength);
217
206
 
218
207
    if (prefix.status != AuthSuccess) {
219
208
        fprintf(stderr, "%s: connection to \"%s\" refused by server\r\n%s: ",
220
209
                "FSlib", server, "FSlib");
221
 
        FSfree((char *) alts);
222
 
        FSfree((char *) svr);
223
 
        FSfree(setup);
224
 
        return (FSServer *) NULL;
 
210
        goto fail;
225
211
    }
226
212
    /* get rest */
227
213
    _FSRead(svr, (char *) &conn, (long) SIZEOF(fsConnSetupAccept));
228
214
 
229
215
    if ((vendor_string = (char *)
230
216
         FSmalloc((unsigned) conn.vendor_len + 1)) == NULL) {
231
 
        errno = ENOMEM;
232
 
        FSfree((char *) auth_data);
233
 
        FSfree((char *) alts);
234
 
        FSfree((char *) svr);
235
 
        return (FSServer *) NULL;
 
217
        goto fail;
236
218
    }
237
219
    _FSReadPad(svr, (char *) vendor_string, conn.vendor_len);
238
220
 
260
242
    svr->last_request_read = 0;
261
243
    svr->last_req = (char *) &_dummy_request;
262
244
 
263
 
    if ((svr->server_name = FSmalloc((unsigned) (strlen(server) + 1)))
264
 
            == NULL) {
265
 
        OutOfMemory(svr, setup);
266
 
        return (FSServer *) NULL;
267
 
    }
268
 
    (void) strcpy(svr->server_name, server);
269
 
 
270
245
    /* setup the output buffers */
271
246
    if ((svr->bufptr = svr->buffer = FSmalloc(BUFSIZE)) == NULL) {
272
 
        OutOfMemory(svr, setup);
273
 
        return (FSServer *) NULL;
 
247
        goto fail;
274
248
    }
275
249
    svr->bufmax = svr->buffer + BUFSIZE;
276
250
 
279
253
    svr->qlen = 0;
280
254
 
281
255
    FSfree(setup);
 
256
    setup = NULL;
282
257
 
283
258
    (void) FSSynchronize(svr, _FSdebug);
284
259
 
286
261
    _FSHeadOfServerList = svr;
287
262
 
288
263
    return (svr);
 
264
 
 
265
  fail: /* Failure: clean up and return null */
 
266
    FSfree((char *) alts);
 
267
    FSfree((char *) alt_data);
 
268
    FSfree((char *) auth_data);
 
269
    OutOfMemory(svr, setup);
 
270
    return (FSServer *) NULL;
 
271
 
289
272
}