extern http_t *_cupsConnect(void) _CUPS_PRIVATE;
extern char *_cupsCreateDest(const char *name, const char *info, const char *device_id, const char *device_uri, char *uri, size_t urisize) _CUPS_PRIVATE;
-extern ipp_attribute_t *_cupsEncodeOption(ipp_t *ipp, ipp_tag_t group_tag, _ipp_option_t *map, const char *name, const char *value) _CUPS_PRIVATE;
+extern bool _cupsDirCreate(const char *path, mode_t mode) _CUPS_PRIVATE;extern ipp_attribute_t *_cupsEncodeOption(ipp_t *ipp, ipp_tag_t group_tag, _ipp_option_t *map, const char *name, const char *value) _CUPS_PRIVATE;
extern int _cupsGet1284Values(const char *device_id, cups_option_t **values) _CUPS_PRIVATE;
extern const char *_cupsGetDestResource(cups_dest_t *dest, unsigned flags, char *resource, size_t resourcesize) _CUPS_PRIVATE;
extern int _cupsGetDests(http_t *http, ipp_op_t op, const char *name, cups_dest_t **dests, cups_ptype_t type, cups_ptype_t mask) _CUPS_PRIVATE;
* Create ~/.cups subdirectory...
*/
- mkdir(cg->userconfig, 0700);
+ _cupsDirCreate(cg->userconfig, 0700);
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);
}
* Include necessary headers...
*/
-#include "cups.h"
+#include "cups-private.h"
#include "string-private.h"
#include "debug-internal.h"
#include "dir.h"
+//
+// Common code...
+//
+
+bool // O - `true` on success, `false` on failure
+_cupsDirCreate(const char *path, // I - Directory path
+ mode_t mode) // I - Permissions of final directory
+{
+ bool ret = true; // Return value
+ char *copypath, // Copy of path
+ *ptr; // Pointer into path
+
+
+ // Copy the path
+ if ((copypath = strdup(path)) == NULL)
+ return (false);
+
+ // Create any intermediate paths as needed...
+ for (ptr = strchr(copypath + 1, '/'); ptr; ptr = strchr(ptr + 1, '/'))
+ {
+ // Truncate path for the subdir and create it modulo the umask...
+ *ptr = '\0';
+ if (mkdir(copypath, 0777) && errno != EEXIST)
+ {
+ ret = false;
+ break;
+ }
+ *ptr = '/';
+ }
+
+ // Free the copy of the path and then make the last component...
+ free(copypath);
+ if (ret && mkdir(path, mode) && errno != EEXIST)
+ ret = false;
+
+ return (ret);
+}
+
+
/*
* Windows implementation...
*/
if (cg->userconfig)
{
- if (mkdir(cg->userconfig, 0755) && errno != EEXIST)
- {
- DEBUG_printf("1http_default_path: Failed to make directory '%s': %s", cg->userconfig, strerror(errno));
- return (NULL);
- }
-
snprintf(buffer, bufsize, "%s/ssl", cg->userconfig);
- if (mkdir(buffer, 0700) && errno != EEXIST)
+ if (!_cupsDirCreate(buffer, 0700))
{
DEBUG_printf("1http_default_path: Failed to make directory '%s': %s", buffer, strerror(errno));
return (NULL);
}
else
{
- if (mkdir(cg->sysconfig, 0755) && errno != EEXIST)
- {
- DEBUG_printf("1http_default_path: Failed to make directory '%s': %s", cg->sysconfig, strerror(errno));
- return (NULL);
- }
-
snprintf(buffer, bufsize, "%s/ssl", cg->sysconfig);
- if (mkdir(buffer, 0700) && errno != EEXIST)
+ if (!_cupsDirCreate(buffer, 0700))
{
DEBUG_printf("1http_default_path: Failed to make directory '%s': %s", buffer, strerror(errno));
return (NULL);