2 * "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $"
4 * Configuration routines for the CUPS scheduler.
6 * Copyright 2007-2011 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 * cupsdAddAlias() - Add a host alias.
18 * cupsdCheckPermissions() - Fix the mode and ownership of a file or
20 * cupsdFreeAliases() - Free all of the alias entries.
21 * cupsdReadConfiguration() - Read the cupsd.conf file.
22 * get_address() - Get an address + port number from a line.
23 * get_addr_and_mask() - Get an IP address and netmask.
24 * mime_error_cb() - Log a MIME error.
25 * parse_aaa() - Parse authentication, authorization, and access
27 * parse_fatal_errors() - Parse FatalErrors values in a string.
28 * parse_groups() - Parse system group names in a string.
29 * parse_protocols() - Parse browse protocols in a string.
30 * read_configuration() - Read a configuration file.
31 * read_location() - Read a <Location path> definition.
32 * read_policy() - Read a <Policy name> definition.
33 * set_policy_defaults() - Set default policy values as needed.
37 * Include necessary headers...
43 #include <sys/utsname.h>
48 #endif /* HAVE_LIBPAPER */
52 * Possibly missing network definitions...
56 # define INADDR_NONE 0xffffffff
57 #endif /* !INADDR_NONE */
61 * Configuration variable structure...
66 CUPSD_VARTYPE_INTEGER
, /* Integer option */
67 CUPSD_VARTYPE_STRING
, /* String option */
68 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
69 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
74 const char *name
; /* Name of variable */
75 void *ptr
; /* Pointer to variable */
76 cupsd_vartype_t type
; /* Type (int, string, address) */
84 static const cupsd_var_t variables
[] =
86 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
87 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
89 { "BrowseDNSSDRegType", &DNSSDRegType
, CUPSD_VARTYPE_STRING
},
90 #endif /* HAVE_DNSSD */
91 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
92 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
93 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
94 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
95 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
96 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
97 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
98 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
99 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
100 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
101 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
102 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
103 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
104 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
105 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
106 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
107 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
108 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
109 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
110 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
111 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_INTEGER
},
112 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
113 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
114 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
115 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
117 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
118 #endif /* HAVE_LAUNCHD */
119 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
120 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
121 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
122 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
123 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
124 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
127 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
139 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
140 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
141 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
142 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
143 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
144 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
145 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
146 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
147 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
148 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
149 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
150 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
151 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
152 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
154 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
155 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
156 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
157 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
158 #endif /* HAVE_SSL */
159 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
160 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
161 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
162 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
163 #ifdef HAVE_AUTHORIZATION_H
164 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
165 #endif /* HAVE_AUTHORIZATION_H */
166 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
167 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
168 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
170 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
173 static const unsigned ones
[4] =
175 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
177 static const unsigned zeros
[4] =
179 0x00000000, 0x00000000, 0x00000000, 0x00000000
187 static http_addrlist_t
*get_address(const char *value
, int defport
);
188 static int get_addr_and_mask(const char *value
, unsigned *ip
,
190 static void mime_error_cb(void *ctx
, const char *message
);
191 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
192 char *value
, int linenum
);
193 static int parse_fatal_errors(const char *s
);
194 static int parse_groups(const char *s
);
195 static int parse_protocols(const char *s
);
196 static int read_configuration(cups_file_t
*fp
);
197 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
198 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
199 static void set_policy_defaults(cupsd_policy_t
*pol
);
203 * 'cupsdAddAlias()' - Add a host alias.
207 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
208 const char *name
) /* I - Name to add */
210 cupsd_alias_t
*a
; /* New alias */
211 size_t namelen
; /* Length of name */
214 namelen
= strlen(name
);
216 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
219 a
->namelen
= namelen
;
220 strcpy(a
->name
, name
); /* OK since a->name is allocated */
222 cupsArrayAdd(aliases
, a
);
227 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
230 int /* O - 0 on success, -1 on error, 1 on warning */
231 cupsdCheckPermissions(
232 const char *filename
, /* I - File/directory name */
233 const char *suffix
, /* I - Additional file/directory name */
234 int mode
, /* I - Permissions */
235 int user
, /* I - Owner */
236 int group
, /* I - Group */
237 int is_dir
, /* I - 1 = directory, 0 = file */
238 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
240 int dir_created
= 0; /* Did we create a directory? */
241 char pathname
[1024]; /* File name with prefix */
242 struct stat fileinfo
; /* Stat buffer */
243 int is_symlink
; /* Is "filename" a symlink? */
247 * Prepend the given root to the filename before testing it...
252 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
257 * See if we can stat the file/directory...
260 if (lstat(filename
, &fileinfo
))
262 if (errno
== ENOENT
&& create_dir
)
265 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
268 if (mkdir(filename
, mode
))
271 cupsdLogMessage(CUPSD_LOG_ERROR
,
272 "Unable to create directory \"%s\" - %s", filename
,
275 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
282 fileinfo
.st_mode
= mode
| S_IFDIR
;
285 return (create_dir
? -1 : 1);
288 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
290 if (stat(filename
, &fileinfo
))
292 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
293 filename
, strerror(errno
));
299 * Make sure it's a regular file or a directory as needed...
302 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
304 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
308 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
311 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
313 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
319 * If the filename is a symlink, do not change permissions (STR #2937)...
326 * Fix owner, group, and mode as needed...
329 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
332 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
335 if (chown(filename
, user
, group
) && !getuid())
338 cupsdLogMessage(CUPSD_LOG_ERROR
,
339 "Unable to change ownership of \"%s\" - %s", filename
,
342 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
349 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
352 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
355 if (chmod(filename
, mode
))
358 cupsdLogMessage(CUPSD_LOG_ERROR
,
359 "Unable to change permissions of \"%s\" - %s", filename
,
362 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
370 * Everything is OK...
378 * 'cupsdFreeAliases()' - Free all of the alias entries.
382 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
384 cupsd_alias_t
*a
; /* Current alias */
387 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
389 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
392 cupsArrayDelete(aliases
);
397 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
400 int /* O - 1 on success, 0 otherwise */
401 cupsdReadConfiguration(void)
403 int i
; /* Looping var */
404 cups_file_t
*fp
; /* Configuration file */
405 int status
; /* Return status */
406 char temp
[1024], /* Temporary buffer */
407 mimedir
[1024], /* MIME directory */
408 *slash
; /* Directory separator */
409 cups_lang_t
*language
; /* Language */
410 struct passwd
*user
; /* Default user */
411 struct group
*group
; /* Default group */
412 char *old_serverroot
, /* Old ServerRoot */
413 *old_requestroot
; /* Old RequestRoot */
414 int old_remote_port
; /* Old RemotePort */
415 const char *tmpdir
; /* TMPDIR environment variable */
416 struct stat tmpinfo
; /* Temporary directory info */
417 cupsd_policy_t
*p
; /* Policy */
421 * Save the old root paths...
424 old_serverroot
= NULL
;
425 cupsdSetString(&old_serverroot
, ServerRoot
);
426 old_requestroot
= NULL
;
427 cupsdSetString(&old_requestroot
, RequestRoot
);
430 * Reset the server configuration data...
433 cupsdDeleteAllLocations();
435 cupsdDeleteAllListeners();
437 old_remote_port
= RemotePort
;
444 cupsdFreeAliases(ServerAlias
);
447 cupsdClearString(&ServerName
);
448 cupsdClearString(&ServerAdmin
);
449 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
450 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
451 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
452 cupsdSetString(&DataDir
, CUPS_DATADIR
);
453 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
454 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
455 cupsdClearString(&ErrorLog
);
456 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
457 cupsdSetString(&PageLogFormat
,
458 "%p %u %j %T %P %C %{job-billing} "
459 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
460 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
461 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
462 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
463 cupsdSetString(&RemoteRoot
, "remroot");
464 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
466 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
468 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
469 PrintcapFormat
= PRINTCAP_SOLARIS
;
470 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
471 "/Library/Preferences/org.cups.printers.plist"))
472 PrintcapFormat
= PRINTCAP_PLIST
;
474 PrintcapFormat
= PRINTCAP_BSD
;
476 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
477 if ((slash
= strrchr(temp
, '/')) != NULL
)
480 cupsdSetString(&ServerRoot
, temp
);
482 cupsdClearString(&Classification
);
483 ClassifyOverride
= 0;
487 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
489 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
490 cupsdSetString(&ServerKey
, "ssl/server.key");
491 # endif /* HAVE_CDSASSL */
492 #endif /* HAVE_SSL */
494 language
= cupsLangDefault();
496 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
497 cupsdSetString(&DefaultLanguage
, "en");
499 cupsdSetString(&DefaultLanguage
, language
->language
);
501 cupsdClearString(&DefaultPaperSize
);
503 cupsdSetString(&RIPCache
, "128m");
505 cupsdSetString(&TempDir
, NULL
);
508 * Find the default user...
511 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
516 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
517 * complement number...)
526 * Find the default group...
529 group
= getgrnam(CUPS_DEFAULT_GROUP
);
533 Group
= group
->gr_gid
;
537 * Fallback to group "nobody"...
540 group
= getgrnam("nobody");
544 Group
= group
->gr_gid
;
548 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
549 * complement number...)
560 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
561 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
562 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
563 DefaultAuthType
= CUPSD_AUTH_BASIC
;
565 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
566 SSLOptions
= CUPSD_SSL_NONE
;
567 #endif /* HAVE_SSL */
568 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
569 JobKillDelay
= DEFAULT_TIMEOUT
;
571 JobRetryInterval
= 300;
576 HostNameLookups
= FALSE
;
578 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
579 ListenBackLog
= SOMAXCONN
;
580 LogDebugHistory
= 200;
581 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
582 LogLevel
= CUPSD_LOG_WARN
;
583 LogTimeFormat
= CUPSD_TIME_STANDARD
;
585 MaxClientsPerHost
= 0;
586 MaxLogSize
= 1024 * 1024;
588 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
589 ReloadTimeout
= DEFAULT_KEEPALIVE
;
590 RootCertDuration
= 300;
591 Timeout
= DEFAULT_TIMEOUT
;
593 WebInterface
= CUPS_DEFAULT_WEBIF
;
595 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
597 Browsing
= CUPS_DEFAULT_BROWSING
;
598 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
601 cupsdSetString(&DNSSDRegType
, "_ipp._tcp,_cups");
602 #endif /* HAVE_DNSSD */
604 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
605 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
607 cupsdSetString(&ErrorPolicy
, "stop-printer");
609 JobHistory
= DEFAULT_HISTORY
;
610 JobFiles
= DEFAULT_FILES
;
615 MaxJobsPerPrinter
= 0;
616 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
618 cupsdDeleteAllPolicies();
619 cupsdClearString(&DefaultPolicy
);
621 #ifdef HAVE_AUTHORIZATION_H
622 cupsdClearString(&SystemGroupAuthKey
);
623 #endif /* HAVE_AUTHORIZATION_H */
625 MaxSubscriptions
= 100;
626 MaxSubscriptionsPerJob
= 0;
627 MaxSubscriptionsPerPrinter
= 0;
628 MaxSubscriptionsPerUser
= 0;
629 DefaultLeaseDuration
= 86400;
630 MaxLeaseDuration
= 0;
633 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
634 #endif /* HAVE_LAUNCHD */
637 * Setup environment variables...
643 * Read the configuration file...
646 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
649 status
= read_configuration(fp
);
657 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
661 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
662 RemotePort
? "enabled" : "disabled");
665 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
668 * See if the ServerName is an IP address...
674 ServerAlias
= cupsArrayNew(NULL
, NULL
);
676 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
680 if (gethostname(temp
, sizeof(temp
)))
682 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
684 strlcpy(temp
, "localhost", sizeof(temp
));
687 cupsdSetString(&ServerName
, temp
);
690 ServerAlias
= cupsArrayNew(NULL
, NULL
);
692 cupsdAddAlias(ServerAlias
, temp
);
693 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
695 if (HostNameLookups
|| RemotePort
)
697 struct hostent
*host
; /* Host entry to get FQDN */
699 if ((host
= gethostbyname(temp
)) != NULL
)
701 if (_cups_strcasecmp(temp
, host
->h_name
))
703 cupsdSetString(&ServerName
, host
->h_name
);
704 cupsdAddAlias(ServerAlias
, host
->h_name
);
705 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
711 for (i
= 0; host
->h_aliases
[i
]; i
++)
712 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
714 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
715 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
723 * Make sure we have the base hostname added as an alias, too!
726 if ((slash
= strchr(temp
, '.')) != NULL
)
729 cupsdAddAlias(ServerAlias
, temp
);
730 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
734 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
736 ServerNameIsIP
= !*slash
;
739 * Make sure ServerAdmin is initialized...
743 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
746 * Use the default system group if none was supplied in cupsd.conf...
749 if (NumSystemGroups
== 0)
751 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
754 * Find the group associated with GID 0...
761 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
763 cupsdSetString(&SystemGroups
[0], "unknown");
765 SystemGroupIDs
[0] = 0;
771 * Open the system log for cupsd if necessary...
775 if (!strcmp(AccessLog
, "syslog") ||
776 !strcmp(ErrorLog
, "syslog") ||
777 !strcmp(PageLog
, "syslog"))
778 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
779 #endif /* HAVE_VSYSLOG */
782 * Make sure each of the log files exists and gets rotated as necessary...
785 if (strcmp(AccessLog
, "syslog"))
786 cupsdCheckLogFile(&AccessFile
, AccessLog
);
788 if (strcmp(ErrorLog
, "syslog"))
789 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
791 if (strcmp(PageLog
, "syslog"))
792 cupsdCheckLogFile(&PageFile
, PageLog
);
795 * Log the configuration file that was used...
798 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
802 * Validate the Group and SystemGroup settings - they cannot be the same,
803 * otherwise the CGI programs will be able to authenticate as root without
809 for (i
= 0; i
< NumSystemGroups
; i
++)
810 if (Group
== SystemGroupIDs
[i
])
813 if (i
< NumSystemGroups
)
816 * Log the error and reset the group to a safe value...
819 cupsdLogMessage(CUPSD_LOG_NOTICE
,
820 "Group and SystemGroup cannot use the same groups.");
821 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
823 group
= getgrnam("nobody");
827 Group
= group
->gr_gid
;
831 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
832 * complement number...)
841 * Check that we have at least one listen/port line; if not, report this
842 * as an error and exit!
845 if (cupsArrayCount(Listeners
) == 0)
851 cupsdLogMessage(CUPSD_LOG_EMERG
,
852 "No valid Listen or Port lines were found in the "
853 "configuration file.");
859 cupsdEndProcess(getpid(), 0);
863 * Set the default locale using the language and charset...
866 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
869 * Update all relative filenames to include the full path from ServerRoot...
872 if (DocumentRoot
[0] != '/')
873 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
875 if (RequestRoot
[0] != '/')
876 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
878 if (ServerBin
[0] != '/')
879 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
881 if (StateDir
[0] != '/')
882 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
884 if (CacheDir
[0] != '/')
885 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
888 if (ServerCertificate
[0] != '/')
889 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
891 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
892 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
894 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
897 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
898 if (ServerKey
[0] != '/')
899 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
901 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
902 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
903 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
905 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
906 #endif /* HAVE_SSL */
909 * Make sure that directories and config files are owned and
910 * writable by the user and group in the cupsd.conf file...
913 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
915 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
917 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
919 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
921 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
923 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
924 SystemGroupIDs
[0], 1, 1) < 0 ||
925 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
927 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
929 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
931 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
933 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
935 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
937 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
939 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
943 * Update TempDir to the default if it hasn't been set already...
948 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
951 * TMPDIR is defined, see if it is OK for us to use...
954 if (stat(tmpdir
, &tmpinfo
))
955 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
956 tmpdir
, strerror(errno
));
957 else if (!S_ISDIR(tmpinfo
.st_mode
))
958 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
960 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
961 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
962 !(tmpinfo
.st_mode
& S_IWOTH
))
963 cupsdLogMessage(CUPSD_LOG_ERROR
,
964 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
966 cupsdSetString(&TempDir
, tmpdir
);
971 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
973 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
978 * Make sure the temporary directory has the right permissions...
981 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
985 * Update ownership and permissions if the CUPS temp directory
986 * is under the spool directory or does not exist...
989 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
990 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
995 * Update environment variables...
1001 * Update default paper size setting as needed...
1004 if (!DefaultPaperSize
)
1006 #ifdef HAVE_LIBPAPER
1007 char *paper_result
; /* Paper size name from libpaper */
1009 if ((paper_result
= systempapername()) != NULL
)
1010 cupsdSetString(&DefaultPaperSize
, paper_result
);
1012 #endif /* HAVE_LIBPAPER */
1013 if (!DefaultLanguage
||
1014 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1015 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1016 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1017 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1018 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1019 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1020 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1023 * These are the only locales that will default to "letter" size...
1026 cupsdSetString(&DefaultPaperSize
, "Letter");
1029 cupsdSetString(&DefaultPaperSize
, "A4");
1033 * Update classification setting as needed...
1036 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1037 cupsdClearString(&Classification
);
1040 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1043 * Check the MaxClients setting, and then allocate memory for it...
1046 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1049 cupsdLogMessage(CUPSD_LOG_INFO
,
1050 "MaxClients limited to 1/3 (%d) of the file descriptor "
1052 MaxFDs
/ 3, MaxFDs
);
1054 MaxClients
= MaxFDs
/ 3;
1057 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1061 * Check the MaxActiveJobs setting; limit to 1/3 the available
1062 * file descriptors, since we need a pipe for each job...
1065 if (MaxActiveJobs
> (MaxFDs
/ 3))
1066 MaxActiveJobs
= MaxFDs
/ 3;
1069 * Update the MaxClientsPerHost value, as needed...
1072 if (MaxClientsPerHost
<= 0)
1073 MaxClientsPerHost
= MaxClients
;
1075 if (MaxClientsPerHost
> MaxClients
)
1076 MaxClientsPerHost
= MaxClients
;
1078 cupsdLogMessage(CUPSD_LOG_INFO
,
1079 "Allowing up to %d client connections per host.",
1083 * Update the default policy, as needed...
1087 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1089 DefaultPolicyPtr
= NULL
;
1091 if (!DefaultPolicyPtr
)
1093 cupsd_location_t
*po
; /* New policy operation */
1097 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1100 cupsdSetString(&DefaultPolicy
, "default");
1102 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1103 cupsdLogMessage(CUPSD_LOG_INFO
,
1104 "Using policy \"default\" as the default.");
1107 cupsdLogMessage(CUPSD_LOG_INFO
,
1108 "Creating CUPS default administrative policy:");
1110 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1112 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1114 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1115 cupsdAddString(&(p
->job_access
), "@OWNER");
1116 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1118 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1119 cupsdAddString(&(p
->job_attrs
), "job-name");
1120 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1121 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1123 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1124 cupsdAddString(&(p
->sub_access
), "@OWNER");
1125 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1127 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1128 cupsdAddString(&(p
->job_attrs
), "notify-events");
1129 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1130 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1131 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1132 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1134 cupsdLogMessage(CUPSD_LOG_INFO
,
1135 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1136 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1138 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1139 po
->order_type
= CUPSD_AUTH_ALLOW
;
1141 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1142 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1143 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1145 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1147 cupsdLogMessage(CUPSD_LOG_INFO
,
1148 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1149 "Release-Job Restart-Job Purge-Jobs "
1150 "Set-Job-Attributes Create-Job-Subscription "
1151 "Renew-Subscription Cancel-Subscription "
1152 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1153 "Suspend-Current-Job Resume-Job "
1154 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1155 "CUPS-Authenticate-Job CUPS-Get-Document>");
1156 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1158 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1159 po
->order_type
= CUPSD_AUTH_ALLOW
;
1160 po
->level
= CUPSD_AUTH_USER
;
1162 cupsdAddName(po
, "@OWNER");
1163 cupsdAddName(po
, "@SYSTEM");
1164 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1166 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1167 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1168 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1169 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1170 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1171 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1172 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1173 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1174 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1175 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1176 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1177 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1178 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1179 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1180 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1181 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1182 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1183 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1184 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1185 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1187 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1189 cupsdLogMessage(CUPSD_LOG_INFO
,
1190 "<Limit Pause-Printer Resume-Printer "
1191 "Set-Printer-Attributes Enable-Printer "
1192 "Disable-Printer Pause-Printer-After-Current-Job "
1193 "Hold-New-Jobs Release-Held-New-Jobs "
1194 "Deactivate-Printer Activate-Printer Restart-Printer "
1195 "Shutdown-Printer Startup-Printer Promote-Job "
1196 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1197 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1198 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1199 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1200 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1202 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1203 po
->order_type
= CUPSD_AUTH_ALLOW
;
1204 po
->type
= CUPSD_AUTH_DEFAULT
;
1205 po
->level
= CUPSD_AUTH_USER
;
1207 cupsdAddName(po
, "@SYSTEM");
1208 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1210 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1211 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1212 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1213 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1214 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1215 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1216 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1217 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1218 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1219 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1220 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1221 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1222 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1223 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1224 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1225 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1226 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1227 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1228 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1229 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1230 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1231 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1233 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1235 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1236 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1238 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1239 po
->order_type
= CUPSD_AUTH_ALLOW
;
1241 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1242 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1246 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1247 cupsArrayCount(Policies
));
1248 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1250 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1251 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1252 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1255 * If we are doing a full reload or the server root has changed, flush
1256 * the jobs, printers, etc. and start from scratch...
1259 if (NeedReload
== RELOAD_ALL
||
1260 old_remote_port
!= RemotePort
||
1261 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1262 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1264 mime_type_t
*type
; /* Current type */
1265 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1266 /* MIME type name */
1269 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1272 * Free all memory...
1275 cupsdDeleteAllSubscriptions();
1277 cupsdDeleteAllPrinters();
1279 DefaultPrinter
= NULL
;
1281 if (MimeDatabase
!= NULL
)
1282 mimeDelete(MimeDatabase
);
1286 for (i
= 0; i
< NumMimeTypes
; i
++)
1287 _cupsStrFree(MimeTypes
[i
]);
1293 * Read the MIME type and conversion database...
1296 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1297 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1299 MimeDatabase
= mimeNew();
1300 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1302 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1303 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1304 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1305 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1309 cupsdLogMessage(CUPSD_LOG_EMERG
,
1310 "Unable to load MIME database from \"%s\" or \"%s\".",
1311 mimedir
, ServerRoot
);
1312 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1316 cupsdLogMessage(CUPSD_LOG_INFO
,
1317 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1318 "%d filters...", mimedir
, ServerRoot
,
1319 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1322 * Create a list of MIME types for the document-format-supported
1326 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1327 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1330 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1332 cupsdLogMessage(CUPSD_LOG_ERROR
,
1333 "Unable to allocate memory for %d MIME types.",
1339 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1341 i
++, type
= mimeNextType(MimeDatabase
))
1343 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1345 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1348 if (i
< NumMimeTypes
)
1349 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1352 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1354 mime_filter_t
*filter
; /* Current filter */
1357 for (type
= mimeFirstType(MimeDatabase
);
1359 type
= mimeNextType(MimeDatabase
))
1360 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1361 type
->super
, type
->type
);
1363 for (filter
= mimeFirstFilter(MimeDatabase
);
1365 filter
= mimeNextFilter(MimeDatabase
))
1366 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1367 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1368 filter
->src
->super
, filter
->src
->type
,
1369 filter
->dst
->super
, filter
->dst
->type
,
1370 filter
->cost
, filter
->filter
);
1377 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1378 cupsdLoadBanners(temp
);
1381 * Load printers and classes...
1384 cupsdLoadAllPrinters();
1385 cupsdLoadAllClasses();
1387 cupsdCreateCommonData();
1390 * Update the printcap file as needed...
1393 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1394 cupsdWritePrintcap();
1397 * Load queued jobs...
1403 * Load subscriptions...
1406 cupsdLoadAllSubscriptions();
1408 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1413 * Not a full reload, so recreate the common printer attributes...
1416 cupsdCreateCommonData();
1419 * Update all printers as needed...
1422 cupsdUpdatePrinters();
1423 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1425 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1429 * Reset the reload state...
1432 NeedReload
= RELOAD_NONE
;
1434 cupsdClearString(&old_serverroot
);
1435 cupsdClearString(&old_requestroot
);
1442 * 'get_address()' - Get an address + port number from a line.
1445 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1446 get_address(const char *value
, /* I - Value string */
1447 int defport
) /* I - Default port */
1449 char buffer
[1024], /* Hostname + port number buffer */
1450 defpname
[255], /* Default port name */
1451 *hostname
, /* Hostname or IP */
1452 *portname
; /* Port number or name */
1453 http_addrlist_t
*addrlist
; /* Address list */
1457 * Check for an empty value...
1462 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1467 * Grab a hostname and port number; if there is no colon and the port name
1468 * is only digits, then we have a port number by itself...
1471 strlcpy(buffer
, value
, sizeof(buffer
));
1473 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1480 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1485 * Use the default port...
1488 sprintf(defpname
, "%d", defport
);
1489 portname
= defpname
;
1495 * The buffer contains just a port number...
1503 if (hostname
&& !strcmp(hostname
, "*"))
1507 * Now lookup the address using httpAddrGetList()...
1510 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1511 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1512 hostname
? hostname
: "(nil)");
1519 * 'get_addr_and_mask()' - Get an IP address and netmask.
1522 static int /* O - 1 on success, 0 on failure */
1523 get_addr_and_mask(const char *value
, /* I - String from config file */
1524 unsigned *ip
, /* O - Address value */
1525 unsigned *mask
) /* O - Mask value */
1527 int i
, j
, /* Looping vars */
1528 family
, /* Address family */
1529 ipcount
; /* Count of fields in address */
1530 unsigned ipval
; /* Value */
1531 const char *maskval
, /* Pointer to start of mask value */
1532 *ptr
, /* Pointer into value */
1537 * Get the address...
1540 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1541 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1543 if ((maskval
= strchr(value
, '/')) != NULL
)
1546 maskval
= value
+ strlen(value
);
1550 * Check for an IPv6 address...
1556 * Parse hexadecimal IPv6/IPv4 address...
1561 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1565 else if (!strncmp(ptr
, "::", 2))
1567 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1569 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1574 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1577 * Read IPv4 dotted quad...
1580 unsigned val
[4] = { 0, 0, 0, 0 };
1581 /* IPv4 address values */
1583 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1587 * Range check the IP numbers...
1590 for (i
= 0; i
< ipcount
; i
++)
1595 * Merge everything into a 32-bit IPv4 address in ip[3]...
1598 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1601 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1604 * If the leading words are all 0's then this is an IPv4 address...
1607 if (!val
[0] && !val
[1] && !val
[2])
1610 while (isdigit(*ptr
& 255) || *ptr
== '.')
1614 else if (isxdigit(*ptr
& 255))
1616 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1618 if (*ptr
== ':' && ptr
[1] != ':')
1627 ip
[i
/ 2] |= ipval
<< 16;
1638 if (*ptr
&& *ptr
!= '/')
1642 #endif /* AF_INET6 */
1645 * Parse dotted-decimal IPv4 address...
1648 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1652 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1655 * Range check the IP numbers...
1658 for (i
= 0; i
< ipcount
; i
++)
1663 * Merge everything into a 32-bit IPv4 address in ip[3]...
1666 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1669 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1675 * Get the netmask value(s)...
1678 memset(mask
, 0, sizeof(unsigned) * 4);
1680 if (strchr(maskval
, '.'))
1683 * Get dotted-decimal mask...
1686 if (family
!= AF_INET
)
1689 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1693 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1694 mask
[0] = mask
[1] = mask
[2] = 0;
1699 * Get address/bits format...
1705 if (family
== AF_INET6
)
1713 mask
[0] = 0xffffffff;
1715 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1718 mask
[1] = 0xffffffff;
1722 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1725 mask
[2] = 0xffffffff;
1729 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1732 mask
[3] = 0xffffffff;
1736 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1739 #endif /* AF_INET6 */
1744 mask
[0] = 0xffffffff;
1745 mask
[1] = 0xffffffff;
1746 mask
[2] = 0xffffffff;
1749 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1751 mask
[3] = 0xffffffff;
1756 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1757 "get_addr_and_mask(value=\"%s\", "
1758 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1759 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1763 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1766 if ((ip
[0] & ~mask
[0]) != 0 ||
1767 (ip
[1] & ~mask
[1]) != 0 ||
1768 (ip
[2] & ~mask
[2]) != 0 ||
1769 (ip
[3] & ~mask
[3]) != 0)
1777 * 'mime_error_cb()' - Log a MIME error.
1781 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
1782 const char *message
) /* I - Message */
1786 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
1791 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1794 static int /* O - 1 on success, 0 on failure */
1795 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1796 char *line
, /* I - Line from file */
1797 char *value
, /* I - Start of value data */
1798 int linenum
) /* I - Current line number */
1800 char *valptr
; /* Pointer into value */
1801 unsigned ip
[4], /* IP address components */
1802 mask
[4]; /* IP netmask components */
1805 if (!_cups_strcasecmp(line
, "Encryption"))
1808 * "Encryption xxx" - set required encryption level...
1811 if (!_cups_strcasecmp(value
, "never"))
1812 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1813 else if (!_cups_strcasecmp(value
, "always"))
1815 cupsdLogMessage(CUPSD_LOG_ERROR
,
1816 "Encryption value \"%s\" on line %d is invalid in this "
1817 "context. Using \"required\" instead.", value
, linenum
);
1819 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1821 else if (!_cups_strcasecmp(value
, "required"))
1822 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1823 else if (!_cups_strcasecmp(value
, "ifrequested"))
1824 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1827 cupsdLogMessage(CUPSD_LOG_ERROR
,
1828 "Unknown Encryption value %s on line %d.", value
, linenum
);
1832 else if (!_cups_strcasecmp(line
, "Order"))
1835 * "Order Deny,Allow" or "Order Allow,Deny"...
1838 if (!_cups_strncasecmp(value
, "deny", 4))
1839 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1840 else if (!_cups_strncasecmp(value
, "allow", 5))
1841 loc
->order_type
= CUPSD_AUTH_DENY
;
1844 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1849 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
1852 * Allow [From] host/ip...
1853 * Deny [From] host/ip...
1858 if (!_cups_strncasecmp(value
, "from", 4))
1861 * Strip leading "from"...
1866 while (_cups_isspace(*value
))
1874 * Find the end of the value...
1877 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
1879 while (_cups_isspace(*valptr
))
1883 * Figure out what form the allow/deny address takes:
1894 * nnn.nnn.nnn.nnn/mm
1895 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1898 if (!_cups_strcasecmp(value
, "all"))
1904 if (!_cups_strcasecmp(line
, "Allow"))
1905 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
1907 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
1909 else if (!_cups_strcasecmp(value
, "none"))
1915 if (!_cups_strcasecmp(line
, "Allow"))
1916 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
1918 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
1921 else if (value
[0] == '*' || value
[0] == '.' ||
1922 (!isdigit(value
[0] & 255) && value
[0] != '['))
1924 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1925 #endif /* AF_INET6 */
1928 * Host or domain name...
1931 if (value
[0] == '*')
1934 if (!_cups_strcasecmp(line
, "Allow"))
1935 cupsdAddNameMask(&(loc
->allow
), value
);
1937 cupsdAddNameMask(&(loc
->deny
), value
);
1942 * One of many IP address forms...
1945 if (!get_addr_and_mask(value
, ip
, mask
))
1947 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1952 if (!_cups_strcasecmp(line
, "Allow"))
1953 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
1955 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
1959 * Advance to next value...
1965 else if (!_cups_strcasecmp(line
, "AuthType"))
1968 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1971 if (!_cups_strcasecmp(value
, "none"))
1973 loc
->type
= CUPSD_AUTH_NONE
;
1974 loc
->level
= CUPSD_AUTH_ANON
;
1976 else if (!_cups_strcasecmp(value
, "basic"))
1978 loc
->type
= CUPSD_AUTH_BASIC
;
1980 if (loc
->level
== CUPSD_AUTH_ANON
)
1981 loc
->level
= CUPSD_AUTH_USER
;
1983 else if (!_cups_strcasecmp(value
, "digest"))
1985 loc
->type
= CUPSD_AUTH_DIGEST
;
1987 if (loc
->level
== CUPSD_AUTH_ANON
)
1988 loc
->level
= CUPSD_AUTH_USER
;
1990 else if (!_cups_strcasecmp(value
, "basicdigest"))
1992 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1994 if (loc
->level
== CUPSD_AUTH_ANON
)
1995 loc
->level
= CUPSD_AUTH_USER
;
1997 else if (!_cups_strcasecmp(value
, "default"))
1999 loc
->type
= CUPSD_AUTH_DEFAULT
;
2001 if (loc
->level
== CUPSD_AUTH_ANON
)
2002 loc
->level
= CUPSD_AUTH_USER
;
2005 else if (!_cups_strcasecmp(value
, "negotiate"))
2007 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2009 if (loc
->level
== CUPSD_AUTH_ANON
)
2010 loc
->level
= CUPSD_AUTH_USER
;
2012 #endif /* HAVE_GSSAPI */
2015 cupsdLogMessage(CUPSD_LOG_WARN
,
2016 "Unknown authorization type %s on line %d.",
2021 else if (!_cups_strcasecmp(line
, "AuthClass"))
2024 * AuthClass anonymous, user, system, group
2027 if (!_cups_strcasecmp(value
, "anonymous"))
2029 loc
->type
= CUPSD_AUTH_NONE
;
2030 loc
->level
= CUPSD_AUTH_ANON
;
2032 cupsdLogMessage(CUPSD_LOG_WARN
,
2033 "\"AuthClass %s\" is deprecated; consider removing "
2037 else if (!_cups_strcasecmp(value
, "user"))
2039 loc
->level
= CUPSD_AUTH_USER
;
2041 cupsdLogMessage(CUPSD_LOG_WARN
,
2042 "\"AuthClass %s\" is deprecated; consider using "
2043 "\"Require valid-user\" on line %d.",
2046 else if (!_cups_strcasecmp(value
, "group"))
2048 loc
->level
= CUPSD_AUTH_GROUP
;
2050 cupsdLogMessage(CUPSD_LOG_WARN
,
2051 "\"AuthClass %s\" is deprecated; consider using "
2052 "\"Require user @groupname\" on line %d.",
2055 else if (!_cups_strcasecmp(value
, "system"))
2057 loc
->level
= CUPSD_AUTH_GROUP
;
2059 cupsdAddName(loc
, "@SYSTEM");
2061 cupsdLogMessage(CUPSD_LOG_WARN
,
2062 "\"AuthClass %s\" is deprecated; consider using "
2063 "\"Require user @SYSTEM\" on line %d.",
2068 cupsdLogMessage(CUPSD_LOG_WARN
,
2069 "Unknown authorization class %s on line %d.",
2074 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2076 cupsdAddName(loc
, value
);
2078 cupsdLogMessage(CUPSD_LOG_WARN
,
2079 "\"AuthGroupName %s\" directive is deprecated; consider "
2080 "using \"Require user @%s\" on line %d.",
2081 value
, value
, linenum
);
2083 else if (!_cups_strcasecmp(line
, "Require"))
2086 * Apache synonym for AuthClass and AuthGroupName...
2090 * Require valid-user
2091 * Require group names
2092 * Require user names
2095 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2100 if (!_cups_strcasecmp(value
, "valid-user") ||
2101 !_cups_strcasecmp(value
, "user"))
2102 loc
->level
= CUPSD_AUTH_USER
;
2103 else if (!_cups_strcasecmp(value
, "group"))
2104 loc
->level
= CUPSD_AUTH_GROUP
;
2107 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2113 * Get the list of names from the line...
2116 for (value
= valptr
; *value
;)
2118 while (_cups_isspace(*value
))
2121 #ifdef HAVE_AUTHORIZATION_H
2122 if (!strncmp(value
, "@AUTHKEY(", 9))
2125 * Grab "@AUTHKEY(name)" value...
2128 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2134 #endif /* HAVE_AUTHORIZATION_H */
2135 if (*value
== '\"' || *value
== '\'')
2138 * Grab quoted name...
2141 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2148 * Grab literal name.
2151 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2157 cupsdAddName(loc
, value
);
2159 for (value
= valptr
; _cups_isspace(*value
); value
++);
2162 else if (!_cups_strcasecmp(line
, "Satisfy"))
2164 if (!_cups_strcasecmp(value
, "all"))
2165 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2166 else if (!_cups_strcasecmp(value
, "any"))
2167 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2170 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2183 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2186 static int /* O - FatalErrors bits */
2187 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2189 int fatal
; /* FatalErrors bits */
2190 char value
[1024], /* Value string */
2191 *valstart
, /* Pointer into value */
2192 *valend
; /* End of value */
2196 * Empty FatalErrors line yields NULL pointer...
2200 return (CUPSD_FATAL_NONE
);
2203 * Loop through the value string,...
2206 strlcpy(value
, s
, sizeof(value
));
2208 fatal
= CUPSD_FATAL_NONE
;
2210 for (valstart
= value
; *valstart
;)
2213 * Get the current space/comma-delimited kind name...
2216 for (valend
= valstart
; *valend
; valend
++)
2217 if (_cups_isspace(*valend
) || *valend
== ',')
2224 * Add the error to the bitmask...
2227 if (!_cups_strcasecmp(valstart
, "all"))
2228 fatal
= CUPSD_FATAL_ALL
;
2229 else if (!_cups_strcasecmp(valstart
, "browse"))
2230 fatal
|= CUPSD_FATAL_BROWSE
;
2231 else if (!_cups_strcasecmp(valstart
, "-browse"))
2232 fatal
&= ~CUPSD_FATAL_BROWSE
;
2233 else if (!_cups_strcasecmp(valstart
, "config"))
2234 fatal
|= CUPSD_FATAL_CONFIG
;
2235 else if (!_cups_strcasecmp(valstart
, "-config"))
2236 fatal
&= ~CUPSD_FATAL_CONFIG
;
2237 else if (!_cups_strcasecmp(valstart
, "listen"))
2238 fatal
|= CUPSD_FATAL_LISTEN
;
2239 else if (!_cups_strcasecmp(valstart
, "-listen"))
2240 fatal
&= ~CUPSD_FATAL_LISTEN
;
2241 else if (!_cups_strcasecmp(valstart
, "log"))
2242 fatal
|= CUPSD_FATAL_LOG
;
2243 else if (!_cups_strcasecmp(valstart
, "-log"))
2244 fatal
&= ~CUPSD_FATAL_LOG
;
2245 else if (!_cups_strcasecmp(valstart
, "permissions"))
2246 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2247 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2248 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2249 else if (_cups_strcasecmp(valstart
, "none"))
2250 cupsdLogMessage(CUPSD_LOG_ERROR
,
2251 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2253 for (valstart
= valend
; *valstart
; valstart
++)
2254 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2263 * 'parse_groups()' - Parse system group names in a string.
2266 static int /* O - 1 on success, 0 on failure */
2267 parse_groups(const char *s
) /* I - Space-delimited groups */
2269 int status
; /* Return status */
2270 char value
[1024], /* Value string */
2271 *valstart
, /* Pointer into value */
2272 *valend
, /* End of value */
2273 quote
; /* Quote character */
2274 struct group
*group
; /* Group */
2278 * Make a copy of the string and parse out the groups...
2281 strlcpy(value
, s
, sizeof(value
));
2286 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2288 if (*valstart
== '\'' || *valstart
== '\"')
2291 * Scan quoted name...
2294 quote
= *valstart
++;
2296 for (valend
= valstart
; *valend
; valend
++)
2297 if (*valend
== quote
)
2303 * Scan space or comma-delimited name...
2306 for (valend
= valstart
; *valend
; valend
++)
2307 if (_cups_isspace(*valend
) || *valend
== ',')
2314 group
= getgrnam(valstart
);
2317 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2318 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2329 while (*valstart
== ',' || _cups_isspace(*valstart
))
2338 * 'parse_protocols()' - Parse browse protocols in a string.
2341 static int /* O - Browse protocol bits */
2342 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2344 int protocols
; /* Browse protocol bits */
2345 char value
[1024], /* Value string */
2346 *valstart
, /* Pointer into value */
2347 *valend
; /* End of value */
2351 * Empty protocol line yields NULL pointer...
2358 * Loop through the value string,...
2361 strlcpy(value
, s
, sizeof(value
));
2365 for (valstart
= value
; *valstart
;)
2368 * Get the current space/comma-delimited protocol name...
2371 for (valend
= valstart
; *valend
; valend
++)
2372 if (_cups_isspace(*valend
) || *valend
== ',')
2379 * Add the protocol to the bitmask...
2382 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2383 !_cups_strcasecmp(valstart
, "dns-sd") ||
2384 !_cups_strcasecmp(valstart
, "bonjour"))
2385 protocols
|= BROWSE_DNSSD
;
2386 else if (!_cups_strcasecmp(valstart
, "all"))
2387 protocols
|= BROWSE_ALL
;
2388 else if (_cups_strcasecmp(valstart
, "none"))
2389 cupsdLogMessage(CUPSD_LOG_ERROR
,
2390 "Unknown browse protocol \"%s\" ignored.", valstart
);
2392 for (valstart
= valend
; *valstart
; valstart
++)
2393 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2402 * 'read_configuration()' - Read a configuration file.
2405 static int /* O - 1 on success, 0 on failure */
2406 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2408 int i
; /* Looping var */
2409 int linenum
; /* Current line number */
2410 char line
[HTTP_MAX_BUFFER
],
2411 /* Line from file */
2412 temp
[HTTP_MAX_BUFFER
],
2413 /* Temporary buffer for value */
2414 *value
, /* Pointer to value */
2415 *valueptr
; /* Pointer into value */
2416 int valuelen
; /* Length of value */
2417 cupsd_var_t
const *var
; /* Current variable */
2418 http_addrlist_t
*addrlist
, /* Address list */
2419 *addr
; /* Current address */
2420 cups_file_t
*incfile
; /* Include file */
2421 char incname
[1024]; /* Include filename */
2422 struct group
*group
; /* Group */
2426 * Loop through each line in the file...
2431 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2434 * Decode the directive...
2437 if (!_cups_strcasecmp(line
, "Include") && value
)
2443 if (value
[0] == '/')
2444 strlcpy(incname
, value
, sizeof(incname
));
2446 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2448 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2449 cupsdLogMessage(CUPSD_LOG_ERROR
,
2450 "Unable to include config file \"%s\" - %s",
2451 incname
, strerror(errno
));
2454 read_configuration(incfile
);
2455 cupsFileClose(incfile
);
2458 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2464 linenum
= read_location(fp
, value
, linenum
);
2468 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2474 linenum
= read_policy(fp
, value
, linenum
);
2478 else if (!_cups_strcasecmp(line
, "FatalErrors"))
2479 FatalErrors
= parse_fatal_errors(value
);
2480 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2482 JobRetryInterval
= atoi(value
);
2483 cupsdLogMessage(CUPSD_LOG_WARN
,
2484 "FaxRetryInterval is deprecated; use "
2485 "JobRetryInterval on line %d.", linenum
);
2487 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2489 JobRetryLimit
= atoi(value
);
2490 cupsdLogMessage(CUPSD_LOG_WARN
,
2491 "FaxRetryLimit is deprecated; use "
2492 "JobRetryLimit on line %d.", linenum
);
2494 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2496 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2497 #endif /* HAVE_SSL */
2501 * Add listening address(es) to the list...
2504 cupsd_listener_t
*lis
; /* New listeners array */
2508 * Get the address list...
2511 addrlist
= get_address(value
, IPP_PORT
);
2515 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2521 * Add each address...
2524 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2527 * See if this address is already present...
2530 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2532 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2533 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2534 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2539 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2540 cupsdLogMessage(CUPSD_LOG_WARN
,
2541 "Duplicate listen address \"%s\" ignored.", temp
);
2546 * Allocate another listener...
2550 Listeners
= cupsArrayNew(NULL
, NULL
);
2554 cupsdLogMessage(CUPSD_LOG_ERROR
,
2555 "Unable to allocate %s at line %d - %s.",
2556 line
, linenum
, strerror(errno
));
2560 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2562 cupsdLogMessage(CUPSD_LOG_ERROR
,
2563 "Unable to allocate %s at line %d - %s.",
2564 line
, linenum
, strerror(errno
));
2568 cupsArrayAdd(Listeners
, lis
);
2571 * Copy the current address and log it...
2574 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2578 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
2579 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2580 #endif /* HAVE_SSL */
2582 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2585 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2586 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2588 #endif /* AF_LOCAL */
2589 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
2590 _httpAddrPort(&(lis
->address
)),
2591 _httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
2593 if (!httpAddrLocalhost(&(lis
->address
)))
2594 RemotePort
= _httpAddrPort(&(lis
->address
));
2601 httpAddrFreeList(addrlist
);
2603 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
2604 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
2607 * "BrowseProtocols name [... name]"
2608 * "BrowseLocalProtocols name [... name]"
2611 int protocols
= parse_protocols(value
);
2615 cupsdLogMessage(CUPSD_LOG_ERROR
,
2616 "Unknown browse protocol \"%s\" on line %d.",
2621 BrowseLocalProtocols
= protocols
;
2623 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
2626 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2629 if (!_cups_strcasecmp(value
, "none"))
2630 DefaultAuthType
= CUPSD_AUTH_NONE
;
2631 else if (!_cups_strcasecmp(value
, "basic"))
2632 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2633 else if (!_cups_strcasecmp(value
, "digest"))
2634 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2635 else if (!_cups_strcasecmp(value
, "basicdigest"))
2636 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2638 else if (!_cups_strcasecmp(value
, "negotiate"))
2639 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2640 #endif /* HAVE_GSSAPI */
2643 cupsdLogMessage(CUPSD_LOG_WARN
,
2644 "Unknown default authorization type %s on line %d.",
2646 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2651 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
2654 * DefaultEncryption {Never,IfRequested,Required}
2657 if (!value
|| !_cups_strcasecmp(value
, "never"))
2658 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2659 else if (!_cups_strcasecmp(value
, "required"))
2660 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2661 else if (!_cups_strcasecmp(value
, "ifrequested"))
2662 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2665 cupsdLogMessage(CUPSD_LOG_WARN
,
2666 "Unknown default encryption %s on line %d.",
2668 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2672 #endif /* HAVE_SSL */
2673 else if (!_cups_strcasecmp(line
, "User") && value
)
2676 * User ID to run as...
2679 if (isdigit(value
[0] & 255))
2681 int uid
= atoi(value
);
2684 cupsdLogMessage(CUPSD_LOG_ERROR
,
2685 "Will not use User 0 as specified on line %d "
2686 "for security reasons. You must use a non-"
2687 "privileged account instead.",
2694 struct passwd
*p
; /* Password information */
2697 p
= getpwnam(value
);
2702 cupsdLogMessage(CUPSD_LOG_ERROR
,
2703 "Will not use User %s (UID=0) as specified on line "
2704 "%d for security reasons. You must use a non-"
2705 "privileged account instead.",
2711 cupsdLogMessage(CUPSD_LOG_ERROR
,
2712 "Unknown User \"%s\" on line %d, ignoring.",
2716 else if (!_cups_strcasecmp(line
, "Group") && value
)
2719 * Group ID to run as...
2722 if (isdigit(value
[0]))
2723 Group
= atoi(value
);
2727 group
= getgrnam(value
);
2730 Group
= group
->gr_gid
;
2732 cupsdLogMessage(CUPSD_LOG_ERROR
,
2733 "Unknown Group \"%s\" on line %d, ignoring.",
2737 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
2740 * SystemGroup (admin) group(s)...
2743 if (!parse_groups(value
))
2744 cupsdLogMessage(CUPSD_LOG_ERROR
,
2745 "Unknown SystemGroup \"%s\" on line %d, ignoring.",
2748 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
2751 * Do hostname lookups?
2754 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
2755 !_cups_strcasecmp(value
, "false"))
2756 HostNameLookups
= 0;
2757 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
2758 !_cups_strcasecmp(value
, "true"))
2759 HostNameLookups
= 1;
2760 else if (!_cups_strcasecmp(value
, "double"))
2761 HostNameLookups
= 2;
2763 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2766 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
2769 * Amount of logging to do to access log...
2772 if (!_cups_strcasecmp(value
, "all"))
2773 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
2774 else if (!_cups_strcasecmp(value
, "actions"))
2775 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
2776 else if (!_cups_strcasecmp(value
, "config"))
2777 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
2779 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
2782 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
2785 * Amount of logging to do to error log...
2788 if (!_cups_strcasecmp(value
, "debug2"))
2789 LogLevel
= CUPSD_LOG_DEBUG2
;
2790 else if (!_cups_strcasecmp(value
, "debug"))
2791 LogLevel
= CUPSD_LOG_DEBUG
;
2792 else if (!_cups_strcasecmp(value
, "info"))
2793 LogLevel
= CUPSD_LOG_INFO
;
2794 else if (!_cups_strcasecmp(value
, "notice"))
2795 LogLevel
= CUPSD_LOG_NOTICE
;
2796 else if (!_cups_strcasecmp(value
, "warn"))
2797 LogLevel
= CUPSD_LOG_WARN
;
2798 else if (!_cups_strcasecmp(value
, "error"))
2799 LogLevel
= CUPSD_LOG_ERROR
;
2800 else if (!_cups_strcasecmp(value
, "crit"))
2801 LogLevel
= CUPSD_LOG_CRIT
;
2802 else if (!_cups_strcasecmp(value
, "alert"))
2803 LogLevel
= CUPSD_LOG_ALERT
;
2804 else if (!_cups_strcasecmp(value
, "emerg"))
2805 LogLevel
= CUPSD_LOG_EMERG
;
2806 else if (!_cups_strcasecmp(value
, "none"))
2807 LogLevel
= CUPSD_LOG_NONE
;
2809 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2812 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
2815 * Amount of logging to do to error log...
2818 if (!_cups_strcasecmp(value
, "standard"))
2819 LogTimeFormat
= CUPSD_TIME_STANDARD
;
2820 else if (!_cups_strcasecmp(value
, "usecs"))
2821 LogTimeFormat
= CUPSD_TIME_USECS
;
2823 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
2826 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
2829 * Format of printcap file?
2832 if (!_cups_strcasecmp(value
, "bsd"))
2833 PrintcapFormat
= PRINTCAP_BSD
;
2834 else if (!_cups_strcasecmp(value
, "plist"))
2835 PrintcapFormat
= PRINTCAP_PLIST
;
2836 else if (!_cups_strcasecmp(value
, "solaris"))
2837 PrintcapFormat
= PRINTCAP_SOLARIS
;
2839 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2842 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
2845 * Set the string used for the Server header...
2848 struct utsname plat
; /* Platform info */
2853 if (!_cups_strcasecmp(value
, "ProductOnly"))
2854 cupsdSetString(&ServerHeader
, "CUPS");
2855 else if (!_cups_strcasecmp(value
, "Major"))
2856 cupsdSetStringf(&ServerHeader
, "CUPS/%d", CUPS_VERSION_MAJOR
);
2857 else if (!_cups_strcasecmp(value
, "Minor"))
2858 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
2859 CUPS_VERSION_MINOR
);
2860 else if (!_cups_strcasecmp(value
, "Minimal"))
2861 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2862 else if (!_cups_strcasecmp(value
, "OS"))
2863 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2864 else if (!_cups_strcasecmp(value
, "Full"))
2865 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/2.1",
2867 else if (!_cups_strcasecmp(value
, "None"))
2868 cupsdClearString(&ServerHeader
);
2870 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2873 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
2876 * PassEnv variable [... variable]
2881 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2882 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2885 if (value
[valuelen
])
2887 value
[valuelen
] = '\0';
2891 cupsdSetEnv(value
, NULL
);
2893 for (value
+= valuelen
; *value
; value
++)
2894 if (!_cups_isspace(*value
) || *value
!= ',')
2898 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
2901 * ServerAlias name [... name]
2905 ServerAlias
= cupsArrayNew(NULL
, NULL
);
2909 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2910 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2913 if (value
[valuelen
])
2915 value
[valuelen
] = '\0';
2919 cupsdAddAlias(ServerAlias
, value
);
2921 for (value
+= valuelen
; *value
; value
++)
2922 if (!_cups_isspace(*value
) || *value
!= ',')
2926 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
2929 * SetEnv variable value
2932 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2940 while (isspace(*valueptr
& 255))
2943 cupsdSetEnv(value
, valueptr
);
2946 cupsdLogMessage(CUPSD_LOG_ERROR
,
2947 "Missing value for SetEnv directive on line %d.",
2951 else if (!_cups_strcasecmp(line
, "SSLOptions"))
2954 * SSLOptions options
2957 if (!value
|| !_cups_strcasecmp(value
, "none"))
2958 SSLOptions
= CUPSD_SSL_NONE
;
2959 else if (!_cups_strcasecmp(value
, "noemptyfragments"))
2960 SSLOptions
= CUPSD_SSL_NOEMPTY
;
2962 cupsdLogMessage(CUPSD_LOG_ERROR
,
2963 "Unknown value \"%s\" for SSLOptions directive on "
2964 "line %d.", value
, linenum
);
2966 #endif /* HAVE_SSL */
2970 * Find a simple variable in the list...
2973 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2974 if (!_cups_strcasecmp(line
, var
->name
))
2980 * Unknown directive! Output an error message and continue...
2984 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
2987 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2994 case CUPSD_VARTYPE_INTEGER
:
2996 cupsdLogMessage(CUPSD_LOG_ERROR
,
2997 "Missing integer value for %s on line %d.",
3002 char *units
; /* Units */
3005 n
= strtol(value
, &units
, 0);
3007 if (units
&& *units
)
3009 if (tolower(units
[0] & 255) == 'g')
3010 n
*= 1024 * 1024 * 1024;
3011 else if (tolower(units
[0] & 255) == 'm')
3013 else if (tolower(units
[0] & 255) == 'k')
3015 else if (tolower(units
[0] & 255) == 't')
3020 cupsdLogMessage(CUPSD_LOG_ERROR
,
3021 "Bad negative integer value for %s on line %d.",
3024 *((int *)var
->ptr
) = n
;
3028 case CUPSD_VARTYPE_BOOLEAN
:
3030 cupsdLogMessage(CUPSD_LOG_ERROR
,
3031 "Missing boolean value for %s on line %d.",
3033 else if (!_cups_strcasecmp(value
, "true") ||
3034 !_cups_strcasecmp(value
, "on") ||
3035 !_cups_strcasecmp(value
, "enabled") ||
3036 !_cups_strcasecmp(value
, "yes") ||
3038 *((int *)var
->ptr
) = TRUE
;
3039 else if (!_cups_strcasecmp(value
, "false") ||
3040 !_cups_strcasecmp(value
, "off") ||
3041 !_cups_strcasecmp(value
, "disabled") ||
3042 !_cups_strcasecmp(value
, "no") ||
3043 !_cups_strcasecmp(value
, "0"))
3044 *((int *)var
->ptr
) = FALSE
;
3046 cupsdLogMessage(CUPSD_LOG_ERROR
,
3047 "Unknown boolean value %s on line %d.",
3051 case CUPSD_VARTYPE_PATHNAME
:
3054 cupsdLogMessage(CUPSD_LOG_ERROR
,
3055 "Missing pathname value for %s on line %d.",
3060 if (value
[0] == '/')
3061 strlcpy(temp
, value
, sizeof(temp
));
3063 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3065 if (access(temp
, 0))
3067 cupsdLogMessage(CUPSD_LOG_ERROR
,
3068 "File or directory for \"%s %s\" on line %d "
3069 "does not exist.", line
, value
, linenum
);
3073 case CUPSD_VARTYPE_STRING
:
3074 cupsdSetString((char **)var
->ptr
, value
);
3085 * 'read_location()' - Read a <Location path> definition.
3088 static int /* O - New line number or 0 on error */
3089 read_location(cups_file_t
*fp
, /* I - Configuration file */
3090 char *location
, /* I - Location name/path */
3091 int linenum
) /* I - Current line number */
3093 cupsd_location_t
*loc
, /* New location */
3094 *parent
; /* Parent location */
3095 char line
[HTTP_MAX_BUFFER
],
3097 *value
, /* Value for directive */
3098 *valptr
; /* Pointer into value */
3101 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3102 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3104 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3108 cupsdAddLocation(parent
);
3110 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3115 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3118 * Decode the directive...
3121 if (!_cups_strcasecmp(line
, "</Location>"))
3123 else if (!_cups_strcasecmp(line
, "<Limit") ||
3124 !_cups_strcasecmp(line
, "<LimitExcept"))
3128 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3129 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3135 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3138 cupsdAddLocation(loc
);
3143 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3148 if (!strcmp(value
, "ALL"))
3149 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3150 else if (!strcmp(value
, "GET"))
3151 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3152 else if (!strcmp(value
, "HEAD"))
3153 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3154 else if (!strcmp(value
, "OPTIONS"))
3155 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3156 else if (!strcmp(value
, "POST"))
3157 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3158 else if (!strcmp(value
, "PUT"))
3159 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3160 else if (!strcmp(value
, "TRACE"))
3161 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3163 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3166 for (value
= valptr
; isspace(*value
& 255); value
++);
3169 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3170 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3172 parent
->limit
&= ~loc
->limit
;
3174 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3175 !_cups_strcasecmp(line
, "</LimitExcept>"))
3179 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3180 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3183 else if (!parse_aaa(loc
, line
, value
, linenum
))
3185 cupsdLogMessage(CUPSD_LOG_ERROR
,
3186 "Unknown Location directive %s on line %d.",
3188 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3193 cupsdLogMessage(CUPSD_LOG_ERROR
,
3194 "Unexpected end-of-file at line %d while reading location.",
3197 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3202 * 'read_policy()' - Read a <Policy name> definition.
3205 static int /* O - New line number or 0 on error */
3206 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3207 char *policy
, /* I - Location name/path */
3208 int linenum
) /* I - Current line number */
3210 int i
; /* Looping var */
3211 cupsd_policy_t
*pol
; /* Policy */
3212 cupsd_location_t
*op
; /* Policy operation */
3213 int num_ops
; /* Number of IPP operations */
3214 ipp_op_t ops
[100]; /* Operations */
3215 char line
[HTTP_MAX_BUFFER
],
3217 *value
, /* Value for directive */
3218 *valptr
; /* Pointer into value */
3222 * Create the policy...
3225 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3226 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3228 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3232 * Read from the file...
3238 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3241 * Decode the directive...
3244 if (!_cups_strcasecmp(line
, "</Policy>"))
3247 cupsdLogMessage(CUPSD_LOG_WARN
,
3248 "Missing </Limit> before </Policy> on line %d.",
3251 set_policy_defaults(pol
);
3255 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3259 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3260 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3267 * Scan for IPP operation names...
3274 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3279 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3281 if (!_cups_strcasecmp(value
, "All"))
3282 ops
[num_ops
] = IPP_ANY_OPERATION
;
3283 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3284 cupsdLogMessage(CUPSD_LOG_ERROR
,
3285 "Bad IPP operation name \"%s\" on line %d.",
3291 cupsdLogMessage(CUPSD_LOG_ERROR
,
3292 "Too many operations listed on line %d.",
3295 for (value
= valptr
; isspace(*value
& 255); value
++);
3299 * If none are specified, apply the policy to all operations...
3304 ops
[0] = IPP_ANY_OPERATION
;
3309 * Add a new policy for the first operation...
3312 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3314 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3317 * Finish the current operation limit...
3323 * Copy the policy to the other operations...
3326 for (i
= 1; i
< num_ops
; i
++)
3327 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3334 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3335 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3338 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3339 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3340 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3341 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3345 cupsdLogMessage(CUPSD_LOG_ERROR
,
3346 "%s directive must appear outside <Limit>...</Limit> "
3347 "on line %d.", line
, linenum
);
3348 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3354 * Pull out whitespace-delimited values...
3360 * Find the end of the current value...
3363 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3369 * Save it appropriately...
3372 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3375 * JobPrivateAccess {all|default|user/group list|@@ACL}
3378 if (!_cups_strcasecmp(value
, "default"))
3380 cupsdAddString(&(pol
->job_access
), "@OWNER");
3381 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3384 cupsdAddString(&(pol
->job_access
), value
);
3386 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3389 * JobPrivateValues {all|none|default|attribute list}
3392 if (!_cups_strcasecmp(value
, "default"))
3394 cupsdAddString(&(pol
->job_attrs
), "job-name");
3395 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3396 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3399 cupsdAddString(&(pol
->job_attrs
), value
);
3401 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3404 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3407 if (!_cups_strcasecmp(value
, "default"))
3409 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3410 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3413 cupsdAddString(&(pol
->sub_access
), value
);
3415 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3418 * SubscriptionPrivateValues {all|none|default|attribute list}
3421 if (!_cups_strcasecmp(value
, "default"))
3423 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3424 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3425 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3426 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3427 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3430 cupsdAddString(&(pol
->sub_attrs
), value
);
3434 * Find the next string on the line...
3437 for (value
= valptr
; isspace(*value
& 255); value
++);
3443 cupsdLogMessage(CUPSD_LOG_ERROR
,
3444 "Missing <Limit ops> directive before %s on line %d.",
3446 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3449 else if (!parse_aaa(op
, line
, value
, linenum
))
3451 cupsdLogMessage(CUPSD_LOG_ERROR
,
3452 "Unknown Policy Limit directive %s on line %d.",
3455 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3460 cupsdLogMessage(CUPSD_LOG_ERROR
,
3461 "Unexpected end-of-file at line %d while reading policy "
3462 "\"%s\".", linenum
, policy
);
3464 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3469 * 'set_policy_defaults()' - Set default policy values as needed.
3473 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
3475 cupsd_location_t
*op
; /* Policy operation */
3479 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3480 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3481 * upgrades do not introduce new security issues...
3484 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3485 op
->op
== IPP_ANY_OPERATION
)
3487 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3488 op
->op
!= IPP_ANY_OPERATION
)
3491 * Add a new limit for Validate-Job using the Print-Job limit as a
3495 cupsdLogMessage(CUPSD_LOG_WARN
,
3496 "No limit for Validate-Job defined in policy %s "
3497 "- using Print-Job's policy.", pol
->name
);
3499 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3502 cupsdLogMessage(CUPSD_LOG_WARN
,
3503 "No limit for Validate-Job defined in policy %s "
3504 "and no suitable template found.", pol
->name
);
3507 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3508 op
->op
== IPP_ANY_OPERATION
)
3510 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
3511 op
->op
!= IPP_ANY_OPERATION
)
3514 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3518 cupsdLogMessage(CUPSD_LOG_WARN
,
3519 "No limit for Cancel-Jobs defined in policy %s "
3520 "- using Pause-Printer's policy.", pol
->name
);
3522 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3525 cupsdLogMessage(CUPSD_LOG_WARN
,
3526 "No limit for Cancel-Jobs defined in policy %s "
3527 "and no suitable template found.", pol
->name
);
3530 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3531 op
->op
== IPP_ANY_OPERATION
)
3533 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3534 op
->op
!= IPP_ANY_OPERATION
)
3537 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3541 cupsdLogMessage(CUPSD_LOG_WARN
,
3542 "No limit for Cancel-My-Jobs defined in policy %s "
3543 "- using Send-Document's policy.", pol
->name
);
3545 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3548 cupsdLogMessage(CUPSD_LOG_WARN
,
3549 "No limit for Cancel-My-Jobs defined in policy %s "
3550 "and no suitable template found.", pol
->name
);
3553 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3554 op
->op
== IPP_ANY_OPERATION
)
3556 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3557 op
->op
!= IPP_ANY_OPERATION
)
3560 * Add a new limit for Close-Job using the Send-Document limit as a
3564 cupsdLogMessage(CUPSD_LOG_WARN
,
3565 "No limit for Close-Job defined in policy %s "
3566 "- using Send-Document's policy.", pol
->name
);
3568 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
3571 cupsdLogMessage(CUPSD_LOG_WARN
,
3572 "No limit for Close-Job defined in policy %s "
3573 "and no suitable template found.", pol
->name
);
3576 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3577 op
->op
== IPP_ANY_OPERATION
)
3579 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3580 op
->op
!= IPP_ANY_OPERATION
)
3583 * Add a new limit for CUPS-Get-Document using the Send-Document
3584 * limit as a template...
3587 cupsdLogMessage(CUPSD_LOG_WARN
,
3588 "No limit for CUPS-Get-Document defined in policy %s "
3589 "- using Send-Document's policy.", pol
->name
);
3591 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3594 cupsdLogMessage(CUPSD_LOG_WARN
,
3595 "No limit for CUPS-Get-Document defined in policy %s "
3596 "and no suitable template found.", pol
->name
);
3600 * Verify we have JobPrivateAccess, JobPrivateValues,
3601 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
3604 if (!pol
->job_access
)
3606 cupsdLogMessage(CUPSD_LOG_WARN
,
3607 "No JobPrivateAccess defined in policy %s "
3608 "- using defaults.", pol
->name
);
3609 cupsdAddString(&(pol
->job_access
), "@OWNER");
3610 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3613 if (!pol
->job_attrs
)
3615 cupsdLogMessage(CUPSD_LOG_WARN
,
3616 "No JobPrivateValues defined in policy %s "
3617 "- using defaults.", pol
->name
);
3618 cupsdAddString(&(pol
->job_attrs
), "job-name");
3619 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3620 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3623 if (!pol
->sub_access
)
3625 cupsdLogMessage(CUPSD_LOG_WARN
,
3626 "No SubscriptionPrivateAccess defined in policy %s "
3627 "- using defaults.", pol
->name
);
3628 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3629 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3632 if (!pol
->sub_attrs
)
3634 cupsdLogMessage(CUPSD_LOG_WARN
,
3635 "No SubscriptionPrivateValues defined in policy %s "
3636 "- using defaults.", pol
->name
);
3637 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3638 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3639 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3640 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3641 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3647 * End of "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $".