[BACK]Return to defs.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / rdist

Annotation of src/usr.bin/rdist/defs.h, Revision 1.24

1.24    ! guenther    1: /*     $OpenBSD: defs.h,v 1.23 2014/07/10 20:35:35 guenther Exp $      */
1.8       millert     2:
1.2       dm          3: #ifndef __DEFS_H__
                      4: #define __DEFS_H__
1.1       deraadt     5: /*
1.2       dm          6:  * Copyright (c) 1983 Regents of the University of California.
                      7:  * All rights reserved.
1.1       deraadt     8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
1.14      millert    17:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
                     32:  */
                     33:
1.2       dm         34: /*
1.13      millert    35:  * $From: defs.h,v 1.6 2001/03/12 18:16:30 kim Exp $
1.2       dm         36:  * @(#)defs.h      5.2 (Berkeley) 3/20/86
                     37:  */
1.1       deraadt    38:
1.21      guenther   39: #include <sys/types.h>
                     40: #include <sys/param.h>
                     41: #include <sys/file.h>
                     42: #include <sys/time.h>
                     43: #include <sys/stat.h>
1.2       dm         44: #include <ctype.h>
1.1       deraadt    45: #include <errno.h>
1.21      guenther   46: #include <grp.h>
1.1       deraadt    47: #include <pwd.h>
1.12      millert    48: #include <regex.h>
1.21      guenther   49: #include <setjmp.h>
                     50: #include <signal.h>
                     51: #include <stdarg.h>
                     52: #include <stdio.h>
                     53: #include <stdlib.h>
                     54: #include <string.h>
1.2       dm         55: #include <syslog.h>
1.21      guenther   56: #include <unistd.h>
1.2       dm         57:
1.13      millert    58: #ifndef __GNUC__
                     59: # ifndef __attribute__
                     60: #  define __attribute__(a)
                     61: # endif
                     62: #endif
                     63:
1.2       dm         64: #include "version.h"
                     65: #include "config-def.h"
                     66: #include "config.h"
                     67: #include "config-data.h"
1.1       deraadt    68: #include "pathnames.h"
1.2       dm         69: #include "types.h"
1.13      millert    70: #include "filesys.h"
1.2       dm         71:
1.1       deraadt    72:
                     73: /*
1.2       dm         74:  * This belongs in os-svr4.h but many SVR4 OS's
                     75:  * define SVR4 externel to Rdist so we put this
                     76:  * check here.
1.1       deraadt    77:  */
1.2       dm         78: #if    defined(SVR4)
                     79: #define NEED_FCNTL_H
                     80: #define NEED_NETDB_H
                     81: #endif /* defined(SVR4) */
                     82:
                     83: #if    defined(NEED_NETDB_H)
                     84: #include <netdb.h>
                     85: #endif /* NEED_NETDB_H */
                     86: #if    defined(NEED_FCNTL_H)
                     87: #include <fcntl.h>
                     88: #endif /* NEED_FCNTL_H */
                     89: #if    defined(NEED_LIMITS_H)
                     90: #include <limits.h>
                     91: #endif /* NEED_LIMITS_H */
1.1       deraadt    92:
1.2       dm         93:        /* boolean truth */
                     94: #ifndef TRUE
                     95: #define TRUE           1
                     96: #endif
                     97: #ifndef FALSE
                     98: #define FALSE          0
                     99: #endif
                    100:
                    101:        /* file modes */
                    102: #ifndef S_IXUSR
                    103: #define S_IXUSR                0000100
                    104: #endif
                    105: #ifndef S_IXGRP
                    106: #define S_IXGRP                0000010
                    107: #endif
                    108: #ifndef S_IXOTH
                    109: #define S_IXOTH                0000001
                    110: #endif
1.1       deraadt   111:
                    112:        /* lexical definitions */
1.2       dm        113: #define        QUOTECHAR       160     /* quote next character */
1.1       deraadt   114:
                    115:        /* table sizes */
                    116: #define HASHSIZE       1021
1.2       dm        117: #define INMAX          3500
1.1       deraadt   118:
                    119:        /* expand type definitions */
1.2       dm        120: #define E_VARS         0x1
                    121: #define E_SHELL                0x2
                    122: #define E_TILDE                0x4
                    123: #define E_ALL          0x7
1.1       deraadt   124:
                    125:        /* actions for lookup() */
