-
Notifications
You must be signed in to change notification settings - Fork 0
/
ckufio.c
8596 lines (7772 loc) · 248 KB
/
ckufio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* C K U F I O -- Kermit file system support for UNIX, Aegis, and Plan 9 */
#define CK_NONBLOCK /* See zoutdump() */
#ifdef aegis
char *ckzv = "Aegis File support, 9.0.224, 28 Sep 2020";
#else
#ifdef Plan9
char *ckzv = "Plan 9 File support, 9.0.224, 28 Sep 2020";
#else
char *ckzv = "UNIX File support, 9.0.224, 28 Sep 2020";
#endif /* Plan9 */
#endif /* aegis */
/*
Author: Frank da Cruz <fdc@columbia.edu>,
Columbia University 1974-2011; The Kermit Project 2011-????.
Copyright (C) 1985, 2020,
Trustees of Columbia University in the City of New York.
1767All rights reserved. See the C-Kermit COPYING.TXT file or the
copyright text in the ckcmai.c module for disclaimer and permissions.
*/
/*
NOTE TO CONTRIBUTORS: This file, and all the other C-Kermit files, must be
compatible with C preprocessors that support only #ifdef, #else, #endif,
#define, and #undef. Please do not use #if, logical operators, or other
preprocessor features in any of the portable C-Kermit modules. You can,
of course, use these constructions in platform-specific modules where you
know they are supported.
*/
/* Include Files */
#ifdef MINIX2
#define _MINIX
#endif /* MINIX2 */
#include "ckcsym.h"
#include "ckcdeb.h"
#include "ckcasc.h"
#ifndef NOCSETS
#include "ckcxla.h"
#endif /* NOCSETS */
/* To avoid pulling in all of ckuusr.h so we copy the few needed prototypes */
struct mtab { /* Macro table, like keyword table */
char *kwd; /* But with pointers for vals */
char *mval; /* instead of ints. */
short flgs;
};
_PROTOTYP( int mlook, (struct mtab [], char *, int) );
_PROTOTYP( int dodo, (int, char *, int) );
_PROTOTYP( int parser, ( int ) );
#ifdef COMMENT
/* This causes trouble in C-Kermit 8.0. I don't remember the original */
/* reason for this being here but it must have been needed at the time... */
#ifdef OSF13
#ifdef CK_ANSIC
#ifdef _NO_PROTO
#undef _NO_PROTO
#endif /* _NO_PROTO */
#endif /* CK_ANSIC */
#endif /* OSF13 */
#endif /* COMMENT */
#ifndef HPUXPRE65
#include <errno.h> /* Error number symbols */
#else
#ifndef ERRNO_INCLUDED
#include <errno.h> /* Error number symbols */
#endif /* ERRNO_INCLUDED */
#endif /* HPUXPRE65 */
#include <signal.h>
#ifdef MINIX2
#undef MINIX
#undef CKSYSLOG
#include <limits.h>
#include <time.h>
#define NOFILEH
#endif /* MINIX2 */
#ifdef MINIX
#include <limits.h>
#include <sys/types.h>
#include <time.h>
#else
#ifdef POSIX
#include <limits.h>
#else
#ifdef SVR3
#include <limits.h>
#endif /* SVR3 */
#endif /* POSIX */
#endif /* MINIX */
/*
Directory Separator macros, to allow this module to work with both UNIX and
OS/2: Because of ambiguity with the command line editor escape \ character,
the directory separator is currently left as / for OS/2 too, because the
OS/2 kernel also accepts / as directory separator.
*/
#ifndef DIRSEP
#define DIRSEP '/'
#endif /* DIRSEP */
#ifndef ISDIRSEP
#define ISDIRSEP(c) ((c)=='/')
#endif /* ISDIRSEP */
#ifdef SDIRENT
#define DIRENT
#endif /* SDIRENT */
#ifdef XNDIR
#include <sys/ndir.h>
#else /* !XNDIR */
#ifdef NDIR
#include <ndir.h>
#else /* !NDIR, !XNDIR */
#ifdef RTU
#include "/usr/lib/ndir.h"
#else /* !RTU, !NDIR, !XNDIR */
#ifdef DIRENT
#ifdef SDIRENT
#include <sys/dirent.h>
#else
#include <dirent.h>
#endif /* SDIRENT */
#else
#include <sys/dir.h>
#endif /* DIRENT */
#endif /* RTU */
#endif /* NDIR */
#endif /* XNDIR */
#ifdef __NetBSD__
#include <sys/wait.h>
#endif /* __NetBSD__ */
#ifdef UNIX /* Pointer arg to wait() allowed */
#define CK_CHILD /* Assume this is safe in all UNIX */
#endif /* UNIX */
extern int binary, recursive, stathack;
#ifdef CK_CTRLZ
extern int eofmethod;
#endif /* CK_CTRLZ */
#include <pwd.h> /* Password file for shell name */
#ifdef CK_SRP
#include <t_pwd.h> /* SRP Password file */
#endif /* CK_SRP */
#ifdef HPUX10_TRUSTED
#include <hpsecurity.h>
#include <prot.h>
#endif /* HPUX10_TRUSTED */
#ifdef COMMENT
/* Moved to ckcdeb.h */
#ifdef POSIX
#define UTIMEH
#else
#ifdef HPUX9
#define UTIMEH
#endif /* HPUX9 */
#endif /* POSIX */
#endif /* COMMENT */
#ifdef SYSUTIMEH /* <sys/utime.h> if requested, */
#include <sys/utime.h> /* for extra fields required by */
#else /* 88Open spec. */
#ifdef UTIMEH /* or <utime.h> if requested */
#include <utime.h> /* (SVR4, POSIX) */
#ifndef BSD44
#ifndef V7
/* Not sure why this is here. What it implies is that the code bracketed
by SYSUTIMEH is valid on all platforms on which we support time
functionality. But we know that is not true because the BSD44 and V7
platforms do not support sys/utime.h and the data structures which
are defined in them. Now this worked before because prior to today's
changes the UTIMEH definition for BSD44 and V7 did not take place
until after SYSUTIMEH was defined. It also would not have been a
problem if the ordering of all the time blocks was consistent. All but
one of the blocks were BSD44, V7, SYSUTIMEH, <OTHER>. That one case
is where this problem was triggered.
*/
#define SYSUTIMEH /* Use this for both cases. */
#endif /* V7 */
#endif /* BSD44 */
#endif /* UTIMEH */
#endif /* SYSUTIMEH */
#ifndef NOTIMESTAMP
#ifdef POSIX
#ifndef AS400
#define TIMESTAMP
#endif /* AS400 */
#endif /* POSIX */
#ifdef BSD44 /* BSD 4.4 */
#ifndef TIMESTAMP
#define TIMESTAMP /* Can do file dates */
#endif /* TIMESTAMP */
#include <sys/time.h>
#include <sys/timeb.h>
#else /* Not BSD44 */
#ifdef BSD4 /* BSD 4.3 and below */
#define TIMESTAMP /* Can do file dates */
#include <time.h> /* Need this */
#include <sys/timeb.h> /* Need this if really BSD */
#else /* Not BSD 4.3 and below */
#ifdef SVORPOSIX /* System V or POSIX */
#ifndef TIMESTAMP
#define TIMESTAMP
#endif /* TIMESTAMP */
#include <time.h>
/* void tzset(); (the "void" type upsets some compilers) */
#ifndef IRIX60
#ifndef ultrix
#ifndef CONVEX9
/* ConvexOS 9.0, supposedly POSIX, has extern char *timezone(int,int) */
#ifndef Plan9
extern long timezone;
#endif /* Plan9 */
#endif /* CONVEX9 */
#endif /* ultrix */
#endif /* IRIX60 */
#endif /* SVORPOSIX */
#endif /* BSD4 */
#endif /* BSD44 */
#ifdef COHERENT
#include <time.h>
#endif /* COHERENT */
/* Is `y' a leap year? */
#define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)
/* Number of leap years from 1970 to `y' (not including `y' itself). */
#define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)
#endif /* NOTIMESTAMP */
#ifdef CIE
#include <stat.h> /* File status */
#else
#include <sys/stat.h>
#endif /* CIE */
/* Macro to alleviate isdir() calls internal to this module */
static struct stat STATBUF;
#define xisdir(a) ((stat(a,&STATBUF)==-1)?0:(S_ISDIR(STATBUF.st_mode)?1:0))
extern char uidbuf[];
extern int xferlog;
extern char * xferfile;
int iklogopen = 0;
static time_t timenow;
#define IKSDMSGLEN CKMAXPATH+512
static char iksdmsg[IKSDMSGLEN];
extern int local;
extern int server, en_mkd, en_cwd, en_del;
/*
Functions (n is one of the predefined file numbers from ckcker.h):
zopeni(n,name) -- Opens an existing file for input.
zopeno(n,name,attr,fcb) -- Opens a new file for output.
zclose(n) -- Closes a file.
zchin(n,&c) -- Gets the next character from an input file.
zsinl(n,&s,x) -- Read a line from file n, max len x, into address s.
zsout(n,s) -- Write a null-terminated string to output file, buffered.
zsoutl(n,s) -- Like zsout, but appends a line terminator.
zsoutx(n,s,x) -- Write x characters to output file, unbuffered.
zchout(n,c) -- Add a character to an output file, unbuffered.
zchki(name) -- Check if named file exists and is readable, return size.
zchko(name) -- Check if named file can be created.
zchkspa(name,n) -- Check if n bytes available to create new file, name.
znewn(name,s) -- Make a new unique file name based on the given name.
zdelet(name) -- Delete the named file.
zxpand(string) -- Expands the given wildcard string into a list of files.
znext(string) -- Returns the next file from the list in "string".
zxrewind() -- Rewind zxpand list.
zxcmd(n,cmd) -- Execute the command in a lower fork on file number n.
zclosf() -- Close input file associated with zxcmd()'s lower fork.
zrtol(n1,n2) -- Convert remote filename into local form.
zltor(n1,n2) -- Convert local filename into remote form.
zchdir(dirnam) -- Change working directory.
zhome() -- Return pointer to home directory name string.
zkself() -- Kill self, log out own job.
zsattr(struct zattr *) -- Return attributes for file which is being sent.
zstime(f, struct zattr *, x) - Set file creation date from attribute packet.
zrename(old, new) -- Rename a file.
zcopy(source,destination) -- Copy a file.
zmkdir(path) -- Create the directory path if possible
zfnqfp(fname,len,fullpath) - Determine full path for file name.
zgetfs(name) -- return file size regardless of accessibility
zchkpid(pid) -- tell if PID is valid and active
*/
/* Kermit-specific includes */
/*
Definitions here supersede those from system include files.
ckcdeb.h is included above.
*/
#include "ckcker.h" /* Kermit definitions */
#include "ckucmd.h" /* For keyword tables */
#include "ckuver.h" /* Version herald */
char *ckzsys = HERALD;
/*
File access checking ... There are two calls to access() in this module.
If this program is installed setuid or setgid on a Berkeley-based UNIX
system that does NOT incorporate the saved-original-effective-uid/gid
feature, then, when we have swapped the effective and original uid/gid,
access() fails because it uses what it thinks are the REAL ids, but we have
swapped them. This occurs on systems where ANYBSD is defined, NOSETREU
is NOT defined, and SAVEDUID is NOT defined. So, in theory, we should take
care of this situation like so:
ifdef ANYBSD
ifndef NOSETREU
ifndef SAVEDUID
define SW_ACC_ID
endif
endif
endif
But we can't test such a general scheme everywhere, so let's only do this
when we know we have to...
*/
#ifdef NEXT /* NeXTSTEP 1.0-3.0 */
#define SW_ACC_ID
#endif /* NEXT */
/* Support for tilde-expansion in file and directory names */
#ifdef POSIX
#define NAMEENV "LOGNAME"
#else
#ifdef BSD4
#define NAMEENV "USER"
#else
#ifdef ATTSV
#define NAMEENV "LOGNAME"
#endif /* ATTSV */
#endif /* BSD4 */
#endif /* POSIX */
/* Berkeley Unix Version 4.x */
/* 4.1bsd support from Charles E Brooks, EDN-VAX */
#ifdef BSD4
#ifdef MAXNAMLEN
#define BSD42
#endif /* MAXNAMLEN */
#endif /* BSD4 */
/* Definitions of some system commands */
char *DELCMD = "rm -f "; /* For file deletion */
char *CPYCMD = "cp "; /* For file copy */
char *RENCMD = "mv "; /* For file rename */
char *PWDCMD = "pwd "; /* For saying where I am */
#ifdef COMMENT
#ifdef HPUX10
char *DIRCMD = "/usr/bin/ls -l "; /* For directory listing */
char *DIRCM2 = "/usr/bin/ls -l "; /* For directory listing, no args */
#else
char *DIRCMD = "/bin/ls -l "; /* For directory listing */
char *DIRCM2 = "/bin/ls -l "; /* For directory listing, no args */
#endif /* HPUX10 */
#else
char *DIRCMD = "ls -l "; /* For directory listing */
char *DIRCM2 = "ls -l "; /* For directory listing, no args */
#endif /* COMMENT */
char *TYPCMD = "cat "; /* For typing a file */
#ifdef HPUX
char *MAILCMD = "mailx"; /* For sending mail */
#else
#ifdef DGUX540
char *MAILCMD = "mailx";
#else
#ifdef UNIX
#ifdef CK_MAILCMD
char *MAILCMD = CK_MAILCMD; /* CFLAGS override */
#else
char *MAILCMD = "Mail"; /* Default */
#endif /* CK_MAILCMD */
#else
char *MAILCMD = "";
#endif /* UNIX */
#endif /* HPUX */
#endif /* DGUX40 */
#ifdef UNIX
#ifdef ANYBSD /* BSD uses lpr to spool */
#ifdef DGUX540 /* And DG/UX */
char * PRINTCMD = "lp";
#else
char * PRINTCMD = "lpr";
#endif /* DGUX540 */
#else /* Sys V uses lp */
#ifdef TRS16 /* except for Tandy-16/6000... */
char * PRINTCMD = "lpr";
#else
char * PRINTCMD = "lp";
#endif /* TRS16 */
#endif /* ANYBSD */
#else /* Not UNIX */
#define PRINTCMD ""
#endif /* UNIX */
#ifdef FT18 /* Fortune For:Pro 1.8 */
#undef BSD4
#endif /* FT18 */
#ifdef BSD4
char *SPACMD = "pwd ; df ."; /* Space in current directory */
#else
#ifdef FT18
char *SPACMD = "pwd ; du ; df .";
#else
char *SPACMD = "df ";
#endif /* FT18 */
#endif /* BSD4 */
char *SPACM2 = "df "; /* For space in specified directory */
#ifdef FT18
#define BSD4
#endif /* FT18 */
#ifdef BSD4
char *WHOCMD = "finger ";
#else
char *WHOCMD = "who ";
#endif /* BSD4 */
/* More system-dependent includes, which depend on symbols defined */
/* in the Kermit-specific includes. Oh what a tangled web we weave... */
#ifdef COHERENT /* <sys/file.h> */
#define NOFILEH
#endif /* COHERENT */
#ifdef MINIX
#define NOFILEH
#endif /* MINIX */
#ifdef aegis
#define NOFILEH
#endif /* aegis */
#ifdef unos
#define NOFILEH
#endif /* unos */
#ifndef NOFILEH
#include <sys/file.h>
#endif /* NOFILEH */
#ifndef is68k /* Whether to include <fcntl.h> */
#ifndef BSD41 /* All but a couple UNIXes have it. */
#ifndef FT18
#ifndef COHERENT
#include <fcntl.h>
#endif /* COHERENT */
#endif /* FT18 */
#endif /* BSD41 */
#endif /* is68k */
#ifdef COHERENT
#ifdef _I386
#include <fcntl.h>
#else
#include <sys/fcntl.h>
#endif /* _I386 */
#endif /* COHERENT */
extern int inserver; /* I am IKSD */
int guest = 0; /* Anonymous user */
#ifdef IKSD
extern int isguest;
extern char * anonroot;
#endif /* IKSD */
#ifdef CK_LOGIN
#define GUESTPASS 256
static char guestpass[GUESTPASS] = { NUL, NUL }; /* Anonymous "password" */
static int logged_in = 0; /* Set when user is logged in */
static int askpasswd = 0; /* Have OK user, must ask for passwd */
#ifdef CK_PAM
extern int gotemptypasswd;
#endif /* CK_PAM */
#endif /* CK_LOGIN */
#ifdef CKROOT
static char ckroot[CKMAXPATH+1] = { NUL, NUL };
static int ckrootset = 0;
int ckrooterr = 0;
#endif /* CKROOT */
_PROTOTYP( VOID ignorsigs, (void) );
_PROTOTYP( VOID restorsigs, (void) );
#ifdef SELECT
_PROTOTYP( int ttwait, (int, int) ); /* ckutio.c */
#endif /* SELECT */
/*
Change argument to "(const char *)" if this causes trouble.
Or... if it causes trouble, then maybe it was already declared
in a header file after all, so you can remove this prototype.
*/
#ifndef NDGPWNAM /* If not defined No Declare getpwnam... */
#ifndef _POSIX_SOURCE
#ifndef NEXT
#ifndef SVR4
/* POSIX <pwd.h> already gave prototypes for these. */
#ifdef IRIX40
_PROTOTYP( struct passwd * getpwnam, (const char *) );
#else
#ifdef IRIX51
_PROTOTYP( struct passwd * getpwnam, (const char *) );
#else
#ifdef M_UNIX
_PROTOTYP( struct passwd * getpwnam, (const char *) );
#else
#ifdef HPUX9
_PROTOTYP( struct passwd * getpwnam, (const char *) );
#else
#ifdef HPUX10
_PROTOTYP( struct passwd * getpwnam, (const char *) );
#else
#ifdef DCGPWNAM
_PROTOTYP( struct passwd * getpwnam, (const char *) );
#else
_PROTOTYP( struct passwd * getpwnam, (char *) );
#endif /* DCGPWNAM */
#endif /* HPUX10 */
#endif /* HPUX9 */
#endif /* M_UNIX */
#endif /* IRIX51 */
#endif /* IRIX40 */
#ifndef SUNOS4
#ifndef HPUX9
#ifndef HPUX10
#ifndef _SCO_DS
_PROTOTYP( struct passwd * getpwuid, (PWID_T) );
#endif /* _SCO_DS */
#endif /* HPUX10 */
#endif /* HPUX9 */
#endif /* SUNOS4 */
_PROTOTYP( struct passwd * getpwent, (void) );
#endif /* SVR4 */
#endif /* NEXT */
#endif /* _POSIX_SOURCE */
#endif /* NDGPWNAM */
#ifdef CK_SHADOW /* Shadow Passwords... */
#include <shadow.h>
#endif /* CK_SHADOW */
#ifdef CK_PAM /* PAM... */
#ifdef MACOSX
#include <pam/pam_appl.h>
#else /* MACOSX */
#include <security/pam_appl.h>
#endif /* MACOSX */
#ifndef PAM_SERVICE_TYPE /* Defines which PAM service we are */
#define PAM_SERVICE_TYPE "kermit"
#endif /* PAM_SERVICE_TYPE */
#ifdef SOLARIS
#define PAM_CONST
#else /* SOLARIS */
#define PAM_CONST CONST
#endif
static char * pam_pw = NULL;
int
#ifdef CK_ANSIC
pam_cb(int num_msg,
PAM_CONST struct pam_message **msg,
struct pam_response **resp,
void *appdata_ptr
)
#else /* CK_ANSIC */
pam_cb(num_msg, msg, resp, appdata_ptr)
int num_msg;
PAM_CONST struct pam_message **msg;
struct pam_response **resp;
void *appdata_ptr;
#endif /* CK_ANSIC */
{
int i;
debug(F111,"pam_cb","num_msg",num_msg);
for (i = 0; i < num_msg; i++) {
char message[PAM_MAX_MSG_SIZE];
/* Issue prompt and get response */
debug(F111,"pam_cb","Message",i);
debug(F111,"pam_cb",msg[i]->msg,msg[i]->msg_style);
if (msg[i]->msg_style == PAM_ERROR_MSG) {
debug(F111,"pam_cb","PAM ERROR",0);
fprintf(stdout,"%s\n", msg[i]->msg);
return(0);
} else if (msg[i]->msg_style == PAM_TEXT_INFO) {
debug(F111,"pam_cb","PAM TEXT INFO",0);
fprintf(stdout,"%s\n", msg[i]->msg);
return(0);
} else if (msg[i]->msg_style == PAM_PROMPT_ECHO_OFF) {
debug(F111,"pam_cb","Reading response, no echo",0);
/* Ugly hack. We check to see if a password has been pushed */
/* into zvpasswd(). This would be true if the password was */
/* received by REMOTE LOGIN. */
if (pam_pw) {
ckstrncpy(message,pam_pw,PAM_MAX_MSG_SIZE);
} else
readpass((char *)msg[i]->msg,message,PAM_MAX_MSG_SIZE);
} else if (msg[i]->msg_style == PAM_PROMPT_ECHO_ON) {
debug(F111,"pam_cb","Reading response, with echo",0);
readtext((char *)msg[i]->msg,message,PAM_MAX_MSG_SIZE);
} else {
debug(F111,"pam_cb","unknown style",0);
return(0);
}
/* Allocate space for this message's response structure */
resp[i] = (struct pam_response *) malloc(sizeof (struct pam_response));
if (!resp[i]) {
int j;
debug(F110,"pam_cb","malloc failure",0);
for (j = 0; j < i; j++) {
free(resp[j]->resp);
free(resp[j]);
}
return(0);
}
/* Allocate a buffer for the response */
resp[i]->resp = (char *) malloc((int)strlen(message) + 1);
if (!resp[i]->resp) {
int j;
debug(F110,"pam_cb","malloc failure",0);
for (j = 0; j < i; j++) {
free(resp[j]->resp);
free(resp[j]);
}
free(resp[i]);
return(0);
}
/* Return the results back to PAM */
strcpy(resp[i]->resp, message); /* safe (prechecked) */
resp[i]->resp_retcode = 0;
}
debug(F110,"pam_cb","Exiting",0);
return(0);
}
#endif /* CK_PAM */
/* Define macros for getting file type */
#ifdef OXOS
/*
Olivetti X/OS 2.3 has S_ISREG and S_ISDIR defined
incorrectly, so we force their redefinition.
*/
#undef S_ISREG
#undef S_ISDIR
#endif /* OXOS */
#ifdef UTSV /* Same deal for Amdahl UTSV */
#undef S_ISREG
#undef S_ISDIR
#endif /* UTSV */
#ifdef UNISYS52 /* And for UNISYS UTS V 5.2 */
#undef S_ISREG
#undef S_ISDIR
#endif /* UNISYS52 */
#ifdef ICLSVR3 /* And for old ICL versions */
#undef S_ISREG
#undef S_ISDIR
#endif /* ICLSVR3 */
#ifdef ISDIRBUG /* Also allow this from command line */
#ifdef S_ISREG
#undef S_ISREG
#endif /* S_ISREG */
#ifdef S_ISDIR
#undef S_ISDIR
#endif /* S_ISDIR */
#endif /* ISDIRBUG */
#ifndef _IFMT
#ifdef S_IFMT
#define _IFMT S_IFMT
#else
#define _IFMT 0170000
#endif /* S_IFMT */
#endif /* _IFMT */
#ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif /* S_ISREG */
#ifndef S_ISDIR
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif /* S_ISDIR */
/* The following mainly for NeXTSTEP... */
#ifndef S_IWUSR
#define S_IWUSR 0000200
#endif /* S_IWUSR */
#ifndef S_IRGRP
#define S_IRGRP 0000040
#endif /* S_IRGRP */
#ifndef S_IWGRP
#define S_IWGRP 0000020
#endif /* S_IWGRP */
#ifndef S_IXGRP
#define S_IXGRP 0000010
#endif /* S_IXGRP */
#ifndef S_IROTH
#define S_IROTH 0000004
#endif /* S_IROTH */
#ifndef S_IWOTH
#define S_IWOTH 0000002
#endif /* S_IWOTH */
#ifndef S_IXOTH
#define S_IXOTH 0000001
#endif /* S_IXOTH */
/*
Define maximum length for a file name if not already defined.
NOTE: This applies to a path segment (directory or file name),
not the entire path string, which can be CKMAXPATH bytes long.
*/
#ifdef QNX
#ifdef _MAX_FNAME
#define MAXNAMLEN _MAX_FNAME
#else
#define MAXNAMLEN 48
#endif /* _MAX_FNAME */
#else
#ifndef MAXNAMLEN
#ifdef sun
#define MAXNAMLEN 255
#else
#ifdef FILENAME_MAX
#define MAXNAMLEN FILENAME_MAX
#else
#ifdef NAME_MAX
#define MAXNAMLEN NAME_MAX
#else
#ifdef _POSIX_NAME_MAX
#define MAXNAMLEN _POSIX_NAME_MAX
#else
#ifdef _D_NAME_MAX
#define MAXNAMLEN _D_NAME_MAX
#else
#ifdef DIRSIZ
#define MAXNAMLEN DIRSIZ
#else
#define MAXNAMLEN 14
#endif /* DIRSIZ */
#endif /* _D_NAME_MAX */
#endif /* _POSIX_NAME_MAX */
#endif /* NAME_MAX */
#endif /* FILENAME_MAX */
#endif /* sun */
#endif /* MAXNAMLEN */
#endif /* QNX */
#ifdef COMMENT
/* As of 2001-11-03 this is handled in ckcdeb.h */
/* Longest pathname ... */
/*
Beware: MAXPATHLEN is one of UNIX's dirty little secrets. Where is it
defined? Who knows... <param.h>, <mod.h>, <unistd.h>, <limits.h>, ...
There is not necessarily even a definition for it anywhere, or it might have
another name. If you get it wrong, bad things happen with getcwd() and/or
getwd(). If you allocate a buffer that is too short, getwd() might write
over memory and getcwd() will fail with ERANGE. The definitions of these
functions (e.g. in SVID or POSIX.1) do not tell you how to determine the
maximum path length in order to allocate a buffer that is the right size.
*/
#ifdef BSD44
#include <sys/param.h> /* For MAXPATHLEN */
#endif /* BSD44 */
#ifdef COHERENT
#include <sys/param.h> /* for MAXPATHLEN, needed for -DDIRENT */
#endif /* COHERENT */
#endif /* COMMENT */
#ifdef MAXPATHLEN
#ifdef MAXPATH
#undef MAXPATH
#endif /* MAXPATH */
#define MAXPATH MAXPATHLEN
#else
#ifdef PATH_MAX
#define MAXPATH PATH_MAX
#else
#ifdef _POSIX_PATH_MAX
#define MAXPATH _POSIX_PATH_MAX
#else
#ifdef BSD42
#define MAXPATH 1024
#else
#ifdef SVR4
#define MAXPATH 1024
#else
#define MAXPATH 255
#endif /* SVR4 */
#endif /* BSD42 */
#endif /* _POSIX_PATH_MAX */
#endif /* PATH_MAX */
#endif /* MAXPATHLEN */
/* Maximum number of filenames for wildcard expansion */
#ifndef MAXWLD
/* Already defined in ckcdeb.h so the following is superfluous. */
/* Don't expect changing them to have any effect. */
#ifdef CK_SMALL
#define MAXWLD 50
#else
#ifdef BIGBUFOK
#define MAXWLD 102400
#else
#define MAXWLD 8192
#endif /* BIGBUFOK */
#endif /* CK_SMALL */
#endif /* MAXWLD */
static int maxnames = MAXWLD;
/* Define the size of the string space for filename expansion. */
#ifndef DYNAMIC
#ifdef PROVX1
#define SSPACE 500
#else
#ifdef BSD29
#define SSPACE 500
#else
#ifdef pdp11
#define SSPACE 500
#else
#ifdef aegis
#define SSPACE 10000 /* Size of string-generating buffer */
#else /* Default static buffer size */
#ifdef BIGBUFOK
#define SSPACE 65000 /* Size of string-generating buffer */
#else
#define SSPACE 2000 /* size of string-generating buffer */
#endif /* BIGBUFOK */
#endif /* aegis */
#endif /* pdp11 */
#endif /* BSD29 */
#endif /* PROVX1 */
static char sspace[SSPACE]; /* Buffer for generating filenames */
#else /* is DYNAMIC */
#ifdef CK_64BIT
#define SSPACE 2000000000 /* Two billion bytes */
#else
#ifdef BIGBUFOK
#define SSPACE 10000000 /* Ten million */
#else
#define SSPACE 10000 /* Ten thousand */
#endif /* BIGBUFOK */
#endif /* CK_64BIT */
char *sspace = (char *)0;
#endif /* DYNAMIC */
static int ssplen = SSPACE; /* Length of string space buffer */
#ifdef DCLFDOPEN
/* fdopen() needs declaring because it's not declared in <stdio.h> */
_PROTOTYP( FILE * fdopen, (int, char *) );
#endif /* DCLFDOPEN */
#ifdef DCLPOPEN
/* popen() needs declaring because it's not declared in <stdio.h> */
_PROTOTYP( FILE * popen, (char *, char *) );
#endif /* DCLPOPEN */
extern int nopush;
/* More internal function prototypes */
/*
* The path structure is used to represent the name to match.
* Each slash-separated segment of the name is kept in one
* such structure, and they are linked together, to make
* traversing the name easier.
*/
struct path {
char npart[MAXNAMLEN+4]; /* name part of path segment */
struct path *fwd; /* forward ptr */
};
#ifndef NOPUSH
_PROTOTYP( int shxpand, (char *, char *[], int ) );
#endif /* NOPUSH */
_PROTOTYP( static int fgen, (char *, char *[], int ) );
_PROTOTYP( static VOID traverse, (struct path *, char *, char *) );
_PROTOTYP( static VOID addresult, (char *, int) );
#ifdef COMMENT
/* Replaced by ckmatch() */
_PROTOTYP( static int match, (char *, char *) );
#endif /* COMMENT */
_PROTOTYP( char * whoami, (void) );
_PROTOTYP( UID_T real_uid, (void) );
_PROTOTYP( static struct path *splitpath, (char *p) );
_PROTOTYP( char * zdtstr, (time_t) );
_PROTOTYP( time_t zstrdt, (char *, int) );
/* Some systems define these symbols in include files, others don't... */
#ifndef R_OK
#define R_OK 4 /* For access */
#endif /* R_OK */
#ifndef W_OK
#define W_OK 2
#endif /* W_OK */
#ifndef X_OK
#define X_OK 1
#endif /* X_OK */
#ifndef O_RDONLY
#define O_RDONLY 000
#endif /* O_RDONLY */
/* syslog and wtmp items for Internet Kermit Service */
extern char * clienthost; /* From ckcmai.c. */
static char fullname[CKMAXPATH+1];
static char tmp2[CKMAXPATH+1];
extern int ckxlogging;
#ifdef CKXPRINTF /* Our printf macro conflicts with */
#undef printf /* use of "printf" in syslog.h */
#endif /* CKXPRINTF */
#ifdef CKSYSLOG
#ifdef RTAIX
#include <sys/syslog.h>
#else /* RTAIX */
#include <syslog.h>
#endif /* RTAIX */
#endif /* CKSYSLOG */
#ifdef CKXPRINTF
#define printf ckxprintf
#endif /* CKXPRINTF */
int ckxanon = 1; /* Anonymous login ok */
int ckxperms = 0040; /* Anonymous file permissions */
int ckxpriv = 1; /* Priv'd login ok */
#ifndef XFERFILE
#define XFERFILE "/var/log/iksd.log"
#endif /* XFERFILE */
/* wtmp logging for IKSD... */
#ifndef CKWTMP /* wtmp logging not selected */
int ckxwtmp = 0; /* Know this at runtime */