1 /* $OpenBSD: defs.h,v 1.40 2024/05/21 05:00:48 jsg Exp $ */ 2 3 #ifndef __DEFS_H__ 4 #define __DEFS_H__ 5 /* 6 * Copyright (c) 1983 Regents of the University of California. 7 * All rights reserved. 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. 17 * 3. Neither the name of the University nor the names of its contributors 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 34 /* 35 * $From: defs.h,v 1.6 2001/03/12 18:16:30 kim Exp $ 36 * @(#)defs.h 5.2 (Berkeley) 3/20/86 37 */ 38 39 #include <pwd.h> 40 #include <setjmp.h> 41 #include <signal.h> 42 43 #ifndef __GNUC__ 44 # ifndef __attribute__ 45 # define __attribute__(a) 46 # endif 47 #endif 48 49 #include "version.h" 50 #include "config.h" 51 #include "pathnames.h" 52 #include "types.h" 53 54 /* 55 * Define the read and write values for the file descriptor array 56 * used by pipe(). 57 */ 58 #define PIPE_READ 0 59 #define PIPE_WRITE 1 60 61 /* boolean truth */ 62 #ifndef TRUE 63 #define TRUE 1 64 #endif 65 #ifndef FALSE 66 #define FALSE 0 67 #endif 68 69 /* Bit flag test macros */ 70 #define IS_ON(b,f) (b & f) 71 #define IS_OFF(b,f) !(IS_ON(b,f)) 72 #define FLAG_ON(b,f) b |= f 73 #define FLAG_OFF(b,f) b &= ~(f) 74 75 /* 76 * Environment variable names 77 */ 78 #define E_FILES "FILES" /* List of files */ 79 #define E_LOCFILE "FILE" /* Local Filename */ 80 #define E_REMFILE "REMFILE" /* Remote Filename */ 81 #define E_BASEFILE "BASEFILE" /* basename of Remote File */ 82 83 /* 84 * Get system error string 85 */ 86 #define SYSERR strerror(errno) 87 88 #define CNULL '\0' /* NULL character */ 89 90 /* 91 * These are the top level protocol commands. 92 */ 93 #define C_NONE '=' /* No command - pass cleanly */ 94 #define C_ERRMSG '\1' /* Log an error message */ 95 #define C_FERRMSG '\2' /* Log a fatal error message */ 96 #define C_NOTEMSG '\3' /* Log a note message */ 97 #define C_LOGMSG '\4' /* Log a message */ 98 #define C_ACK '\5' /* Acknowledge */ 99 #define C_SETCONFIG 'c' /* Set configuration parameters */ 100 #define C_DIRTARGET 'T' /* Set target directory name */ 101 #define C_TARGET 't' /* Set target file name */ 102 #define C_RECVREG 'R' /* Receive a regular file */ 103 #define C_RECVDIR 'D' /* Receive a directory */ 104 #define C_RECVSYMLINK 'K' /* Receive a symbolic link */ 105 #define C_RECVHARDLINK 'k' /* Receive a hard link */ 106 #define C_END 'E' /* Indicate end of receive/send */ 107 #define C_CLEAN 'C' /* Clean up */ 108 #define C_QUERY 'Q' /* Query without checking */ 109 #define C_SPECIAL 'S' /* Execute special command */ 110 #define C_CMDSPECIAL 's' /* Execute cmd special command */ 111 #define C_CHMOG 'M' /* Chown,Chgrp,Chmod a file */ 112 113 #define ack() (void) sendcmd(C_ACK, NULL) 114 #define err() (void) sendcmd(C_ERRMSG, NULL) 115 116 /* 117 * Session startup commands. 118 */ 119 #define S_VERSION 'V' /* Version number */ 120 #define S_REMOTEUSER 'R' /* Remote user name */ 121 #define S_LOCALUSER 'L' /* Local user name */ 122 #define S_END 'E' /* End of session startup commands */ 123 124 /* 125 * These are the commands for "set config". 126 */ 127 #define SC_FREESPACE 's' /* Set min free space */ 128 #define SC_FREEFILES 'f' /* Set min free files */ 129 #define SC_HOSTNAME 'H' /* Set client hostname */ 130 #define SC_LOGGING 'L' /* Set logging options */ 131 #define SC_DEFOWNER 'o' /* Set default owner */ 132 #define SC_DEFGROUP 'g' /* Set default group */ 133 134 /* 135 * Query commands 136 */ 137 #define QC_ONNFS 'F' /* File exists & is on a NFS */ 138 #define QC_ONRO 'O' /* File exists & is on a readonly fs */ 139 #define QC_NO 'N' /* File does not exist */ 140 #define QC_SYM 'l' /* File exists & is a symlink */ 141 #define QC_YES 'Y' /* File does exist */ 142 143 /* 144 * Clean commands 145 */ 146 #define CC_QUERY 'Q' /* Query if file should be rm'ed */ 147 #define CC_END 'E' /* End of cleaning */ 148 #define CC_YES 'Y' /* File doesn't exist - remove */ 149 #define CC_NO 'N' /* File does exist - don't remove */ 150 151 /* 152 * Run Command commands 153 */ 154 #define RC_FILE 'F' /* Name of a target file */ 155 #define RC_COMMAND 'C' /* Command to run */ 156 157 158 extern char *currenthost; /* Name of current host */ 159 extern char *progname; /* Name of this program */ 160 extern char *locuser; /* Local User's name */ 161 extern int debug; /* Debugging flag */ 162 extern int isserver; /* Acting as remote server */ 163 extern int nerrs; /* Number of errors seen */ 164 extern opt_t options; /* Global options */ 165 extern int rem_r; /* Remote file descriptor, reading */ 166 extern int rem_w; /* Remote file descriptor, writing */ 167 extern int rtimeout; /* Response time out in seconds */ 168 extern uid_t userid; /* User ID of rdist user */ 169 extern gid_t groupid; /* Group ID of rdist user */ 170 extern gid_t gidset[]; /* List of group IDs of rdist user */ 171 extern int gidsetlen; /* Number of group IDs in list */ 172 extern jmp_buf finish_jmpbuf; /* Setjmp buffer for finish() */ 173 extern char defowner[64]; /* Default owner */ 174 extern char defgroup[64]; /* Default group */ 175 extern volatile sig_atomic_t contimedout; /* Connection timed out */ 176 177 178 /* 179 * Declarations for files shared between rdist and rdistd 180 */ 181 182 /* common.c */ 183 ssize_t xwrite(int, void *, size_t); 184 int init(int, char **, char **); 185 void finish(void); 186 void lostconn(void); 187 void sighandler(int); 188 int sendcmd(char, const char *, ...) __attribute__((__format__ (printf, 2, 3))); 189 int remline(u_char *, int, int); 190 ssize_t readrem(char *, ssize_t); 191 char *getusername(uid_t, char *, opt_t); 192 char *getgroupname(gid_t, char *, opt_t); 193 int response(void); 194 char *exptilde(char *, char *, size_t); 195 int setfiletime(char *, time_t, time_t); 196 char *getversion(void); 197 void runcommand(char *); 198 void *xmalloc(size_t); 199 void *xrealloc(void *, size_t); 200 void *xcalloc(size_t, size_t); 201 char *xstrdup(const char *); 202 char *xbasename(char *); 203 char *searchpath(char *); 204 205 /* message.c */ 206 void msgprconfig(void); 207 char *msgparseopts(char *, int); 208 void checkhostname(void); 209 void message(int, const char *, ...) __attribute__((format (printf, 2, 3))); 210 void debugmsg(int, const char *, ...) __attribute__((format (printf, 2, 3))); 211 void error(const char *, ...) __attribute__((format (printf, 1, 2))); 212 void fatalerr(const char *, ...) __attribute__((format (printf, 1, 2))); 213 char *getnotifyfile(void); 214 215 /* client.c or server.c */ 216 void cleanup(int); 217 218 #include <vis.h> 219 #define DECODE(a, b) strunvis(a, b) 220 #define ENCODE(a, b) strvis(a, b, VIS_WHITE) 221 222 #endif /* __DEFS_H__ */ 223