1.2       dm        126: #define LOOKUP         0
                    127: #define INSERT         1
                    128: #define REPLACE                2
                    129:
                    130:        /* Bit flag test macros */
                    131: #define IS_ON(b,f)     (b > 0 && (b & f))
                    132: #define IS_OFF(b,f)    !(IS_ON(b,f))
                    133: #define FLAG_ON(b,f)   b |= f
                    134: #define FLAG_OFF(b,f)  b &= ~(f)
                    135:
                    136: #define ALLOC(x)       (struct x *) xmalloc(sizeof(struct x))
                    137: #define A(s)           ((s) ? s : "<null>")
                    138:
                    139: /*
                    140:  * Environment variable names
                    141:  */
                    142: #define E_FILES                "FILES"                 /* List of files */
                    143: #define E_LOCFILE      "FILE"                  /* Local Filename  */
                    144: #define E_REMFILE      "REMFILE"               /* Remote Filename */
                    145: #define E_BASEFILE     "BASEFILE"              /* basename of Remote File */
                    146:
                    147: /*
                    148:  * Suffix to use when saving files
                    149:  */
                    150: #ifndef SAVE_SUFFIX
                    151: #define SAVE_SUFFIX    ".OLD"
                    152: #endif
1.1       deraadt   153:
1.2       dm        154: /*
                    155:  * Get system error string
                    156:  */
                    157: #define SYSERR                 strerror(errno)
                    158:
                    159: #define COMMENT_CHAR   '#'             /* Config file comment char */
                    160: #define CNULL          '\0'            /* NULL character */
                    161:
                    162: /*
                    163:  * These are the top level protocol commands.
                    164:  */
                    165: #define C_NONE         '='             /* No command - pass cleanly */
                    166: #define C_ERRMSG       '\1'            /* Log an error message */
                    167: #define C_FERRMSG      '\2'            /* Log a fatal error message */
                    168: #define C_NOTEMSG      '\3'            /* Log a note message */
                    169: #define C_LOGMSG       '\4'            /* Log a message */
                    170: #define C_ACK          '\5'            /* Acknowledge */
                    171: #define C_SETCONFIG    'c'             /* Set configuration parameters */
                    172: #define C_DIRTARGET    'T'             /* Set target directory name */
                    173: #define C_TARGET       't'             /* Set target file name */
                    174: #define C_RECVREG      'R'             /* Receive a regular file */
                    175: #define C_RECVDIR      'D'             /* Receive a directory */
                    176: #define C_RECVSYMLINK  'K'             /* Receive a symbolic link */
                    177: #define C_RECVHARDLINK 'k'             /* Receive a hard link */
1.15      jmc       178: #define C_END          'E'             /* Indicate end of receive/send */
1.2       dm        179: #define C_CLEAN                'C'             /* Clean up */
                    180: #define C_QUERY                'Q'             /* Query without checking */
                    181: #define C_SPECIAL      'S'             /* Execute special command */
                    182: #define C_CMDSPECIAL   's'             /* Execute cmd special command */
1.13      millert   183: #define C_CHMOG                'M'             /* Chown,Chgrp,Chmod a file */
1.2       dm        184:
1.21      guenther  185: #define        ack()           (void) sendcmd(C_ACK, NULL)
                    186: #define        err()           (void) sendcmd(C_ERRMSG, NULL)
1.2       dm        187:
                    188: /*
                    189:  * Session startup commands.
                    190:  */
                    191: #define S_VERSION      'V'             /* Version number */
                    192: #define S_REMOTEUSER   'R'             /* Remote user name */
                    193: #define S_LOCALUSER    'L'             /* Local user name */
                    194: #define S_END          'E'             /* End of session startup commands */
1.1       deraadt   195:
1.2       dm        196: /*
                    197:  * These are the commands for "set config".
                    198:  */
                    199: #define SC_FREESPACE   's'             /* Set min free space */
                    200: #define SC_FREEFILES   'f'             /* Set min free files */
                    201: #define SC_HOSTNAME    'H'             /* Set client hostname */
                    202: #define SC_LOGGING     'L'             /* Set logging options */
1.13      millert   203: #define SC_DEFOWNER    'o'             /* Set default owner */
                    204: #define SC_DEFGROUP    'g'             /* Set default group */
1.2       dm        205:
                    206: /*
                    207:  * Query commands
                    208:  */
                    209: #define QC_ONNFS       'F'             /* File exists & is on a NFS */
                    210: #define QC_ONRO                'O'             /* File exists & is on a readonly fs */
                    211: #define QC_NO          'N'             /* File does not exist */
                    212: #define QC_SYM         'l'             /* File exists & is a symlink */
                    213: #define QC_YES         'Y'             /* File does exist */
1.1       deraadt   214:
1.2       dm        215: /*
                    216:  * Clean commands
                    217:  */
                    218: #define CC_QUERY       'Q'             /* Query if file should be rm'ed */
                    219: #define CC_END         'E'             /* End of cleaning */
                    220: #define CC_YES         'Y'             /* File doesn't exist - remove */
                    221: #define CC_NO          'N'             /* File does exist - don't remove */
                    222:
                    223: /*
                    224:  * Run Command commands
                    225:  */
                    226: #define RC_FILE                'F'             /* Name of a target file */
                    227: #define RC_COMMAND     'C'             /* Command to run */
                    228:
                    229: /*
                    230:  * Name list
                    231:  */
                    232: struct namelist {              /* for making lists of strings */
1.1       deraadt   233:        char    *n_name;
1.12      millert   234:        regex_t *n_regex;
1.1       deraadt   235:        struct  namelist *n_next;
                    236: };
                    237:
1.2       dm        238: /*
                    239:  * Sub command structure
                    240:  */
1.1       deraadt   241: struct subcmd {
                    242:        short   sc_type;        /* type - INSTALL,NOTIFY,EXCEPT,SPECIAL */
1.2       dm        243:        opt_t   sc_options;
1.1       deraadt   244:        char    *sc_name;
                    245:        struct  namelist *sc_args;
                    246:        struct  subcmd *sc_next;
                    247: };
                    248:
1.2       dm        249: /*
                    250:  * Cmd flags
                    251:  */
                    252: #define CMD_ASSIGNED   0x01    /* This entry has been assigned */
                    253: #define CMD_CONNFAILED 0x02    /* Connection failed */
                    254: #define CMD_NOCHKNFS   0x04    /* Disable NFS checks */
                    255:
                    256: /*
                    257:  * General command structure
                    258:  */
1.1       deraadt   259: struct cmd {
                    260:        int     c_type;         /* type - ARROW,DCOLON */
1.2       dm        261:        int     c_flags;        /* flags - CMD_USED,CMD_FAILED */
1.1       deraadt   262:        char    *c_name;        /* hostname or time stamp file name */
                    263:        char    *c_label;       /* label for partial update */
                    264:        struct  namelist *c_files;
                    265:        struct  subcmd *c_cmds;
                    266:        struct  cmd *c_next;
                    267: };
                    268:
1.2       dm        269: /*
                    270:  * Hard link buffer information
                    271:  */
1.1       deraadt   272: struct linkbuf {
                    273:        ino_t   inum;
                    274:        dev_t   devnum;
                    275:        int     count;
1.10      millert   276:        char    *pathname;
                    277:        char    *src;
                    278:        char    *target;
1.1       deraadt   279:        struct  linkbuf *nextp;
                    280: };
                    281:
1.2       dm        282: extern char           *optarg;         /* Option argument */
                    283: extern char           *path_remsh;     /* Remote shell command */
                    284: extern char            host[];         /* Host name of master copy */
                    285: extern char           *currenthost;    /* Name of current host */
                    286: extern char           *progname;       /* Name of this program */
                    287: extern char          **realargv;       /* Real argv */
                    288: extern int             optind;         /* Option index into argv */
                    289: extern int             debug;          /* Debugging flag */
                    290: extern opt_t           defoptions;     /* Default install options */
                    291: extern int             do_fork;        /* Should we do fork()'ing */
1.13      millert   292: #ifndef __STDC__
1.2       dm        293: extern int             errno;          /* System error number */
1.13      millert   294: #endif
1.2       dm        295: extern int             isserver;       /* Acting as remote server */
                    296: extern int             nerrs;          /* Number of errors seen */
                    297: extern int             nflag;          /* NOP flag, don't execute commands */
                    298: extern opt_t           options;        /* Global options */
                    299: extern int             proto_version;  /* Protocol version number */
                    300: extern int             realargc;       /* Real argc */
                    301: extern int             rem_r;          /* Remote file descriptor, reading */
                    302: extern int             rem_w;          /* Remote file descriptor, writing */
                    303: extern int             rtimeout;       /* Response time out in seconds */
