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/sbin$\"" /* /usr/sbin */
202 " #\"^/usr/sbin/\"" /* /usr/sbin/... */
203 " #\"^/Library/Caches$\""
204 " #\"^/Library/Fonts$\""
205 " #\"^/Library/Fonts/\""
206 " #\"^/Library/Frameworks$\""
207 " #\"^/Library/Frameworks/\""
208 " #\"^/Library/Keychains$\""
209 " #\"^/Library/Keychains/\""
210 " #\"^/Library/Printers$\""
211 " #\"^/Library/Printers/\""
212 " #\"^%s/Library$\"" /* RequestRoot/Library */
213 " #\"^%s/Library/\"" /* RequestRoot/Library/... */
214 " #\"^%s$\"" /* ServerBin */
215 " #\"^%s/\"" /* ServerBin/... */
216 " #\"^%s$\"" /* ServerRoot */
217 " #\"^%s/\"" /* ServerRoot/... */
219 request
, request
, bin
, bin
, root
, root
);
220 if (Sandboxing
== CUPSD_SANDBOXING_RELAXED
)
222 /* Limited write access to /Library/Printers/... */
224 "(allow file-write*\n"
226 " #\"^/Library/Printers/.*/\""
229 "(deny file-write*\n"
231 " #\"^/Library/Printers/PPDs$\""
232 " #\"^/Library/Printers/PPDs/\""
233 " #\"^/Library/Printers/PPD Plugins$\""
234 " #\"^/Library/Printers/PPD Plugins/\""
237 /* Allow execution of child processes */
238 cupsFilePuts(fp
, "(allow process-fork)\n");
240 "(allow process-exec\n"
242 " #\"^/bin/\"" /* /bin/... */
243 " #\"^/usr/bin/\"" /* /usr/bin/... */
244 " #\"^/usr/libexec/cups/\"" /* /usr/libexec/cups/... */
245 " #\"^/usr/libexec/fax/\"" /* /usr/libexec/fax/... */
246 " #\"^/usr/sbin/\"" /* /usr/sbin/... */
247 " #\"^%s/\"" /* ServerBin/... */
248 " #\"^/Library/Printers/.*/\""
251 if (RunUser
&& getenv("CUPS_TESTROOT"))
253 /* Allow source directory access in "make test" environment */
254 char testroot
[1024]; /* Root directory of test files */
256 cupsd_requote(testroot
, getenv("CUPS_TESTROOT"), sizeof(testroot
));
259 "(allow file-write* file-read-data file-read-metadata\n"
261 " #\"^%s$\"" /* CUPS_TESTROOT */
262 " #\"^%s/\"" /* CUPS_TESTROOT/... */
266 "(allow process-exec\n"
268 " #\"^%s/\"" /* CUPS_TESTROOT/... */
274 /* Allow job filters to read the current job files... */
276 "(allow file-read-data file-read-metadata\n"
277 " (regex #\"^%s/([ac]%05d|d%05d-[0-9][0-9][0-9])$\"))\n",
278 request
, job_id
, job_id
);
282 /* Allow email notifications from notifiers... */
284 "(allow process-exec\n"
285 " (literal \"/usr/sbin/sendmail\")\n"
286 " (with no-sandbox))\n");
288 /* Allow outbound networking to local services */
289 cupsFilePuts(fp
, "(allow network-outbound"
290 "\n (regex #\"^/private/var/run/\")");
291 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
293 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
295 if (httpAddrFamily(&(lis
->address
)) == AF_LOCAL
)
297 httpAddrString(&(lis
->address
), domain
, sizeof(domain
));
298 cupsFilePrintf(fp
, "\n (literal \"%s\")", domain
);
301 if (allow_networking
)
303 /* Allow TCP and UDP networking off the machine... */
304 cupsFilePuts(fp
, "\n (remote tcp))\n");
305 cupsFilePuts(fp
, "(allow network-bind)\n"); /* for LPD resvport */
306 cupsFilePuts(fp
, "(allow network*\n"
307 " (local udp \"*:*\")\n"
308 " (remote udp \"*:*\"))\n");
310 /* Also allow access to Bluetooth, USB, device files, etc. */
311 cupsFilePuts(fp
, "(allow iokit-open)\n");
312 cupsFilePuts(fp
, "(allow file-write* file-read-data file-read-metadata file-ioctl\n"
313 " (regex #\"^/dev/\"))\n");
314 cupsFilePuts(fp
, "(allow distributed-notification-post)\n");
318 /* Only allow SNMP (UDP) off the machine... */
319 cupsFilePuts(fp
, ")\n");
320 cupsFilePuts(fp
, "(allow network-outbound\n"
321 " (remote udp \"*:161\"))\n");
322 cupsFilePuts(fp
, "(allow network-inbound\n"
323 " (local udp \"localhost:*\"))\n");
327 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d,allow_networking=%d) = \"%s\"", job_id
, allow_networking
, profile
);
328 return ((void *)strdup(profile
));
331 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
334 #endif /* HAVE_SANDBOX_H */
339 * 'cupsdDestroyProfile()' - Delete an execution profile.
343 cupsdDestroyProfile(void *profile
) /* I - Profile */
345 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeleteProfile(profile=\"%s\")",
346 profile
? (char *)profile
: "(null)");
348 #ifdef HAVE_SANDBOX_H
351 unlink((char *)profile
);
354 #endif /* HAVE_SANDBOX_H */
359 * 'cupsdEndProcess()' - End a process.
362 int /* O - 0 on success, -1 on failure */
363 cupsdEndProcess(int pid
, /* I - Process ID */
364 int force
) /* I - Force child to die */
366 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdEndProcess(pid=%d, force=%d)", pid
,
375 * When running as root, cupsd puts child processes in their own process
376 * group. Using "-pid" sends a signal to all processes in the group.
383 return (kill(pid
, SIGKILL
));
385 return (kill(pid
, SIGTERM
));
390 * 'cupsdFinishProcess()' - Finish a process and get its name.
393 const char * /* O - Process name */
394 cupsdFinishProcess(int pid
, /* I - Process ID */
395 char *name
, /* I - Name buffer */
396 size_t namelen
, /* I - Size of name buffer */
397 int *job_id
) /* O - Job ID pointer or NULL */
399 cupsd_proc_t key
, /* Search key */
400 *proc
; /* Matching process */
405 if ((proc
= (cupsd_proc_t
*)cupsArrayFind(process_array
, &key
)) != NULL
)
408 *job_id
= proc
->job_id
;
410 strlcpy(name
, proc
->name
, namelen
);
411 cupsArrayRemove(process_array
, proc
);
419 strlcpy(name
, "unknown", namelen
);
422 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
);
429 * 'cupsdStartProcess()' - Start a process.
432 int /* O - Process ID or 0 */
434 const char *command
, /* I - Full path to command */
435 char *argv
[], /* I - Command-line arguments */
436 char *envp
[], /* I - Environment */
437 int infd
, /* I - Standard input file descriptor */
438 int outfd
, /* I - Standard output file descriptor */
439 int errfd
, /* I - Standard error file descriptor */
440 int backfd
, /* I - Backchannel file descriptor */
441 int sidefd
, /* I - Sidechannel file descriptor */
442 int root
, /* I - Run as root? */
443 void *profile
, /* I - Security profile to use */
444 cupsd_job_t
*job
, /* I - Job associated with process */
445 int *pid
) /* O - Process ID */
447 int i
; /* Looping var */
448 const char *exec_path
= command
; /* Command to be exec'd */
449 char *real_argv
[110], /* Real command-line arguments */
450 cups_exec
[1024]; /* Path to "cups-exec" program */
451 uid_t user
; /* Command UID */
452 cupsd_proc_t
*proc
; /* New process record */
453 #ifdef HAVE_POSIX_SPAWN
454 posix_spawn_file_actions_t actions
; /* Spawn file actions */
455 posix_spawnattr_t attrs
; /* Spawn attributes */
456 char user_str
[16], /* User string */
457 group_str
[16], /* Group string */
458 nice_str
[16]; /* FilterNice string */
459 #elif defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
460 struct sigaction action
; /* POSIX signal handler */
461 #endif /* HAVE_POSIX_SPAWN */
462 #if defined(__APPLE__)
463 char processPath
[1024], /* CFProcessPath environment variable */
464 linkpath
[1024]; /* Link path for symlinks... */
465 int linkbytes
; /* Bytes for link path */
466 #endif /* __APPLE__ */
472 * Figure out the UID for the child process...
483 * Check the permissions of the command we are running...
486 if (_cupsFileCheck(command
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
487 cupsdLogFCMessage
, job
? job
->printer
: NULL
))
490 #if defined(__APPLE__)
494 * Add special voodoo magic for OS X - this allows OS X programs to access
495 * their bundle resources properly...
498 if ((linkbytes
= readlink(command
, linkpath
, sizeof(linkpath
) - 1)) > 0)
501 * Yes, this is a symlink to the actual program, nul-terminate and
505 linkpath
[linkbytes
] = '\0';
507 if (linkpath
[0] == '/')
508 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s",
511 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s/%s",
512 dirname((char *)command
), linkpath
);
515 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s", command
);
517 envp
[0] = processPath
; /* Replace <CFProcessPath> string */
519 #endif /* __APPLE__ */
522 * Use helper program when we have a sandbox profile...
525 #ifndef HAVE_POSIX_SPAWN
527 #endif /* !HAVE_POSIX_SPAWN */
529 snprintf(cups_exec
, sizeof(cups_exec
), "%s/daemon/cups-exec", ServerBin
);
530 snprintf(user_str
, sizeof(user_str
), "%d", user
);
531 snprintf(group_str
, sizeof(group_str
), "%d", Group
);
532 snprintf(nice_str
, sizeof(nice_str
), "%d", FilterNice
);
534 real_argv
[0] = cups_exec
;
535 real_argv
[1] = (char *)"-g";
536 real_argv
[2] = group_str
;
537 real_argv
[3] = (char *)"-n";
538 real_argv
[4] = nice_str
;
539 real_argv
[5] = (char *)"-u";
540 real_argv
[6] = user_str
;
541 real_argv
[7] = profile
;
542 real_argv
[8] = (char *)command
;
545 i
< (int)(sizeof(real_argv
) / sizeof(real_argv
[0]) - 10) && argv
[i
];
547 real_argv
[i
+ 9] = argv
[i
];
549 real_argv
[i
+ 9] = NULL
;
552 exec_path
= cups_exec
;
555 if (LogLevel
== CUPSD_LOG_DEBUG2
)
557 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Preparing to start \"%s\", arguments:", command
);
559 for (i
= 0; argv
[i
]; i
++)
560 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: argv[%d] = \"%s\"", i
, argv
[i
]);
563 #ifdef HAVE_POSIX_SPAWN
565 * Setup attributes and file actions for the spawn...
568 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting spawn attributes.");
569 posix_spawnattr_init(&attrs
);
570 posix_spawnattr_setflags(&attrs
, POSIX_SPAWN_SETPGROUP
| POSIX_SPAWN_SETSIGDEF
);
572 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting file actions.");
573 posix_spawn_file_actions_init(&actions
);
577 posix_spawn_file_actions_addopen(&actions
, 0, "/dev/null", O_WRONLY
, 0);
579 posix_spawn_file_actions_adddup2(&actions
, infd
, 0);
585 posix_spawn_file_actions_addopen(&actions
, 1, "/dev/null", O_WRONLY
, 0);
587 posix_spawn_file_actions_adddup2(&actions
, outfd
, 1);
593 posix_spawn_file_actions_addopen(&actions
, 2, "/dev/null", O_WRONLY
, 0);
595 posix_spawn_file_actions_adddup2(&actions
, errfd
, 2);
598 if (backfd
!= 3 && backfd
>= 0)
599 posix_spawn_file_actions_adddup2(&actions
, backfd
, 3);
601 if (sidefd
!= 4 && sidefd
>= 0)
602 posix_spawn_file_actions_adddup2(&actions
, sidefd
, 4);
604 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Calling posix_spawn.");
606 if (posix_spawn(pid
, exec_path
, &actions
, &attrs
, argv
, envp
? envp
: environ
))
608 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
, strerror(errno
));
613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: pid=%d", (int)*pid
);
615 posix_spawn_file_actions_destroy(&actions
);
616 posix_spawnattr_destroy(&attrs
);
620 * Block signals before forking...
625 if ((*pid
= fork()) == 0)
628 * Child process goes here; update stderr as needed...
634 errfd
= open("/dev/null", O_WRONLY
);
644 * Put this process in its own process group so that we can kill any child
645 * processes it creates.
649 if (!RunUser
&& setpgid(0, 0))
652 if (!RunUser
&& setpgrp())
654 # endif /* HAVE_SETPGID */
657 * Update the remaining file descriptors as needed...
663 infd
= open("/dev/null", O_RDONLY
);
675 outfd
= open("/dev/null", O_WRONLY
);
684 if (backfd
!= 3 && backfd
>= 0)
688 fcntl(3, F_SETFL
, O_NDELAY
);
691 if (sidefd
!= 4 && sidefd
>= 0)
695 fcntl(4, F_SETFL
, O_NDELAY
);
699 * Change the priority of the process based on the FilterNice setting.
700 * (this is not done for root processes...)
707 * Reset group membership to just the main one we belong to.
710 if (!RunUser
&& setgid(Group
))
713 if (!RunUser
&& setgroups(1, &Group
))
717 * Change user to something "safe"...
720 if (!RunUser
&& user
&& setuid(user
))
724 * Change umask to restrict permissions on created files...
730 * Unblock signals before doing the exec...
734 sigset(SIGTERM
, SIG_DFL
);
735 sigset(SIGCHLD
, SIG_DFL
);
736 sigset(SIGPIPE
, SIG_DFL
);
737 # elif defined(HAVE_SIGACTION)
738 memset(&action
, 0, sizeof(action
));
740 sigemptyset(&action
.sa_mask
);
741 action
.sa_handler
= SIG_DFL
;
743 sigaction(SIGTERM
, &action
, NULL
);
744 sigaction(SIGCHLD
, &action
, NULL
);
745 sigaction(SIGPIPE
, &action
, NULL
);
747 signal(SIGTERM
, SIG_DFL
);
748 signal(SIGCHLD
, SIG_DFL
);
749 signal(SIGPIPE
, SIG_DFL
);
750 # endif /* HAVE_SIGSET */
752 cupsdReleaseSignals();
755 * Execute the command; if for some reason this doesn't work, log an error
756 * exit with a non-zero value...
760 execve(exec_path
, argv
, envp
);
762 execv(exec_path
, argv
);
769 * Error - couldn't fork a new process!
772 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
,
778 cupsdReleaseSignals();
779 #endif /* HAVE_POSIX_SPAWN */
784 process_array
= cupsArrayNew((cups_array_func_t
)compare_procs
, NULL
);
788 if ((proc
= calloc(1, sizeof(cupsd_proc_t
) + strlen(command
))) != NULL
)
791 proc
->job_id
= job
? job
->id
: 0;
792 _cups_strcpy(proc
->name
, command
);
794 cupsArrayAdd(process_array
, proc
);
799 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
800 "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
801 "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
802 "profile=%p, job=%p(%d), pid=%p) = %d",
803 command
, argv
, envp
, infd
, outfd
, errfd
, backfd
, sidefd
,
804 root
, profile
, job
, job
? job
->id
: 0, pid
, *pid
);
811 * 'compare_procs()' - Compare two processes.
814 static int /* O - Result of comparison */
815 compare_procs(cupsd_proc_t
*a
, /* I - First process */
816 cupsd_proc_t
*b
) /* I - Second process */
818 return (a
->pid
- b
->pid
);
822 #ifdef HAVE_SANDBOX_H
824 * 'cupsd_requote()' - Make a regular-expression version of a string.
827 static char * /* O - Quoted string */
828 cupsd_requote(char *dst
, /* I - Destination buffer */
829 const char *src
, /* I - Source string */
830 size_t dstsize
) /* I - Size of destination buffer */
832 int ch
; /* Current character */
833 char *dstptr
, /* Current position in buffer */
834 *dstend
; /* End of destination buffer */
838 dstend
= dst
+ dstsize
- 2;
840 while (*src
&& dstptr
< dstend
)
844 if (ch
== '/' && !*src
)
845 break; /* Don't add trailing slash */
847 if (strchr(".?*()[]^$\\", ch
))
850 *dstptr
++ = (char)ch
;
857 #endif /* HAVE_SANDBOX_H */