]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Main header file for the CUPS scheduler. | |
3 | * | |
4 | * Copyright 2007-2014 by Apple Inc. | |
5 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. | |
6 | * | |
7 | * These coded instructions, statements, and computer programs are the | |
8 | * property of Apple Inc. and are protected by Federal copyright | |
9 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
10 | * "LICENSE" which should have been included with this file. If this | |
11 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
12 | */ | |
13 | ||
14 | ||
15 | /* | |
16 | * Include necessary headers. | |
17 | */ | |
18 | ||
19 | #include <cups/cups-private.h> | |
20 | #include <cups/file-private.h> | |
21 | #include <cups/ppd-private.h> | |
22 | ||
23 | #include <limits.h> | |
24 | #include <time.h> | |
25 | #include <signal.h> | |
26 | #include <fcntl.h> | |
27 | #include <math.h> | |
28 | #include <sys/types.h> | |
29 | #include <sys/time.h> | |
30 | #include <sys/stat.h> | |
31 | #include <sys/wait.h> | |
32 | ||
33 | #ifdef WIN32 | |
34 | # include <direct.h> | |
35 | #else | |
36 | # include <unistd.h> | |
37 | #endif /* WIN32 */ | |
38 | ||
39 | #include "mime.h" | |
40 | ||
41 | #if defined(HAVE_CDSASSL) | |
42 | # include <CoreFoundation/CoreFoundation.h> | |
43 | #endif /* HAVE_CDSASSL */ | |
44 | ||
45 | ||
46 | /* | |
47 | * Some OS's don't have hstrerror(), most notably Solaris... | |
48 | */ | |
49 | ||
50 | #ifndef HAVE_HSTRERROR | |
51 | # ifdef hstrerror | |
52 | # undef hstrerror | |
53 | # endif /* hstrerror */ | |
54 | # define hstrerror cups_hstrerror | |
55 | ||
56 | extern const char *cups_hstrerror(int); | |
57 | #endif /* !HAVE_HSTRERROR */ | |
58 | ||
59 | ||
60 | /* | |
61 | * Common constants. | |
62 | */ | |
63 | ||
64 | #ifndef FALSE | |
65 | # define FALSE 0 | |
66 | # define TRUE (!FALSE) | |
67 | #endif /* !FALSE */ | |
68 | ||
69 | ||
70 | /* | |
71 | * Implementation limits... | |
72 | */ | |
73 | ||
74 | #define MAX_ENV 100 /* Maximum number of environment strings */ | |
75 | #define MAX_USERPASS 33 /* Maximum size of username/password */ | |
76 | #define MAX_FILTERS 20 /* Maximum number of filters */ | |
77 | #define MAX_SYSTEM_GROUPS 32 /* Maximum number of system groups */ | |
78 | ||
79 | ||
80 | /* | |
81 | * Defaults... | |
82 | */ | |
83 | ||
84 | #define DEFAULT_HISTORY INT_MAX /* Preserve job history? */ | |
85 | #define DEFAULT_FILES 86400 /* Preserve job files? */ | |
86 | #define DEFAULT_TIMEOUT 300 /* Timeout during requests/updates */ | |
87 | #define DEFAULT_KEEPALIVE 30 /* Timeout between requests */ | |
88 | ||
89 | ||
90 | /* | |
91 | * Global variable macros... | |
92 | */ | |
93 | ||
94 | #ifdef _MAIN_C_ | |
95 | # define VAR | |
96 | # define VALUE(x) =x | |
97 | # define VALUE2(x,y) ={x,y} | |
98 | #else | |
99 | # define VAR extern | |
100 | # define VALUE(x) | |
101 | # define VALUE2(x,y) | |
102 | #endif /* _MAIN_C */ | |
103 | ||
104 | ||
105 | /* | |
106 | * Other stuff for the scheduler... | |
107 | */ | |
108 | ||
109 | #include "sysman.h" | |
110 | #include "statbuf.h" | |
111 | #include "cert.h" | |
112 | #include "auth.h" | |
113 | #include "client.h" | |
114 | #include "policy.h" | |
115 | #include "printers.h" | |
116 | #include "classes.h" | |
117 | #include "job.h" | |
118 | #include "colorman.h" | |
119 | #include "conf.h" | |
120 | #include "banners.h" | |
121 | #include "dirsvc.h" | |
122 | #include "network.h" | |
123 | #include "subscriptions.h" | |
124 | ||
125 | ||
126 | /* | |
127 | * Reload types... | |
128 | */ | |
129 | ||
130 | #define RELOAD_NONE 0 /* No reload needed */ | |
131 | #define RELOAD_ALL 1 /* Reload everything */ | |
132 | #define RELOAD_CUPSD 2 /* Reload only cupsd.conf */ | |
133 | ||
134 | ||
135 | /* | |
136 | * Select callback function type... | |
137 | */ | |
138 | ||
139 | typedef void (*cupsd_selfunc_t)(void *data); | |
140 | ||
141 | ||
142 | /* | |
143 | * Globals... | |
144 | */ | |
145 | ||
146 | VAR int TestConfigFile VALUE(0); | |
147 | /* Test the cupsd.conf file? */ | |
148 | VAR int MaxFDs VALUE(0); | |
149 | /* Maximum number of files */ | |
150 | ||
151 | VAR time_t ReloadTime VALUE(0); | |
152 | /* Time of reload request... */ | |
153 | VAR int NeedReload VALUE(RELOAD_ALL), | |
154 | /* Need to load configuration? */ | |
155 | DoingShutdown VALUE(0); | |
156 | /* Shutting down the scheduler? */ | |
157 | VAR void *DefaultProfile VALUE(0); | |
158 | /* Default security profile */ | |
159 | ||
160 | #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) | |
161 | VAR int OnDemand VALUE(0); | |
162 | /* Launched on demand */ | |
163 | #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */ | |
164 | ||
165 | ||
166 | /* | |
167 | * Prototypes... | |
168 | */ | |
169 | ||
170 | /* env.c */ | |
171 | extern void cupsdInitEnv(void); | |
172 | extern int cupsdLoadEnv(char *envp[], int envmax); | |
173 | extern void cupsdSetEnv(const char *name, const char *value); | |
174 | extern void cupsdSetEnvf(const char *name, const char *value, ...) | |
175 | __attribute__ ((__format__ (__printf__, 2, 3))); | |
176 | extern void cupsdUpdateEnv(void); | |
177 | ||
178 | /* file.c */ | |
179 | extern void cupsdCleanFiles(const char *path, const char *pattern); | |
180 | extern int cupsdCloseCreatedConfFile(cups_file_t *fp, | |
181 | const char *filename); | |
182 | extern void cupsdClosePipe(int *fds); | |
183 | extern cups_file_t *cupsdCreateConfFile(const char *filename, mode_t mode); | |
184 | extern cups_file_t *cupsdOpenConfFile(const char *filename); | |
185 | extern int cupsdOpenPipe(int *fds); | |
186 | extern int cupsdRemoveFile(const char *filename); | |
187 | extern int cupsdUnlinkOrRemoveFile(const char *filename); | |
188 | ||
189 | /* main.c */ | |
190 | extern int cupsdAddString(cups_array_t **a, const char *s); | |
191 | extern void cupsdCheckProcess(void); | |
192 | extern void cupsdClearString(char **s); | |
193 | extern void cupsdFreeStrings(cups_array_t **a); | |
194 | extern void cupsdHoldSignals(void); | |
195 | extern char *cupsdMakeUUID(const char *name, int number, | |
196 | char *buffer, size_t bufsize); | |
197 | extern void cupsdReleaseSignals(void); | |
198 | extern void cupsdSetString(char **s, const char *v); | |
199 | extern void cupsdSetStringf(char **s, const char *f, ...) | |
200 | __attribute__ ((__format__ (__printf__, 2, 3))); | |
201 | ||
202 | /* process.c */ | |
203 | extern void *cupsdCreateProfile(int job_id, int allow_networking); | |
204 | extern void cupsdDestroyProfile(void *profile); | |
205 | extern int cupsdEndProcess(int pid, int force); | |
206 | extern const char *cupsdFinishProcess(int pid, char *name, size_t namelen, int *job_id); | |
207 | extern int cupsdStartProcess(const char *command, char *argv[], | |
208 | char *envp[], int infd, int outfd, | |
209 | int errfd, int backfd, int sidefd, | |
210 | int root, void *profile, | |
211 | cupsd_job_t *job, int *pid); | |
212 | ||
213 | /* select.c */ | |
214 | extern int cupsdAddSelect(int fd, cupsd_selfunc_t read_cb, | |
215 | cupsd_selfunc_t write_cb, void *data); | |
216 | extern int cupsdDoSelect(long timeout); | |
217 | #ifdef CUPSD_IS_SELECTING | |
218 | extern int cupsdIsSelecting(int fd); | |
219 | #endif /* CUPSD_IS_SELECTING */ | |
220 | extern void cupsdRemoveSelect(int fd); | |
221 | extern void cupsdStartSelect(void); | |
222 | extern void cupsdStopSelect(void); | |
223 | ||
224 | /* server.c */ | |
225 | extern void cupsdStartServer(void); | |
226 | extern void cupsdStopServer(void); |