typedef struct
{
- int pid; /* Process ID */
+ int pid, /* Process ID */
+ job_id; /* Job associated with process */
char name[1]; /* Name of process */
} cupsd_proc_t;
temp[1024]; /* Quoted TempDir */
+ if (!UseProfiles || RunUser)
+ {
+ /*
+ * Only use sandbox profiles as root...
+ */
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCreateProfile(job_id=%d) = NULL",
+ job_id);
+
+ return (NULL);
+ }
+
if ((fp = cupsTempFile2(profile, sizeof(profile))) == NULL)
{
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCreateProfile(job_id=%d) = NULL",
+ job_id);
cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create security profile: %s",
strerror(errno));
return (NULL);
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCreateProfile(job_id=%d) = \"%s\"",
job_id, profile);
return ((void *)strdup(profile));
+
#else
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCreateProfile(job_id=%d) = NULL",
+ job_id);
return (NULL);
#endif /* HAVE_SANDBOX_H */
void
cupsdDestroyProfile(void *profile) /* I - Profile */
{
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeleteProfile(profile=\"%s\")",
+ profile ? (char *)profile : "(null)");
+
#ifdef HAVE_SANDBOX_H
if (profile)
{
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeleteProfile(profile=\"%s\")",
- (char *)profile);
unlink((char *)profile);
free(profile);
}
cupsdEndProcess(int pid, /* I - Process ID */
int force) /* I - Force child to die */
{
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdEndProcess(pid=%d, force=%d)", pid,
+ force);
+
if (force)
return (kill(pid, SIGKILL));
else
const char * /* O - Process name */
cupsdFinishProcess(int pid, /* I - Process ID */
char *name, /* I - Name buffer */
- int namelen) /* I - Size of name buffer */
+ int namelen, /* I - Size of name buffer */
+ int *job_id) /* O - Job ID pointer or NULL */
{
cupsd_proc_t key, /* Search key */
*proc; /* Matching process */
if ((proc = (cupsd_proc_t *)cupsArrayFind(process_array, &key)) != NULL)
{
+ if (job_id)
+ *job_id = proc->job_id;
+
strlcpy(name, proc->name, namelen);
cupsArrayRemove(process_array, proc);
free(proc);
-
- return (name);
}
else
- return ("unknown");
+ {
+ if (job_id)
+ *job_id = 0;
+
+ strlcpy(name, "unknown", namelen);
+ }
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdFinishProcess(pid=%d, name=%p, namelen=%d, "
+ "job_id=%p(%d)) = \"%s\"", pid, name, namelen, job_id,
+ job_id ? *job_id : 0, name);
+
+ return (name);
}
int /* O - Process ID or 0 */
cupsdStartProcess(
- const char *command, /* I - Full path to command */
- char *argv[], /* I - Command-line arguments */
- char *envp[], /* I - Environment */
- int infd, /* I - Standard input file descriptor */
- int outfd, /* I - Standard output file descriptor */
- int errfd, /* I - Standard error file descriptor */
- int backfd, /* I - Backchannel file descriptor */
- int sidefd, /* I - Sidechannel file descriptor */
- int root, /* I - Run as root? */
- void *profile, /* I - Security profile to use */
- int *pid) /* O - Process ID */
+ const char *command, /* I - Full path to command */
+ char *argv[], /* I - Command-line arguments */
+ char *envp[], /* I - Environment */
+ int infd, /* I - Standard input file descriptor */
+ int outfd, /* I - Standard output file descriptor */
+ int errfd, /* I - Standard error file descriptor */
+ int backfd, /* I - Backchannel file descriptor */
+ int sidefd, /* I - Sidechannel file descriptor */
+ int root, /* I - Run as root? */
+ void *profile, /* I - Security profile to use */
+ cupsd_job_t *job, /* I - Job associated with process */
+ int *pid) /* O - Process ID */
{
int user; /* Command UID */
struct stat commandinfo; /* Command file information */
#endif /* __APPLE__ */
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdStartProcess(\"%s\", %p, %p, %d, %d, %d)",
- command, argv, envp, infd, outfd, errfd);
-
if (RunUser)
user = RunUser;
else if (root)
if (stat(command, &commandinfo))
{
+ *pid = 0;
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
+ "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
+ "profile=%p, job=%p(%d), pid=%p) = %d",
+ command, argv, envp, infd, outfd, errfd, backfd, sidefd,
+ root, profile, job, job ? job->id : 0, pid, *pid);
cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to execute %s: %s", command,
strerror(errno));
- *pid = 0;
+
+ if (job && job->printer)
+ cupsdSetPrinterReasons(job->printer, "+cups-missing-filter-warning");
+
return (0);
}
- else if (commandinfo.st_mode & S_IWOTH)
+ else if (commandinfo.st_mode & (S_ISUID | S_IWOTH))
{
+ *pid = 0;
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
+ "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
+ "profile=%p, job=%p(%d), pid=%p) = %d",
+ command, argv, envp, infd, outfd, errfd, backfd, sidefd,
+ root, profile, job, job ? job->id : 0, pid, *pid);
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to execute %s: insecure file permissions (0%o)",
command, commandinfo.st_mode);
- *pid = 0;
+
+ if (job && job->printer)
+ cupsdSetPrinterReasons(job->printer, "+cups-insecure-filter-warning");
+
errno = EPERM;
+
return (0);
}
else if ((commandinfo.st_uid != user || !(commandinfo.st_mode & S_IXUSR)) &&
(commandinfo.st_gid != Group || !(commandinfo.st_mode & S_IXGRP)) &&
!(commandinfo.st_mode & S_IXOTH))
{
+ *pid = 0;
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
+ "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
+ "profile=%p, job=%p(%d), pid=%p) = %d",
+ command, argv, envp, infd, outfd, errfd, backfd, sidefd,
+ root, profile, job, job ? job->id : 0, pid, *pid);
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to execute %s: no execute permissions (0%o)",
command, commandinfo.st_mode);
- *pid = 0;
+
errno = EPERM;
return (0);
}
{
if ((proc = calloc(1, sizeof(cupsd_proc_t) + strlen(command))) != NULL)
{
- proc->pid = *pid;
+ proc->pid = *pid;
+ proc->job_id = job ? job->id : 0;
strcpy(proc->name, command);
cupsArrayAdd(process_array, proc);
cupsdReleaseSignals();
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
+ "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
+ "profile=%p, job=%p(%d), pid=%p) = %d",
+ command, argv, envp, infd, outfd, errfd, backfd, sidefd,
+ root, profile, job, job ? job->id : 0, pid, *pid);
+
return (*pid);
}