File indexing completed on 2025-02-21 10:09:02
0001 *
0002 * $Id$
0003 *
0004 * $Log$
0005 * Revision 1.1 1996/03/01 11:38:49 mclareni
0006 * Initial revision
0007 *
0008 *
0009 *
0010 *CMZ : 13/11/95 18.36.34 by Timo Hakulinen
0011 *-- Author : Timo Hakulinen 25/08/94
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef STAGERD_H
0022 #define STAGERD_H
0023
0024
0025
0026 #include <stdio.h>
0027 #include <stdlib.h>
0028 #include <stdarg.h>
0029 #include <string.h>
0030 #include <setjmp.h>
0031 #include <signal.h>
0032 #include <time.h>
0033 #include <errno.h>
0034 #include <ctype.h>
0035
0036 #include <pwd.h>
0037 #include <fcntl.h>
0038 #include <syslog.h>
0039 #include <unistd.h>
0040 #include <sys/types.h>
0041 #include <sys/wait.h>
0042 #include <sys/param.h>
0043 #include <sys/stat.h>
0044 #ifdef _AIX
0045 #define NBBY 8
0046 #include <sys/select.h>
0047 #endif
0048
0049 #include <netdb.h>
0050 #include <sys/socket.h>
0051 #include <netinet/in.h>
0052 #include <netinet/tcp.h>
0053 #include <arpa/inet.h>
0054
0055
0056
0057 #define SGD_MSG_NONE 0
0058 #define SGD_MSG_ERROR 1
0059 #define SGD_MSG_OK 2
0060
0061 #define SGD_MSG_STAGE 3
0062 #define SGD_MSG_STATUS 4
0063 #define SGD_MSG_INIT 5
0064 #define SGD_MSG_PING 6
0065 #define SGD_MSG_FORGET 7
0066 #define SGD_MSG_TRANS 8
0067
0068
0069
0070 #define SGD_FTYP_NONE 0
0071 #define SGD_FTYP_LOCAL 1
0072 #define SGD_FTYP_TAPE 2
0073 #define SGD_FTYP_FATMEN 3
0074
0075
0076
0077 #define SGD_STATUS_NONE 0
0078 #define SGD_STATUS_ERROR 1
0079 #define SGD_STATUS_DONE 2
0080 #define SGD_STATUS_RUNNING 3
0081 #define SGD_STATUS_PENDING 4
0082 #define SGD_STATUS_CONNECT 5
0083
0084
0085
0086
0087 #define SGD_RET_OK 0
0088 #define SGD_RET_STAGERBIN 1
0089 #define SGD_RET_FTPBIN 2
0090 #define SGD_RET_PATHLEN 3
0091 #define SGD_RET_SFNAME 4
0092
0093 #define SGD_RET_FOPEN 6
0094 #define SGD_RET_POPEN 7
0095 #define SGD_RET_STAT 8
0096 #define SGD_RET_PW 9
0097 #define SGD_RET_PWDIR 10
0098 #define SGD_RET_CHDIR 11
0099 #define SGD_RET_CHMOD 12
0100 #define SGD_RET_CHOWN 13
0101 #define SGD_RET_FTPCONN 14
0102 #define SGD_RET_FTPREAD 15
0103 #define SGD_RET_FTPCD 16
0104 #define SGD_RET_FTPLOGIN 17
0105 #define SGD_RET_HBOOKFORM 18
0106 #define SGD_RET_WRITE 19
0107 #define SGD_RET_CLIOTIMEOUT 20
0108 #define SGD_RET_SIGNAL 21
0109 #define SGD_RET_FATMENFILE 22
0110 #define SGD_RET_TOOLONG 23
0111 #define SGD_RET_TAPEID 24
0112 #define SGD_RET_FATMENBIN 25
0113 #define SGD_RET_LOCKERR 26
0114 #define SGD_RET_RMBIN 27
0115 #define SGD_RET_FORKERR 28
0116 #define SGD_RET_CONCHECK 29
0117 #define SGD_RET_TFNAME 30
0118 #define SGD_RET_PIAFHOME 31
0119 #define SGD_RET_UNKNOWN 32
0120
0121 #define SGD_RET_LASTCODE SGD_RET_UNKNOWN
0122
0123
0124
0125 #define HBOOK_WORD_BYTES 4
0126 #define HBOOK_WORD_BITS (HBOOK_WORD_BYTES * 8)
0127 #define HBOOK_EXT ".hbook"
0128
0129 #define FSTRIPE_SIG "###FSTRIPE-V001###"
0130
0131 #define do_striping (bftp.bf_stripenum > 0)
0132
0133
0134
0135
0136 struct peer {
0137 char *pr_machname;
0138 char *pr_ipaddr;
0139 time_t pr_last;
0140 int pr_conport;
0141 int pr_lisport;
0142 int pr_sock;
0143 int pr_up;
0144 int pr_keep;
0145
0146
0147 struct peer *pr_next;
0148 };
0149
0150
0151
0152 struct pfinfo {
0153 char *pf_name;
0154 unsigned long pf_size;
0155 long pf_nrec;
0156 FILE *pf_out;
0157 struct peer *pf_peer;
0158 };
0159
0160
0161
0162 struct revector {
0163 unsigned long rt_stageid;
0164 time_t rt_time;
0165 struct revector *rt_next;
0166 };
0167
0168
0169
0170 struct transfer {
0171 pid_t tf_pid;
0172 struct transfer *tf_next;
0173 };
0174
0175
0176
0177 struct stage {
0178
0179
0180 char *sg_sfname;
0181 char *sg_tfname;
0182 char *sg_prserver;
0183 int sg_ftyp;
0184 unsigned long sg_fsiz;
0185 int sg_nowait;
0186
0187
0188 int sg_fnum;
0189 struct pfinfo *sg_ptfname;
0190 char *sg_masterip;
0191 char *sg_serverip;
0192 unsigned long sg_stageid;
0193 time_t sg_queuetime;
0194 time_t sg_starttime;
0195 time_t sg_endtime;
0196
0197
0198 char *sg_otfname;
0199
0200 char *sg_psfname;
0201 unsigned long sg_fdone;
0202
0203 int sg_status;
0204 int sg_retcode;
0205
0206
0207 char *sg_slavelist;
0208 pid_t sg_childpid;
0209 char *sg_lfname;
0210 struct stage *sg_next;
0211 };
0212
0213
0214
0215 struct client {
0216 char *ct_username;
0217 char *ct_machname;
0218 char *ct_ipaddr;
0219 char *ct_fusername;
0220 char *ct_passwd;
0221
0222 unsigned long ct_clientid;
0223 struct stage *ct_stagelist;
0224 struct client *ct_next;
0225 };
0226
0227
0228
0229 struct cliopar {
0230
0231
0232 char *bc_blocksize;
0233 char *bc_fileid;
0234 char *bc_format;
0235 char *bc_reclen;
0236 int bc_datsiz;
0237
0238
0239 int bc_version;
0240 char *bc_server;
0241 int bc_port;
0242 char *bc_login;
0243 int bc_retries;
0244 int bc_wait;
0245 };
0246
0247 struct ftppar {
0248 long bf_bufsize;
0249 int bf_stripenum;
0250 long bf_minsize;
0251 long bf_dotransfer;
0252 };
0253
0254 struct tcppar {
0255 long tc_rcvbuf;
0256 long tc_sndbuf;
0257 int tc_nodelay;
0258 };
0259
0260
0261 #define SIZE(s) (int)(sizeof(s) / sizeof((s)[0]))
0262
0263
0264 #define streql(a,b) !strcmp(a,b)
0265 #define strneql(a,b,n) !strncmp(a,b,n)
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287 #define IDBITS 32
0288
0289 #define MASTERBITS 3
0290 #define TIMESTAMPBITS 25
0291 #define REQUESTBITS 4
0292
0293 #define MAX_MASTERS (1 << MASTERBITS)
0294 #define MAX_TIMESTAMPS (1 << TIMESTAMPBITS)
0295 #define MAX_REQUESTS (1 << REQUESTBITS)
0296
0297 #define NEW_CLIENTID new_id(1)
0298 #define NEW_STAGEID new_id(0)
0299
0300 #define MAST_NUM(x) ((x) >> (IDBITS - MASTERBITS))
0301
0302
0303 #define MAX_SYSATTEMPTS 100
0304
0305
0306 #define RECV_ALARMTIMEOUT 300
0307
0308
0309 #define DEF_PENDINGTIME (5 * 60)
0310 #define DEF_SELECTTIMEOUT (5 * 60)
0311 #define DEF_STAGETIMEOUT -1
0312 #define DEF_PINGINTERVAL -1
0313 #define DEF_STAGECANCEL -1
0314
0315
0316 #define DEF_USERUMASK 026
0317
0318 #define useruperm (userumask ^ 0666)
0319
0320
0321 #define DEF_TMPPATH "/tmp/"
0322 #define DEF_NFSPATH "/nfs/"
0323
0324
0325 #define DEF_TRRECVBUF (16 * 1024)
0326
0327
0328 #define DEF_PIAFHOME "piaf/"
0329
0330
0331 #define TMP_TEMPLATE "stagerdXXXXXX"
0332
0333
0334 #define LOCKFILE_EXT ".#fslock#"
0335
0336
0337 #define MAX_PASSWD 40
0338
0339
0340
0341 #ifndef PATH_MAX
0342 # ifdef MAXPATHLEN
0343 # define PATH_MAX MAXPATHLEN
0344 # else
0345 # define PATH_MAX 255
0346 # endif
0347 #endif
0348 #if defined(ultrix) || defined(__hpux) || defined(_AIX)
0349 extern void syslog(int,char *,...);
0350 #endif
0351 #ifndef S_ISLNK
0352 # define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
0353 #endif
0354 #ifndef LOG_AUTH
0355 # define LOG_LOCAL0 0
0356 # define LOG_LOCAL1 0
0357 # define LOG_LOCAL2 0
0358 # define LOG_LOCAL3 0
0359 # define LOG_LOCAL4 0
0360 # define LOG_LOCAL5 0
0361 # define LOG_LOCAL6 0
0362 # define LOG_LOCAL7 0
0363 #endif
0364 #ifndef LOG_PID
0365 # define LOG_PID 0
0366 #endif
0367 #ifndef LOG_CONS
0368 # define LOG_CONS 0
0369 #endif
0370
0371
0372 #define MAX_VOLID 6
0373 #define MAX_FSEQID 2
0374 #define MAX_LBLTYP 3
0375 #define MAX_VOLSER 6
0376 #define MAX_TAPEID (MAX_VOLID + MAX_FSEQID + MAX_LBLTYP + MAX_VOLSER + 3)
0377
0378
0379 #define FSEQID_DEFAULT 1
0380 #define LBLTYP_DEFAULT "sl"
0381
0382
0383
0384 #define MAX_ULSTR 20
0385
0386
0387 #define MAX_MSGSTR 20
0388
0389 #define send_msg(s,m) sendstr(s,sgd_msg[m])
0390 #define send_ftyp(s,m) sendstr(s,sgd_ftyp[m])
0391 #define send_status(s,m) sendstr(s,sgd_status[m])
0392 #define recv_msg(s) recvmstr(s,sgd_msg)
0393 #define recv_ftyp(s) recvmstr(s,sgd_ftyp)
0394 #define recv_status(s) recvmstr(s,sgd_status)
0395
0396 #define find_slavebyip(ip) find_peerbyip(slavelist,ip)
0397 #define find_masterbyip(ip) find_peerbyip(selectlist,ip)
0398 #define tcplisaddr(p) tcpaddr(0,p)
0399 #define tcpconaddr(p) tcpaddr(1,p)
0400
0401 #ifndef PSTAGE
0402
0403
0404
0405
0406
0407 extern int recvul(int,unsigned long *);
0408 extern int sendul(int,unsigned long);
0409 extern int recvstr(int,char **,size_t *);
0410 extern int recvmstr(int,char **);
0411 extern int sendstr(int,char *);
0412
0413
0414
0415 #ifdef DEBUG_LOG
0416 # define DLOG_OPEN(s) dlog_open(s)
0417 # define DLOG_REOPEN(s) (dlog_close(), dlog_open(s))
0418 # define DLOG_CLOSE() dlog_close()
0419 # define DLOG_MSG(s) dlog_msg s
0420 # define DLOG_ERROR(s) dlog_error s
0421 # define DLOG_CLIENT(s) dlog_client(s)
0422 # define DLOG_STAGE(s) dlog_stage(s)
0423 # define DLOG_SOCKADDR_IN(a) dlog_sockaddr_in(a)
0424 extern void dlog_open(char *);
0425 extern void dlog_close(void);
0426 extern void dlog_msg(char *,...);
0427 extern void dvlog_error(char *,va_list);
0428 extern void dlog_error(char *,...);
0429 extern void dlog_client(struct client *);
0430 extern void dlog_stage(struct stage *);
0431 extern void dlog_sockaddr_in(struct sockaddr_in *);
0432 #else
0433 # define DLOG_OPEN(s)
0434 # define DLOG_REOPEN(s)
0435 # define DLOG_CLOSE()
0436 # define DLOG_MSG(s)
0437 # define DLOG_ERROR(s)
0438 # define DLOG_CLIENT(s)
0439 # define DLOG_STAGE(s)
0440 # define DLOG_SOCKADDR_IN(a)
0441 #endif
0442
0443
0444
0445 extern int m_master_ops(int,struct revector **);
0446 extern int m_flush_pending(long *);
0447
0448
0449
0450 extern int s_slave_ops(int,struct revector **);
0451 extern int s_check_children(void);
0452 extern int s_init_masters(void);
0453 extern int s_ping_masters(long *);
0454
0455
0456
0457 extern void c_child_ops(struct client *,struct stage *);
0458
0459
0460
0461 #ifdef DEBUG_ALLOC
0462 extern void dump_xallocinfo(FILE *);
0463 #endif
0464 extern void * x_malloc(size_t);
0465 extern void x_free(void *);
0466 extern int x_select(int,fd_set *,fd_set *,fd_set *,struct timeval *);
0467 extern int x_socket(int,int,int);
0468 extern int x_setsockopt(int,int,int,char *,int);
0469 extern int x_connect(int,struct sockaddr *,int);
0470 extern int x_accept(int,struct sockaddr *,int *);
0471 extern int x_bind(int,struct sockaddr *,int);
0472 extern int x_listen(int,int);
0473 extern int x_close(int);
0474 extern int x_shutdown(int,int);
0475
0476
0477
0478 extern void dumpstatus(void);
0479
0480
0481
0482 extern char * st_retcodestr(int);
0483
0484
0485
0486 extern void errlog(int,char *,...);
0487 extern void joblog(struct client *,struct stage *);
0488 extern void fatal(int,char *,...);
0489 extern void get_child_stat(pid_t,int,struct stage *);
0490
0491
0492
0493
0494 extern int is_striped(char *);
0495 extern unsigned long new_id(int);
0496 extern char * dcpass(char *);
0497 extern char * dupstr(char *);
0498 extern struct revector * add_revect(unsigned long);
0499 extern void remove_revect(struct revector *);
0500 extern struct revector * find_revect(unsigned long);
0501
0502
0503
0504 extern int tcpsockopt(int);
0505 extern char * get_peerip(int,struct sockaddr_in **);
0506 extern int tcpconnect(struct sockaddr_in *);
0507 extern int tcplisten(struct sockaddr_in *);
0508 extern struct sockaddr_in * tcpaddr(int,struct peer *);
0509 extern int ping_peer(struct peer *);
0510 extern void tell_to_forget(struct peer *,struct revector *);
0511
0512
0513
0514 extern struct client * find_client(struct client *);
0515 extern struct peer * find_peerbyip(struct peer *,char *);
0516 extern char * find_peeripbyname(char *);
0517 extern char * find_peeripbypath(char *);
0518 extern struct stage * find_stagebyid(unsigned long,struct client **);
0519 extern struct client * find_clientbyid(unsigned long);
0520 extern struct client * find_clientbystageid(unsigned long);
0521 extern struct stage * find_stagebypid(pid_t);
0522 extern void remove_transferbypid(pid_t);
0523 extern void release_peer(struct peer *);
0524 extern void release_client(struct client *);
0525 extern void release_stage(struct stage *);
0526 extern void remove_client(struct client *);
0527 extern void remove_stage(struct client *,struct stage *);
0528 extern size_t prlen_ulong(unsigned long);
0529 extern size_t prlen_long(long);
0530 extern size_t prlen_stage(struct stage *);
0531
0532
0533
0534 extern int put_client(int,struct client *);
0535 extern int get_client(int,struct client *);
0536 extern int put_stage(int,struct stage *);
0537 extern int get_stage(int,struct stage *);
0538
0539
0540
0541 extern int ftp_clio(FILE *,struct client *,struct stage *,
0542 char *,char *,char *,char *);
0543 extern int ftp_ftp(FILE *,struct client *,struct stage *,char *,char *);
0544
0545
0546
0547 extern int master;
0548 extern char *myname;
0549 extern char *myipaddr;
0550 extern char *mymachname;
0551 extern char *mailbin;
0552 extern char *ftpbin;
0553 extern char *stagerbin;
0554 extern char *fatmenbin;
0555 extern char *dpmbin;
0556 extern char *rmbin;
0557 extern char *nfspath;
0558 extern char *tmppath;
0559 extern struct cliopar bclio;
0560 extern struct ftppar bftp;
0561 extern struct tcppar tcpparam;
0562 extern char *syslogchn;
0563 extern char *errlogname;
0564 extern char *joblogname;
0565 extern char *dumpname;
0566 extern char *admin;
0567 extern char *piafhome;
0568 extern int pendingtime;
0569 extern int selecttimeout;
0570 extern int stagetimeout;
0571 extern int pinginterval;
0572 extern int stagecancel;
0573 extern int userumask;
0574 extern char *configfile;
0575 extern int updateconfig;
0576 extern int doshutdown;
0577 extern unsigned long master_id;
0578 extern struct client *clientlist;
0579 extern struct peer *selectlist;
0580 extern struct peer *slavelist;
0581 extern struct revector *revectorlist;
0582 extern struct transfer *transferlist;
0583 extern struct client cl_init;
0584 extern struct stage st_init;
0585 extern struct peer pe_init;
0586 extern char *ftyptb[];
0587 extern char *statustb[];
0588 extern char *sgd_msg[];
0589 extern char *sgd_ftyp[];
0590 extern char *sgd_status[];
0591
0592 #endif
0593
0594 #endif