~ubuntu-branches/ubuntu/precise/sup/precise

« back to all changes in this revision

Viewing changes to supfilesrv.c

  • Committer: Bazaar Package Importer
  • Author(s): Jochen Friedrich
  • Date: 2009-10-20 17:18:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091020171849-76d7gzmhnvns6jof
Tags: 20091019-1
* Update to new upstream snapshot.
* Convert to debhelper 7 and quilt.
* Fix compile on GNU/kFreeBSD. (Closes: #403816)
* Add patch to fix man pages.
* Bumped standards version to 3.8.3.
* Update Makefile patch to not strip any binaries. (Closes: #438074)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $NetBSD: supfilesrv.c,v 1.36 2006/05/10 21:45:40 mrg Exp $      */
 
1
/*      $NetBSD: supfilesrv.c,v 1.43 2009/10/17 20:46:03 christos Exp $ */
2
2
 
3
3
/*
4
4
 * Copyright (c) 1992 Carnegie Mellon University
50
50
 *      across the network to save BandWidth
51
51
 *
52
52
 * Revision 1.20  92/09/09  22:05:00  mrt
53
 
 *      Added Brad's change to make sendfile take a va_list.
 
53
 *      Added Brad's change to make send_file take a va_list.
54
54
 *      Added support in login to accept an non-encrypted login
55
55
 *      message if no user or password is being sent. This supports
56
56
 *      a non-crypting version of sup. Also fixed to skip leading
208
208
 **********************************************************************
209
209
 */
210
210
 
211
 
#include "libc.h"
212
211
#ifdef AFS
213
212
#include <afs/param.h>
214
213
#undef MAXNAMLEN
215
214
#endif
216
215
#include <sys/param.h>
217
 
#include "c.h"
218
216
#include <signal.h>
219
217
#include <errno.h>
220
218
#include <setjmp.h>
259
257
#include "supextern.h"
260
258
#define MSGFILE
261
259
#include "supmsg.h"
 
260
#include "libc.h"
 
261
#include "c.h"
262
262
 
263
263
extern char *crypt(const char *, const char *);
264
264
 
351
351
void srvlogin(void);
352
352
void listfiles(void);
353
353
int denyone(TREE *, void *);
354
 
void sendfiles(void);
355
 
int sendone(TREE *, void *);
356
 
int senddir(TREE *, void *);
357
 
int sendfile(TREE *, va_list);
 
354
void send_files(void);
 
355
int send_one(TREE *, void *);
 
356
int send_dir(TREE *, void *);
 
357
int send_file(TREE *, va_list);
358
358
void srvfinishup(time_t);
359
359
void Hfree(HASH **);
360
360
HASH *Hlookup(HASH **, int, int);
363
363
char *uconvert(int);
364
364
char *gconvert(int);
365
365
char *changeuid(char *, char *, int, int);
366
 
void goaway(char *, ...);
 
366
void goaway(const char *, ...);
367
367
char *fmttime(time_t);
368
368
int local_file(int, struct stat *);
369
369
int stat_info_ok(struct stat *, struct stat *);
387
387
 
388
388
        /* initialize global variables */
389
389
        pgmversion = PGMVERSION;/* export version number */
390
 
        server = TRUE;          /* export that we're not a server */
 
390
        isserver = TRUE;        /* export that we're not a server */
391
391
        collname = NULL;        /* no current collection yet */
392
392
        maxchildren = MAXCHILDREN;      /* defined in sup.h */
393
393
 
478
478
 */
479
479
 
480
480
void
481
 
chldsig(int snum)
 
481
chldsig(int snum __unused)
482
482
{
483
483
        int w;
484
484
 
571
571
                case '4':
572
572
                        af = AF_INET;
573
573
                        break;
 
574
#ifdef AF_INET6
574
575
                case '6':
575
576
                        af = AF_INET6;
576
577
                        break;
 
578
#endif
577
579
                default:
578
580
                        fprintf(stderr, "Unknown flag %s ignored\n", argv[0]);
579
581
                        break;
591
593
                        uidH[i] = gidH[i] = inodeH[i] = NULL;
592
594
                return;
593
595
        }
594
 
        server = FALSE;
 
596
        isserver = FALSE;
595
597
        if (argc < 1)
596
598
                usage();
597
599
        f = fopen(cryptkey, "r");
598
600
        if (f == NULL)
599
601
                quit(1, "Unable to open cryptfile %s\n", cryptkey);
600
602
        if ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
601
 
                if ((q = index(p, '\n')) != NULL)
 
603
                if ((q = strchr(p, '\n')) != NULL)
602
604
                        *q = '\0';
603
605
                if (*p == '\0')
604
606
                        quit(1, "No cryptkey found in %s\n", cryptkey);
718
720
                        exit(0);
719
721
                }
720
722
                listfiles();
721
 
                sendfiles();
 
723
                send_files();
722
724
        }
