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...
949 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
950 strncmp(tmpdir
, "/private/tmp", 12))
952 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
953 #endif /* __APPLE__ */
956 * TMPDIR is defined, see if it is OK for us to use...
959 if (stat(tmpdir
, &tmpinfo
))
960 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
961 tmpdir
, strerror(errno
));
962 else if (!S_ISDIR(tmpinfo
.st_mode
))
963 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
965 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
966 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
967 !(tmpinfo
.st_mode
& S_IWOTH
))
968 cupsdLogMessage(CUPSD_LOG_ERROR
,
969 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
971 cupsdSetString(&TempDir
, tmpdir
);
976 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
978 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
983 * Make sure the temporary directory has the right permissions...
986 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
990 * Update ownership and permissions if the CUPS temp directory
991 * is under the spool directory or does not exist...
994 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
995 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1000 * Update environment variables...
1006 * Update default paper size setting as needed...
1009 if (!DefaultPaperSize
)
1011 #ifdef HAVE_LIBPAPER
1012 char *paper_result
; /* Paper size name from libpaper */
1014 if ((paper_result
= systempapername()) != NULL
)
1015 cupsdSetString(&DefaultPaperSize
, paper_result
);
1017 #endif /* HAVE_LIBPAPER */
1018 if (!DefaultLanguage
||
1019 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1020 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1021 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1022 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1023 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1024 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1025 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1028 * These are the only locales that will default to "letter" size...
1031 cupsdSetString(&DefaultPaperSize
, "Letter");
1034 cupsdSetString(&DefaultPaperSize
, "A4");
1038 * Update classification setting as needed...
1041 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1042 cupsdClearString(&Classification
);
1045 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1048 * Check the MaxClients setting, and then allocate memory for it...
1051 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1054 cupsdLogMessage(CUPSD_LOG_INFO
,
1055 "MaxClients limited to 1/3 (%d) of the file descriptor "
1057 MaxFDs
/ 3, MaxFDs
);
1059 MaxClients
= MaxFDs
/ 3;
1062 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1066 * Check the MaxActiveJobs setting; limit to 1/3 the available
1067 * file descriptors, since we need a pipe for each job...
1070 if (MaxActiveJobs
> (MaxFDs
/ 3))
1071 MaxActiveJobs
= MaxFDs
/ 3;
1074 * Update the MaxClientsPerHost value, as needed...
1077 if (MaxClientsPerHost
<= 0)
1078 MaxClientsPerHost
= MaxClients
;
1080 if (MaxClientsPerHost
> MaxClients
)
1081 MaxClientsPerHost
= MaxClients
;
1083 cupsdLogMessage(CUPSD_LOG_INFO
,
1084 "Allowing up to %d client connections per host.",
1088 * Update the default policy, as needed...
1092 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1094 DefaultPolicyPtr
= NULL
;
1096 if (!DefaultPolicyPtr
)
1098 cupsd_location_t
*po
; /* New policy operation */
1102 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1105 cupsdSetString(&DefaultPolicy
, "default");
1107 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1108 cupsdLogMessage(CUPSD_LOG_INFO
,
1109 "Using policy \"default\" as the default.");
1112 cupsdLogMessage(CUPSD_LOG_INFO
,
1113 "Creating CUPS default administrative policy:");
1115 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1117 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1119 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1120 cupsdAddString(&(p
->job_access
), "@OWNER");
1121 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1123 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1124 cupsdAddString(&(p
->job_attrs
), "job-name");
1125 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1126 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1128 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1129 cupsdAddString(&(p
->sub_access
), "@OWNER");
1130 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1132 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1133 cupsdAddString(&(p
->job_attrs
), "notify-events");
1134 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1135 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1136 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1137 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1139 cupsdLogMessage(CUPSD_LOG_INFO
,
1140 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1141 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1143 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1144 po
->order_type
= CUPSD_AUTH_ALLOW
;
1146 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1147 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1148 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1150 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1152 cupsdLogMessage(CUPSD_LOG_INFO
,
1153 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1154 "Release-Job Restart-Job Purge-Jobs "
1155 "Set-Job-Attributes Create-Job-Subscription "
1156 "Renew-Subscription Cancel-Subscription "
1157 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1158 "Suspend-Current-Job Resume-Job "
1159 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1160 "CUPS-Authenticate-Job CUPS-Get-Document>");
1161 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1163 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1164 po
->order_type
= CUPSD_AUTH_ALLOW
;
1165 po
->level
= CUPSD_AUTH_USER
;
1167 cupsdAddName(po
, "@OWNER");
1168 cupsdAddName(po
, "@SYSTEM");
1169 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1171 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1172 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1173 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1174 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1175 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1176 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1177 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1178 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1179 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1180 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1181 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1182 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1183 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1184 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1185 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1186 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1187 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1188 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1189 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1190 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1192 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1194 cupsdLogMessage(CUPSD_LOG_INFO
,
1195 "<Limit Pause-Printer Resume-Printer "
1196 "Set-Printer-Attributes Enable-Printer "
1197 "Disable-Printer Pause-Printer-After-Current-Job "
1198 "Hold-New-Jobs Release-Held-New-Jobs "
1199 "Deactivate-Printer Activate-Printer Restart-Printer "
1200 "Shutdown-Printer Startup-Printer Promote-Job "
1201 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1202 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1203 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1204 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1205 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1207 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1208 po
->order_type
= CUPSD_AUTH_ALLOW
;
1209 po
->type
= CUPSD_AUTH_DEFAULT
;
1210 po
->level
= CUPSD_AUTH_USER
;
1212 cupsdAddName(po
, "@SYSTEM");
1213 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1215 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1216 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1217 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1218 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1219 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1220 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1221 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1222 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1223 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1224 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1225 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1226 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1227 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1228 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1229 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1230 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1231 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1232 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1233 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1234 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1235 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1236 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1238 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1240 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1241 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1243 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1244 po
->order_type
= CUPSD_AUTH_ALLOW
;
1246 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1247 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1251 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1252 cupsArrayCount(Policies
));
1253 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1255 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1256 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1257 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1260 * If we are doing a full reload or the server root has changed, flush
1261 * the jobs, printers, etc. and start from scratch...
1264 if (NeedReload
== RELOAD_ALL
||
1265 old_remote_port
!= RemotePort
||
1266 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1267 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1269 mime_type_t
*type
; /* Current type */
1270 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1271 /* MIME type name */
1274 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1277 * Free all memory...
1280 cupsdDeleteAllSubscriptions();
1282 cupsdDeleteAllPrinters();
1284 DefaultPrinter
= NULL
;
1286 if (MimeDatabase
!= NULL
)
1287 mimeDelete(MimeDatabase
);
1291 for (i
= 0; i
< NumMimeTypes
; i
++)
1292 _cupsStrFree(MimeTypes
[i
]);
1298 * Read the MIME type and conversion database...
1301 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1302 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1304 MimeDatabase
= mimeNew();
1305 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1307 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1308 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1309 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1310 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1314 cupsdLogMessage(CUPSD_LOG_EMERG
,
1315 "Unable to load MIME database from \"%s\" or \"%s\".",
1316 mimedir
, ServerRoot
);
1317 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1321 cupsdLogMessage(CUPSD_LOG_INFO
,
1322 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1323 "%d filters...", mimedir
, ServerRoot
,
1324 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1327 * Create a list of MIME types for the document-format-supported
1331 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1332 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1335 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1337 cupsdLogMessage(CUPSD_LOG_ERROR
,
1338 "Unable to allocate memory for %d MIME types.",
1344 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1346 i
++, type
= mimeNextType(MimeDatabase
))
1348 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1350 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1353 if (i
< NumMimeTypes
)
1354 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1357 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1359 mime_filter_t
*filter
; /* Current filter */
1362 for (type
= mimeFirstType(MimeDatabase
);
1364 type
= mimeNextType(MimeDatabase
))
1365 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1366 type
->super
, type
->type
);
1368 for (filter
= mimeFirstFilter(MimeDatabase
);
1370 filter
= mimeNextFilter(MimeDatabase
))
1371 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1372 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1373 filter
->src
->super
, filter
->src
->type
,
1374 filter
->dst
->super
, filter
->dst
->type
,
1375 filter
->cost
, filter
->filter
);
1382 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1383 cupsdLoadBanners(temp
);
1386 * Load printers and classes...
1389 cupsdLoadAllPrinters();
1390 cupsdLoadAllClasses();
1392 cupsdCreateCommonData();
1395 * Update the printcap file as needed...
1398 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1399 cupsdWritePrintcap();
1402 * Load queued jobs...
1408 * Load subscriptions...
1411 cupsdLoadAllSubscriptions();
1413 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1418 * Not a full reload, so recreate the common printer attributes...
1421 cupsdCreateCommonData();
1424 * Update all printers as needed...
1427 cupsdUpdatePrinters();
1428 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1430 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1434 * Reset the reload state...
1437 NeedReload
= RELOAD_NONE
;
1439 cupsdClearString(&old_serverroot
);
1440 cupsdClearString(&old_requestroot
);
1447 * 'get_address()' - Get an address + port number from a line.
1450 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1451 get_address(const char *value
, /* I - Value string */
1452 int defport
) /* I - Default port */
1454 char buffer
[1024], /* Hostname + port number buffer */
1455 defpname
[255], /* Default port name */
1456 *hostname
, /* Hostname or IP */
1457 *portname
; /* Port number or name */
1458 http_addrlist_t
*addrlist
; /* Address list */
1462 * Check for an empty value...
1467 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1472 * Grab a hostname and port number; if there is no colon and the port name
1473 * is only digits, then we have a port number by itself...
1476 strlcpy(buffer
, value
, sizeof(buffer
));
1478 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1485 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1490 * Use the default port...
1493 sprintf(defpname
, "%d", defport
);
1494 portname
= defpname
;
1500 * The buffer contains just a port number...
1508 if (hostname
&& !strcmp(hostname
, "*"))
1512 * Now lookup the address using httpAddrGetList()...
1515 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1516 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1517 hostname
? hostname
: "(nil)");
1524 * 'get_addr_and_mask()' - Get an IP address and netmask.
1527 static int /* O - 1 on success, 0 on failure */
1528 get_addr_and_mask(const char *value
, /* I - String from config file */
1529 unsigned *ip
, /* O - Address value */
1530 unsigned *mask
) /* O - Mask value */
1532 int i
, j
, /* Looping vars */
1533 family
, /* Address family */
1534 ipcount
; /* Count of fields in address */
1535 unsigned ipval
; /* Value */
1536 const char *maskval
, /* Pointer to start of mask value */
1537 *ptr
, /* Pointer into value */
1542 * Get the address...
1545 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1546 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1548 if ((maskval
= strchr(value
, '/')) != NULL
)
1551 maskval
= value
+ strlen(value
);
1555 * Check for an IPv6 address...
1561 * Parse hexadecimal IPv6/IPv4 address...
1566 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1570 else if (!strncmp(ptr
, "::", 2))
1572 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1574 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1579 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1582 * Read IPv4 dotted quad...
1585 unsigned val
[4] = { 0, 0, 0, 0 };
1586 /* IPv4 address values */
1588 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1592 * Range check the IP numbers...
1595 for (i
= 0; i
< ipcount
; i
++)
1600 * Merge everything into a 32-bit IPv4 address in ip[3]...
1603 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1606 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1609 * If the leading words are all 0's then this is an IPv4 address...
1612 if (!val
[0] && !val
[1] && !val
[2])
1615 while (isdigit(*ptr
& 255) || *ptr
== '.')
1619 else if (isxdigit(*ptr
& 255))
1621 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1623 if (*ptr
== ':' && ptr
[1] != ':')
1632 ip
[i
/ 2] |= ipval
<< 16;
1643 if (*ptr
&& *ptr
!= '/')
1647 #endif /* AF_INET6 */
1650 * Parse dotted-decimal IPv4 address...
1653 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1657 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1660 * Range check the IP numbers...
1663 for (i
= 0; i
< ipcount
; i
++)
1668 * Merge everything into a 32-bit IPv4 address in ip[3]...
1671 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1674 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1680 * Get the netmask value(s)...
1683 memset(mask
, 0, sizeof(unsigned) * 4);
1685 if (strchr(maskval
, '.'))
1688 * Get dotted-decimal mask...
1691 if (family
!= AF_INET
)
1694 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1698 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1699 mask
[0] = mask
[1] = mask
[2] = 0;
1704 * Get address/bits format...
1710 if (family
== AF_INET6
)
1718 mask
[0] = 0xffffffff;
1720 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1723 mask
[1] = 0xffffffff;
1727 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1730 mask
[2] = 0xffffffff;
1734 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1737 mask
[3] = 0xffffffff;
1741 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1744 #endif /* AF_INET6 */
1749 mask
[0] = 0xffffffff;
1750 mask
[1] = 0xffffffff;
1751 mask
[2] = 0xffffffff;
1754 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1756 mask
[3] = 0xffffffff;
1761 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1762 "get_addr_and_mask(value=\"%s\", "
1763 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1764 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1768 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1771 if ((ip
[0] & ~mask
[0]) != 0 ||
1772 (ip
[1] & ~mask
[1]) != 0 ||
1773 (ip
[2] & ~mask
[2]) != 0 ||
1774 (ip
[3] & ~mask
[3]) != 0)
1782 * 'mime_error_cb()' - Log a MIME error.
1786 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
1787 const char *message
) /* I - Message */
1791 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
1796 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1799 static int /* O - 1 on success, 0 on failure */
1800 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1801 char *line
, /* I - Line from file */
1802 char *value
, /* I - Start of value data */
1803 int linenum
) /* I - Current line number */
1805 char *valptr
; /* Pointer into value */
1806 unsigned ip
[4], /* IP address components */
1807 mask
[4]; /* IP netmask components */
1810 if (!_cups_strcasecmp(line
, "Encryption"))
1813 * "Encryption xxx" - set required encryption level...
1816 if (!_cups_strcasecmp(value
, "never"))
1817 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1818 else if (!_cups_strcasecmp(value
, "always"))
1820 cupsdLogMessage(CUPSD_LOG_ERROR
,
1821 "Encryption value \"%s\" on line %d is invalid in this "
1822 "context. Using \"required\" instead.", value
, linenum
);
1824 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1826 else if (!_cups_strcasecmp(value
, "required"))
1827 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1828 else if (!_cups_strcasecmp(value
, "ifrequested"))
1829 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1832 cupsdLogMessage(CUPSD_LOG_ERROR
,
1833 "Unknown Encryption value %s on line %d.", value
, linenum
);
1837 else if (!_cups_strcasecmp(line
, "Order"))
1840 * "Order Deny,Allow" or "Order Allow,Deny"...
1843 if (!_cups_strncasecmp(value
, "deny", 4))
1844 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1845 else if (!_cups_strncasecmp(value
, "allow", 5))
1846 loc
->order_type
= CUPSD_AUTH_DENY
;
1849 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1854 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
1857 * Allow [From] host/ip...
1858 * Deny [From] host/ip...
1863 if (!_cups_strncasecmp(value
, "from", 4))
1866 * Strip leading "from"...
1871 while (_cups_isspace(*value
))
1879 * Find the end of the value...
1882 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
1884 while (_cups_isspace(*valptr
))
1888 * Figure out what form the allow/deny address takes:
1899 * nnn.nnn.nnn.nnn/mm
1900 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1903 if (!_cups_strcasecmp(value
, "all"))
1909 if (!_cups_strcasecmp(line
, "Allow"))
1910 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
1912 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
1914 else if (!_cups_strcasecmp(value
, "none"))
1920 if (!_cups_strcasecmp(line
, "Allow"))
1921 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
1923 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
1926 else if (value
[0] == '*' || value
[0] == '.' ||
1927 (!isdigit(value
[0] & 255) && value
[0] != '['))
1929 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1930 #endif /* AF_INET6 */
1933 * Host or domain name...
1936 if (value
[0] == '*')
1939 if (!_cups_strcasecmp(line
, "Allow"))
1940 cupsdAddNameMask(&(loc
->allow
), value
);
1942 cupsdAddNameMask(&(loc
->deny
), value
);
1947 * One of many IP address forms...
1950 if (!get_addr_and_mask(value
, ip
, mask
))
1952 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1957 if (!_cups_strcasecmp(line
, "Allow"))
1958 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
1960 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
1964 * Advance to next value...
1970 else if (!_cups_strcasecmp(line
, "AuthType"))
1973 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1976 if (!_cups_strcasecmp(value
, "none"))
1978 loc
->type
= CUPSD_AUTH_NONE
;
1979 loc
->level
= CUPSD_AUTH_ANON
;
1981 else if (!_cups_strcasecmp(value
, "basic"))
1983 loc
->type
= CUPSD_AUTH_BASIC
;
1985 if (loc
->level
== CUPSD_AUTH_ANON
)
1986 loc
->level
= CUPSD_AUTH_USER
;
1988 else if (!_cups_strcasecmp(value
, "digest"))
1990 loc
->type
= CUPSD_AUTH_DIGEST
;
1992 if (loc
->level
== CUPSD_AUTH_ANON
)
1993 loc
->level
= CUPSD_AUTH_USER
;
1995 else if (!_cups_strcasecmp(value
, "basicdigest"))
1997 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1999 if (loc
->level
== CUPSD_AUTH_ANON
)
2000 loc
->level
= CUPSD_AUTH_USER
;
2002 else if (!_cups_strcasecmp(value
, "default"))
2004 loc
->type
= CUPSD_AUTH_DEFAULT
;
2006 if (loc
->level
== CUPSD_AUTH_ANON
)
2007 loc
->level
= CUPSD_AUTH_USER
;
2010 else if (!_cups_strcasecmp(value
, "negotiate"))
2012 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2014 if (loc
->level
== CUPSD_AUTH_ANON
)
2015 loc
->level
= CUPSD_AUTH_USER
;
2017 #endif /* HAVE_GSSAPI */
2020 cupsdLogMessage(CUPSD_LOG_WARN
,
2021 "Unknown authorization type %s on line %d.",
2026 else if (!_cups_strcasecmp(line
, "AuthClass"))
2029 * AuthClass anonymous, user, system, group
2032 if (!_cups_strcasecmp(value
, "anonymous"))
2034 loc
->type
= CUPSD_AUTH_NONE
;
2035 loc
->level
= CUPSD_AUTH_ANON
;
2037 cupsdLogMessage(CUPSD_LOG_WARN
,
2038 "\"AuthClass %s\" is deprecated; consider removing "
2042 else if (!_cups_strcasecmp(value
, "user"))
2044 loc
->level
= CUPSD_AUTH_USER
;
2046 cupsdLogMessage(CUPSD_LOG_WARN
,
2047 "\"AuthClass %s\" is deprecated; consider using "
2048 "\"Require valid-user\" on line %d.",
2051 else if (!_cups_strcasecmp(value
, "group"))
2053 loc
->level
= CUPSD_AUTH_GROUP
;
2055 cupsdLogMessage(CUPSD_LOG_WARN
,
2056 "\"AuthClass %s\" is deprecated; consider using "
2057 "\"Require user @groupname\" on line %d.",
2060 else if (!_cups_strcasecmp(value
, "system"))
2062 loc
->level
= CUPSD_AUTH_GROUP
;
2064 cupsdAddName(loc
, "@SYSTEM");
2066 cupsdLogMessage(CUPSD_LOG_WARN
,
2067 "\"AuthClass %s\" is deprecated; consider using "
2068 "\"Require user @SYSTEM\" on line %d.",
2073 cupsdLogMessage(CUPSD_LOG_WARN
,
2074 "Unknown authorization class %s on line %d.",
2079 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2081 cupsdAddName(loc
, value
);
2083 cupsdLogMessage(CUPSD_LOG_WARN
,
2084 "\"AuthGroupName %s\" directive is deprecated; consider "
2085 "using \"Require user @%s\" on line %d.",
2086 value
, value
, linenum
);
2088 else if (!_cups_strcasecmp(line
, "Require"))
2091 * Apache synonym for AuthClass and AuthGroupName...
2095 * Require valid-user
2096 * Require group names
2097 * Require user names
2100 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2105 if (!_cups_strcasecmp(value
, "valid-user") ||
2106 !_cups_strcasecmp(value
, "user"))
2107 loc
->level
= CUPSD_AUTH_USER
;
2108 else if (!_cups_strcasecmp(value
, "group"))
2109 loc
->level
= CUPSD_AUTH_GROUP
;
2112 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2118 * Get the list of names from the line...
2121 for (value
= valptr
; *value
;)
2123 while (_cups_isspace(*value
))
2126 #ifdef HAVE_AUTHORIZATION_H
2127 if (!strncmp(value
, "@AUTHKEY(", 9))
2130 * Grab "@AUTHKEY(name)" value...
2133 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2139 #endif /* HAVE_AUTHORIZATION_H */
2140 if (*value
== '\"' || *value
== '\'')
2143 * Grab quoted name...
2146 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2153 * Grab literal name.
2156 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2162 cupsdAddName(loc
, value
);
2164 for (value
= valptr
; _cups_isspace(*value
); value
++);
2167 else if (!_cups_strcasecmp(line
, "Satisfy"))
2169 if (!_cups_strcasecmp(value
, "all"))
2170 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2171 else if (!_cups_strcasecmp(value
, "any"))
2172 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2175 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2188 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2191 static int /* O - FatalErrors bits */
2192 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2194 int fatal
; /* FatalErrors bits */
2195 char value
[1024], /* Value string */
2196 *valstart
, /* Pointer into value */
2197 *valend
; /* End of value */
2201 * Empty FatalErrors line yields NULL pointer...
2205 return (CUPSD_FATAL_NONE
);
2208 * Loop through the value string,...
2211 strlcpy(value
, s
, sizeof(value
));
2213 fatal
= CUPSD_FATAL_NONE
;
2215 for (valstart
= value
; *valstart
;)
2218 * Get the current space/comma-delimited kind name...
2221 for (valend
= valstart
; *valend
; valend
++)
2222 if (_cups_isspace(*valend
) || *valend
== ',')
2229 * Add the error to the bitmask...
2232 if (!_cups_strcasecmp(valstart
, "all"))
2233 fatal
= CUPSD_FATAL_ALL
;
2234 else if (!_cups_strcasecmp(valstart
, "browse"))
2235 fatal
|= CUPSD_FATAL_BROWSE
;
2236 else if (!_cups_strcasecmp(valstart
, "-browse"))
2237 fatal
&= ~CUPSD_FATAL_BROWSE
;
2238 else if (!_cups_strcasecmp(valstart
, "config"))
2239 fatal
|= CUPSD_FATAL_CONFIG
;
2240 else if (!_cups_strcasecmp(valstart
, "-config"))
2241 fatal
&= ~CUPSD_FATAL_CONFIG
;
2242 else if (!_cups_strcasecmp(valstart
, "listen"))
2243 fatal
|= CUPSD_FATAL_LISTEN
;
2244 else if (!_cups_strcasecmp(valstart
, "-listen"))
2245 fatal
&= ~CUPSD_FATAL_LISTEN
;
2246 else if (!_cups_strcasecmp(valstart
, "log"))
2247 fatal
|= CUPSD_FATAL_LOG
;
2248 else if (!_cups_strcasecmp(valstart
, "-log"))
2249 fatal
&= ~CUPSD_FATAL_LOG
;
2250 else if (!_cups_strcasecmp(valstart
, "permissions"))
2251 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2252 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2253 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2254 else if (_cups_strcasecmp(valstart
, "none"))
2255 cupsdLogMessage(CUPSD_LOG_ERROR
,
2256 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2258 for (valstart
= valend
; *valstart
; valstart
++)
2259 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2268 * 'parse_groups()' - Parse system group names in a string.
2271 static int /* O - 1 on success, 0 on failure */
2272 parse_groups(const char *s
) /* I - Space-delimited groups */
2274 int status
; /* Return status */
2275 char value
[1024], /* Value string */
2276 *valstart
, /* Pointer into value */
2277 *valend
, /* End of value */
2278 quote
; /* Quote character */
2279 struct group
*group
; /* Group */
2283 * Make a copy of the string and parse out the groups...
2286 strlcpy(value
, s
, sizeof(value
));
2291 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2293 if (*valstart
== '\'' || *valstart
== '\"')
2296 * Scan quoted name...
2299 quote
= *valstart
++;
2301 for (valend
= valstart
; *valend
; valend
++)
2302 if (*valend
== quote
)
2308 * Scan space or comma-delimited name...
2311 for (valend
= valstart
; *valend
; valend
++)
2312 if (_cups_isspace(*valend
) || *valend
== ',')
2319 group
= getgrnam(valstart
);
2322 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2323 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2334 while (*valstart
== ',' || _cups_isspace(*valstart
))
2343 * 'parse_protocols()' - Parse browse protocols in a string.
2346 static int /* O - Browse protocol bits */
2347 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2349 int protocols
; /* Browse protocol bits */
2350 char value
[1024], /* Value string */
2351 *valstart
, /* Pointer into value */
2352 *valend
; /* End of value */
2356 * Empty protocol line yields NULL pointer...
2363 * Loop through the value string,...
2366 strlcpy(value
, s
, sizeof(value
));
2370 for (valstart
= value
; *valstart
;)
2373 * Get the current space/comma-delimited protocol name...
2376 for (valend
= valstart
; *valend
; valend
++)
2377 if (_cups_isspace(*valend
) || *valend
== ',')
2384 * Add the protocol to the bitmask...
2387 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2388 !_cups_strcasecmp(valstart
, "dns-sd") ||
2389 !_cups_strcasecmp(valstart
, "bonjour"))
2390 protocols
|= BROWSE_DNSSD
;
2391 else if (!_cups_strcasecmp(valstart
, "all"))
2392 protocols
|= BROWSE_ALL
;
2393 else if (_cups_strcasecmp(valstart
, "none"))
2394 cupsdLogMessage(CUPSD_LOG_ERROR
,
2395 "Unknown browse protocol \"%s\" ignored.", valstart
);
2397 for (valstart
= valend
; *valstart
; valstart
++)
2398 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2407 * 'read_configuration()' - Read a configuration file.
2410 static int /* O - 1 on success, 0 on failure */
2411 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2413 int i
; /* Looping var */
2414 int linenum
; /* Current line number */
2415 char line
[HTTP_MAX_BUFFER
],
2416 /* Line from file */
2417 temp
[HTTP_MAX_BUFFER
],
2418 /* Temporary buffer for value */
2419 *value
, /* Pointer to value */
2420 *valueptr
; /* Pointer into value */
2421 int valuelen
; /* Length of value */
2422 cupsd_var_t
const *var
; /* Current variable */
2423 http_addrlist_t
*addrlist
, /* Address list */
2424 *addr
; /* Current address */
2425 cups_file_t
*incfile
; /* Include file */
2426 char incname
[1024]; /* Include filename */
2427 struct group
*group
; /* Group */
2431 * Loop through each line in the file...
2436 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2439 * Decode the directive...
2442 if (!_cups_strcasecmp(line
, "Include") && value
)
2448 if (value
[0] == '/')
2449 strlcpy(incname
, value
, sizeof(incname
));
2451 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2453 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2454 cupsdLogMessage(CUPSD_LOG_ERROR
,
2455 "Unable to include config file \"%s\" - %s",
2456 incname
, strerror(errno
));
2459 read_configuration(incfile
);
2460 cupsFileClose(incfile
);
2463 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2469 linenum
= read_location(fp
, value
, linenum
);
2473 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2479 linenum
= read_policy(fp
, value
, linenum
);
2483 else if (!_cups_strcasecmp(line
, "FatalErrors"))
2484 FatalErrors
= parse_fatal_errors(value
);
2485 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2487 JobRetryInterval
= atoi(value
);
2488 cupsdLogMessage(CUPSD_LOG_WARN
,
2489 "FaxRetryInterval is deprecated; use "
2490 "JobRetryInterval on line %d.", linenum
);
2492 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2494 JobRetryLimit
= atoi(value
);
2495 cupsdLogMessage(CUPSD_LOG_WARN
,
2496 "FaxRetryLimit is deprecated; use "
2497 "JobRetryLimit on line %d.", linenum
);
2499 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2501 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2502 #endif /* HAVE_SSL */
2506 * Add listening address(es) to the list...
2509 cupsd_listener_t
*lis
; /* New listeners array */
2513 * Get the address list...
2516 addrlist
= get_address(value
, IPP_PORT
);
2520 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2526 * Add each address...
2529 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2532 * See if this address is already present...
2535 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2537 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2538 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2539 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2544 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2545 cupsdLogMessage(CUPSD_LOG_WARN
,
2546 "Duplicate listen address \"%s\" ignored.", temp
);
2551 * Allocate another listener...
2555 Listeners
= cupsArrayNew(NULL
, NULL
);
2559 cupsdLogMessage(CUPSD_LOG_ERROR
,
2560 "Unable to allocate %s at line %d - %s.",
2561 line
, linenum
, strerror(errno
));
2565 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2567 cupsdLogMessage(CUPSD_LOG_ERROR
,
2568 "Unable to allocate %s at line %d - %s.",
2569 line
, linenum
, strerror(errno
));
2573 cupsArrayAdd(Listeners
, lis
);
2576 * Copy the current address and log it...
2579 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2583 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
2584 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2585 #endif /* HAVE_SSL */
2587 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2590 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2591 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2593 #endif /* AF_LOCAL */
2594 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
2595 _httpAddrPort(&(lis
->address
)),
2596 _httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
2598 if (!httpAddrLocalhost(&(lis
->address
)))
2599 RemotePort
= _httpAddrPort(&(lis
->address
));
2606 httpAddrFreeList(addrlist
);
2608 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
2609 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
2612 * "BrowseProtocols name [... name]"
2613 * "BrowseLocalProtocols name [... name]"
2616 int protocols
= parse_protocols(value
);
2620 cupsdLogMessage(CUPSD_LOG_ERROR
,
2621 "Unknown browse protocol \"%s\" on line %d.",
2626 BrowseLocalProtocols
= protocols
;
2628 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
2631 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2634 if (!_cups_strcasecmp(value
, "none"))
2635 DefaultAuthType
= CUPSD_AUTH_NONE
;
2636 else if (!_cups_strcasecmp(value
, "basic"))
2637 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2638 else if (!_cups_strcasecmp(value
, "digest"))
2639 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2640 else if (!_cups_strcasecmp(value
, "basicdigest"))
2641 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2643 else if (!_cups_strcasecmp(value
, "negotiate"))
2644 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2645 #endif /* HAVE_GSSAPI */
2648 cupsdLogMessage(CUPSD_LOG_WARN
,
2649 "Unknown default authorization type %s on line %d.",
2651 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2656 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
2659 * DefaultEncryption {Never,IfRequested,Required}
2662 if (!value
|| !_cups_strcasecmp(value
, "never"))
2663 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2664 else if (!_cups_strcasecmp(value
, "required"))
2665 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2666 else if (!_cups_strcasecmp(value
, "ifrequested"))
2667 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2670 cupsdLogMessage(CUPSD_LOG_WARN
,
2671 "Unknown default encryption %s on line %d.",
2673 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2677 #endif /* HAVE_SSL */
2678 else if (!_cups_strcasecmp(line
, "User") && value
)
2681 * User ID to run as...
2684 if (isdigit(value
[0] & 255))
2686 int uid
= atoi(value
);
2689 cupsdLogMessage(CUPSD_LOG_ERROR
,
2690 "Will not use User 0 as specified on line %d "
2691 "for security reasons. You must use a non-"
2692 "privileged account instead.",
2699 struct passwd
*p
; /* Password information */
2702 p
= getpwnam(value
);
2707 cupsdLogMessage(CUPSD_LOG_ERROR
,
2708 "Will not use User %s (UID=0) as specified on line "
2709 "%d for security reasons. You must use a non-"
2710 "privileged account instead.",
2716 cupsdLogMessage(CUPSD_LOG_ERROR
,
2717 "Unknown User \"%s\" on line %d, ignoring.",
2721 else if (!_cups_strcasecmp(line
, "Group") && value
)
2724 * Group ID to run as...
2727 if (isdigit(value
[0]))
2728 Group
= atoi(value
);
2732 group
= getgrnam(value
);
2735 Group
= group
->gr_gid
;
2737 cupsdLogMessage(CUPSD_LOG_ERROR
,
2738 "Unknown Group \"%s\" on line %d, ignoring.",
2742 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
2745 * SystemGroup (admin) group(s)...
2748 if (!parse_groups(value
))
2749 cupsdLogMessage(CUPSD_LOG_ERROR
,
2750 "Unknown SystemGroup \"%s\" on line %d, ignoring.",
2753 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
2756 * Do hostname lookups?
2759 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
2760 !_cups_strcasecmp(value
, "false"))
2761 HostNameLookups
= 0;
2762 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
2763 !_cups_strcasecmp(value
, "true"))
2764 HostNameLookups
= 1;
2765 else if (!_cups_strcasecmp(value
, "double"))
2766 HostNameLookups
= 2;
2768 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2771 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
2774 * Amount of logging to do to access log...
2777 if (!_cups_strcasecmp(value
, "all"))
2778 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
2779 else if (!_cups_strcasecmp(value
, "actions"))
2780 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
2781 else if (!_cups_strcasecmp(value
, "config"))
2782 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
2784 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
2787 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
2790 * Amount of logging to do to error log...
2793 if (!_cups_strcasecmp(value
, "debug2"))
2794 LogLevel
= CUPSD_LOG_DEBUG2
;
2795 else if (!_cups_strcasecmp(value
, "debug"))
2796 LogLevel
= CUPSD_LOG_DEBUG
;
2797 else if (!_cups_strcasecmp(value
, "info"))
2798 LogLevel
= CUPSD_LOG_INFO
;
2799 else if (!_cups_strcasecmp(value
, "notice"))
2800 LogLevel
= CUPSD_LOG_NOTICE
;
2801 else if (!_cups_strcasecmp(value
, "warn"))
2802 LogLevel
= CUPSD_LOG_WARN
;
2803 else if (!_cups_strcasecmp(value
, "error"))
2804 LogLevel
= CUPSD_LOG_ERROR
;
2805 else if (!_cups_strcasecmp(value
, "crit"))
2806 LogLevel
= CUPSD_LOG_CRIT
;
2807 else if (!_cups_strcasecmp(value
, "alert"))
2808 LogLevel
= CUPSD_LOG_ALERT
;
2809 else if (!_cups_strcasecmp(value
, "emerg"))
2810 LogLevel
= CUPSD_LOG_EMERG
;
2811 else if (!_cups_strcasecmp(value
, "none"))
2812 LogLevel
= CUPSD_LOG_NONE
;
2814 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2817 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
2820 * Amount of logging to do to error log...
2823 if (!_cups_strcasecmp(value
, "standard"))
2824 LogTimeFormat
= CUPSD_TIME_STANDARD
;
2825 else if (!_cups_strcasecmp(value
, "usecs"))
2826 LogTimeFormat
= CUPSD_TIME_USECS
;
2828 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
2831 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
2834 * Format of printcap file?
2837 if (!_cups_strcasecmp(value
, "bsd"))
2838 PrintcapFormat
= PRINTCAP_BSD
;
2839 else if (!_cups_strcasecmp(value
, "plist"))
2840 PrintcapFormat
= PRINTCAP_PLIST
;
2841 else if (!_cups_strcasecmp(value
, "solaris"))
2842 PrintcapFormat
= PRINTCAP_SOLARIS
;
2844 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2847 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
2850 * Set the string used for the Server header...
2853 struct utsname plat
; /* Platform info */
2858 if (!_cups_strcasecmp(value
, "ProductOnly"))
2859 cupsdSetString(&ServerHeader
, "CUPS");
2860 else if (!_cups_strcasecmp(value
, "Major"))
2861 cupsdSetStringf(&ServerHeader
, "CUPS/%d", CUPS_VERSION_MAJOR
);
2862 else if (!_cups_strcasecmp(value
, "Minor"))
2863 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
2864 CUPS_VERSION_MINOR
);
2865 else if (!_cups_strcasecmp(value
, "Minimal"))
2866 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2867 else if (!_cups_strcasecmp(value
, "OS"))
2868 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2869 else if (!_cups_strcasecmp(value
, "Full"))
2870 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/2.1",
2872 else if (!_cups_strcasecmp(value
, "None"))
2873 cupsdClearString(&ServerHeader
);
2875 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2878 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
2881 * PassEnv variable [... variable]
2886 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2887 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2890 if (value
[valuelen
])
2892 value
[valuelen
] = '\0';
2896 cupsdSetEnv(value
, NULL
);
2898 for (value
+= valuelen
; *value
; value
++)
2899 if (!_cups_isspace(*value
) || *value
!= ',')
2903 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
2906 * ServerAlias name [... name]
2910 ServerAlias
= cupsArrayNew(NULL
, NULL
);
2914 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2915 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2918 if (value
[valuelen
])
2920 value
[valuelen
] = '\0';
2924 cupsdAddAlias(ServerAlias
, value
);
2926 for (value
+= valuelen
; *value
; value
++)
2927 if (!_cups_isspace(*value
) || *value
!= ',')
2931 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
2934 * SetEnv variable value
2937 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2945 while (isspace(*valueptr
& 255))
2948 cupsdSetEnv(value
, valueptr
);
2951 cupsdLogMessage(CUPSD_LOG_ERROR
,
2952 "Missing value for SetEnv directive on line %d.",
2956 else if (!_cups_strcasecmp(line
, "SSLOptions"))
2959 * SSLOptions options
2962 if (!value
|| !_cups_strcasecmp(value
, "none"))
2963 SSLOptions
= CUPSD_SSL_NONE
;
2964 else if (!_cups_strcasecmp(value
, "noemptyfragments"))
2965 SSLOptions
= CUPSD_SSL_NOEMPTY
;
2967 cupsdLogMessage(CUPSD_LOG_ERROR
,
2968 "Unknown value \"%s\" for SSLOptions directive on "
2969 "line %d.", value
, linenum
);
2971 #endif /* HAVE_SSL */
2975 * Find a simple variable in the list...
2978 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2979 if (!_cups_strcasecmp(line
, var
->name
))
2985 * Unknown directive! Output an error message and continue...
2989 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
2992 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2999 case CUPSD_VARTYPE_INTEGER
:
3001 cupsdLogMessage(CUPSD_LOG_ERROR
,
3002 "Missing integer value for %s on line %d.",
3007 char *units
; /* Units */
3010 n
= strtol(value
, &units
, 0);
3012 if (units
&& *units
)
3014 if (tolower(units
[0] & 255) == 'g')
3015 n
*= 1024 * 1024 * 1024;
3016 else if (tolower(units
[0] & 255) == 'm')
3018 else if (tolower(units
[0] & 255) == 'k')
3020 else if (tolower(units
[0] & 255) == 't')
3025 cupsdLogMessage(CUPSD_LOG_ERROR
,
3026 "Bad negative integer value for %s on line %d.",
3029 *((int *)var
->ptr
) = n
;
3033 case CUPSD_VARTYPE_BOOLEAN
:
3035 cupsdLogMessage(CUPSD_LOG_ERROR
,
3036 "Missing boolean value for %s on line %d.",
3038 else if (!_cups_strcasecmp(value
, "true") ||
3039 !_cups_strcasecmp(value
, "on") ||
3040 !_cups_strcasecmp(value
, "enabled") ||
3041 !_cups_strcasecmp(value
, "yes") ||
3043 *((int *)var
->ptr
) = TRUE
;
3044 else if (!_cups_strcasecmp(value
, "false") ||
3045 !_cups_strcasecmp(value
, "off") ||
3046 !_cups_strcasecmp(value
, "disabled") ||
3047 !_cups_strcasecmp(value
, "no") ||
3048 !_cups_strcasecmp(value
, "0"))
3049 *((int *)var
->ptr
) = FALSE
;
3051 cupsdLogMessage(CUPSD_LOG_ERROR
,
3052 "Unknown boolean value %s on line %d.",
3056 case CUPSD_VARTYPE_PATHNAME
:
3059 cupsdLogMessage(CUPSD_LOG_ERROR
,
3060 "Missing pathname value for %s on line %d.",
3065 if (value
[0] == '/')
3066 strlcpy(temp
, value
, sizeof(temp
));
3068 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3070 if (access(temp
, 0))
3072 cupsdLogMessage(CUPSD_LOG_ERROR
,
3073 "File or directory for \"%s %s\" on line %d "
3074 "does not exist.", line
, value
, linenum
);
3078 case CUPSD_VARTYPE_STRING
:
3079 cupsdSetString((char **)var
->ptr
, value
);
3090 * 'read_location()' - Read a <Location path> definition.
3093 static int /* O - New line number or 0 on error */
3094 read_location(cups_file_t
*fp
, /* I - Configuration file */
3095 char *location
, /* I - Location name/path */
3096 int linenum
) /* I - Current line number */
3098 cupsd_location_t
*loc
, /* New location */
3099 *parent
; /* Parent location */
3100 char line
[HTTP_MAX_BUFFER
],
3102 *value
, /* Value for directive */
3103 *valptr
; /* Pointer into value */
3106 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3107 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3109 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3113 cupsdAddLocation(parent
);
3115 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3120 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3123 * Decode the directive...
3126 if (!_cups_strcasecmp(line
, "</Location>"))
3128 else if (!_cups_strcasecmp(line
, "<Limit") ||
3129 !_cups_strcasecmp(line
, "<LimitExcept"))
3133 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3134 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3140 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3143 cupsdAddLocation(loc
);
3148 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3153 if (!strcmp(value
, "ALL"))
3154 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3155 else if (!strcmp(value
, "GET"))
3156 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3157 else if (!strcmp(value
, "HEAD"))
3158 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3159 else if (!strcmp(value
, "OPTIONS"))
3160 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3161 else if (!strcmp(value
, "POST"))
3162 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3163 else if (!strcmp(value
, "PUT"))
3164 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3165 else if (!strcmp(value
, "TRACE"))
3166 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3168 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3171 for (value
= valptr
; isspace(*value
& 255); value
++);
3174 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3175 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3177 parent
->limit
&= ~loc
->limit
;
3179 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3180 !_cups_strcasecmp(line
, "</LimitExcept>"))
3184 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3185 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3188 else if (!parse_aaa(loc
, line
, value
, linenum
))
3190 cupsdLogMessage(CUPSD_LOG_ERROR
,
3191 "Unknown Location directive %s on line %d.",
3193 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3198 cupsdLogMessage(CUPSD_LOG_ERROR
,
3199 "Unexpected end-of-file at line %d while reading location.",
3202 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3207 * 'read_policy()' - Read a <Policy name> definition.
3210 static int /* O - New line number or 0 on error */
3211 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3212 char *policy
, /* I - Location name/path */
3213 int linenum
) /* I - Current line number */
3215 int i
; /* Looping var */
3216 cupsd_policy_t
*pol
; /* Policy */
3217 cupsd_location_t
*op
; /* Policy operation */
3218 int num_ops
; /* Number of IPP operations */
3219 ipp_op_t ops
[100]; /* Operations */
3220 char line
[HTTP_MAX_BUFFER
],
3222 *value
, /* Value for directive */
3223 *valptr
; /* Pointer into value */
3227 * Create the policy...
3230 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3231 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3233 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3237 * Read from the file...
3243 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3246 * Decode the directive...
3249 if (!_cups_strcasecmp(line
, "</Policy>"))
3252 cupsdLogMessage(CUPSD_LOG_WARN
,
3253 "Missing </Limit> before </Policy> on line %d.",
3256 set_policy_defaults(pol
);
3260 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3264 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3265 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3272 * Scan for IPP operation names...
3279 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3284 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3286 if (!_cups_strcasecmp(value
, "All"))
3287 ops
[num_ops
] = IPP_ANY_OPERATION
;
3288 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3289 cupsdLogMessage(CUPSD_LOG_ERROR
,
3290 "Bad IPP operation name \"%s\" on line %d.",
3296 cupsdLogMessage(CUPSD_LOG_ERROR
,
3297 "Too many operations listed on line %d.",
3300 for (value
= valptr
; isspace(*value
& 255); value
++);
3304 * If none are specified, apply the policy to all operations...
3309 ops
[0] = IPP_ANY_OPERATION
;
3314 * Add a new policy for the first operation...
3317 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3319 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3322 * Finish the current operation limit...
3328 * Copy the policy to the other operations...
3331 for (i
= 1; i
< num_ops
; i
++)
3332 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3339 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3340 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3343 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3344 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3345 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3346 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3350 cupsdLogMessage(CUPSD_LOG_ERROR
,
3351 "%s directive must appear outside <Limit>...</Limit> "
3352 "on line %d.", line
, linenum
);
3353 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3359 * Pull out whitespace-delimited values...
3365 * Find the end of the current value...
3368 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3374 * Save it appropriately...
3377 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3380 * JobPrivateAccess {all|default|user/group list|@@ACL}
3383 if (!_cups_strcasecmp(value
, "default"))
3385 cupsdAddString(&(pol
->job_access
), "@OWNER");
3386 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3389 cupsdAddString(&(pol
->job_access
), value
);
3391 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3394 * JobPrivateValues {all|none|default|attribute list}
3397 if (!_cups_strcasecmp(value
, "default"))
3399 cupsdAddString(&(pol
->job_attrs
), "job-name");
3400 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3401 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3404 cupsdAddString(&(pol
->job_attrs
), value
);
3406 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3409 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3412 if (!_cups_strcasecmp(value
, "default"))
3414 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3415 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3418 cupsdAddString(&(pol
->sub_access
), value
);
3420 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3423 * SubscriptionPrivateValues {all|none|default|attribute list}
3426 if (!_cups_strcasecmp(value
, "default"))
3428 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3429 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3430 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3431 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3432 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3435 cupsdAddString(&(pol
->sub_attrs
), value
);
3439 * Find the next string on the line...
3442 for (value
= valptr
; isspace(*value
& 255); value
++);
3448 cupsdLogMessage(CUPSD_LOG_ERROR
,
3449 "Missing <Limit ops> directive before %s on line %d.",
3451 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3454 else if (!parse_aaa(op
, line
, value
, linenum
))
3456 cupsdLogMessage(CUPSD_LOG_ERROR
,
3457 "Unknown Policy Limit directive %s on line %d.",
3460 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3465 cupsdLogMessage(CUPSD_LOG_ERROR
,
3466 "Unexpected end-of-file at line %d while reading policy "
3467 "\"%s\".", linenum
, policy
);
3469 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3474 * 'set_policy_defaults()' - Set default policy values as needed.
3478 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
3480 cupsd_location_t
*op
; /* Policy operation */
3484 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3485 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3486 * upgrades do not introduce new security issues...
3489 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3490 op
->op
== IPP_ANY_OPERATION
)
3492 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3493 op
->op
!= IPP_ANY_OPERATION
)
3496 * Add a new limit for Validate-Job using the Print-Job limit as a
3500 cupsdLogMessage(CUPSD_LOG_WARN
,
3501 "No limit for Validate-Job defined in policy %s "
3502 "- using Print-Job's policy.", pol
->name
);
3504 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3507 cupsdLogMessage(CUPSD_LOG_WARN
,
3508 "No limit for Validate-Job defined in policy %s "
3509 "and no suitable template found.", pol
->name
);
3512 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3513 op
->op
== IPP_ANY_OPERATION
)
3515 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
3516 op
->op
!= IPP_ANY_OPERATION
)
3519 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3523 cupsdLogMessage(CUPSD_LOG_WARN
,
3524 "No limit for Cancel-Jobs defined in policy %s "
3525 "- using Pause-Printer's policy.", pol
->name
);
3527 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3530 cupsdLogMessage(CUPSD_LOG_WARN
,
3531 "No limit for Cancel-Jobs defined in policy %s "
3532 "and no suitable template found.", pol
->name
);
3535 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3536 op
->op
== IPP_ANY_OPERATION
)
3538 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3539 op
->op
!= IPP_ANY_OPERATION
)
3542 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3546 cupsdLogMessage(CUPSD_LOG_WARN
,
3547 "No limit for Cancel-My-Jobs defined in policy %s "
3548 "- using Send-Document's policy.", pol
->name
);
3550 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3553 cupsdLogMessage(CUPSD_LOG_WARN
,
3554 "No limit for Cancel-My-Jobs defined in policy %s "
3555 "and no suitable template found.", pol
->name
);
3558 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3559 op
->op
== IPP_ANY_OPERATION
)
3561 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3562 op
->op
!= IPP_ANY_OPERATION
)
3565 * Add a new limit for Close-Job using the Send-Document limit as a
3569 cupsdLogMessage(CUPSD_LOG_WARN
,
3570 "No limit for Close-Job defined in policy %s "
3571 "- using Send-Document's policy.", pol
->name
);
3573 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
3576 cupsdLogMessage(CUPSD_LOG_WARN
,
3577 "No limit for Close-Job defined in policy %s "
3578 "and no suitable template found.", pol
->name
);
3581 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3582 op
->op
== IPP_ANY_OPERATION
)
3584 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3585 op
->op
!= IPP_ANY_OPERATION
)
3588 * Add a new limit for CUPS-Get-Document using the Send-Document
3589 * limit as a template...
3592 cupsdLogMessage(CUPSD_LOG_WARN
,
3593 "No limit for CUPS-Get-Document defined in policy %s "
3594 "- using Send-Document's policy.", pol
->name
);
3596 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3599 cupsdLogMessage(CUPSD_LOG_WARN
,
3600 "No limit for CUPS-Get-Document defined in policy %s "
3601 "and no suitable template found.", pol
->name
);
3605 * Verify we have JobPrivateAccess, JobPrivateValues,
3606 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
3609 if (!pol
->job_access
)
3611 cupsdLogMessage(CUPSD_LOG_WARN
,
3612 "No JobPrivateAccess defined in policy %s "
3613 "- using defaults.", pol
->name
);
3614 cupsdAddString(&(pol
->job_access
), "@OWNER");
3615 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3618 if (!pol
->job_attrs
)
3620 cupsdLogMessage(CUPSD_LOG_WARN
,
3621 "No JobPrivateValues defined in policy %s "
3622 "- using defaults.", pol
->name
);
3623 cupsdAddString(&(pol
->job_attrs
), "job-name");
3624 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3625 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3628 if (!pol
->sub_access
)
3630 cupsdLogMessage(CUPSD_LOG_WARN
,
3631 "No SubscriptionPrivateAccess defined in policy %s "
3632 "- using defaults.", pol
->name
);
3633 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3634 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3637 if (!pol
->sub_attrs
)
3639 cupsdLogMessage(CUPSD_LOG_WARN
,
3640 "No SubscriptionPrivateValues defined in policy %s "
3641 "- using defaults.", pol
->name
);
3642 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3643 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3644 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3645 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3646 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3652 * End of "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $".