~ubuntu-branches/ubuntu/jaunty/lpr/jaunty

« back to all changes in this revision

Viewing changes to common_source/common.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Majer
  • Date: 2006-11-04 23:21:59 UTC
  • mfrom: (3.1.2 feisty)
  • Revision ID: james.westby@ubuntu.com-20061104232159-4sbjww5mmvuwcrqx
Tags: 1:2006.11.04
* Added upstream patches
   + lpr.c [rev. 1.39] - portability patch s/0/SEEK_SET/ in lseek
* /var/log/lp-{acct,errs} are now rotated weekly with lp:adm
   ownership with 0640 permissions. The latter is to counteract any
   security related information being leaked from filter's stderr to
   the log to the user. (closes: #390720)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $OpenBSD: common.c,v 1.25 2003/06/02 23:36:53 millert Exp $     */
 
1
/*      $OpenBSD: common.c,v 1.29 2004/11/17 02:31:30 itojun Exp $      */
2
2
/*      $NetBSD: common.c,v 1.21 2000/08/09 14:28:50 itojun Exp $       */
3
3
 
4
4
/*
39
39
#if 0
40
40
static const char sccsid[] = "@(#)common.c      8.5 (Berkeley) 4/28/95";
41
41
#else
42
 
static const char rcsid[] = "$OpenBSD: common.c,v 1.25 2003/06/02 23:36:53 millert Exp $";
 
42
static const char rcsid[] = "$OpenBSD: common.c,v 1.29 2004/11/17 02:31:30 itojun Exp $";
43
43
#endif
44
44
#endif /* not lint */
45
45
 
167
167
                if (s < 0) {
168
168
                        /* fall back to non-privileged port */
169
169
                        if (errno != EACCES ||
170
 
                            (s = socket(r->ai_family, SOCK_STREAM, 0)) < 0)
 
170
                            (s = socket(r->ai_family, SOCK_STREAM, 0)) < 0) {
 
171
                                freeaddrinfo(res);
171
172
                                return(-1);
 
173
                        }
172
174
                }
173
175
                siginterrupt(SIGINT, 1);
174
176
                if (connect(s, r->ai_addr, r->ai_addrlen) < 0) {
241
243
getq(struct queue ***namelist)
242
244
{
243
245
        struct dirent *d;
244
 
        struct queue *q, **queue;
245
 
        size_t nitems, arraysz;
 
246
        struct queue *q, **queue = NULL;
 
247
        size_t nitems = 0, arraysz;
246
248
        struct stat stbuf;
247
249
        DIR *dirp;
248
250
 
263
265
        if (queue == NULL)
264
266
                goto errdone;
265
267
 
266
 
        nitems = 0;
267
268
        while ((d = readdir(dirp)) != NULL) {
268
269
                if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
269
270
                        continue;       /* daemon control files only */
283
284
                 * Check to make sure the array has space left and
284
285
                 * realloc the maximum size.
285
286
                 */
286
 
                if (++nitems > arraysz) {
287
 
                        arraysz *= 2;
288
 
                        queue = (struct queue **)realloc(queue,
289
 
                                arraysz * sizeof(struct queue *));
290
 
                        if (queue == NULL)
 
287
                if (nitems == arraysz) {
 
288
                        struct queue **newqueue;
 
289
                        size_t newarraysz = arraysz * 2;
 
290
                        newqueue = (struct queue **)realloc(queue,
 
291
                                newarraysz * sizeof(struct queue *));
 
292
                        if (newqueue == NULL) {
 
293
                                free(q);
291
294
                                goto errdone;
 
295
                        }
 
296
                        queue = newqueue;
 
297
                        arraysz = newarraysz;
292
298
                }
293
 
                queue[nitems-1] = q;
 
299
                queue[nitems++] = q;
294
300
        }
295
301
        closedir(dirp);
296
302
        if (nitems)
299
305
        return(nitems);
300
306
 
301
307
errdone:
 
308
        if (queue != NULL) {
 
309
                while (nitems--)
 
310
                        free(queue[nitems]);
 
311
                free(queue);
 
312
        }
302
313
        closedir(dirp);
303
314
        return(-1);
304
315
}
327
338
        static char errbuf[128];
328
339
        int error;
329
340
        struct ifaddrs *ifap, *ifa;
330
 
#ifdef NI_WITHSCOPEID
331
 
        const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
332
 
#else
333
341
        const int niflags = NI_NUMERICHOST;
334
 
#endif
335
342
#ifdef __KAME__
336
343
        struct sockaddr_in6 sin6;
337
344
        struct sockaddr_in6 *sin6p;