723
725
        srvfinishup(starttime);
724
726
        if (collname)
827
829
                                struct stat fsbuf;
828
830
 
829
831
                                while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
830
 
                                        q = index(p, '\n');
 
832
                                        q = strchr(p, '\n');
831
833
                                        if (q)
832
834
                                                *q = 0;
833
 
                                        if (index("#;:", *p))
 
835
                                        if (strchr("#;:", *p))
834
836
                                                continue;
835
837
                                        q = nxtarg(&p, " \t");
836
838
                                        if (*p == '\0')
884
886
                f = fopen(buf, "r");
885
887
                if (f) {
886
888
                        while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
887
 
                                q = index(p, '\n');
 
889
                                q = strchr(p, '\n');
888
890
                                if (q)
889
891
                                        *q = 0;
890
 
                                if (index("#;:", *p))
 
892
                                if (strchr("#;:", *p))
891
893
                                        continue;
892
894
                                q = nxtarg(&p, " \t=");
893
895
                                if (strcmp(q, collname) == 0) {
909
911
        f = fopen(buf, "r");
910
912
        if (f) {
911
913
                while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
912
 
                        q = index(p, '\n');
 
914
                        q = strchr(p, '\n');
913
915
                        if (q)
914
916
                                *q = 0;
915
 
                        if (index("#;:", *p))
 
917
                        if (strchr("#;:", *p))
916
918
                                continue;
917
919
                        prefix = estrdup(p);
918
920
                        if (chdir(prefix) < 0)
961
963
                        int hostok = FALSE;
962
964
                        while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
963
965
                                int not;
964
 
                                q = index(p, '\n');
 
966
                                q = strchr(p, '\n');
965
967
                                if (q)
966
968
                                        *q = 0;
967
 
                                if (index("#;:", *p))
 
969
                                if (strchr("#;:", *p))
968
970
                                        continue;
969
971
                                q = nxtarg(&p, " \t");
970
972
                                if ((not = (*q == '!')) && *++q == '\0')
1037
1039
 
1038
1040
                                if (cryptkey == NULL &&
1039
1041
                                    (p = fgets(buf, STRINGLENGTH, f))) {
1040
 
                                        if ((q = index(p, '\n')) != NULL)
 
1042
                                        if ((q = strchr(p, '\n')) != NULL)
1041
1043
                                                *q = '\0';
1042
1044
                                        if (*p)
1043
1045
                                                cryptkey = estrdup(buf);
1159
1161
 
1160
1162
 
1161
1163
int
1162
 
denyone(TREE * t, void *v)
 
1164
denyone(TREE * t, void *v __unused)
1163
1165
{
1164
1166
        TREELIST *tl;
1165
1167
        char *name = t->Tname;
1218
1220
 *********************************/
1219
1221
 
1220
1222
void
1221
 
sendfiles(void)
 
1223
send_files(void)
1222
1224
{
1223
1225
        TREELIST *tl;
1224
1226
        int x;
1244
1246
                        }
1245
1247
                }
1246
1248
#endif
1247
 
                (void) Tprocess(tl->TLtree, sendone, NULL);
 
1249
                (void) Tprocess(tl->TLtree, send_one, NULL);
1248
1250
        }
1249
1251
        /* send directories in reverse order */
1250
1252
        for (tl = listTL; tl != NULL; tl = tl->TLnext) {
1251
1253
                cdprefix(tl->TLprefix);
1252
 
                (void) Trprocess(tl->TLtree, senddir, NULL);
 
1254
                (void) Trprocess(tl->TLtree, send_dir, NULL);
1253
1255
        }
1254
1256
        x = msgsend();
1255
1257
        if (x != SCMOK)
1256
1258
                goaway("Error reading receive file request from client");
1257
1259
        upgradeT = NULL;
1258
 
        x = msgrecv(sendfile, 0);
 
1260
        x = msgrecv(send_file, 0);
1259
1261
        if (x != SCMOK)
1260
1262
                goaway("Error sending file to client");
1261
1263
}
1262
1264
 
1263
1265
int
1264
 
sendone(TREE * t, void *v)
 
1266
send_one(TREE * t, void *v __unused)
1265
1267
{
1266
1268
        int x, fd;
1267
1269
        char temp_file[STRINGLENGTH];
1380
1382
                        t->Tgroup = estrdup(gconvert(t->Tgid));
1381
1383
                }
1382
1384
        }
1383
 
        x = msgrecv(sendfile, fd);
 
1385
        x = msgrecv(send_file, fd);
1384
1386
        if (docompress)
1385
1387
                unlink(temp_file);
1386
1388
#ifdef RCS
1393
1395
}
1394
1396
 
