Annotation of src/usr.bin/rdist/defs.h, Revision 1.37
1.37 ! millert 1: /* $OpenBSD: defs.h,v 1.36 2015/01/21 03:05:03 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:
39: #include <pwd.h>
1.21 guenther 40: #include <setjmp.h>
41: #include <signal.h>
1.2 dm 42:
1.13 millert 43: #ifndef __GNUC__
44: # ifndef __attribute__
45: # define __attribute__(a)
46: # endif
47: #endif
48:
1.2 dm 49: #include "version.h"
50: #include "config.h"
1.1 deraadt 51: #include "pathnames.h"
1.2 dm 52: #include "types.h"
53:
1.29 guenther 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
1.1 deraadt 60:
1.2 dm 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 */
1.36 guenther 70: #define IS_ON(b,f) (b & f)
1.2 dm 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: */
1.35 guenther 86: #define SYSERR strerror(errno)
1.2 dm 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 */
1.15 jmc 106: #define C_END 'E' /* Indicate end of receive/send */
1.2 dm 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 */
1.13 millert 111: #define C_CHMOG 'M' /* Chown,Chgrp,Chmod a file */
1.2 dm 112:
1.35 guenther 113: #define ack() (void) sendcmd(C_ACK, NULL)
114: #define err() (void) sendcmd(C_ERRMSG, NULL)
1.2 dm 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 */
1.1 deraadt 123:
1.2 dm 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 */
1.13 millert 131: #define SC_DEFOWNER 'o' /* Set default owner */
132: #define SC_DEFGROUP 'g' /* Set default group */
1.2 dm 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 */
1.1 deraadt 142:
1.2 dm 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:
1.35 guenther 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 */
1.2 dm 165: extern int rem_r; /* Remote file descriptor, reading */
1.35 guenther 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 */
1.37 ! millert 169: extern gid_t groupid; /* Group ID of rdist user */
1.35 guenther 170: extern jmp_buf finish_jmpbuf; /* Setjmp buffer for finish() */
1.13 millert 171: extern char defowner[64]; /* Default owner */
172: extern char defgroup[64]; /* Default group */
173: extern volatile sig_atomic_t contimedout; /* Connection timed out */
1.2 dm 174:
1.35 guenther 175:
1.2 dm 176: /*
1.35 guenther 177: * Declarations for files shared between rdist and rdistd
1.2 dm 178: */
179:
1.13 millert 180: /* common.c */
1.23 guenther 181: ssize_t xwrite(int, void *, size_t);
1.13 millert 182: int init(int, char **, char **);
183: void finish(void);
184: void lostconn(void);
185: void coredump(void);
186: void sighandler(int);
1.21 guenther 187: int sendcmd(char, const char *, ...) __attribute__((__format__ (printf, 2, 3)));
1.13 millert 188: int remline(u_char *, int, int);
1.17 krw 189: ssize_t readrem(char *, ssize_t);
1.22 guenther 190: char *getusername(uid_t, char *, opt_t);
191: char *getgroupname(gid_t, char *, opt_t);
1.13 millert 192: int response(void);
193: char *exptilde(char *, char *, size_t);
194: int becomeuser(void);
195: int becomeroot(void);
196: int setfiletime(char *, time_t, time_t);
197: char *getversion(void);
198: void runcommand(char *);
1.20 guenther 199: void *xmalloc(size_t);
200: void *xrealloc(void *, size_t);
201: void *xcalloc(size_t, size_t);
1.13 millert 202: char *xstrdup(const char *);
203: char *xbasename(char *);
204: char *searchpath(char *);
205:
206: /* message.c */
207: void msgprusage(void);
208: void msgprconfig(void);
209: char *msgparseopts(char *, int);
210: void checkhostname(void);
1.19 guenther 211: void message(int, const char *, ...) __attribute__((format (printf, 2, 3)));
212: void debugmsg(int, const char *, ...) __attribute__((format (printf, 2, 3)));
213: void error(const char *, ...) __attribute__((format (printf, 1, 2)));
214: void fatalerr(const char *, ...) __attribute__((format (printf, 1, 2)));
1.13 millert 215: char *getnotifyfile(void);
216:
1.35 guenther 217: /* client.c or server.c */
218: void cleanup(int);
1.13 millert 219:
220: #include <vis.h>
221: #define DECODE(a, b) strunvis(a, b)
222: #define ENCODE(a, b) strvis(a, b, VIS_WHITE)
1.2 dm 223:
224: #endif /* __DEFS_H__ */