1 /*
2  * Configuration file definitions for the CUPS scheduler.
3  *
4  * Copyright © 2007-2018 by Apple Inc.
5  * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
6  *
7  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
8  * information.
9  */
10 
11 
12 /*
13  * Log levels...
14  */
15 
16 typedef enum
17 {
18   CUPSD_LOG_PPD = -5,			/* Used internally for PPD keywords */
19   CUPSD_LOG_ATTR,			/* Used internally for attributes */
20   CUPSD_LOG_STATE,			/* Used internally for printer-state-reasons */
21   CUPSD_LOG_JOBSTATE,			/* Used internally for job-state-reasons */
22   CUPSD_LOG_PAGE,			/* Used internally for page logging */
23   CUPSD_LOG_NONE,
24   CUPSD_LOG_EMERG,			/* Emergency issues */
25   CUPSD_LOG_ALERT,			/* Something bad happened that needs attention */
26   CUPSD_LOG_CRIT,			/* Critical error but server continues */
27   CUPSD_LOG_ERROR,			/* Error condition */
28   CUPSD_LOG_WARN,			/* Warning */
29   CUPSD_LOG_NOTICE,			/* Normal condition that needs logging */
30   CUPSD_LOG_INFO,			/* General information */
31   CUPSD_LOG_DEBUG,			/* General debugging */
32   CUPSD_LOG_DEBUG2			/* Detailed debugging */
33 } cupsd_loglevel_t;
34 
35 typedef enum
36 {
37   CUPSD_ACCESSLOG_NONE,			/* Log no requests */
38   CUPSD_ACCESSLOG_CONFIG,		/* Log config requests */
39   CUPSD_ACCESSLOG_ACTIONS,		/* Log config, print, and job management requests */
40   CUPSD_ACCESSLOG_ALL			/* Log everything */
41 } cupsd_accesslog_t;
42 
43 typedef enum
44 {
45   CUPSD_TIME_STANDARD,			/* "Standard" Apache/CLF format */
46   CUPSD_TIME_USECS			/* Standard format with microseconds */
47 } cupsd_time_t;
48 
49 typedef enum
50 {
51   CUPSD_SANDBOXING_OFF,			/* No sandboxing */
52   CUPSD_SANDBOXING_RELAXED,		/* Relaxed sandboxing */
53   CUPSD_SANDBOXING_STRICT		/* Strict sandboxing */
54 } cupsd_sandboxing_t;
55 
56 
57 /*
58  * FatalErrors flags...
59  */
60 
61 #define CUPSD_FATAL_NONE	0	/* No errors are fatal */
62 #define CUPSD_FATAL_BROWSE	1	/* Browse bind errors are fatal */
63 #define CUPSD_FATAL_CONFIG	2	/* Config file syntax errors are fatal */
64 #define CUPSD_FATAL_LISTEN	4	/* Listen/Port bind errors are fatal */
65 #define CUPSD_FATAL_LOG		8	/* Log file errors are fatal */
66 #define CUPSD_FATAL_PERMISSIONS	16	/* File permission errors are fatal */
67 #define CUPSD_FATAL_ALL		~0	/* All errors are fatal */
68 
69 
70 /*
71  * Printcap formats...
72  */
73 
74 #define PRINTCAP_BSD		0	/* Berkeley LPD format */
75 #define PRINTCAP_SOLARIS	1	/* Solaris lpsched format */
76 #define PRINTCAP_PLIST		2	/* macOS plist format */
77 
78 
79 /*
80  * ServerAlias data...
81  */
82 
83 typedef struct
84 {
85   size_t	namelen;		/* Length of alias name */
86   char		name[1];		/* Alias name */
87 } cupsd_alias_t;
88 
89 
90 /*
91  * Globals...
92  */
93 
94 VAR char		*ConfigurationFile	VALUE(NULL),
95 					/* cupsd.conf file to use */
96 			*CupsFilesFile		VALUE(NULL),
97 					/* cups-files.conf file to use */
98 			*ServerName		VALUE(NULL),
99 					/* FQDN for server */
100 			*ServerAdmin		VALUE(NULL),
101 					/* Administrator's email */
102 			*ServerRoot		VALUE(NULL),
103 					/* Root directory for scheduler */
104 			*ServerBin		VALUE(NULL),
105 					/* Root directory for binaries */
106 			*StateDir		VALUE(NULL),
107 					/* Root directory for state data */
108 			*RequestRoot		VALUE(NULL),
109 					/* Directory for request files */
110 			*DocumentRoot		VALUE(NULL);
111 					/* Root directory for documents */
112 VAR cups_array_t	*ServerAlias		VALUE(NULL);
113 					/* Alias names for server */
114 VAR int			ServerNameIsIP		VALUE(0);
115 					/* Is the ServerName an IP address? */
116 VAR int			NumSystemGroups		VALUE(0);
117 					/* Number of system group names */
118 VAR char		*SystemGroups[MAX_SYSTEM_GROUPS]
119 						VALUE({0});
120 					/* System group names */
121 VAR gid_t		SystemGroupIDs[MAX_SYSTEM_GROUPS]
122 						VALUE({0});
123 					/* System group IDs */
124 VAR char		*AccessLog		VALUE(NULL),
125 					/* Access log filename */
126 			*ErrorLog		VALUE(NULL),
127 					/* Error log filename */
128 			*PageLog		VALUE(NULL),
129 					/* Page log filename */
130 			*CacheDir		VALUE(NULL),
131 					/* Cache file directory */
132 			*DataDir		VALUE(NULL),
133 					/* Data file directory */
134 			*DefaultLanguage	VALUE(NULL),
135 					/* Default language encoding */
136 			*DefaultLocale		VALUE(NULL),
137 					/* Default locale */
138 			*DefaultPaperSize	VALUE(NULL),
139 					/* Default paper size */
140 			*ErrorPolicy		VALUE(NULL),
141 					/* Default printer-error-policy */
142 			*RIPCache		VALUE(NULL),
143 					/* Amount of memory for RIPs */
144 			*TempDir		VALUE(NULL),
145 					/* Temporary directory */
146 			*Printcap		VALUE(NULL),
147 					/* Printcap file */
148 			*FontPath		VALUE(NULL),
149 					/* Font search path */
150 			*RemoteRoot		VALUE(NULL),
151 					/* Remote root user */
152 			*Classification		VALUE(NULL);
153 					/* Classification of system */
154 VAR uid_t		User			VALUE(1),
155 					/* User ID for server */
156 			RunUser			VALUE(0);
157 					/* User to run as, used for files */
158 VAR gid_t		Group			VALUE(0);
159 					/* Group ID for server */
160 VAR cupsd_accesslog_t	AccessLogLevel		VALUE(CUPSD_ACCESSLOG_ACTIONS);
161 					/* Access log level */
162 VAR int			ClassifyOverride	VALUE(0),
163 					/* Allow overrides? */
164 			LogDebugHistory		VALUE(200),
165 					/* Amount of automatic debug history */
166 			FatalErrors		VALUE(CUPSD_FATAL_CONFIG),
167 					/* Which errors are fatal? */
168 			StrictConformance	VALUE(FALSE),
169 					/* Require strict IPP conformance? */
170 			SyncOnClose		VALUE(FALSE);
171 					/* Call fsync() when closing files? */
172 VAR mode_t		ConfigFilePerm		VALUE(0640U),
173 					/* Permissions for config files */
174 			LogFilePerm		VALUE(0644U);
175 					/* Permissions for log files */
176 VAR cupsd_loglevel_t	LogLevel		VALUE(CUPSD_LOG_WARN);
177 					/* Error log level */
178 VAR cupsd_time_t	LogTimeFormat		VALUE(CUPSD_TIME_STANDARD);
179 					/* Log file time format */
180 VAR cups_file_t		*LogStderr		VALUE(NULL);
181 					/* Stderr file, if any */
182 VAR cupsd_sandboxing_t	Sandboxing		VALUE(CUPSD_SANDBOXING_STRICT);
183 					/* Sandboxing level */
184 VAR int			UseSandboxing	VALUE(1);
185 					/* Use sandboxing for child procs? */
186 VAR int			MaxClients		VALUE(100),
187 					/* Maximum number of clients */
188 			MaxClientsPerHost	VALUE(0),
189 					/* Maximum number of clients per host */
190 			MaxCopies		VALUE(CUPS_DEFAULT_MAX_COPIES),
191 					/* Maximum number of copies per job */
192 			MaxLogSize		VALUE(1024 * 1024),
193 					/* Maximum size of log files */
194 			MaxRequestSize		VALUE(0),
195 					/* Maximum size of IPP requests */
196 			HostNameLookups		VALUE(FALSE),
197 					/* Do we do reverse lookups? */
198 			Timeout			VALUE(DEFAULT_TIMEOUT),
199 					/* Timeout during requests */
200 			KeepAlive		VALUE(TRUE),
201 					/* Support the Keep-Alive option? */
202 			KeepAliveTimeout	VALUE(DEFAULT_KEEPALIVE),
203 					/* Timeout between requests */
204 			FileDevice		VALUE(FALSE),
205 					/* Allow file: devices? */
206 			FilterLimit		VALUE(0),
207 					/* Max filter cost at any time */
208 			FilterLevel		VALUE(0),
209 					/* Current filter level */
210 			FilterNice		VALUE(0),
211 					/* Nice value for filters */
212 			ReloadTimeout		VALUE(DEFAULT_KEEPALIVE),
213 					/* Timeout before reload from SIGHUP */
214 			RootCertDuration	VALUE(300),
215 					/* Root certificate update interval */
216 			PrintcapFormat		VALUE(PRINTCAP_BSD),
217 					/* Format of printcap file? */
218 			DefaultShared		VALUE(TRUE),
219 					/* Share printers by default? */
220 			MultipleOperationTimeout VALUE(DEFAULT_TIMEOUT),
221 					/* multiple-operation-time-out value */
222 			WebInterface		VALUE(CUPS_DEFAULT_WEBIF);
223 					/* Enable the web interface? */
224 VAR cups_file_t		*AccessFile		VALUE(NULL),
225 					/* Access log file */
226 			*ErrorFile		VALUE(NULL),
227 					/* Error log file */
228 			*PageFile		VALUE(NULL);
229 					/* Page log file */
230 VAR char		*PageLogFormat		VALUE(NULL);
231 					/* Page log format */
232 VAR mime_t		*MimeDatabase		VALUE(NULL);
233 					/* MIME type database */
234 VAR int			NumMimeTypes		VALUE(0);
235 					/* Number of MIME types */
236 VAR const char		**MimeTypes		VALUE(NULL);
237 					/* Array of MIME types */
238 
239 #ifdef HAVE_SSL
240 VAR int			CreateSelfSignedCerts	VALUE(TRUE);
241 					/* Automatically create self-signed certs? */
242 VAR char		*ServerKeychain		VALUE(NULL);
243 					/* Keychain holding cert + key */
244 #endif /* HAVE_SSL */
245 
246 #ifdef HAVE_ONDEMAND
247 VAR int			IdleExitTimeout		VALUE(60);
248 					/* Time after which an idle cupsd will exit */
249 #endif /* HAVE_ONDEMAND */
250 
251 #ifdef HAVE_AUTHORIZATION_H
252 VAR char		*SystemGroupAuthKey	VALUE(NULL);
253 					/* System group auth key */
254 #endif /* HAVE_AUTHORIZATION_H */
255 
256 #ifdef HAVE_GSSAPI
257 VAR char		*GSSServiceName		VALUE(NULL);
258 					/* GSS service name */
259 VAR int			HaveServerCreds		VALUE(0);
260 					/* Do we have server credentials? */
261 VAR gss_cred_id_t	ServerCreds;	/* Server's GSS credentials */
262 #endif /* HAVE_GSSAPI */
263 
264 
265 /*
266  * Prototypes...
267  */
268 
269 extern void	cupsdAddAlias(cups_array_t *aliases, const char *name);
270 extern int	cupsdCheckLogFile(cups_file_t **lf, const char *logname);
271 extern int	cupsdCheckPermissions(const char *filename,
272 		                      const char *suffix, mode_t mode,
273 	 			      uid_t user, gid_t group, int is_dir,
274 				      int create_dir);
275 extern int	cupsdCheckProgram(const char *filename, cupsd_printer_t *p);
276 extern int	cupsdDefaultAuthType(void);
277 extern void	cupsdFreeAliases(cups_array_t *aliases);
278 extern char	*cupsdGetDateTime(struct timeval *t, cupsd_time_t format);
279 extern int	cupsdLogClient(cupsd_client_t *con, int level, const char *message, ...) _CUPS_FORMAT(3, 4);
280 extern void	cupsdLogFCMessage(void *context, _cups_fc_result_t result, const char *message);
281 #ifdef HAVE_GSSAPI
282 extern int	cupsdLogGSSMessage(int level, OM_uint32 major_status, OM_uint32 minor_status, const char *message, ...) _CUPS_FORMAT(4, 5);
283 #endif /* HAVE_GSSAPI */
284 extern int	cupsdLogJob(cupsd_job_t *job, int level, const char *message,
285 		            ...) _CUPS_FORMAT(3, 4);
286 extern int	cupsdLogMessage(int level, const char *message, ...) _CUPS_FORMAT(2, 3);
287 extern int	cupsdLogPage(cupsd_job_t *job, const char *page);
288 extern int	cupsdLogRequest(cupsd_client_t *con, http_status_t code);
289 extern int	cupsdReadConfiguration(void);
290 extern int	cupsdWriteErrorLog(int level, const char *message);
291