1.3       dm        304: extern int             setjmp_ok;      /* setjmp/longjmp flag */
1.22      guenther  305: extern uid_t           userid;         /* User ID of rdist user */
1.2       dm        306: extern jmp_buf                 finish_jmpbuf;  /* Setjmp buffer for finish() */
                    307: extern struct linkbuf  *ihead; /* list of files with more than one link */
                    308: extern struct passwd   *pw;    /* pointer to static area used by getpwent */
1.13      millert   309: extern char defowner[64];              /* Default owner */
                    310: extern char defgroup[64];              /* Default group */
                    311: extern volatile sig_atomic_t contimedout; /* Connection timed out */
1.2       dm        312: #ifdef USE_STATDB
                    313: extern int             dostatdb;
                    314: extern int             juststatdb;
                    315: #endif /* USE_STATDB */
                    316:
                    317: /*
1.13      millert   318:  * Our own declarations.
1.2       dm        319:  */
                    320:
1.13      millert   321: /* child.c */
                    322: void waitup(void);
                    323: int spawn(struct cmd *, struct cmd *);
                    324:
                    325: /* client.c */
                    326: char *remfilename(char *, char *, char *, char *, int);
                    327: int inlist(struct namelist *, char *);
                    328: void runcmdspecial(struct cmd *, opt_t);
                    329: int checkfilename(char *);
                    330: void freelinkinfo(struct linkbuf *);
                    331: void cleanup(int);
                    332: int install(char *, char *, int, int , opt_t);
                    333:
                    334: /* common.c */
1.23      guenther  335: ssize_t xwrite(int, void *, size_t);
1.13      millert   336: int init(int, char **, char **);
                    337: void finish(void);
                    338: void lostconn(void);
                    339: void coredump(void);
                    340: void sighandler(int);
1.21      guenther  341: int sendcmd(char, const char *, ...) __attribute__((__format__ (printf, 2, 3)));
1.13      millert   342: int remline(u_char *, int, int);
1.17      krw       343: ssize_t readrem(char *, ssize_t);
1.22      guenther  344: char *getusername(uid_t, char *, opt_t);
                    345: char *getgroupname(gid_t, char *, opt_t);
1.13      millert   346: int response(void);
                    347: char *exptilde(char *, char *, size_t);
                    348: int becomeuser(void);
                    349: int becomeroot(void);
                    350: int setfiletime(char *, time_t, time_t);
                    351: char *getversion(void);
                    352: void runcommand(char *);
1.20      guenther  353: void *xmalloc(size_t);
                    354: void *xrealloc(void *, size_t);
                    355: void *xcalloc(size_t, size_t);
1.13      millert   356: char *xstrdup(const char *);
                    357: char *xbasename(char *);
                    358: char *searchpath(char *);
                    359:
                    360: /* distopt.c */
                    361: DISTOPTINFO *getdistopt(char *, int *);
                    362: int parsedistopts(char *, opt_t *, int);
                    363: char *getdistoptlist(void);
                    364: char *getondistoptlist(opt_t);
                    365:
                    366: /* docmd.c */
                    367: void markassigned(struct cmd *, struct cmd *);
                    368: int okname(char *);
                    369: int except(char *);
                    370: void docmds(struct namelist *, int, char **);
                    371:
                    372: /* expand.c */
                    373: struct namelist *expand(struct namelist *, int);
                    374: u_char *xstrchr(u_char *, int);
                    375: void expstr(u_char *);
                    376: void expsh(u_char *);
                    377: void matchdir(char *);
                    378: int execbrc(u_char *, u_char *);
                    379: int match(char *, char *);
                    380: int amatch(char *, u_char *);
                    381:
                    382: /* filesys.c */
                    383: char *find_file(char *, struct stat *, int *);
                    384: mntent_t *findmnt(struct stat *, struct mntinfo *);
                    385: int isdupmnt(mntent_t *, struct mntinfo *);
                    386: void wakeup(int);
                    387: struct mntinfo *makemntinfo(struct mntinfo *);
                    388: mntent_t *getmntpt(char *, struct stat *, int *);
                    389: int is_nfs_mounted(char *, struct stat *, int *);
                    390: int is_ro_mounted(char *, struct stat *, int *);
                    391: int is_symlinked(char *, struct stat *, int *);
