4 * Process management routines for the CUPS scheduler.
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
24 #endif /* __APPLE__ */
25 #ifdef HAVE_POSIX_SPAWN
27 extern char **environ
;
28 #endif /* HAVE_POSIX_SPAWN */
32 * Process structure...
37 int pid
, /* Process ID */
38 job_id
; /* Job associated with process */
39 char name
[1]; /* Name of process */
47 static cups_array_t
*process_array
= NULL
;
54 static int compare_procs(cupsd_proc_t
*a
, cupsd_proc_t
*b
);
56 static char *cupsd_requote(char *dst
, const char *src
, size_t dstsize
);
57 #endif /* HAVE_SANDBOX_H */
61 * 'cupsdCreateProfile()' - Create an execution profile for a subprocess.
64 void * /* O - Profile or NULL on error */
65 cupsdCreateProfile(int job_id
, /* I - Job ID or 0 for none */
66 int allow_networking
)/* I - Allow networking off machine? */
69 cups_file_t
*fp
; /* File pointer */
70 char profile
[1024], /* File containing the profile */
71 bin
[1024], /* Quoted ServerBin */
72 cache
[1024], /* Quoted CacheDir */
73 domain
[1024], /* Domain socket, if any */
74 request
[1024], /* Quoted RequestRoot */
75 root
[1024], /* Quoted ServerRoot */
76 temp
[1024]; /* Quoted TempDir */
77 const char *nodebug
; /* " (with no-log)" for no debug */
78 cupsd_listener_t
*lis
; /* Current listening socket */
81 if (!UseSandboxing
|| Sandboxing
== CUPSD_SANDBOXING_OFF
)
84 * Only use sandbox profiles as root...
87 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
92 if ((fp
= cupsTempFile2(profile
, sizeof(profile
))) == NULL
)
94 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
95 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create security profile: %s",
100 fchown(cupsFileNumber(fp
), RunUser
, Group
);
101 fchmod(cupsFileNumber(fp
), 0640);
103 cupsd_requote(bin
, ServerBin
, sizeof(bin
));
104 cupsd_requote(cache
, CacheDir
, sizeof(cache
));
105 cupsd_requote(request
, RequestRoot
, sizeof(request
));
106 cupsd_requote(root
, ServerRoot
, sizeof(root
));
107 cupsd_requote(temp
, TempDir
, sizeof(temp
));
109 nodebug
= LogLevel
< CUPSD_LOG_DEBUG
? " (with no-log)" : "";
111 cupsFilePuts(fp
, "(version 1)\n");
112 if (Sandboxing
== CUPSD_SANDBOXING_STRICT
)
113 cupsFilePuts(fp
, "(deny default)\n");
115 cupsFilePuts(fp
, "(allow default)\n");
116 if (LogLevel
>= CUPSD_LOG_DEBUG
)
117 cupsFilePuts(fp
, "(debug deny)\n");
118 cupsFilePuts(fp
, "(import \"system.sb\")\n");
119 cupsFilePuts(fp
, "(system-network)\n");
120 cupsFilePuts(fp
, "(allow mach-per-user-lookup)\n");
121 cupsFilePuts(fp
, "(allow ipc-posix-sem)\n");
122 cupsFilePuts(fp
, "(allow ipc-posix-shm)\n");
123 cupsFilePuts(fp
, "(allow ipc-sysv-shm)\n");
124 cupsFilePuts(fp
, "(allow mach-lookup)\n");
126 "(deny file-write* file-read-data file-read-metadata\n"
128 " #\"^%s$\"" /* RequestRoot */
129 " #\"^%s/\"" /* RequestRoot/... */
131 request
, request
, nodebug
);
134 "(deny file-write* file-read-data file-read-metadata\n"
140 "(deny file-write*\n"
142 " #\"^%s$\"" /* ServerRoot */
143 " #\"^%s/\"" /* ServerRoot/... */
144 " #\"^/private/etc$\""
145 " #\"^/private/etc/\""
146 " #\"^/usr/local/etc$\""
147 " #\"^/usr/local/etc/\""
153 root
, root
, nodebug
);
154 /* Specifically allow applications to stat RequestRoot and some other system folders */
156 "(allow file-read-metadata\n"
159 " #\"^/usr$\"" /* /usr */
160 " #\"^/Library$\"" /* /Library */
161 " #\"^/Library/Printers$\"" /* /Library/Printers */
162 " #\"^%s$\"" /* RequestRoot */
165 /* Read and write TempDir, CacheDir, and other common folders */
167 "(allow file-write* file-read-data file-read-metadata\n"
169 " #\"^%s$\"" /* TempDir */
170 " #\"^%s/\"" /* TempDir/... */
171 " #\"^%s$\"" /* CacheDir */
172 " #\"^%s/\"" /* CacheDir/... */
173 " #\"^/private/var/db/\""
174 " #\"^/private/var/folders/\""
175 " #\"^/private/var/run/\""
176 " #\"^/Library/Application Support/\""
177 " #\"^/Library/Caches/\""
178 " #\"^/Library/Preferences/\""
179 " #\"^/Users/Shared/\""
181 temp
, temp
, cache
, cache
);
182 /* Read common folders */
184 "(allow file-read-data file-read-metadata\n"
186 " #\"^/AppleInternal$\""
187 " #\"^/AppleInternal/\""
188 " #\"^/bin$\"" /* /bin */
189 " #\"^/bin/\"" /* /bin/... */
191 " #\"^/private/etc$\""
192 " #\"^/private/etc/\""
193 " #\"^/private/var$\""
194 " #\"^/private/var/db$\""
195 " #\"^/private/var/folders$\""
196 " #\"^/private/var/spool$\""
197 " #\"^/usr/bin$\"" /* /usr/bin */
198 " #\"^/usr/bin/\"" /* /usr/bin/... */
199 " #\"^/usr/libexec/cups$\"" /* /usr/libexec/cups */
200 " #\"^/usr/libexec/cups/\"" /* /usr/libexec/cups/... */
201 " #\"^/usr/libexec/fax$\"" /* /usr/libexec/fax */
202 " #\"^/usr/libexec/fax/\"" /* /usr/libexec/fax/... */
203 " #\"^/usr/sbin$\"" /* /usr/sbin */
204 " #\"^/usr/sbin/\"" /* /usr/sbin/... */
205 " #\"^/Library/Application Support$\""
206 " #\"^/Library/Application Support/\""
207 " #\"^/Library/Caches$\""
208 " #\"^/Library/Fonts$\""
209 " #\"^/Library/Fonts/\""
210 " #\"^/Library/Frameworks$\""
211 " #\"^/Library/Frameworks/\""
212 " #\"^/Library/Keychains$\""
213 " #\"^/Library/Keychains/\""
214 " #\"^/Library/Printers$\""
215 " #\"^/Library/Printers/\""
216 " #\"^%s/Library$\"" /* RequestRoot/Library */
217 " #\"^%s/Library/\"" /* RequestRoot/Library/... */
218 " #\"^%s$\"" /* ServerBin */
219 " #\"^%s/\"" /* ServerBin/... */
220 " #\"^%s$\"" /* ServerRoot */
221 " #\"^%s/\"" /* ServerRoot/... */
223 request
, request
, bin
, bin
, root
, root
);
224 if (Sandboxing
== CUPSD_SANDBOXING_RELAXED
)
226 /* Limited write access to /Library/Printers/... */
228 "(allow file-write*\n"
230 " #\"^/Library/Printers/.*/\""
233 "(deny file-write*\n"
235 " #\"^/Library/Printers/PPDs$\""
236 " #\"^/Library/Printers/PPDs/\""
237 " #\"^/Library/Printers/PPD Plugins$\""
238 " #\"^/Library/Printers/PPD Plugins/\""
241 /* Allow execution of child processes */
242 cupsFilePuts(fp
, "(allow process-fork)\n");
244 "(allow process-exec\n"
246 " #\"^/bin/\"" /* /bin/... */
247 " #\"^/usr/bin/\"" /* /usr/bin/... */
248 " #\"^/usr/libexec/cups/\"" /* /usr/libexec/cups/... */
249 " #\"^/usr/libexec/fax/\"" /* /usr/libexec/fax/... */
250 " #\"^/usr/sbin/\"" /* /usr/sbin/... */
251 " #\"^%s/\"" /* ServerBin/... */
252 " #\"^/Library/Printers/.*/\""
253 " #\"^/System/Library/Frameworks/Python.framework/\""
256 if (RunUser
&& getenv("CUPS_TESTROOT"))
258 /* Allow source directory access in "make test" environment */
259 char testroot
[1024]; /* Root directory of test files */
261 cupsd_requote(testroot
, getenv("CUPS_TESTROOT"), sizeof(testroot
));
264 "(allow file-write* file-read-data file-read-metadata\n"
266 " #\"^%s$\"" /* CUPS_TESTROOT */
267 " #\"^%s/\"" /* CUPS_TESTROOT/... */
271 "(allow process-exec\n"
273 " #\"^%s/\"" /* CUPS_TESTROOT/... */
279 /* Allow job filters to read the current job files... */
281 "(allow file-read-data file-read-metadata\n"
282 " (regex #\"^%s/([ac]%05d|d%05d-[0-9][0-9][0-9])$\"))\n",
283 request
, job_id
, job_id
);
287 /* Allow email notifications from notifiers... */
289 "(allow process-exec\n"
290 " (literal \"/usr/sbin/sendmail\")\n"
291 " (with no-sandbox))\n");
293 /* Allow outbound networking to local services */
294 cupsFilePuts(fp
, "(allow network-outbound"
295 "\n (regex #\"^/private/var/run/\")");
296 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
298 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
300 if (httpAddrFamily(&(lis
->address
)) == AF_LOCAL
)
302 httpAddrString(&(lis
->address
), domain
, sizeof(domain
));
303 cupsFilePrintf(fp
, "\n (literal \"%s\")", domain
);
306 if (allow_networking
)
308 /* Allow TCP and UDP networking off the machine... */
309 cupsFilePuts(fp
, "\n (remote tcp))\n");
310 cupsFilePuts(fp
, "(allow network-bind)\n"); /* for LPD resvport */
311 cupsFilePuts(fp
, "(allow network*\n"
312 " (local udp \"*:*\")\n"
313 " (remote udp \"*:*\"))\n");
315 /* Also allow access to Bluetooth, USB, device files, etc. */
316 cupsFilePuts(fp
, "(allow iokit*)\n");
317 cupsFilePuts(fp
, "(allow file-write* file-read-data file-read-metadata file-ioctl\n"
318 " (regex #\"^/dev/\"))\n");
319 cupsFilePuts(fp
, "(allow distributed-notification-post)\n");
323 /* Only allow SNMP (UDP) off the machine... */
324 cupsFilePuts(fp
, ")\n");
325 cupsFilePuts(fp
, "(allow network-outbound\n"
326 " (remote udp \"*:161\"))\n");
327 cupsFilePuts(fp
, "(allow network-inbound\n"
328 " (local udp \"localhost:*\"))\n");
329 cupsFilePuts(fp
, "(deny iokit* (with no-report))\n");
333 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d,allow_networking=%d) = \"%s\"", job_id
, allow_networking
, profile
);
334 return ((void *)strdup(profile
));
337 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
340 #endif /* HAVE_SANDBOX_H */
345 * 'cupsdDestroyProfile()' - Delete an execution profile.
349 cupsdDestroyProfile(void *profile
) /* I - Profile */
351 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeleteProfile(profile=\"%s\")",
352 profile
? (char *)profile
: "(null)");
354 #ifdef HAVE_SANDBOX_H
357 unlink((char *)profile
);
360 #endif /* HAVE_SANDBOX_H */
365 * 'cupsdEndProcess()' - End a process.
368 int /* O - 0 on success, -1 on failure */
369 cupsdEndProcess(int pid
, /* I - Process ID */
370 int force
) /* I - Force child to die */
372 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdEndProcess(pid=%d, force=%d)", pid
,
381 * When running as root, cupsd puts child processes in their own process
382 * group. Using "-pid" sends a signal to all processes in the group.
389 return (kill(pid
, SIGKILL
));
391 return (kill(pid
, SIGTERM
));
396 * 'cupsdFinishProcess()' - Finish a process and get its name.
399 const char * /* O - Process name */
400 cupsdFinishProcess(int pid
, /* I - Process ID */
401 char *name
, /* I - Name buffer */
402 size_t namelen
, /* I - Size of name buffer */
403 int *job_id
) /* O - Job ID pointer or NULL */
405 cupsd_proc_t key
, /* Search key */
406 *proc
; /* Matching process */
411 if ((proc
= (cupsd_proc_t
*)cupsArrayFind(process_array
, &key
)) != NULL
)
414 *job_id
= proc
->job_id
;
416 strlcpy(name
, proc
->name
, namelen
);
417 cupsArrayRemove(process_array
, proc
);
425 strlcpy(name
, "unknown", namelen
);
428 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFinishProcess(pid=%d, name=%p, namelen=" CUPS_LLFMT
", job_id=%p(%d)) = \"%s\"", pid
, name
, CUPS_LLCAST namelen
, job_id
, job_id
? *job_id
: 0, name
);
435 * 'cupsdStartProcess()' - Start a process.
438 int /* O - Process ID or 0 */
440 const char *command
, /* I - Full path to command */
441 char *argv
[], /* I - Command-line arguments */
442 char *envp
[], /* I - Environment */
443 int infd
, /* I - Standard input file descriptor */
444 int outfd
, /* I - Standard output file descriptor */
445 int errfd
, /* I - Standard error file descriptor */
446 int backfd
, /* I - Backchannel file descriptor */
447 int sidefd
, /* I - Sidechannel file descriptor */
448 int root
, /* I - Run as root? */
449 void *profile
, /* I - Security profile to use */
450 cupsd_job_t
*job
, /* I - Job associated with process */
451 int *pid
) /* O - Process ID */
453 int i
; /* Looping var */
454 const char *exec_path
= command
; /* Command to be exec'd */
455 char *real_argv
[110], /* Real command-line arguments */
456 cups_exec
[1024]; /* Path to "cups-exec" program */
457 uid_t user
; /* Command UID */
458 cupsd_proc_t
*proc
; /* New process record */
459 #ifdef HAVE_POSIX_SPAWN
460 posix_spawn_file_actions_t actions
; /* Spawn file actions */
461 posix_spawnattr_t attrs
; /* Spawn attributes */
462 char user_str
[16], /* User string */
463 group_str
[16], /* Group string */
464 nice_str
[16]; /* FilterNice string */
465 #elif defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
466 struct sigaction action
; /* POSIX signal handler */
467 #endif /* HAVE_POSIX_SPAWN */
468 #if defined(__APPLE__)
469 char processPath
[1024], /* CFProcessPath environment variable */
470 linkpath
[1024]; /* Link path for symlinks... */
471 int linkbytes
; /* Bytes for link path */
472 #endif /* __APPLE__ */
478 * Figure out the UID for the child process...
489 * Check the permissions of the command we are running...
492 if (_cupsFileCheck(command
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
493 cupsdLogFCMessage
, job
? job
->printer
: NULL
))
496 #if defined(__APPLE__)
500 * Add special voodoo magic for OS X - this allows OS X programs to access
501 * their bundle resources properly...
504 if ((linkbytes
= readlink(command
, linkpath
, sizeof(linkpath
) - 1)) > 0)
507 * Yes, this is a symlink to the actual program, nul-terminate and
511 linkpath
[linkbytes
] = '\0';
513 if (linkpath
[0] == '/')
514 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s",
517 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s/%s",
518 dirname((char *)command
), linkpath
);
521 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s", command
);
523 envp
[0] = processPath
; /* Replace <CFProcessPath> string */
525 #endif /* __APPLE__ */
528 * Use helper program when we have a sandbox profile...
531 #ifndef HAVE_POSIX_SPAWN
533 #endif /* !HAVE_POSIX_SPAWN */
535 snprintf(cups_exec
, sizeof(cups_exec
), "%s/daemon/cups-exec", ServerBin
);
536 snprintf(user_str
, sizeof(user_str
), "%d", user
);
537 snprintf(group_str
, sizeof(group_str
), "%d", Group
);
538 snprintf(nice_str
, sizeof(nice_str
), "%d", FilterNice
);
540 real_argv
[0] = cups_exec
;
541 real_argv
[1] = (char *)"-g";
542 real_argv
[2] = group_str
;
543 real_argv
[3] = (char *)"-n";
544 real_argv
[4] = nice_str
;
545 real_argv
[5] = (char *)"-u";
546 real_argv
[6] = user_str
;
547 real_argv
[7] = profile
? profile
: "none";
548 real_argv
[8] = (char *)command
;
551 i
< (int)(sizeof(real_argv
) / sizeof(real_argv
[0]) - 10) && argv
[i
];
553 real_argv
[i
+ 9] = argv
[i
];
555 real_argv
[i
+ 9] = NULL
;
558 exec_path
= cups_exec
;
561 if (LogLevel
== CUPSD_LOG_DEBUG2
)
563 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Preparing to start \"%s\", arguments:", command
);
565 for (i
= 0; argv
[i
]; i
++)
566 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: argv[%d] = \"%s\"", i
, argv
[i
]);
569 #ifdef HAVE_POSIX_SPAWN
571 * Setup attributes and file actions for the spawn...
574 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting spawn attributes.");
575 posix_spawnattr_init(&attrs
);
576 posix_spawnattr_setflags(&attrs
, POSIX_SPAWN_SETPGROUP
| POSIX_SPAWN_SETSIGDEF
);
578 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting file actions.");
579 posix_spawn_file_actions_init(&actions
);
583 posix_spawn_file_actions_addopen(&actions
, 0, "/dev/null", O_WRONLY
, 0);
585 posix_spawn_file_actions_adddup2(&actions
, infd
, 0);
591 posix_spawn_file_actions_addopen(&actions
, 1, "/dev/null", O_WRONLY
, 0);
593 posix_spawn_file_actions_adddup2(&actions
, outfd
, 1);
599 posix_spawn_file_actions_addopen(&actions
, 2, "/dev/null", O_WRONLY
, 0);
601 posix_spawn_file_actions_adddup2(&actions
, errfd
, 2);
604 if (backfd
!= 3 && backfd
>= 0)
605 posix_spawn_file_actions_adddup2(&actions
, backfd
, 3);
607 if (sidefd
!= 4 && sidefd
>= 0)
608 posix_spawn_file_actions_adddup2(&actions
, sidefd
, 4);
610 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Calling posix_spawn.");
612 if (posix_spawn(pid
, exec_path
, &actions
, &attrs
, argv
, envp
? envp
: environ
))
614 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
, strerror(errno
));
619 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: pid=%d", (int)*pid
);
621 posix_spawn_file_actions_destroy(&actions
);
622 posix_spawnattr_destroy(&attrs
);
626 * Block signals before forking...
631 if ((*pid
= fork()) == 0)
634 * Child process goes here; update stderr as needed...
640 errfd
= open("/dev/null", O_WRONLY
);
650 * Put this process in its own process group so that we can kill any child
651 * processes it creates.
655 if (!RunUser
&& setpgid(0, 0))
658 if (!RunUser
&& setpgrp())
660 # endif /* HAVE_SETPGID */
663 * Update the remaining file descriptors as needed...
669 infd
= open("/dev/null", O_RDONLY
);
681 outfd
= open("/dev/null", O_WRONLY
);
690 if (backfd
!= 3 && backfd
>= 0)
694 fcntl(3, F_SETFL
, O_NDELAY
);
697 if (sidefd
!= 4 && sidefd
>= 0)
701 fcntl(4, F_SETFL
, O_NDELAY
);
705 * Change the priority of the process based on the FilterNice setting.
706 * (this is not done for root processes...)
713 * Reset group membership to just the main one we belong to.
716 if (!RunUser
&& setgid(Group
))
719 if (!RunUser
&& setgroups(1, &Group
))
723 * Change user to something "safe"...
726 if (!RunUser
&& user
&& setuid(user
))
730 * Change umask to restrict permissions on created files...
736 * Unblock signals before doing the exec...
740 sigset(SIGTERM
, SIG_DFL
);
741 sigset(SIGCHLD
, SIG_DFL
);
742 sigset(SIGPIPE
, SIG_DFL
);
743 # elif defined(HAVE_SIGACTION)
744 memset(&action
, 0, sizeof(action
));
746 sigemptyset(&action
.sa_mask
);
747 action
.sa_handler
= SIG_DFL
;
749 sigaction(SIGTERM
, &action
, NULL
);
750 sigaction(SIGCHLD
, &action
, NULL
);
751 sigaction(SIGPIPE
, &action
, NULL
);
753 signal(SIGTERM
, SIG_DFL
);
754 signal(SIGCHLD
, SIG_DFL
);
755 signal(SIGPIPE
, SIG_DFL
);
756 # endif /* HAVE_SIGSET */
758 cupsdReleaseSignals();
761 * Execute the command; if for some reason this doesn't work, log an error
762 * exit with a non-zero value...
766 execve(exec_path
, argv
, envp
);
768 execv(exec_path
, argv
);
775 * Error - couldn't fork a new process!
778 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
,
784 cupsdReleaseSignals();
785 #endif /* HAVE_POSIX_SPAWN */
790 process_array
= cupsArrayNew((cups_array_func_t
)compare_procs
, NULL
);
794 if ((proc
= calloc(1, sizeof(cupsd_proc_t
) + strlen(command
))) != NULL
)
797 proc
->job_id
= job
? job
->id
: 0;
798 _cups_strcpy(proc
->name
, command
);
800 cupsArrayAdd(process_array
, proc
);
805 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
806 "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
807 "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
808 "profile=%p, job=%p(%d), pid=%p) = %d",
809 command
, argv
, envp
, infd
, outfd
, errfd
, backfd
, sidefd
,
810 root
, profile
, job
, job
? job
->id
: 0, pid
, *pid
);
817 * 'compare_procs()' - Compare two processes.
820 static int /* O - Result of comparison */
821 compare_procs(cupsd_proc_t
*a
, /* I - First process */
822 cupsd_proc_t
*b
) /* I - Second process */
824 return (a
->pid
- b
->pid
);
828 #ifdef HAVE_SANDBOX_H
830 * 'cupsd_requote()' - Make a regular-expression version of a string.
833 static char * /* O - Quoted string */
834 cupsd_requote(char *dst
, /* I - Destination buffer */
835 const char *src
, /* I - Source string */
836 size_t dstsize
) /* I - Size of destination buffer */
838 int ch
; /* Current character */
839 char *dstptr
, /* Current position in buffer */
840 *dstend
; /* End of destination buffer */
844 dstend
= dst
+ dstsize
- 2;
846 while (*src
&& dstptr
< dstend
)
850 if (ch
== '/' && !*src
)
851 break; /* Don't add trailing slash */
853 if (strchr(".?*()[]^$\\", ch
))
856 *dstptr
++ = (char)ch
;
863 #endif /* HAVE_SANDBOX_H */