1395
1397
int
1396
 
senddir(TREE * t, void *v)
 
1398
send_dir(TREE * t, void *v __unused)
1397
1399
{
1398
1400
        int x;
1399
1401
 
1407
1409
        upgradeT = t;           /* upgrade file pointer */
1408
1410
        t->Tuser = estrdup(uconvert(t->Tuid));
1409
1411
        t->Tgroup = estrdup(gconvert(t->Tgid));
1410
 
        x = msgrecv(sendfile, 0);
 
1412
        x = msgrecv(send_file, 0);
1411
1413
        if (x != SCMOK)
1412
1414
                goaway("Error sending file %s to client", t->Tname);
1413
1415
        return (SCMOK);
1414
1416
}
1415
1417
 
1416
1418
int
1417
 
sendfile(TREE * t, va_list ap)
 
1419
send_file(TREE * t, va_list ap)
1418
1420
{
1419
1421
        int x, fd;
1420
1422
 
1631
1633
                pswdp = NULL;
1632
1634
        } else {
1633
1635
                (void) strcpy(nbuf, namep);
1634
 
                account = group = index(nbuf, ',');
 
1636
                account = group = strchr(nbuf, ',');
1635
1637
                if (group != NULL) {
1636
1638
                        *group++ = '\0';
1637
 
                        account = index(group, ',');
 
1639
                        account = strchr(group, ',');
1638
1640
                        if (account != NULL) {
1639
1641
                                *account++ = '\0';
1640
1642
                                if (*account == '\0')
1775
1777
}
1776
1778
 
1777
1779
void
1778
 
goaway(char *fmt, ...)
 
1780
goaway(const char *fmt, ...)
1779
1781
{
1780
1782
        char buf[STRINGLENGTH];
1781
1783
        va_list ap;
1911
1913
         * determined this empirically -- DLC).  Without a fstatvfs()
1912
1914
         * system call, this will have to do for now.
1913
1915
         */
1914
 
#if defined(__SVR4) || __NetBSD_Version__ > 200030000
 
1916
#if defined(__SVR4) || __NetBSD_Version__ > 299000900
1915
1917
        {
1916
1918
                struct statvfs sf;
1917
1919
 
1991
1993
#else                           /* MACH */
1992
1994
/*ARGSUSED*/
1993
1995
int
1994
 
link_nofollow(int on)
 
1996
link_nofollow(int on __unused)
1995
1997
{
1996
1998
        return (0);
1997
1999
}