2 * "$Id: conf.c 6365 2007-03-19 20:56:57Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdReadConfiguration() - Read the cupsd.conf file.
27 * check_permissions() - Fix the mode and ownership of a file or
29 * get_address() - Get an address + port number from a line.
30 * get_addr_and_mask() - Get an IP address and netmask.
31 * parse_aaa() - Parse authentication, authorization, and
32 * access control lines.
33 * parse_groups() - Parse system group names in a string.
34 * parse_protocols() - Parse browse protocols in a string.
35 * read_configuration() - Read a configuration file.
36 * read_location() - Read a <Location path> definition.
37 * read_policy() - Read a <Policy name> definition.
41 * Include necessary headers...
47 #include <sys/utsname.h>
52 #endif /* HAVE_VSYSLOG */
56 * Possibly missing network definitions...
60 # define INADDR_NONE 0xffffffff
61 #endif /* !INADDR_NONE */
65 * Configuration variable structure...
70 CUPSD_VARTYPE_INTEGER
, /* Integer option */
71 CUPSD_VARTYPE_STRING
, /* String option */
72 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
77 char *name
; /* Name of variable */
78 void *ptr
; /* Pointer to variable */
79 cupsd_vartype_t type
; /* Type (int, string, address) */
87 static cupsd_var_t variables
[] =
89 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
91 { "AppleQuotas", &AppleQuotas
, CUPSD_VARTYPE_BOOLEAN
},
92 #endif /* __APPLE__ */
93 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
94 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
96 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
97 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
98 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
99 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
100 #endif /* HAVE_LDAP */
101 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
102 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
103 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
104 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
105 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
106 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
107 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
108 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
109 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
110 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
111 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
112 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
113 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
114 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
115 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
116 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
117 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
118 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
119 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
120 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
121 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
122 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
124 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
125 #endif /* HAVE_GSSAPI */
126 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
127 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
128 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
129 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
130 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
131 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
133 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
134 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
135 #endif /* HAVE_LAUNCHD */
136 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
137 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
138 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
152 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
153 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
154 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
155 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
156 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
157 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
158 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
159 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
160 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
161 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
162 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
163 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
164 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
165 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
166 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
168 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
169 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
170 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
171 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
172 #endif /* HAVE_SSL */
173 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
174 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
175 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
176 #ifdef HAVE_AUTHORIZATION_H
177 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
178 #endif /* HAVE_AUTHORIZATION_H */
179 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
180 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
181 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
183 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
186 static unsigned ones
[4] =
188 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
190 static unsigned zeros
[4] =
192 0x00000000, 0x00000000, 0x00000000, 0x00000000
199 static int check_permissions(const char *filename
,
200 const char *suffix
, int mode
,
201 int user
, int group
, int is_dir
,
203 static http_addrlist_t
*get_address(const char *value
, int defport
);
204 static int get_addr_and_mask(const char *value
, unsigned *ip
,
206 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
207 char *value
, int linenum
);
208 static int parse_groups(const char *s
);
209 static int parse_protocols(const char *s
);
210 static int read_configuration(cups_file_t
*fp
);
211 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
212 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
216 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
219 int /* O - 1 on success, 0 otherwise */
220 cupsdReadConfiguration(void)
222 int i
; /* Looping var */
223 cups_file_t
*fp
; /* Configuration file */
224 int status
; /* Return status */
225 char temp
[1024], /* Temporary buffer */
226 *slash
; /* Directory separator */
227 cups_lang_t
*language
; /* Language */
228 struct passwd
*user
; /* Default user */
229 struct group
*group
; /* Default group */
230 char *old_serverroot
, /* Old ServerRoot */
231 *old_requestroot
; /* Old RequestRoot */
232 const char *tmpdir
; /* TMPDIR environment variable */
233 struct stat tmpinfo
; /* Temporary directory info */
237 * Save the old root paths...
240 old_serverroot
= NULL
;
241 cupsdSetString(&old_serverroot
, ServerRoot
);
242 old_requestroot
= NULL
;
243 cupsdSetString(&old_requestroot
, RequestRoot
);
246 * Reset the server configuration data...
249 cupsdDeleteAllLocations();
268 for (i
= 0; i
< NumRelays
; i
++)
269 if (Relays
[i
].from
.type
== AUTH_NAME
)
270 free(Relays
[i
].from
.mask
.name
.name
);
277 cupsdDeleteAllListeners();
283 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
284 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
285 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
286 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
287 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
288 cupsdSetString(&DataDir
, CUPS_DATADIR
);
289 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
290 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
291 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
292 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
293 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
294 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
295 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
296 cupsdSetString(&RemoteRoot
, "remroot");
297 cupsdSetString(&ServerHeader
, "CUPS/1.2");
298 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
300 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
301 #endif /* HAVE_GSSAPI */
303 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
304 PrintcapFormat
= PRINTCAP_SOLARIS
;
306 PrintcapFormat
= PRINTCAP_BSD
;
308 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
309 if ((slash
= strrchr(temp
, '/')) != NULL
)
312 cupsdSetString(&ServerRoot
, temp
);
314 cupsdClearString(&Classification
);
315 ClassifyOverride
= 0;
319 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
321 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
322 cupsdSetString(&ServerKey
, "ssl/server.key");
323 # endif /* HAVE_CDSASSL */
324 #endif /* HAVE_SSL */
326 language
= cupsLangDefault();
328 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
329 cupsdSetString(&DefaultLanguage
, "en");
331 cupsdSetString(&DefaultLanguage
, language
->language
);
333 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
335 cupsdSetString(&RIPCache
, "8m");
337 cupsdSetString(&TempDir
, NULL
);
340 * Find the default user...
343 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
348 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
349 * complement number...)
358 * Find the default group...
361 group
= getgrnam(CUPS_DEFAULT_GROUP
);
365 Group
= group
->gr_gid
;
369 * Fallback to group "nobody"...
372 group
= getgrnam("nobody");
376 Group
= group
->gr_gid
;
380 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
381 * complement number...)
392 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
393 DefaultAuthType
= AUTH_BASIC
;
395 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
396 #endif /* HAVE_SSL */
398 JobRetryInterval
= 300;
403 HostNameLookups
= FALSE
;
404 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
405 ImplicitAnyClasses
= FALSE
;
406 HideImplicitMembers
= TRUE
;
408 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
409 ListenBackLog
= SOMAXCONN
;
410 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
411 LogLevel
= CUPSD_LOG_ERROR
;
413 MaxClientsPerHost
= 0;
414 MaxLogSize
= 1024 * 1024;
415 MaxPrinterHistory
= 10;
418 RootCertDuration
= 300;
419 Timeout
= DEFAULT_TIMEOUT
;
422 BrowseInterval
= DEFAULT_INTERVAL
;
423 BrowsePort
= ippPort();
424 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
425 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
426 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
427 BrowseTimeout
= DEFAULT_TIMEOUT
;
428 Browsing
= CUPS_DEFAULT_BROWSING
;
429 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
431 cupsdClearString(&BrowseLocalOptions
);
432 cupsdClearString(&BrowseRemoteOptions
);
435 cupsdClearString(&BrowseLDAPBindDN
);
436 cupsdClearString(&BrowseLDAPDN
);
437 cupsdClearString(&BrowseLDAPPassword
);
438 cupsdClearString(&BrowseLDAPServer
);
439 #endif /* HAVE_LDAP */
441 JobHistory
= DEFAULT_HISTORY
;
442 JobFiles
= DEFAULT_FILES
;
447 MaxJobsPerPrinter
= 0;
448 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
450 cupsdDeleteAllPolicies();
451 cupsdClearString(&DefaultPolicy
);
453 #ifdef HAVE_AUTHORIZATION_H
454 cupsdClearString(&SystemGroupAuthKey
);
455 #endif /* HAVE_AUTHORIZATION_H */
457 MaxSubscriptions
= 100;
458 MaxSubscriptionsPerJob
= 0;
459 MaxSubscriptionsPerPrinter
= 0;
460 MaxSubscriptionsPerUser
= 0;
461 DefaultLeaseDuration
= 86400;
462 MaxLeaseDuration
= 0;
465 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
466 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
467 #endif /* HAVE_LAUNCHD */
471 #endif /* __APPLE__ */
474 * Read the configuration file...
477 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
480 status
= read_configuration(fp
);
490 * See if the ServerName is an IP address...
493 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
495 ServerNameIsIP
= !*slash
;
498 * Use the default system group if none was supplied in cupsd.conf...
501 if (NumSystemGroups
== 0)
503 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
506 * Find the group associated with GID 0...
513 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
515 cupsdSetString(&SystemGroups
[0], "unknown");
517 SystemGroupIDs
[0] = 0;
523 * Get the access control list for browsing...
526 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
529 * Open the system log for cupsd if necessary...
533 if (!strcmp(AccessLog
, "syslog") ||
534 !strcmp(ErrorLog
, "syslog") ||
535 !strcmp(PageLog
, "syslog"))
536 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
537 #endif /* HAVE_VSYSLOG */
540 * Log the configuration file that was used...
543 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
547 * Validate the Group and SystemGroup settings - they cannot be the same,
548 * otherwise the CGI programs will be able to authenticate as root without
554 for (i
= 0; i
< NumSystemGroups
; i
++)
555 if (Group
== SystemGroupIDs
[i
])
558 if (i
< NumSystemGroups
)
561 * Log the error and reset the group to a safe value...
564 cupsdLogMessage(CUPSD_LOG_NOTICE
,
565 "Group and SystemGroup cannot use the same groups!");
566 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
568 group
= getgrnam("nobody");
572 Group
= group
->gr_gid
;
576 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
577 * complement number...)
586 * Check that we have at least one listen/port line; if not, report this
587 * as an error and exit!
590 if (cupsArrayCount(Listeners
) == 0)
596 cupsdLogMessage(CUPSD_LOG_EMERG
,
597 "No valid Listen or Port lines were found in the configuration file!");
603 cupsdEndProcess(getpid(), 0);
607 * Set the default locale using the language and charset...
610 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
613 * Update all relative filenames to include the full path from ServerRoot...
616 if (DocumentRoot
[0] != '/')
617 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
619 if (RequestRoot
[0] != '/')
620 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
622 if (ServerBin
[0] != '/')
623 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
625 if (StateDir
[0] != '/')
626 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
628 if (CacheDir
[0] != '/')
629 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
632 if (ServerCertificate
[0] != '/')
633 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
635 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
637 chown(ServerCertificate
, RunUser
, Group
);
638 chmod(ServerCertificate
, 0600);
641 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
642 if (ServerKey
[0] != '/')
643 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
645 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
647 chown(ServerKey
, RunUser
, Group
);
648 chmod(ServerKey
, 0600);
650 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
651 #endif /* HAVE_SSL */
654 * Make sure that directories and config files are owned and
655 * writable by the user and group in the cupsd.conf file...
658 if (check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1) < 0 ||
659 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1) < 0 ||
660 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
661 SystemGroupIDs
[0], 1, 1) < 0 ||
662 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0) < 0 ||
663 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1) < 0 ||
664 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0) < 0 ||
665 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
667 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
,
669 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
,
671 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0) < 0)
675 * Update TempDir to the default if it hasn't been set already...
680 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
683 * TMPDIR is defined, see if it is OK for us to use...
686 if (stat(tmpdir
, &tmpinfo
))
687 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
688 tmpdir
, strerror(errno
));
689 else if (!S_ISDIR(tmpinfo
.st_mode
))
690 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
692 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
693 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
694 !(tmpinfo
.st_mode
& S_IWOTH
))
695 cupsdLogMessage(CUPSD_LOG_ERROR
,
696 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
698 cupsdSetString(&TempDir
, tmpdir
);
703 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
705 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
710 * Make sure the request and temporary directories have the right
714 if (check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1) < 0)
717 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
721 * Update ownership and permissions if the CUPS temp directory
722 * is under the spool directory or does not exist...
725 if (check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
729 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
732 * Clean out the temporary directory...
735 cups_dir_t
*dir
; /* Temporary directory */
736 cups_dentry_t
*dent
; /* Directory entry */
737 char tempfile
[1024]; /* Temporary filename */
740 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
742 cupsdLogMessage(CUPSD_LOG_INFO
,
743 "Cleaning out old temporary files in \"%s\"...", TempDir
);
745 while ((dent
= cupsDirRead(dir
)) != NULL
)
747 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
749 if (unlink(tempfile
))
750 cupsdLogMessage(CUPSD_LOG_ERROR
,
751 "Unable to remove temporary file \"%s\" - %s",
752 tempfile
, strerror(errno
));
754 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
761 cupsdLogMessage(CUPSD_LOG_ERROR
,
762 "Unable to open temporary directory \"%s\" - %s",
763 TempDir
, strerror(errno
));
767 * Setup environment variables...
773 * Check the MaxClients setting, and then allocate memory for it...
776 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
779 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
782 MaxClients
= MaxFDs
/ 3;
785 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
789 * Check the MaxActiveJobs setting; limit to 1/3 the available
790 * file descriptors, since we need a pipe for each job...
793 if (MaxActiveJobs
> (MaxFDs
/ 3))
794 MaxActiveJobs
= MaxFDs
/ 3;
796 if (Classification
&& !strcasecmp(Classification
, "none"))
797 cupsdClearString(&Classification
);
800 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
803 * Update the MaxClientsPerHost value, as needed...
806 if (MaxClientsPerHost
<= 0)
807 MaxClientsPerHost
= MaxClients
;
809 if (MaxClientsPerHost
> MaxClients
)
810 MaxClientsPerHost
= MaxClients
;
812 cupsdLogMessage(CUPSD_LOG_INFO
,
813 "Allowing up to %d client connections per host.",
817 * Make sure that BrowseTimeout is at least twice the interval...
820 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
822 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
826 BrowseTimeout
= BrowseInterval
* 2;
828 BrowseTimeout
= DEFAULT_TIMEOUT
;
830 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
835 * Update the default policy, as needed...
839 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
841 DefaultPolicyPtr
= NULL
;
843 if (!DefaultPolicyPtr
)
845 cupsd_policy_t
*p
; /* New policy */
846 cupsd_location_t
*po
; /* New policy operation */
850 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
853 cupsdSetString(&DefaultPolicy
, "default");
855 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
856 cupsdLogMessage(CUPSD_LOG_INFO
,
857 "Using policy \"default\" as the default!");
860 cupsdLogMessage(CUPSD_LOG_INFO
,
861 "Creating CUPS default administrative policy:");
863 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
865 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
866 cupsdLogMessage(CUPSD_LOG_INFO
,
867 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
868 "Release-Job Restart-Job Purge-Jobs "
869 "Set-Job-Attributes Create-Job-Subscription "
870 "Renew-Subscription Cancel-Subscription "
871 "Get-Notifications Reprocess-Job Cancel-Current-Job "
872 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
873 "CUPS-Authenticate-Job>");
874 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
876 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
877 po
->order_type
= AUTH_ALLOW
;
878 po
->level
= AUTH_USER
;
880 cupsdAddName(po
, "@OWNER");
881 cupsdAddName(po
, "@SYSTEM");
882 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
884 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
885 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
886 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
887 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
888 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
889 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
890 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
891 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
892 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
893 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
894 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
895 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
896 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
897 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
898 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
899 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
900 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
902 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
904 cupsdLogMessage(CUPSD_LOG_INFO
,
905 "<Limit Pause-Printer Resume-Printer "
906 "Set-Printer-Attributes Enable-Printer "
907 "Disable-Printer Pause-Printer-After-Current-Job "
908 "Hold-New-Jobs Release-Held-New-Jobs "
909 "Deactivate-Printer Activate-Printer Restart-Printer "
910 "Shutdown-Printer Startup-Printer Promote-Job "
911 "Schedule-Job-After CUPS-Add-Printer "
912 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
913 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
914 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
915 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
917 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
918 po
->order_type
= AUTH_ALLOW
;
919 po
->type
= AUTH_BASIC
;
920 po
->level
= AUTH_USER
;
922 cupsdAddName(po
, "@SYSTEM");
923 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
925 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
926 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
927 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
928 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
929 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
930 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
931 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
932 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
933 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
934 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
935 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
936 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
937 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
938 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
939 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
940 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
941 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
942 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
943 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
944 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
945 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
947 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
949 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
950 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
952 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
953 po
->order_type
= AUTH_ALLOW
;
955 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
956 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
960 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
962 for (i
= 0; i
< NumPolicies
; i
++)
963 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
964 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
968 * If we are doing a full reload or the server root has changed, flush
969 * the jobs, printers, etc. and start from scratch...
972 if (NeedReload
== RELOAD_ALL
||
973 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
974 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
976 mime_type_t
*type
; /* Current type */
977 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
981 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
987 cupsdDeleteAllSubscriptions();
989 cupsdDeleteAllClasses();
990 cupsdDeleteAllPrinters();
992 DefaultPrinter
= NULL
;
994 if (MimeDatabase
!= NULL
)
995 mimeDelete(MimeDatabase
);
999 for (i
= 0; i
< NumMimeTypes
; i
++)
1000 _cupsStrFree(MimeTypes
[i
]);
1006 * Read the MIME type and conversion database...
1009 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1011 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
1015 cupsdLogMessage(CUPSD_LOG_EMERG
,
1016 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1020 cupsdLogMessage(CUPSD_LOG_INFO
,
1021 "Loaded MIME database from \'%s\': %d types, %d filters...",
1022 ServerRoot
, mimeNumTypes(MimeDatabase
),
1023 mimeNumFilters(MimeDatabase
));
1026 * Create a list of MIME types for the document-format-supported
1030 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1031 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1034 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
1036 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1038 i
++, type
= mimeNextType(MimeDatabase
))
1040 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1042 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1045 if (i
< NumMimeTypes
)
1046 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1048 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1050 mime_filter_t
*filter
; /* Current filter */
1053 for (type
= mimeFirstType(MimeDatabase
);
1055 type
= mimeNextType(MimeDatabase
))
1056 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1057 type
->super
, type
->type
);
1059 for (filter
= mimeFirstFilter(MimeDatabase
);
1061 filter
= mimeNextFilter(MimeDatabase
))
1062 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1063 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1064 filter
->src
->super
, filter
->src
->type
,
1065 filter
->dst
->super
, filter
->dst
->type
,
1066 filter
->cost
, filter
->filter
);
1073 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1074 cupsdLoadBanners(temp
);
1077 * Load printers and classes...
1080 cupsdLoadAllPrinters();
1081 cupsdLoadAllClasses();
1082 cupsdLoadRemoteCache();
1083 cupsdWritePrintcap();
1085 cupsdCreateCommonData();
1088 * Load queued jobs...
1094 * Load subscriptions...
1097 cupsdLoadAllSubscriptions();
1099 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1104 * Not a full reload, so recreate the common printer attributes...
1107 cupsdCreateCommonData();
1110 * Update all printers as needed...
1113 cupsdUpdatePrinters();
1114 cupsdWritePrintcap();
1116 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1120 * Reset the reload state...
1123 NeedReload
= RELOAD_NONE
;
1125 cupsdClearString(&old_serverroot
);
1126 cupsdClearString(&old_requestroot
);
1133 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1136 static int /* O - 0 on success, -1 on error, 1 on warning */
1137 check_permissions(const char *filename
, /* I - File/directory name */
1138 const char *suffix
, /* I - Additional file/directory name */
1139 int mode
, /* I - Permissions */
1140 int user
, /* I - Owner */
1141 int group
, /* I - Group */
1142 int is_dir
, /* I - 1 = directory, 0 = file */
1143 int create_dir
)/* I - 1 = create directory, 0 = not */
1145 int dir_created
= 0; /* Did we create a directory? */
1146 char pathname
[1024]; /* File name with prefix */
1147 struct stat fileinfo
; /* Stat buffer */
1151 * Prepend the given root to the filename before testing it...
1156 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1157 filename
= pathname
;
1161 * See if we can stat the file/directory...
1164 if (stat(filename
, &fileinfo
))
1166 if (errno
== ENOENT
&& create_dir
)
1168 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1171 if (mkdir(filename
, mode
))
1173 cupsdLogMessage(CUPSD_LOG_ERROR
,
1174 "Unable to create directory \"%s\" - %s", filename
,
1182 return (create_dir
? -1 : 1);
1186 * Make sure it's a regular file...
1189 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1191 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1195 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1197 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1202 * Fix owner, group, and mode as needed...
1205 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1207 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1209 if (chown(filename
, user
, group
))
1211 cupsdLogMessage(CUPSD_LOG_ERROR
,
1212 "Unable to change ownership of \"%s\" - %s", filename
,
1218 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
1220 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1222 if (chmod(filename
, mode
))
1224 cupsdLogMessage(CUPSD_LOG_ERROR
,
1225 "Unable to change permissions of \"%s\" - %s", filename
,
1232 * Everything is OK...
1240 * 'get_address()' - Get an address + port number from a line.
1243 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1244 get_address(const char *value
, /* I - Value string */
1245 int defport
) /* I - Default port */
1247 char buffer
[1024], /* Hostname + port number buffer */
1248 defpname
[255], /* Default port name */
1249 *hostname
, /* Hostname or IP */
1250 *portname
; /* Port number or name */
1251 http_addrlist_t
*addrlist
; /* Address list */
1255 * Check for an empty value...
1260 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1265 * Grab a hostname and port number; if there is no colon and the port name
1266 * is only digits, then we have a port number by itself...
1269 strlcpy(buffer
, value
, sizeof(buffer
));
1271 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1278 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1283 * Use the default port...
1286 sprintf(defpname
, "%d", defport
);
1287 portname
= defpname
;
1293 * The buffer contains just a port number...
1301 if (hostname
&& !strcmp(hostname
, "*"))
1305 * Now lookup the address using httpAddrGetList()...
1308 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1309 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1310 hostname
? hostname
: "(nil)");
1317 * 'get_addr_and_mask()' - Get an IP address and netmask.
1320 static int /* O - 1 on success, 0 on failure */
1321 get_addr_and_mask(const char *value
, /* I - String from config file */
1322 unsigned *ip
, /* O - Address value */
1323 unsigned *mask
) /* O - Mask value */
1325 int i
, j
, /* Looping vars */
1326 family
, /* Address family */
1327 ipcount
; /* Count of fields in address */
1328 unsigned ipval
; /* Value */
1329 const char *maskval
, /* Pointer to start of mask value */
1330 *ptr
, /* Pointer into value */
1335 * Get the address...
1338 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1339 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1341 if ((maskval
= strchr(value
, '/')) != NULL
)
1344 maskval
= value
+ strlen(value
);
1348 * Check for an IPv6 address...
1354 * Parse hexadecimal IPv6 address...
1359 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1363 else if (!strncmp(ptr
, "::", 2))
1365 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1367 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1372 else if (isxdigit(*ptr
& 255))
1374 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1382 ip
[i
/ 2] |= ipval
<< 16;
1396 if (*ptr
&& *ptr
!= '/')
1400 #endif /* AF_INET6 */
1403 * Parse dotted-decimal IPv4 address...
1406 unsigned val
[4]; /* IPv4 address values */
1410 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1413 * Range check the IP numbers...
1416 for (i
= 0; i
< ipcount
; i
++)
1421 * Make sure the trailing values are zeroed, as some C libraries like
1422 * glibc apparently like to fill the unused arguments with garbage...
1425 for (i
= ipcount
; i
< 4; i
++)
1429 * Merge everything into a 32-bit IPv4 address in ip[3]...
1432 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1435 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1441 * Get the netmask value(s)...
1444 memset(mask
, 0, sizeof(unsigned) * 4);
1446 if (strchr(maskval
, '.'))
1449 * Get dotted-decimal mask...
1452 if (family
!= AF_INET
)
1455 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1458 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1459 mask
[0] = mask
[1] = mask
[2] = 0;
1464 * Get address/bits format...
1470 if (family
== AF_INET6
)
1478 mask
[0] = 0xffffffff;
1480 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1483 mask
[1] = 0xffffffff;
1487 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1490 mask
[2] = 0xffffffff;
1494 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1497 mask
[3] = 0xffffffff;
1501 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1504 #endif /* AF_INET6 */
1509 mask
[0] = 0xffffffff;
1510 mask
[1] = 0xffffffff;
1511 mask
[2] = 0xffffffff;
1514 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1516 mask
[3] = 0xffffffff;
1521 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1522 "get_addr_and_mask(value=\"%s\", "
1523 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1524 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1528 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1531 if ((ip
[0] & ~mask
[0]) != 0 ||
1532 (ip
[1] & ~mask
[1]) != 0 ||
1533 (ip
[2] & ~mask
[2]) != 0 ||
1534 (ip
[3] & ~mask
[3]) != 0)
1542 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1545 static int /* O - 1 on success, 0 on failure */
1546 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1547 char *line
, /* I - Line from file */
1548 char *value
, /* I - Start of value data */
1549 int linenum
) /* I - Current line number */
1551 char *valptr
; /* Pointer into value */
1552 unsigned ip
[4], /* IP address components */
1553 mask
[4]; /* IP netmask components */
1556 if (!strcasecmp(line
, "Encryption"))
1559 * "Encryption xxx" - set required encryption level...
1562 if (!strcasecmp(value
, "never"))
1563 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1564 else if (!strcasecmp(value
, "always"))
1566 cupsdLogMessage(CUPSD_LOG_ERROR
,
1567 "Encryption value \"%s\" on line %d is invalid in this "
1568 "context. Using \"required\" instead.", value
, linenum
);
1570 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1572 else if (!strcasecmp(value
, "required"))
1573 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1574 else if (!strcasecmp(value
, "ifrequested"))
1575 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1578 cupsdLogMessage(CUPSD_LOG_ERROR
,
1579 "Unknown Encryption value %s on line %d.", value
, linenum
);
1583 else if (!strcasecmp(line
, "Order"))
1586 * "Order Deny,Allow" or "Order Allow,Deny"...
1589 if (!strncasecmp(value
, "deny", 4))
1590 loc
->order_type
= AUTH_ALLOW
;
1591 else if (!strncasecmp(value
, "allow", 5))
1592 loc
->order_type
= AUTH_DENY
;
1595 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1600 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1603 * Allow [From] host/ip...
1604 * Deny [From] host/ip...
1607 if (!strncasecmp(value
, "from", 4))
1610 * Strip leading "from"...
1615 while (isspace(*value
& 255))
1620 * Figure out what form the allow/deny address takes:
1631 * nnn.nnn.nnn.nnn/mm
1632 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1635 if (!strcasecmp(value
, "all"))
1641 if (!strcasecmp(line
, "Allow"))
1642 cupsdAllowIP(loc
, zeros
, zeros
);
1644 cupsdDenyIP(loc
, zeros
, zeros
);
1646 else if (!strcasecmp(value
, "none"))
1652 if (!strcasecmp(line
, "Allow"))
1653 cupsdAllowIP(loc
, ones
, zeros
);
1655 cupsdDenyIP(loc
, ones
, zeros
);
1658 else if (value
[0] == '*' || value
[0] == '.' ||
1659 (!isdigit(value
[0] & 255) && value
[0] != '['))
1661 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1662 #endif /* AF_INET6 */
1665 * Host or domain name...
1668 if (value
[0] == '*')
1671 if (!strcasecmp(line
, "Allow"))
1672 cupsdAllowHost(loc
, value
);
1674 cupsdDenyHost(loc
, value
);
1679 * One of many IP address forms...
1682 if (!get_addr_and_mask(value
, ip
, mask
))
1684 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1689 if (!strcasecmp(line
, "Allow"))
1690 cupsdAllowIP(loc
, ip
, mask
);
1692 cupsdDenyIP(loc
, ip
, mask
);
1695 else if (!strcasecmp(line
, "AuthType"))
1698 * AuthType {none,basic,digest,basicdigest}
1701 if (!strcasecmp(value
, "none"))
1703 loc
->type
= AUTH_NONE
;
1704 loc
->level
= AUTH_ANON
;
1706 else if (!strcasecmp(value
, "basic"))
1708 loc
->type
= AUTH_BASIC
;
1710 if (loc
->level
== AUTH_ANON
)
1711 loc
->level
= AUTH_USER
;
1713 else if (!strcasecmp(value
, "digest"))
1715 loc
->type
= AUTH_DIGEST
;
1717 if (loc
->level
== AUTH_ANON
)
1718 loc
->level
= AUTH_USER
;
1720 else if (!strcasecmp(value
, "basicdigest"))
1722 loc
->type
= AUTH_BASICDIGEST
;
1724 if (loc
->level
== AUTH_ANON
)
1725 loc
->level
= AUTH_USER
;
1728 else if (!strcasecmp(value
, "negotiate"))
1730 loc
->type
= AUTH_NEGOTIATE
;
1732 if (loc
->level
== AUTH_ANON
)
1733 loc
->level
= AUTH_USER
;
1735 #endif /* HAVE_GSSAPI */
1738 cupsdLogMessage(CUPSD_LOG_WARN
,
1739 "Unknown authorization type %s on line %d.",
1744 else if (!strcasecmp(line
, "AuthClass"))
1747 * AuthClass anonymous, user, system, group
1750 if (!strcasecmp(value
, "anonymous"))
1752 loc
->type
= AUTH_NONE
;
1753 loc
->level
= AUTH_ANON
;
1755 cupsdLogMessage(CUPSD_LOG_WARN
,
1756 "\"AuthClass %s\" is deprecated; consider removing "
1760 else if (!strcasecmp(value
, "user"))
1762 loc
->level
= AUTH_USER
;
1764 cupsdLogMessage(CUPSD_LOG_WARN
,
1765 "\"AuthClass %s\" is deprecated; consider using "
1766 "\"Require valid-user\" on line %d.",
1769 else if (!strcasecmp(value
, "group"))
1771 loc
->level
= AUTH_GROUP
;
1773 cupsdLogMessage(CUPSD_LOG_WARN
,
1774 "\"AuthClass %s\" is deprecated; consider using "
1775 "\"Require @groupname\" on line %d.",
1778 else if (!strcasecmp(value
, "system"))
1780 loc
->level
= AUTH_GROUP
;
1782 cupsdAddName(loc
, "@SYSTEM");
1784 cupsdLogMessage(CUPSD_LOG_WARN
,
1785 "\"AuthClass %s\" is deprecated; consider using "
1786 "\"Require @SYSTEM\" on line %d.",
1791 cupsdLogMessage(CUPSD_LOG_WARN
,
1792 "Unknown authorization class %s on line %d.",
1797 else if (!strcasecmp(line
, "AuthGroupName"))
1799 cupsdAddName(loc
, value
);
1801 cupsdLogMessage(CUPSD_LOG_WARN
,
1802 "\"AuthGroupName %s\" directive is deprecated; consider "
1803 "using \"Require @%s\" on line %d.",
1804 value
, value
, linenum
);
1806 else if (!strcasecmp(line
, "Require"))
1809 * Apache synonym for AuthClass and AuthGroupName...
1813 * Require valid-user
1814 * Require group names
1815 * Require user names
1818 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1823 if (!strcasecmp(value
, "valid-user") ||
1824 !strcasecmp(value
, "user"))
1825 loc
->level
= AUTH_USER
;
1826 else if (!strcasecmp(value
, "group"))
1827 loc
->level
= AUTH_GROUP
;
1830 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1836 * Get the list of names from the line...
1839 for (value
= valptr
; *value
;)
1841 while (isspace(*value
& 255))
1844 #ifdef HAVE_AUTHORIZATION_H
1845 if (!strncmp(value
, "@AUTHKEY(", 9))
1848 * Grab "@AUTHKEY(name)" value...
1851 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1857 #endif /* HAVE_AUTHORIZATION_H */
1858 if (*value
== '\"' || *value
== '\'')
1861 * Grab quoted name...
1864 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1871 * Grab literal name.
1874 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1880 cupsdAddName(loc
, value
);
1882 for (value
= valptr
; isspace(*value
& 255); value
++);
1885 else if (!strcasecmp(line
, "Satisfy"))
1887 if (!strcasecmp(value
, "all"))
1888 loc
->satisfy
= AUTH_SATISFY_ALL
;
1889 else if (!strcasecmp(value
, "any"))
1890 loc
->satisfy
= AUTH_SATISFY_ANY
;
1893 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1906 * 'parse_groups()' - Parse system group names in a string.
1909 static int /* O - 1 on success, 0 on failure */
1910 parse_groups(const char *s
) /* I - Space-delimited groups */
1912 int status
; /* Return status */
1913 char value
[1024], /* Value string */
1914 *valstart
, /* Pointer into value */
1915 *valend
, /* End of value */
1916 quote
; /* Quote character */
1917 struct group
*group
; /* Group */
1921 * Make a copy of the string and parse out the groups...
1924 strlcpy(value
, s
, sizeof(value
));
1929 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1931 if (*valstart
== '\'' || *valstart
== '\"')
1934 * Scan quoted name...
1937 quote
= *valstart
++;
1939 for (valend
= valstart
; *valend
; valend
++)
1940 if (*valend
== quote
)
1946 * Scan space or comma-delimited name...
1949 for (valend
= valstart
; *valend
; valend
++)
1950 if (isspace(*valend
) || *valend
== ',')
1957 group
= getgrnam(valstart
);
1960 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1961 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1972 while (*valstart
== ',' || isspace(*valstart
))
1981 * 'parse_protocols()' - Parse browse protocols in a string.
1984 static int /* O - Browse protocol bits */
1985 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1987 int protocols
; /* Browse protocol bits */
1988 char value
[1024], /* Value string */
1989 *valstart
, /* Pointer into value */
1990 *valend
; /* End of value */
1994 * Empty protocol line yields NULL pointer...
2001 * Loop through the value string,...
2004 strlcpy(value
, s
, sizeof(value
));
2008 for (valstart
= value
; *valstart
;)
2011 * Get the current space/comma-delimited protocol name...
2014 for (valend
= valstart
; *valend
; valend
++)
2015 if (isspace(*valend
& 255) || *valend
== ',')
2022 * Add the protocol to the bitmask...
2025 if (!strcasecmp(valstart
, "cups"))
2026 protocols
|= BROWSE_CUPS
;
2027 else if (!strcasecmp(valstart
, "slp"))
2028 protocols
|= BROWSE_SLP
;
2029 else if (!strcasecmp(valstart
, "ldap"))
2030 protocols
|= BROWSE_LDAP
;
2031 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
2032 protocols
|= BROWSE_DNSSD
;
2033 else if (!strcasecmp(valstart
, "all"))
2034 protocols
|= BROWSE_ALL
;
2035 else if (strcasecmp(valstart
, "none"))
2038 for (valstart
= valend
; *valstart
; valstart
++)
2039 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2048 * 'read_configuration()' - Read a configuration file.
2051 static int /* O - 1 on success, 0 on failure */
2052 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2054 int i
; /* Looping var */
2055 int linenum
; /* Current line number */
2056 char line
[HTTP_MAX_BUFFER
],
2057 /* Line from file */
2058 temp
[HTTP_MAX_BUFFER
],
2059 /* Temporary buffer for value */
2060 temp2
[HTTP_MAX_BUFFER
],
2061 /* Temporary buffer 2 for value */
2062 *ptr
, /* Pointer into line/temp */
2063 *value
, /* Pointer to value */
2064 *valueptr
; /* Pointer into value */
2065 int valuelen
; /* Length of value */
2066 cupsd_var_t
*var
; /* Current variable */
2067 http_addrlist_t
*addrlist
, /* Address list */
2068 *addr
; /* Current address */
2069 unsigned ip
[4], /* Address value */
2070 mask
[4]; /* Netmask value */
2071 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2072 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2073 cupsd_location_t
*location
; /* Browse location */
2074 cups_file_t
*incfile
; /* Include file */
2075 char incname
[1024]; /* Include filename */
2076 struct group
*group
; /* Group */
2080 * Loop through each line in the file...
2085 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2088 * Decode the directive...
2091 if (!strcasecmp(line
, "Include"))
2097 if (value
[0] == '/')
2098 strlcpy(incname
, value
, sizeof(incname
));
2100 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2102 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2103 cupsdLogMessage(CUPSD_LOG_ERROR
,
2104 "Unable to include config file \"%s\" - %s",
2105 incname
, strerror(errno
));
2108 read_configuration(incfile
);
2109 cupsFileClose(incfile
);
2112 else if (!strcasecmp(line
, "<Location"))
2120 linenum
= read_location(fp
, value
, linenum
);
2126 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2131 else if (!strcasecmp(line
, "<Policy"))
2139 linenum
= read_policy(fp
, value
, linenum
);
2145 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2149 else if (!strcasecmp(line
, "FaxRetryInterval"))
2153 JobRetryInterval
= atoi(value
);
2154 cupsdLogMessage(CUPSD_LOG_WARN
,
2155 "FaxRetryInterval is deprecated; use "
2156 "JobRetryInterval on line %d.", linenum
);
2160 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2164 else if (!strcasecmp(line
, "FaxRetryLimit"))
2168 JobRetryLimit
= atoi(value
);
2169 cupsdLogMessage(CUPSD_LOG_WARN
,
2170 "FaxRetryLimit is deprecated; use "
2171 "JobRetryLimit on line %d.", linenum
);
2175 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2179 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2181 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2182 #endif /* HAVE_SSL */
2186 * Add listening address(es) to the list...
2189 cupsd_listener_t
*lis
; /* New listeners array */
2193 * Get the address list...
2196 addrlist
= get_address(value
, IPP_PORT
);
2200 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2206 * Add each address...
2209 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2212 * Allocate another listener...
2216 Listeners
= cupsArrayNew(NULL
, NULL
);
2220 cupsdLogMessage(CUPSD_LOG_ERROR
,
2221 "Unable to allocate %s at line %d - %s.",
2222 line
, linenum
, strerror(errno
));
2226 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2228 cupsdLogMessage(CUPSD_LOG_ERROR
,
2229 "Unable to allocate %s at line %d - %s.",
2230 line
, linenum
, strerror(errno
));
2234 cupsArrayAdd(Listeners
, lis
);
2237 * Copy the current address and log it...
2240 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2244 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2245 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2246 #endif /* HAVE_SSL */
2248 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2251 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2252 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2253 ntohs(lis
->address
.ipv6
.sin6_port
));
2255 #endif /* AF_INET6 */
2257 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2258 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2260 #endif /* AF_LOCAL */
2261 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2262 ntohs(lis
->address
.ipv4
.sin_port
));
2269 httpAddrFreeList(addrlist
);
2271 else if (!strcasecmp(line
, "BrowseAddress"))
2274 * Add a browse address to the list...
2277 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2280 if (NumBrowsers
== 0)
2281 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2283 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2287 cupsdLogMessage(CUPSD_LOG_ERROR
,
2288 "Unable to allocate BrowseAddress at line %d - %s.",
2289 linenum
, strerror(errno
));
2294 dira
+= NumBrowsers
;
2296 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2298 if (!strcasecmp(value
, "@LOCAL"))
2301 * Send browse data to all local interfaces...
2304 strcpy(dira
->iface
, "*");
2307 else if (!strncasecmp(value
, "@IF(", 4))
2310 * Send browse data to the named interface...
2313 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2315 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2321 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2324 * Only IPv4 addresses are supported...
2327 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2328 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2333 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2334 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2336 cupsdLogMessage(CUPSD_LOG_INFO
,
2337 "Sending browsing info to %s:%d (IPv4)",
2338 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2343 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2346 httpAddrFreeList(addrlist
);
2349 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2352 else if (!strcasecmp(line
, "BrowseOrder"))
2355 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2358 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2359 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2361 if (location
== NULL
)
2362 cupsdLogMessage(CUPSD_LOG_ERROR
,
2363 "Unable to initialize browse access control list!");
2364 else if (!strncasecmp(value
, "deny", 4))
2365 location
->order_type
= AUTH_ALLOW
;
2366 else if (!strncasecmp(value
, "allow", 5))
2367 location
->order_type
= AUTH_DENY
;
2369 cupsdLogMessage(CUPSD_LOG_ERROR
,
2370 "Unknown BrowseOrder value %s on line %d.",
2373 else if (!strcasecmp(line
, "BrowseProtocols") ||
2374 !strcasecmp(line
, "BrowseLocalProtocols") ||
2375 !strcasecmp(line
, "BrowseRemoteProtocols"))
2378 * "BrowseProtocols name [... name]"
2379 * "BrowseLocalProtocols name [... name]"
2380 * "BrowseRemoteProtocols name [... name]"
2383 int protocols
= parse_protocols(value
);
2387 cupsdLogMessage(CUPSD_LOG_ERROR
,
2388 "Unknown browse protocol \"%s\" on line %d.",
2393 if (strcasecmp(line
, "BrowseLocalProtocols"))
2394 BrowseRemoteProtocols
= protocols
;
2395 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2396 BrowseLocalProtocols
= protocols
;
2398 else if (!strcasecmp(line
, "BrowseAllow") ||
2399 !strcasecmp(line
, "BrowseDeny"))
2402 * BrowseAllow [From] host/ip...
2403 * BrowseDeny [From] host/ip...
2406 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2407 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2409 if (location
== NULL
)
2410 cupsdLogMessage(CUPSD_LOG_ERROR
,
2411 "Unable to initialize browse access control list!");
2414 if (!strncasecmp(value
, "from ", 5))
2417 * Strip leading "from"...
2422 while (isspace(*value
))
2427 * Figure out what form the allow/deny address takes:
2438 * nnn.nnn.nnn.nnn/mm
2439 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2442 if (!strcasecmp(value
, "all"))
2448 if (!strcasecmp(line
, "BrowseAllow"))
2449 cupsdAllowIP(location
, zeros
, zeros
);
2451 cupsdDenyIP(location
, zeros
, zeros
);
2453 else if (!strcasecmp(value
, "none"))
2459 if (!strcasecmp(line
, "BrowseAllow"))
2460 cupsdAllowIP(location
, ones
, zeros
);
2462 cupsdDenyIP(location
, ones
, zeros
);
2465 else if (value
[0] == '*' || value
[0] == '.' ||
2466 (!isdigit(value
[0] & 255) && value
[0] != '['))
2468 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2469 #endif /* AF_INET6 */
2472 * Host or domain name...
2475 if (value
[0] == '*')
2478 if (!strcasecmp(line
, "BrowseAllow"))
2479 cupsdAllowHost(location
, value
);
2481 cupsdDenyHost(location
, value
);
2486 * One of many IP address forms...
2489 if (!get_addr_and_mask(value
, ip
, mask
))
2491 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2496 if (!strcasecmp(line
, "BrowseAllow"))
2497 cupsdAllowIP(location
, ip
, mask
);
2499 cupsdDenyIP(location
, ip
, mask
);
2503 else if (!strcasecmp(line
, "BrowseRelay"))
2506 * BrowseRelay [from] source [to] destination
2510 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2512 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2516 cupsdLogMessage(CUPSD_LOG_ERROR
,
2517 "Unable to allocate BrowseRelay at line %d - %s.",
2518 linenum
, strerror(errno
));
2525 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2527 if (!strncasecmp(value
, "from ", 5))
2530 * Strip leading "from"...
2535 while (isspace(*value
))
2540 * Figure out what form the from address takes:
2549 * nnn.nnn.nnn.nnn/mm
2550 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2554 if (value
[0] == '*' || value
[0] == '.' ||
2555 (!isdigit(value
[0] & 255) && value
[0] != '['))
2557 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2558 #endif /* AF_INET6 */
2561 * Host or domain name...
2564 if (value
[0] == '*')
2567 strlcpy(temp
, value
, sizeof(temp
));
2568 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2571 relay
->from
.type
= AUTH_NAME
;
2572 relay
->from
.mask
.name
.name
= strdup(temp
);
2573 relay
->from
.mask
.name
.length
= strlen(temp
);
2578 * One of many IP address forms...
2581 if (!get_addr_and_mask(value
, ip
, mask
))
2583 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2588 relay
->from
.type
= AUTH_IP
;
2589 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2590 sizeof(relay
->from
.mask
.ip
.address
));
2591 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2592 sizeof(relay
->from
.mask
.ip
.netmask
));
2596 * Skip value and trailing whitespace...
2599 for (; *value
; value
++)
2600 if (isspace(*value
))
2603 while (isspace(*value
))
2606 if (!strncasecmp(value
, "to ", 3))
2609 * Strip leading "to"...
2614 while (isspace(*value
))
2619 * Get "to" address and port...
2622 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2625 * Only IPv4 addresses are supported...
2628 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2629 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2634 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2636 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2638 if (relay
->from
.type
== AUTH_IP
)
2639 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2640 relay
->from
.mask
.ip
.address
[0],
2641 relay
->from
.mask
.ip
.address
[1],
2642 relay
->from
.mask
.ip
.address
[2],
2643 relay
->from
.mask
.ip
.address
[3],
2644 relay
->from
.mask
.ip
.netmask
[0],
2645 relay
->from
.mask
.ip
.netmask
[1],
2646 relay
->from
.mask
.ip
.netmask
[2],
2647 relay
->from
.mask
.ip
.netmask
[3]);
2649 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2651 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2652 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2657 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2660 httpAddrFreeList(addrlist
);
2664 if (relay
->from
.type
== AUTH_NAME
)
2665 free(relay
->from
.mask
.name
.name
);
2667 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2671 else if (!strcasecmp(line
, "BrowsePoll"))
2674 * BrowsePoll address[:port]
2677 char *portname
; /* Port name */
2678 int portnum
; /* Port number */
2679 struct servent
*service
; /* Service */
2683 * Extract the port name from the address...
2686 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2690 if (isdigit(*portname
& 255))
2691 portnum
= atoi(portname
);
2692 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2693 portnum
= ntohs(service
->s_port
);
2696 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2702 portnum
= ippPort();
2705 * Add the poll entry...
2709 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2711 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2715 cupsdLogMessage(CUPSD_LOG_ERROR
,
2716 "Unable to allocate BrowsePoll at line %d - %s.",
2717 linenum
, strerror(errno
));
2725 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2727 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2728 pollp
->port
= portnum
;
2730 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2733 else if (!strcasecmp(line
, "DefaultAuthType"))
2736 * DefaultAuthType {basic,digest,basicdigest}
2739 if (!strcasecmp(value
, "basic"))
2740 DefaultAuthType
= AUTH_BASIC
;
2741 else if (!strcasecmp(value
, "digest"))
2742 DefaultAuthType
= AUTH_DIGEST
;
2743 else if (!strcasecmp(value
, "basicdigest"))
2744 DefaultAuthType
= AUTH_BASICDIGEST
;
2746 else if (!strcasecmp(value
, "negotiate"))
2747 DefaultAuthType
= AUTH_NEGOTIATE
;
2748 #endif /* HAVE_GSSAPI */
2751 cupsdLogMessage(CUPSD_LOG_WARN
,
2752 "Unknown default authorization type %s on line %d.",
2758 else if (!strcasecmp(line
, "DefaultEncryption"))
2761 * DefaultEncryption {Never,IfRequested,Required}
2764 if (!value
|| !strcasecmp(value
, "never"))
2765 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2766 else if (!strcasecmp(value
, "required"))
2767 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2768 else if (!strcasecmp(value
, "ifrequested"))
2769 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2772 cupsdLogMessage(CUPSD_LOG_WARN
,
2773 "Unknown default encryption %s on line %d.",
2778 #endif /* HAVE_SSL */
2780 else if (!strcasecmp(line
, "Krb5Keytab"))
2782 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2785 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2786 gsskrb5_register_acceptor_identity(value
);
2788 cupsdSetEnv("KRB5_KTNAME", value
);
2789 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2791 #endif /* HAVE_GSSAPI */
2792 else if (!strcasecmp(line
, "User"))
2795 * User ID to run as...
2798 if (value
&& isdigit(value
[0] & 255))
2800 int uid
= atoi(value
);
2803 cupsdLogMessage(CUPSD_LOG_ERROR
,
2804 "Will not use User 0 as specified on line %d "
2805 "for security reasons. You must use a non-"
2806 "privileged account instead.",
2813 struct passwd
*p
; /* Password information */
2816 p
= getpwnam(value
);
2821 cupsdLogMessage(CUPSD_LOG_ERROR
,
2822 "Will not use User %s (UID=0) as specified on line "
2823 "%d for security reasons. You must use a non-"
2824 "privileged account instead.",
2830 cupsdLogMessage(CUPSD_LOG_ERROR
,
2831 "Unknown User \"%s\" on line %d, ignoring!",
2835 cupsdLogMessage(CUPSD_LOG_ERROR
,
2836 "User directive on line %d missing the username!",
2839 else if (!strcasecmp(line
, "Group"))
2842 * Group ID to run as...
2845 if (isdigit(value
[0]))
2846 Group
= atoi(value
);
2850 group
= getgrnam(value
);
2853 Group
= group
->gr_gid
;
2855 cupsdLogMessage(CUPSD_LOG_ERROR
,
2856 "Unknown Group \"%s\" on line %d, ignoring!",
2860 else if (!strcasecmp(line
, "SystemGroup"))
2863 * SystemGroup (admin) group(s)...
2866 if (!parse_groups(value
))
2867 cupsdLogMessage(CUPSD_LOG_ERROR
,
2868 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2871 else if (!strcasecmp(line
, "HostNameLookups"))
2874 * Do hostname lookups?
2877 if (!strcasecmp(value
, "off"))
2878 HostNameLookups
= 0;
2879 else if (!strcasecmp(value
, "on"))
2880 HostNameLookups
= 1;
2881 else if (!strcasecmp(value
, "double"))
2882 HostNameLookups
= 2;
2884 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2887 else if (!strcasecmp(line
, "LogLevel"))
2890 * Amount of logging to do...
2893 if (!strcasecmp(value
, "debug2"))
2894 LogLevel
= CUPSD_LOG_DEBUG2
;
2895 else if (!strcasecmp(value
, "debug"))
2896 LogLevel
= CUPSD_LOG_DEBUG
;
2897 else if (!strcasecmp(value
, "info"))
2898 LogLevel
= CUPSD_LOG_INFO
;
2899 else if (!strcasecmp(value
, "notice"))
2900 LogLevel
= CUPSD_LOG_NOTICE
;
2901 else if (!strcasecmp(value
, "warn"))
2902 LogLevel
= CUPSD_LOG_WARN
;
2903 else if (!strcasecmp(value
, "error"))
2904 LogLevel
= CUPSD_LOG_ERROR
;
2905 else if (!strcasecmp(value
, "crit"))
2906 LogLevel
= CUPSD_LOG_CRIT
;
2907 else if (!strcasecmp(value
, "alert"))
2908 LogLevel
= CUPSD_LOG_ALERT
;
2909 else if (!strcasecmp(value
, "emerg"))
2910 LogLevel
= CUPSD_LOG_EMERG
;
2911 else if (!strcasecmp(value
, "none"))
2912 LogLevel
= CUPSD_LOG_NONE
;
2914 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2917 else if (!strcasecmp(line
, "PrintcapFormat"))
2920 * Format of printcap file?
2923 if (!strcasecmp(value
, "bsd"))
2924 PrintcapFormat
= PRINTCAP_BSD
;
2925 else if (!strcasecmp(value
, "solaris"))
2926 PrintcapFormat
= PRINTCAP_SOLARIS
;
2928 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2931 else if (!strcasecmp(line
, "ServerTokens"))
2934 * Set the string used for the Server header...
2937 struct utsname plat
; /* Platform info */
2942 if (!strcasecmp(value
, "ProductOnly"))
2943 cupsdSetString(&ServerHeader
, "CUPS");
2944 else if (!strcasecmp(value
, "Major"))
2945 cupsdSetString(&ServerHeader
, "CUPS/1");
2946 else if (!strcasecmp(value
, "Minor"))
2947 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2948 else if (!strcasecmp(value
, "Minimal"))
2949 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2950 else if (!strcasecmp(value
, "OS"))
2951 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2952 else if (!strcasecmp(value
, "Full"))
2953 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2955 else if (!strcasecmp(value
, "None"))
2956 cupsdClearString(&ServerHeader
);
2958 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2961 else if (!strcasecmp(line
, "PassEnv"))
2964 * PassEnv variable [... variable]
2969 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2970 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2973 if (value
[valuelen
])
2975 value
[valuelen
] = '\0';
2979 cupsdSetEnv(value
, NULL
);
2981 for (value
+= valuelen
; *value
; value
++)
2982 if (!isspace(*value
) || *value
!= ',')
2986 else if (!strcasecmp(line
, "SetEnv"))
2989 * SetEnv variable value
2992 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3000 while (isspace(*valueptr
& 255))
3003 cupsdSetEnv(value
, valueptr
);
3006 cupsdLogMessage(CUPSD_LOG_ERROR
,
3007 "Missing value for SetEnv directive on line %d.",
3013 * Find a simple variable in the list...
3016 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3017 if (!strcasecmp(line
, var
->name
))
3023 * Unknown directive! Output an error message and continue...
3026 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3033 case CUPSD_VARTYPE_INTEGER
:
3035 cupsdLogMessage(CUPSD_LOG_ERROR
,
3036 "Missing integer value for %s on line %d!",
3041 char *units
; /* Units */
3044 n
= strtol(value
, &units
, 0);
3046 if (units
&& *units
)
3048 if (tolower(units
[0] & 255) == 'g')
3049 n
*= 1024 * 1024 * 1024;
3050 else if (tolower(units
[0] & 255) == 'm')
3052 else if (tolower(units
[0] & 255) == 'k')
3054 else if (tolower(units
[0] & 255) == 't')
3059 cupsdLogMessage(CUPSD_LOG_ERROR
,
3060 "Bad negative integer value for %s on line %d!",
3063 *((int *)var
->ptr
) = n
;
3067 case CUPSD_VARTYPE_BOOLEAN
:
3069 cupsdLogMessage(CUPSD_LOG_ERROR
,
3070 "Missing boolean value for %s on line %d!",
3072 else if (!strcasecmp(value
, "true") ||
3073 !strcasecmp(value
, "on") ||
3074 !strcasecmp(value
, "enabled") ||
3075 !strcasecmp(value
, "yes") ||
3077 *((int *)var
->ptr
) = TRUE
;
3078 else if (!strcasecmp(value
, "false") ||
3079 !strcasecmp(value
, "off") ||
3080 !strcasecmp(value
, "disabled") ||
3081 !strcasecmp(value
, "no") ||
3082 !strcasecmp(value
, "0"))
3083 *((int *)var
->ptr
) = FALSE
;
3085 cupsdLogMessage(CUPSD_LOG_ERROR
,
3086 "Unknown boolean value %s on line %d.",
3090 case CUPSD_VARTYPE_STRING
:
3091 cupsdSetString((char **)var
->ptr
, value
);
3102 * 'read_location()' - Read a <Location path> definition.
3105 static int /* O - New line number or 0 on error */
3106 read_location(cups_file_t
*fp
, /* I - Configuration file */
3107 char *location
, /* I - Location name/path */
3108 int linenum
) /* I - Current line number */
3110 cupsd_location_t
*loc
, /* New location */
3111 *parent
; /* Parent location */
3112 char line
[HTTP_MAX_BUFFER
],
3114 *value
, /* Value for directive */
3115 *valptr
; /* Pointer into value */
3118 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3121 parent
->limit
= AUTH_LIMIT_ALL
;
3124 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3127 * Decode the directive...
3130 if (!strcasecmp(line
, "</Location>"))
3132 else if (!strcasecmp(line
, "<Limit") ||
3133 !strcasecmp(line
, "<LimitExcept"))
3137 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3141 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3147 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3152 if (!strcmp(value
, "ALL"))
3153 loc
->limit
= AUTH_LIMIT_ALL
;
3154 else if (!strcmp(value
, "GET"))
3155 loc
->limit
|= AUTH_LIMIT_GET
;
3156 else if (!strcmp(value
, "HEAD"))
3157 loc
->limit
|= AUTH_LIMIT_HEAD
;
3158 else if (!strcmp(value
, "OPTIONS"))
3159 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3160 else if (!strcmp(value
, "POST"))
3161 loc
->limit
|= AUTH_LIMIT_POST
;
3162 else if (!strcmp(value
, "PUT"))
3163 loc
->limit
|= AUTH_LIMIT_PUT
;
3164 else if (!strcmp(value
, "TRACE"))
3165 loc
->limit
|= AUTH_LIMIT_TRACE
;
3167 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3170 for (value
= valptr
; isspace(*value
& 255); value
++);
3173 if (!strcasecmp(line
, "<LimitExcept"))
3174 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3176 parent
->limit
&= ~loc
->limit
;
3178 else if (!strcasecmp(line
, "</Limit>"))
3180 else if (!parse_aaa(loc
, line
, value
, linenum
))
3182 cupsdLogMessage(CUPSD_LOG_ERROR
,
3183 "Unknown Location directive %s on line %d.",
3189 cupsdLogMessage(CUPSD_LOG_ERROR
,
3190 "Unexpected end-of-file at line %d while reading location!",
3198 * 'read_policy()' - Read a <Policy name> definition.
3201 static int /* O - New line number or 0 on error */
3202 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3203 char *policy
, /* I - Location name/path */
3204 int linenum
) /* I - Current line number */
3206 int i
; /* Looping var */
3207 cupsd_policy_t
*pol
; /* Policy */
3208 cupsd_location_t
*op
; /* Policy operation */
3209 int num_ops
; /* Number of IPP operations */
3210 ipp_op_t ops
[100]; /* Operations */
3211 char line
[HTTP_MAX_BUFFER
],
3213 *value
, /* Value for directive */
3214 *valptr
; /* Pointer into value */
3218 * Create the policy...
3221 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3225 * Read from the file...
3231 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3234 * Decode the directive...
3237 if (!strcasecmp(line
, "</Policy>"))
3240 cupsdLogMessage(CUPSD_LOG_WARN
,
3241 "Missing </Limit> before </Policy> on line %d!",
3246 else if (!strcasecmp(line
, "<Limit") && !op
)
3250 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3255 * Scan for IPP operation names...
3262 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3267 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3269 if (!strcasecmp(value
, "All"))
3270 ops
[num_ops
] = IPP_ANY_OPERATION
;
3271 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3272 cupsdLogMessage(CUPSD_LOG_ERROR
,
3273 "Bad IPP operation name \"%s\" on line %d!",
3279 cupsdLogMessage(CUPSD_LOG_ERROR
,
3280 "Too many operations listed on line %d!",
3283 for (value
= valptr
; isspace(*value
& 255); value
++);
3287 * If none are specified, apply the policy to all operations...
3292 ops
[0] = IPP_ANY_OPERATION
;
3297 * Add a new policy for the first operation...
3300 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3302 else if (!strcasecmp(line
, "</Limit>") && op
)
3305 * Finish the current operation limit...
3311 * Copy the policy to the other operations...
3314 for (i
= 1; i
< num_ops
; i
++)
3315 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3322 cupsdLogMessage(CUPSD_LOG_ERROR
,
3323 "Missing <Limit ops> directive before %s on line %d.",
3327 else if (!parse_aaa(op
, line
, value
, linenum
))
3330 cupsdLogMessage(CUPSD_LOG_ERROR
,
3331 "Unknown Policy Limit directive %s on line %d.",
3334 cupsdLogMessage(CUPSD_LOG_ERROR
,
3335 "Unknown Policy directive %s on line %d.",
3342 cupsdLogMessage(CUPSD_LOG_ERROR
,
3343 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3351 * End of "$Id: conf.c 6365 2007-03-19 20:56:57Z mike $".