1.17      krw       392: int getfilesysinfo(char *, int64_t *, int64_t *);
1.13      millert   393:
                    394: /* gram.c */
                    395: int yylex(void);
                    396: int any(int, char *);
                    397: void insert(char *, struct namelist *, struct namelist *, struct subcmd *);
                    398: void append(char *, struct namelist *, char *, struct subcmd *);
                    399: void yyerror(char *);
                    400: struct namelist *makenl(char *);
                    401: struct subcmd *makesubcmd(int);
                    402: int yyparse(void);
                    403:
                    404: /* hasmntopt.c */
                    405: #ifdef NEED_HASMNTOPT
                    406: char *hasmntopt(struct mntent *, char *);
                    407: #endif
                    408:
                    409: /* isexec.c */
                    410: int isexec(char *, struct stat *);
                    411:
                    412: /* lookup.c */
                    413: void define(char *);
                    414: struct namelist *lookup(char *, int, struct namelist *);
                    415:
                    416: /* message.c */
                    417: void msgprusage(void);
                    418: void msgprconfig(void);
                    419: char *msgparseopts(char *, int);
                    420: void checkhostname(void);
1.19      guenther  421: void message(int, const char *, ...) __attribute__((format (printf, 2, 3)));
                    422: void debugmsg(int, const char *, ...) __attribute__((format (printf, 2, 3)));
                    423: void error(const char *, ...) __attribute__((format (printf, 1, 2)));
                    424: void fatalerr(const char *, ...) __attribute__((format (printf, 1, 2)));
1.13      millert   425: char *getnotifyfile(void);
                    426:
                    427: /* rdist.c */
                    428: FILE *opendist(char *);
                    429: void docmdargs(int, char *[]);
                    430: char *getnlstr(struct namelist *);
                    431:
                    432: /* rshrcmd.c */
                    433: int rshrcmd(char **, u_short, char *, char *, char *, int *);
                    434:
                    435: /* server.c */
                    436: void server(void);
                    437:
                    438: /* setargs.c */
                    439: void setargs_settup(int, char **, char **);
                    440: void _setproctitle(char *);
                    441: void setproctitle(const char *, ...);
                    442:
                    443: /* signal.c */
                    444: #ifdef NEED_SIGBLOCK
                    445: int sigblock(int);
                    446: #endif
                    447: #ifdef NEED_SIGMASK
                    448: int sigsetmask(int);
                    449: #endif
                    450:
                    451: /* strcasecmp.c */
                    452: #ifdef NEED_STRCASECMP
                    453: int strcasecmp(char *, char *);
                    454: int strncasecmp(char *, char *, int);
                    455: #endif
                    456:
                    457: /* strerror.c */
                    458: #ifdef NEED_STRERROR
                    459: char *strerror(int);
                    460: #endif
                    461:
                    462: /* strtol.c */
                    463: #ifdef NEED_STRTOL
                    464: long strtol(char *, char **, int);
                    465: #endif
                    466:
                    467: /* unvis.c */
                    468: #ifdef NEED_VIS
                    469: int unvis(char *, int, int *, int );
                    470: int strunvis(char *, const char *);
                    471: #endif
                    472:
                    473: /* vis.c */
                    474: #ifdef NEED_VIS
                    475: char *vis(char *, int, int, int );
                    476: int strvis(char *, const char *, int);
                    477: int strvisx(char *, const char *, size_t, int);
                    478: #endif
                    479:
                    480: /* vsnprintf.c */
                    481: #ifdef NEED_VSNPRINTF
                    482: int vsnprintf(char *, size_t, const char *, va_list);
                    483: int snprintf(char *, size_t, const char *, ...);
                    484: #endif
                    485:
                    486: /* zopen.c */
                    487: int zread(void *, char *, int);
                    488: int zwrite(void *, const char *, int);
                    489: int z_close(void *);
                    490: void *z_open(int, char *, int);
                    491:
                    492: #include <vis.h>
                    493: #define DECODE(a, b)   strunvis(a, b)
                    494: #define ENCODE(a, b)   strvis(a, b, VIS_WHITE)
1.2       dm        495:
                    496: #endif /* __DEFS_H__ */