| 70 | */ |
| 71 | |
| 72 | void * /* O - Profile or NULL on error */ |
| 73 | cupsdCreateProfile(int job_id, /* I - Job ID or 0 for none */ |
| 74 | int allow_networking)/* I - Allow networking off machine? */ |
| 75 | { |
| 76 | #ifdef HAVE_SANDBOX_H |
| 77 | cups_file_t *fp; /* File pointer */ |
| 78 | char profile[1024], /* File containing the profile */ |
| 79 | bin[1024], /* Quoted ServerBin */ |
| 80 | cache[1024], /* Quoted CacheDir */ |
| 81 | domain[1024], /* Domain socket, if any */ |
| 82 | request[1024], /* Quoted RequestRoot */ |
| 83 | root[1024], /* Quoted ServerRoot */ |
| 84 | state[1024], /* Quoted StateDir */ |
| 85 | temp[1024]; /* Quoted TempDir */ |
| 86 | const char *nodebug; /* " (with no-log)" for no debug */ |
| 87 | cupsd_listener_t *lis; /* Current listening socket */ |
| 88 | |
| 89 | |
| 90 | if (!UseSandboxing || Sandboxing == CUPSD_SANDBOXING_OFF) |
| 91 | { |
| 92 | /* |
| 93 | * Only use sandbox profiles as root... |
| 94 | */ |
| 95 | |
| 96 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id, allow_networking); |
| 97 | |
| 98 | return (NULL); |
| 99 | } |
| 100 | |
| 101 | if ((fp = cupsTempFile2(profile, sizeof(profile))) == NULL) |
| 102 | { |
| 103 | /* |
| 104 | * This should never happen, and is fatal when sandboxing is enabled. |
| 105 | */ |
| 106 | |
| 107 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id, allow_networking); |
| 108 | cupsdLogMessage(CUPSD_LOG_EMERG, "Unable to create security profile: %s", strerror(errno)); |
| 109 | kill(getpid(), SIGTERM); |
| 110 | return (NULL); |
| 111 | } |
| 112 | |
| 113 | fchown(cupsFileNumber(fp), RunUser, Group); |
| 114 | fchmod(cupsFileNumber(fp), 0640); |
| 115 | |
| 116 | cupsd_requote(bin, ServerBin, sizeof(bin)); |
| 117 | cupsd_requote(cache, CacheDir, sizeof(cache)); |
| 118 | cupsd_requote(request, RequestRoot, sizeof(request)); |
| 119 | cupsd_requote(root, ServerRoot, sizeof(root)); |
| 120 | cupsd_requote(state, StateDir, sizeof(state)); |
| 121 | cupsd_requote(temp, TempDir, sizeof(temp)); |
| 122 | |
| 123 | nodebug = LogLevel < CUPSD_LOG_DEBUG ? " (with no-log)" : ""; |
| 124 | |
| 125 | cupsFilePuts(fp, "(version 1)\n"); |
| 126 | if (Sandboxing == CUPSD_SANDBOXING_STRICT) |
| 127 | cupsFilePuts(fp, "(deny default)\n"); |
| 128 | else |
| 129 | cupsFilePuts(fp, "(allow default)\n"); |
no test coverage detected