2 * "$Id: conf.c 7694 2008-06-26 00:23:20Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 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 * cupsdCheckPermissions() - Fix the mode and ownership of a file or
19 * cupsdReadConfiguration() - Read the cupsd.conf file.
20 * get_address() - Get an address + port number from a line.
21 * get_addr_and_mask() - Get an IP address and netmask.
22 * parse_aaa() - Parse authentication, authorization, and
23 * access control lines.
24 * parse_groups() - Parse system group names in a string.
25 * parse_protocols() - Parse browse protocols in a string.
26 * read_configuration() - Read a configuration file.
27 * read_location() - Read a <Location path> definition.
28 * read_policy() - Read a <Policy name> definition.
32 * Include necessary headers...
38 #include <sys/utsname.h>
43 * Possibly missing network definitions...
47 # define INADDR_NONE 0xffffffff
48 #endif /* !INADDR_NONE */
52 * Configuration variable structure...
57 CUPSD_VARTYPE_INTEGER
, /* Integer option */
58 CUPSD_VARTYPE_STRING
, /* String option */
59 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
60 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
65 char *name
; /* Name of variable */
66 void *ptr
; /* Pointer to variable */
67 cupsd_vartype_t type
; /* Type (int, string, address) */
75 static const cupsd_var_t variables
[] =
77 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
79 { "AppleQuotas", &AppleQuotas
, CUPSD_VARTYPE_BOOLEAN
},
80 #endif /* __APPLE__ */
81 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
82 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
84 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
86 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
87 # endif /* HAVE_LDAP_SSL */
88 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
89 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
90 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
91 #endif /* HAVE_LDAP */
92 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
93 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
94 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
95 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
96 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
97 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
98 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
99 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
100 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
101 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
102 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
103 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
104 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
105 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
106 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
107 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
108 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
109 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
110 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
111 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
112 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
113 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
114 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
115 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
116 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
118 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
119 #endif /* HAVE_GSSAPI */
120 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
121 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
122 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
123 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
124 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
125 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
126 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
128 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
129 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
130 #endif /* HAVE_LAUNCHD */
131 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
132 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
133 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
134 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
135 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
151 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
152 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
153 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
154 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
155 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
156 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
157 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
158 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
159 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
160 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
161 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
162 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
163 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
165 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
166 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
167 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
168 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
169 #endif /* HAVE_SSL */
170 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
171 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
172 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
173 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
174 #ifdef HAVE_AUTHORIZATION_H
175 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
176 #endif /* HAVE_AUTHORIZATION_H */
177 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
178 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
179 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
181 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
184 static const unsigned ones
[4] =
186 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
188 static const unsigned zeros
[4] =
190 0x00000000, 0x00000000, 0x00000000, 0x00000000
197 static http_addrlist_t
*get_address(const char *value
, int defport
);
198 static int get_addr_and_mask(const char *value
, unsigned *ip
,
200 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
201 char *value
, int linenum
);
202 static int parse_groups(const char *s
);
203 static int parse_protocols(const char *s
);
204 static int read_configuration(cups_file_t
*fp
);
205 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
206 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
210 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
213 int /* O - 0 on success, -1 on error, 1 on warning */
214 cupsdCheckPermissions(
215 const char *filename
, /* I - File/directory name */
216 const char *suffix
, /* I - Additional file/directory name */
217 int mode
, /* I - Permissions */
218 int user
, /* I - Owner */
219 int group
, /* I - Group */
220 int is_dir
, /* I - 1 = directory, 0 = file */
221 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
223 int dir_created
= 0; /* Did we create a directory? */
224 char pathname
[1024]; /* File name with prefix */
225 struct stat fileinfo
; /* Stat buffer */
229 * Prepend the given root to the filename before testing it...
234 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
239 * See if we can stat the file/directory...
242 if (stat(filename
, &fileinfo
))
244 if (errno
== ENOENT
&& create_dir
)
247 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
250 if (mkdir(filename
, mode
))
253 cupsdLogMessage(CUPSD_LOG_ERROR
,
254 "Unable to create directory \"%s\" - %s", filename
,
257 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
266 return (create_dir
? -1 : 1);
270 * Make sure it's a regular file...
273 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
275 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
279 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
282 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
284 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
290 * Fix owner, group, and mode as needed...
293 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
296 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
299 if (chown(filename
, user
, group
) && !getuid())
302 cupsdLogMessage(CUPSD_LOG_ERROR
,
303 "Unable to change ownership of \"%s\" - %s", filename
,
306 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
313 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
316 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
319 if (chmod(filename
, mode
))
322 cupsdLogMessage(CUPSD_LOG_ERROR
,
323 "Unable to change permissions of \"%s\" - %s", filename
,
326 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
334 * Everything is OK...
342 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
345 int /* O - 1 on success, 0 otherwise */
346 cupsdReadConfiguration(void)
348 int i
; /* Looping var */
349 cups_file_t
*fp
; /* Configuration file */
350 int status
; /* Return status */
351 char temp
[1024], /* Temporary buffer */
352 mimedir
[1024], /* MIME directory */
353 *slash
; /* Directory separator */
354 cups_lang_t
*language
; /* Language */
355 struct passwd
*user
; /* Default user */
356 struct group
*group
; /* Default group */
357 char *old_serverroot
, /* Old ServerRoot */
358 *old_requestroot
; /* Old RequestRoot */
359 const char *tmpdir
; /* TMPDIR environment variable */
360 struct stat tmpinfo
; /* Temporary directory info */
361 cupsd_policy_t
*p
; /* Policy */
365 * Save the old root paths...
368 old_serverroot
= NULL
;
369 cupsdSetString(&old_serverroot
, ServerRoot
);
370 old_requestroot
= NULL
;
371 cupsdSetString(&old_requestroot
, RequestRoot
);
374 * Reset the server configuration data...
377 cupsdDeleteAllLocations();
396 for (i
= 0; i
< NumRelays
; i
++)
397 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
398 free(Relays
[i
].from
.mask
.name
.name
);
405 cupsdDeleteAllListeners();
411 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
412 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
413 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
414 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
415 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
416 cupsdSetString(&DataDir
, CUPS_DATADIR
);
417 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
418 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
419 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
420 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
421 cupsdSetString(&PageLogFormat
,
422 "%p %j %u %T %P %C %{job-billing} "
423 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
424 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
425 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
426 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
427 cupsdSetString(&RemoteRoot
, "remroot");
428 cupsdSetString(&ServerHeader
, "CUPS/1.4");
429 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
431 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
432 #endif /* HAVE_GSSAPI */
434 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
435 PrintcapFormat
= PRINTCAP_SOLARIS
;
437 PrintcapFormat
= PRINTCAP_BSD
;
439 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
440 if ((slash
= strrchr(temp
, '/')) != NULL
)
443 cupsdSetString(&ServerRoot
, temp
);
445 cupsdClearString(&Classification
);
446 ClassifyOverride
= 0;
450 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
452 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
453 cupsdSetString(&ServerKey
, "ssl/server.key");
454 # endif /* HAVE_CDSASSL */
455 #endif /* HAVE_SSL */
457 language
= cupsLangDefault();
459 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
460 cupsdSetString(&DefaultLanguage
, "en");
462 cupsdSetString(&DefaultLanguage
, language
->language
);
464 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
466 cupsdClearString(&DefaultPaperSize
);
468 cupsdSetString(&RIPCache
, "8m");
470 cupsdSetString(&TempDir
, NULL
);
473 * Find the default user...
476 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
481 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
482 * complement number...)
491 * Find the default group...
494 group
= getgrnam(CUPS_DEFAULT_GROUP
);
498 Group
= group
->gr_gid
;
502 * Fallback to group "nobody"...
505 group
= getgrnam("nobody");
509 Group
= group
->gr_gid
;
513 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
514 * complement number...)
525 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
526 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
527 DefaultAuthType
= CUPSD_AUTH_BASIC
;
529 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
530 #endif /* HAVE_SSL */
531 DirtyCleanInterval
= 60;
533 JobRetryInterval
= 300;
538 HostNameLookups
= FALSE
;
539 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
540 ImplicitAnyClasses
= FALSE
;
541 HideImplicitMembers
= TRUE
;
543 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
544 ListenBackLog
= SOMAXCONN
;
545 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
546 LogLevel
= CUPSD_LOG_WARN
;
548 MaxClientsPerHost
= 0;
549 MaxLogSize
= 1024 * 1024;
550 MaxPrinterHistory
= 10;
553 RootCertDuration
= 300;
554 Timeout
= DEFAULT_TIMEOUT
;
557 BrowseInterval
= DEFAULT_INTERVAL
;
558 BrowsePort
= ippPort();
559 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
560 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
561 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
562 BrowseTimeout
= DEFAULT_TIMEOUT
;
563 Browsing
= CUPS_DEFAULT_BROWSING
;
564 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
566 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
567 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
569 cupsdClearString(&BrowseLocalOptions
);
570 cupsdClearString(&BrowseRemoteOptions
);
572 cupsdSetString(&ErrorPolicy
, "stop-printer");
575 cupsdClearString(&BrowseLDAPBindDN
);
576 cupsdClearString(&BrowseLDAPDN
);
577 cupsdClearString(&BrowseLDAPPassword
);
578 cupsdClearString(&BrowseLDAPServer
);
579 # ifdef HAVE_LDAP_SSL
580 cupsdClearString(&BrowseLDAPCACertFile
);
581 # endif /* HAVE_LDAP_SSL */
582 #endif /* HAVE_LDAP */
584 JobHistory
= DEFAULT_HISTORY
;
585 JobFiles
= DEFAULT_FILES
;
590 MaxJobsPerPrinter
= 0;
591 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
593 cupsdDeleteAllPolicies();
594 cupsdClearString(&DefaultPolicy
);
596 #ifdef HAVE_AUTHORIZATION_H
597 cupsdClearString(&SystemGroupAuthKey
);
598 #endif /* HAVE_AUTHORIZATION_H */
600 MaxSubscriptions
= 100;
601 MaxSubscriptionsPerJob
= 0;
602 MaxSubscriptionsPerPrinter
= 0;
603 MaxSubscriptionsPerUser
= 0;
604 DefaultLeaseDuration
= 86400;
605 MaxLeaseDuration
= 0;
608 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
609 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
610 #endif /* HAVE_LAUNCHD */
614 #endif /* __APPLE__ */
617 * Read the configuration file...
620 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
623 status
= read_configuration(fp
);
633 * See if the ServerName is an IP address...
636 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
638 ServerNameIsIP
= !*slash
;
641 * Use the default system group if none was supplied in cupsd.conf...
644 if (NumSystemGroups
== 0)
646 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
649 * Find the group associated with GID 0...
656 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
658 cupsdSetString(&SystemGroups
[0], "unknown");
660 SystemGroupIDs
[0] = 0;
666 * Get the access control list for browsing...
669 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
672 * Open the system log for cupsd if necessary...
676 if (!strcmp(AccessLog
, "syslog") ||
677 !strcmp(ErrorLog
, "syslog") ||
678 !strcmp(PageLog
, "syslog"))
679 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
680 #endif /* HAVE_VSYSLOG */
683 * Log the configuration file that was used...
686 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
690 * Validate the Group and SystemGroup settings - they cannot be the same,
691 * otherwise the CGI programs will be able to authenticate as root without
697 for (i
= 0; i
< NumSystemGroups
; i
++)
698 if (Group
== SystemGroupIDs
[i
])
701 if (i
< NumSystemGroups
)
704 * Log the error and reset the group to a safe value...
707 cupsdLogMessage(CUPSD_LOG_NOTICE
,
708 "Group and SystemGroup cannot use the same groups!");
709 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
711 group
= getgrnam("nobody");
715 Group
= group
->gr_gid
;
719 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
720 * complement number...)
729 * Check that we have at least one listen/port line; if not, report this
730 * as an error and exit!
733 if (cupsArrayCount(Listeners
) == 0)
739 cupsdLogMessage(CUPSD_LOG_EMERG
,
740 "No valid Listen or Port lines were found in the configuration file!");
746 cupsdEndProcess(getpid(), 0);
750 * Set the default locale using the language and charset...
753 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
756 * Update all relative filenames to include the full path from ServerRoot...
759 if (DocumentRoot
[0] != '/')
760 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
762 if (RequestRoot
[0] != '/')
763 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
765 if (ServerBin
[0] != '/')
766 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
768 if (StateDir
[0] != '/')
769 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
771 if (CacheDir
[0] != '/')
772 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
775 if (ServerCertificate
[0] != '/')
776 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
778 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
780 chown(ServerCertificate
, RunUser
, Group
);
781 chmod(ServerCertificate
, 0600);
784 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
785 if (ServerKey
[0] != '/')
786 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
788 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
790 chown(ServerKey
, RunUser
, Group
);
791 chmod(ServerKey
, 0600);
793 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
794 #endif /* HAVE_SSL */
797 * Make sure that directories and config files are owned and
798 * writable by the user and group in the cupsd.conf file...
801 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
803 if (cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
805 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
807 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
809 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
811 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
812 SystemGroupIDs
[0], 1, 1) < 0 ||
813 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
815 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
817 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
819 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
821 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
823 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
825 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
830 * Update TempDir to the default if it hasn't been set already...
835 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
838 * TMPDIR is defined, see if it is OK for us to use...
841 if (stat(tmpdir
, &tmpinfo
))
842 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
843 tmpdir
, strerror(errno
));
844 else if (!S_ISDIR(tmpinfo
.st_mode
))
845 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
847 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
848 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
849 !(tmpinfo
.st_mode
& S_IWOTH
))
850 cupsdLogMessage(CUPSD_LOG_ERROR
,
851 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
853 cupsdSetString(&TempDir
, tmpdir
);
858 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
860 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
865 * Make sure the temporary directory has the right permissions...
868 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
872 * Update ownership and permissions if the CUPS temp directory
873 * is under the spool directory or does not exist...
876 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
881 * Setup environment variables...
887 * Update default paper size setting as needed...
890 if (!DefaultPaperSize
)
893 char *paper_result
; /* Paper size name from libpaper */
895 if ((paper_result
= systempapername()) != NULL
)
896 cupsdSetString(&DefaultPaperSize
, paper_result
);
898 #endif /* HAVE_LIBPAPER */
899 if (!DefaultLanguage
||
900 !strcasecmp(DefaultLanguage
, "C") ||
901 !strcasecmp(DefaultLanguage
, "POSIX") ||
902 !strcasecmp(DefaultLanguage
, "en") ||
903 !strncasecmp(DefaultLanguage
, "en.", 3) ||
904 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
905 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
906 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
909 * These are the only locales that will default to "letter" size...
912 cupsdSetString(&DefaultPaperSize
, "Letter");
915 cupsdSetString(&DefaultPaperSize
, "A4");
919 * Update classification setting as needed...
922 if (Classification
&& !strcasecmp(Classification
, "none"))
923 cupsdClearString(&Classification
);
926 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
929 * Check the MaxClients setting, and then allocate memory for it...
932 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
935 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
938 MaxClients
= MaxFDs
/ 3;
941 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
945 * Check the MaxActiveJobs setting; limit to 1/3 the available
946 * file descriptors, since we need a pipe for each job...
949 if (MaxActiveJobs
> (MaxFDs
/ 3))
950 MaxActiveJobs
= MaxFDs
/ 3;
953 * Update the MaxClientsPerHost value, as needed...
956 if (MaxClientsPerHost
<= 0)
957 MaxClientsPerHost
= MaxClients
;
959 if (MaxClientsPerHost
> MaxClients
)
960 MaxClientsPerHost
= MaxClients
;
962 cupsdLogMessage(CUPSD_LOG_INFO
,
963 "Allowing up to %d client connections per host.",
967 * Make sure that BrowseTimeout is at least twice the interval...
970 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
972 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
976 BrowseTimeout
= BrowseInterval
* 2;
978 BrowseTimeout
= DEFAULT_TIMEOUT
;
980 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
985 * Update the default policy, as needed...
989 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
991 DefaultPolicyPtr
= NULL
;
993 if (!DefaultPolicyPtr
)
995 cupsd_location_t
*po
; /* New policy operation */
999 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1002 cupsdSetString(&DefaultPolicy
, "default");
1004 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1005 cupsdLogMessage(CUPSD_LOG_INFO
,
1006 "Using policy \"default\" as the default!");
1009 cupsdLogMessage(CUPSD_LOG_INFO
,
1010 "Creating CUPS default administrative policy:");
1012 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1014 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1015 cupsdLogMessage(CUPSD_LOG_INFO
,
1016 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1017 "Release-Job Restart-Job Purge-Jobs "
1018 "Set-Job-Attributes Create-Job-Subscription "
1019 "Renew-Subscription Cancel-Subscription "
1020 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1021 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1022 "CUPS-Authenticate-Job CUPS-Get-Document>");
1023 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1025 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1026 po
->order_type
= CUPSD_AUTH_ALLOW
;
1027 po
->level
= CUPSD_AUTH_USER
;
1029 cupsdAddName(po
, "@OWNER");
1030 cupsdAddName(po
, "@SYSTEM");
1031 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1033 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1034 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1035 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1036 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1037 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1038 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1039 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1040 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1041 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1042 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1043 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1044 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1045 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1046 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1047 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1048 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1049 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1050 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1052 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1054 cupsdLogMessage(CUPSD_LOG_INFO
,
1055 "<Limit Pause-Printer Resume-Printer "
1056 "Set-Printer-Attributes Enable-Printer "
1057 "Disable-Printer Pause-Printer-After-Current-Job "
1058 "Hold-New-Jobs Release-Held-New-Jobs "
1059 "Deactivate-Printer Activate-Printer Restart-Printer "
1060 "Shutdown-Printer Startup-Printer Promote-Job "
1061 "Schedule-Job-After CUPS-Add-Printer "
1062 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1063 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1064 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1065 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1067 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1068 po
->order_type
= CUPSD_AUTH_ALLOW
;
1069 po
->type
= CUPSD_AUTH_DEFAULT
;
1070 po
->level
= CUPSD_AUTH_USER
;
1072 cupsdAddName(po
, "@SYSTEM");
1073 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1075 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1076 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1077 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1078 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1079 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1080 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1081 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1082 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1083 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1084 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1085 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1086 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1087 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1088 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1089 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1090 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1091 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1092 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1093 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1094 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1095 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1097 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1099 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1100 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1102 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1103 po
->order_type
= CUPSD_AUTH_ALLOW
;
1105 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1106 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1110 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1111 cupsArrayCount(Policies
));
1112 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1114 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1115 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1116 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1119 * If we are doing a full reload or the server root has changed, flush
1120 * the jobs, printers, etc. and start from scratch...
1123 if (NeedReload
== RELOAD_ALL
||
1124 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1125 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1127 mime_type_t
*type
; /* Current type */
1128 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1129 /* MIME type name */
1132 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1135 * Free all memory...
1138 cupsdDeleteAllSubscriptions();
1140 cupsdDeleteAllClasses();
1141 cupsdDeleteAllPrinters();
1143 DefaultPrinter
= NULL
;
1145 if (MimeDatabase
!= NULL
)
1146 mimeDelete(MimeDatabase
);
1150 for (i
= 0; i
< NumMimeTypes
; i
++)
1151 _cupsStrFree(MimeTypes
[i
]);
1157 * Read the MIME type and conversion database...
1160 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1161 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1163 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1164 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1165 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1166 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1170 cupsdLogMessage(CUPSD_LOG_EMERG
,
1171 "Unable to load MIME database from \"%s\" or \"%s\"!",
1172 mimedir
, ServerRoot
);
1176 cupsdLogMessage(CUPSD_LOG_INFO
,
1177 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1178 "%d filters...", mimedir
, ServerRoot
,
1179 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1182 * Create a list of MIME types for the document-format-supported
1186 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1187 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1190 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1192 cupsdLogMessage(CUPSD_LOG_ERROR
,
1193 "Unable to allocate memory for %d MIME types!",
1199 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1201 i
++, type
= mimeNextType(MimeDatabase
))
1203 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1205 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1208 if (i
< NumMimeTypes
)
1209 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1212 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1214 mime_filter_t
*filter
; /* Current filter */
1217 for (type
= mimeFirstType(MimeDatabase
);
1219 type
= mimeNextType(MimeDatabase
))
1220 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1221 type
->super
, type
->type
);
1223 for (filter
= mimeFirstFilter(MimeDatabase
);
1225 filter
= mimeNextFilter(MimeDatabase
))
1226 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1227 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1228 filter
->src
->super
, filter
->src
->type
,
1229 filter
->dst
->super
, filter
->dst
->type
,
1230 filter
->cost
, filter
->filter
);
1237 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1238 cupsdLoadBanners(temp
);
1241 * Load printers and classes...
1244 cupsdLoadAllPrinters();
1245 cupsdLoadAllClasses();
1246 cupsdLoadRemoteCache();
1247 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1249 cupsdCreateCommonData();
1252 * Load queued jobs...
1258 * Load subscriptions...
1261 cupsdLoadAllSubscriptions();
1263 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1268 * Not a full reload, so recreate the common printer attributes...
1271 cupsdCreateCommonData();
1274 * Update all printers as needed...
1277 cupsdUpdatePrinters();
1278 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1280 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1284 * Reset the reload state...
1287 NeedReload
= RELOAD_NONE
;
1289 cupsdClearString(&old_serverroot
);
1290 cupsdClearString(&old_requestroot
);
1297 * 'get_address()' - Get an address + port number from a line.
1300 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1301 get_address(const char *value
, /* I - Value string */
1302 int defport
) /* I - Default port */
1304 char buffer
[1024], /* Hostname + port number buffer */
1305 defpname
[255], /* Default port name */
1306 *hostname
, /* Hostname or IP */
1307 *portname
; /* Port number or name */
1308 http_addrlist_t
*addrlist
; /* Address list */
1312 * Check for an empty value...
1317 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1322 * Grab a hostname and port number; if there is no colon and the port name
1323 * is only digits, then we have a port number by itself...
1326 strlcpy(buffer
, value
, sizeof(buffer
));
1328 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1335 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1340 * Use the default port...
1343 sprintf(defpname
, "%d", defport
);
1344 portname
= defpname
;
1350 * The buffer contains just a port number...
1358 if (hostname
&& !strcmp(hostname
, "*"))
1362 * Now lookup the address using httpAddrGetList()...
1365 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1366 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1367 hostname
? hostname
: "(nil)");
1374 * 'get_addr_and_mask()' - Get an IP address and netmask.
1377 static int /* O - 1 on success, 0 on failure */
1378 get_addr_and_mask(const char *value
, /* I - String from config file */
1379 unsigned *ip
, /* O - Address value */
1380 unsigned *mask
) /* O - Mask value */
1382 int i
, j
, /* Looping vars */
1383 family
, /* Address family */
1384 ipcount
; /* Count of fields in address */
1385 unsigned ipval
; /* Value */
1386 const char *maskval
, /* Pointer to start of mask value */
1387 *ptr
, /* Pointer into value */
1392 * Get the address...
1395 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1396 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1398 if ((maskval
= strchr(value
, '/')) != NULL
)
1401 maskval
= value
+ strlen(value
);
1405 * Check for an IPv6 address...
1411 * Parse hexadecimal IPv6 address...
1416 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1420 else if (!strncmp(ptr
, "::", 2))
1422 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1424 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1429 else if (isxdigit(*ptr
& 255))
1431 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1439 ip
[i
/ 2] |= ipval
<< 16;
1453 if (*ptr
&& *ptr
!= '/')
1457 #endif /* AF_INET6 */
1460 * Parse dotted-decimal IPv4 address...
1463 unsigned val
[4]; /* IPv4 address values */
1467 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1470 * Range check the IP numbers...
1473 for (i
= 0; i
< ipcount
; i
++)
1478 * Make sure the trailing values are zeroed, as some C libraries like
1479 * glibc apparently like to fill the unused arguments with garbage...
1482 for (i
= ipcount
; i
< 4; i
++)
1486 * Merge everything into a 32-bit IPv4 address in ip[3]...
1489 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1492 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1498 * Get the netmask value(s)...
1501 memset(mask
, 0, sizeof(unsigned) * 4);
1503 if (strchr(maskval
, '.'))
1506 * Get dotted-decimal mask...
1509 if (family
!= AF_INET
)
1512 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1515 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1516 mask
[0] = mask
[1] = mask
[2] = 0;
1521 * Get address/bits format...
1527 if (family
== AF_INET6
)
1535 mask
[0] = 0xffffffff;
1537 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1540 mask
[1] = 0xffffffff;
1544 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1547 mask
[2] = 0xffffffff;
1551 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1554 mask
[3] = 0xffffffff;
1558 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1561 #endif /* AF_INET6 */
1566 mask
[0] = 0xffffffff;
1567 mask
[1] = 0xffffffff;
1568 mask
[2] = 0xffffffff;
1571 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1573 mask
[3] = 0xffffffff;
1578 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1579 "get_addr_and_mask(value=\"%s\", "
1580 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1581 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1585 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1588 if ((ip
[0] & ~mask
[0]) != 0 ||
1589 (ip
[1] & ~mask
[1]) != 0 ||
1590 (ip
[2] & ~mask
[2]) != 0 ||
1591 (ip
[3] & ~mask
[3]) != 0)
1599 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1602 static int /* O - 1 on success, 0 on failure */
1603 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1604 char *line
, /* I - Line from file */
1605 char *value
, /* I - Start of value data */
1606 int linenum
) /* I - Current line number */
1608 char *valptr
; /* Pointer into value */
1609 unsigned ip
[4], /* IP address components */
1610 mask
[4]; /* IP netmask components */
1613 if (!strcasecmp(line
, "Encryption"))
1616 * "Encryption xxx" - set required encryption level...
1619 if (!strcasecmp(value
, "never"))
1620 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1621 else if (!strcasecmp(value
, "always"))
1623 cupsdLogMessage(CUPSD_LOG_ERROR
,
1624 "Encryption value \"%s\" on line %d is invalid in this "
1625 "context. Using \"required\" instead.", value
, linenum
);
1627 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1629 else if (!strcasecmp(value
, "required"))
1630 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1631 else if (!strcasecmp(value
, "ifrequested"))
1632 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1635 cupsdLogMessage(CUPSD_LOG_ERROR
,
1636 "Unknown Encryption value %s on line %d.", value
, linenum
);
1640 else if (!strcasecmp(line
, "Order"))
1643 * "Order Deny,Allow" or "Order Allow,Deny"...
1646 if (!strncasecmp(value
, "deny", 4))
1647 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1648 else if (!strncasecmp(value
, "allow", 5))
1649 loc
->order_type
= CUPSD_AUTH_DENY
;
1652 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1657 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1660 * Allow [From] host/ip...
1661 * Deny [From] host/ip...
1664 if (!strncasecmp(value
, "from", 4))
1667 * Strip leading "from"...
1672 while (isspace(*value
& 255))
1677 * Figure out what form the allow/deny address takes:
1688 * nnn.nnn.nnn.nnn/mm
1689 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1692 if (!strcasecmp(value
, "all"))
1698 if (!strcasecmp(line
, "Allow"))
1699 cupsdAllowIP(loc
, zeros
, zeros
);
1701 cupsdDenyIP(loc
, zeros
, zeros
);
1703 else if (!strcasecmp(value
, "none"))
1709 if (!strcasecmp(line
, "Allow"))
1710 cupsdAllowIP(loc
, ones
, zeros
);
1712 cupsdDenyIP(loc
, ones
, zeros
);
1715 else if (value
[0] == '*' || value
[0] == '.' ||
1716 (!isdigit(value
[0] & 255) && value
[0] != '['))
1718 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1719 #endif /* AF_INET6 */
1722 * Host or domain name...
1725 if (value
[0] == '*')
1728 if (!strcasecmp(line
, "Allow"))
1729 cupsdAllowHost(loc
, value
);
1731 cupsdDenyHost(loc
, value
);
1736 * One of many IP address forms...
1739 if (!get_addr_and_mask(value
, ip
, mask
))
1741 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1746 if (!strcasecmp(line
, "Allow"))
1747 cupsdAllowIP(loc
, ip
, mask
);
1749 cupsdDenyIP(loc
, ip
, mask
);
1752 else if (!strcasecmp(line
, "AuthType"))
1755 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1758 if (!strcasecmp(value
, "none"))
1760 loc
->type
= CUPSD_AUTH_NONE
;
1761 loc
->level
= CUPSD_AUTH_ANON
;
1763 else if (!strcasecmp(value
, "basic"))
1765 loc
->type
= CUPSD_AUTH_BASIC
;
1767 if (loc
->level
== CUPSD_AUTH_ANON
)
1768 loc
->level
= CUPSD_AUTH_USER
;
1770 else if (!strcasecmp(value
, "digest"))
1772 loc
->type
= CUPSD_AUTH_DIGEST
;
1774 if (loc
->level
== CUPSD_AUTH_ANON
)
1775 loc
->level
= CUPSD_AUTH_USER
;
1777 else if (!strcasecmp(value
, "basicdigest"))
1779 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1781 if (loc
->level
== CUPSD_AUTH_ANON
)
1782 loc
->level
= CUPSD_AUTH_USER
;
1784 else if (!strcasecmp(value
, "default"))
1786 loc
->type
= CUPSD_AUTH_DEFAULT
;
1788 if (loc
->level
== CUPSD_AUTH_ANON
)
1789 loc
->level
= CUPSD_AUTH_USER
;
1792 else if (!strcasecmp(value
, "negotiate"))
1794 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1796 if (loc
->level
== CUPSD_AUTH_ANON
)
1797 loc
->level
= CUPSD_AUTH_USER
;
1799 #endif /* HAVE_GSSAPI */
1802 cupsdLogMessage(CUPSD_LOG_WARN
,
1803 "Unknown authorization type %s on line %d.",
1808 else if (!strcasecmp(line
, "AuthClass"))
1811 * AuthClass anonymous, user, system, group
1814 if (!strcasecmp(value
, "anonymous"))
1816 loc
->type
= CUPSD_AUTH_NONE
;
1817 loc
->level
= CUPSD_AUTH_ANON
;
1819 cupsdLogMessage(CUPSD_LOG_WARN
,
1820 "\"AuthClass %s\" is deprecated; consider removing "
1824 else if (!strcasecmp(value
, "user"))
1826 loc
->level
= CUPSD_AUTH_USER
;
1828 cupsdLogMessage(CUPSD_LOG_WARN
,
1829 "\"AuthClass %s\" is deprecated; consider using "
1830 "\"Require valid-user\" on line %d.",
1833 else if (!strcasecmp(value
, "group"))
1835 loc
->level
= CUPSD_AUTH_GROUP
;
1837 cupsdLogMessage(CUPSD_LOG_WARN
,
1838 "\"AuthClass %s\" is deprecated; consider using "
1839 "\"Require user @groupname\" on line %d.",
1842 else if (!strcasecmp(value
, "system"))
1844 loc
->level
= CUPSD_AUTH_GROUP
;
1846 cupsdAddName(loc
, "@SYSTEM");
1848 cupsdLogMessage(CUPSD_LOG_WARN
,
1849 "\"AuthClass %s\" is deprecated; consider using "
1850 "\"Require user @SYSTEM\" on line %d.",
1855 cupsdLogMessage(CUPSD_LOG_WARN
,
1856 "Unknown authorization class %s on line %d.",
1861 else if (!strcasecmp(line
, "AuthGroupName"))
1863 cupsdAddName(loc
, value
);
1865 cupsdLogMessage(CUPSD_LOG_WARN
,
1866 "\"AuthGroupName %s\" directive is deprecated; consider "
1867 "using \"Require user @%s\" on line %d.",
1868 value
, value
, linenum
);
1870 else if (!strcasecmp(line
, "Require"))
1873 * Apache synonym for AuthClass and AuthGroupName...
1877 * Require valid-user
1878 * Require group names
1879 * Require user names
1882 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1887 if (!strcasecmp(value
, "valid-user") ||
1888 !strcasecmp(value
, "user"))
1889 loc
->level
= CUPSD_AUTH_USER
;
1890 else if (!strcasecmp(value
, "group"))
1891 loc
->level
= CUPSD_AUTH_GROUP
;
1894 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1900 * Get the list of names from the line...
1903 for (value
= valptr
; *value
;)
1905 while (isspace(*value
& 255))
1908 #ifdef HAVE_AUTHORIZATION_H
1909 if (!strncmp(value
, "@AUTHKEY(", 9))
1912 * Grab "@AUTHKEY(name)" value...
1915 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1921 #endif /* HAVE_AUTHORIZATION_H */
1922 if (*value
== '\"' || *value
== '\'')
1925 * Grab quoted name...
1928 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1935 * Grab literal name.
1938 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1944 cupsdAddName(loc
, value
);
1946 for (value
= valptr
; isspace(*value
& 255); value
++);
1949 else if (!strcasecmp(line
, "Satisfy"))
1951 if (!strcasecmp(value
, "all"))
1952 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
1953 else if (!strcasecmp(value
, "any"))
1954 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
1957 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1970 * 'parse_groups()' - Parse system group names in a string.
1973 static int /* O - 1 on success, 0 on failure */
1974 parse_groups(const char *s
) /* I - Space-delimited groups */
1976 int status
; /* Return status */
1977 char value
[1024], /* Value string */
1978 *valstart
, /* Pointer into value */
1979 *valend
, /* End of value */
1980 quote
; /* Quote character */
1981 struct group
*group
; /* Group */
1985 * Make a copy of the string and parse out the groups...
1988 strlcpy(value
, s
, sizeof(value
));
1993 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1995 if (*valstart
== '\'' || *valstart
== '\"')
1998 * Scan quoted name...
2001 quote
= *valstart
++;
2003 for (valend
= valstart
; *valend
; valend
++)
2004 if (*valend
== quote
)
2010 * Scan space or comma-delimited name...
2013 for (valend
= valstart
; *valend
; valend
++)
2014 if (isspace(*valend
) || *valend
== ',')
2021 group
= getgrnam(valstart
);
2024 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2025 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2036 while (*valstart
== ',' || isspace(*valstart
))
2045 * 'parse_protocols()' - Parse browse protocols in a string.
2048 static int /* O - Browse protocol bits */
2049 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2051 int protocols
; /* Browse protocol bits */
2052 char value
[1024], /* Value string */
2053 *valstart
, /* Pointer into value */
2054 *valend
; /* End of value */
2058 * Empty protocol line yields NULL pointer...
2065 * Loop through the value string,...
2068 strlcpy(value
, s
, sizeof(value
));
2072 for (valstart
= value
; *valstart
;)
2075 * Get the current space/comma-delimited protocol name...
2078 for (valend
= valstart
; *valend
; valend
++)
2079 if (isspace(*valend
& 255) || *valend
== ',')
2086 * Add the protocol to the bitmask...
2089 if (!strcasecmp(valstart
, "cups"))
2090 protocols
|= BROWSE_CUPS
;
2091 else if (!strcasecmp(valstart
, "slp"))
2092 protocols
|= BROWSE_SLP
;
2093 else if (!strcasecmp(valstart
, "ldap"))
2094 protocols
|= BROWSE_LDAP
;
2095 else if (!strcasecmp(valstart
, "dnssd") ||
2096 !strcasecmp(valstart
, "dns-sd") ||
2097 !strcasecmp(valstart
, "bonjour"))
2098 protocols
|= BROWSE_DNSSD
;
2099 else if (!strcasecmp(valstart
, "lpd"))
2100 protocols
|= BROWSE_LPD
;
2101 else if (!strcasecmp(valstart
, "smb"))
2102 protocols
|= BROWSE_SMB
;
2103 else if (!strcasecmp(valstart
, "all"))
2104 protocols
|= BROWSE_ALL
;
2105 else if (strcasecmp(valstart
, "none"))
2106 cupsdLogMessage(CUPSD_LOG_ERROR
,
2107 "Unknown browse protocol \"%s\" ignored!", valstart
);
2109 for (valstart
= valend
; *valstart
; valstart
++)
2110 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2119 * 'read_configuration()' - Read a configuration file.
2122 static int /* O - 1 on success, 0 on failure */
2123 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2125 int i
; /* Looping var */
2126 int linenum
; /* Current line number */
2127 char line
[HTTP_MAX_BUFFER
],
2128 /* Line from file */
2129 temp
[HTTP_MAX_BUFFER
],
2130 /* Temporary buffer for value */
2131 temp2
[HTTP_MAX_BUFFER
],
2132 /* Temporary buffer 2 for value */
2133 *ptr
, /* Pointer into line/temp */
2134 *value
, /* Pointer to value */
2135 *valueptr
; /* Pointer into value */
2136 int valuelen
; /* Length of value */
2137 cupsd_var_t
const *var
; /* Current variable */
2138 http_addrlist_t
*addrlist
, /* Address list */
2139 *addr
; /* Current address */
2140 unsigned ip
[4], /* Address value */
2141 mask
[4]; /* Netmask value */
2142 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2143 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2144 cupsd_location_t
*location
; /* Browse location */
2145 cups_file_t
*incfile
; /* Include file */
2146 char incname
[1024]; /* Include filename */
2147 struct group
*group
; /* Group */
2151 * Loop through each line in the file...
2156 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2159 * Decode the directive...
2162 if (!strcasecmp(line
, "Include") && value
)
2168 if (value
[0] == '/')
2169 strlcpy(incname
, value
, sizeof(incname
));
2171 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2173 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2174 cupsdLogMessage(CUPSD_LOG_ERROR
,
2175 "Unable to include config file \"%s\" - %s",
2176 incname
, strerror(errno
));
2179 read_configuration(incfile
);
2180 cupsFileClose(incfile
);
2183 else if (!strcasecmp(line
, "<Location") && value
)
2189 linenum
= read_location(fp
, value
, linenum
);
2193 else if (!strcasecmp(line
, "<Policy") && value
)
2199 linenum
= read_policy(fp
, value
, linenum
);
2203 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2205 JobRetryInterval
= atoi(value
);
2206 cupsdLogMessage(CUPSD_LOG_WARN
,
2207 "FaxRetryInterval is deprecated; use "
2208 "JobRetryInterval on line %d.", linenum
);
2210 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2212 JobRetryLimit
= atoi(value
);
2213 cupsdLogMessage(CUPSD_LOG_WARN
,
2214 "FaxRetryLimit is deprecated; use "
2215 "JobRetryLimit on line %d.", linenum
);
2217 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2219 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2220 #endif /* HAVE_SSL */
2224 * Add listening address(es) to the list...
2227 cupsd_listener_t
*lis
; /* New listeners array */
2231 * Get the address list...
2234 addrlist
= get_address(value
, IPP_PORT
);
2238 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2244 * Add each address...
2247 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2250 * Allocate another listener...
2254 Listeners
= cupsArrayNew(NULL
, NULL
);
2258 cupsdLogMessage(CUPSD_LOG_ERROR
,
2259 "Unable to allocate %s at line %d - %s.",
2260 line
, linenum
, strerror(errno
));
2264 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2266 cupsdLogMessage(CUPSD_LOG_ERROR
,
2267 "Unable to allocate %s at line %d - %s.",
2268 line
, linenum
, strerror(errno
));
2272 cupsArrayAdd(Listeners
, lis
);
2275 * Copy the current address and log it...
2278 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2282 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2283 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2284 #endif /* HAVE_SSL */
2286 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2289 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2290 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2291 ntohs(lis
->address
.ipv6
.sin6_port
));
2293 #endif /* AF_INET6 */
2295 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2296 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2298 #endif /* AF_LOCAL */
2299 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2300 ntohs(lis
->address
.ipv4
.sin_port
));
2307 httpAddrFreeList(addrlist
);
2309 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2312 * Add a browse address to the list...
2315 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2318 if (NumBrowsers
== 0)
2319 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2321 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2325 cupsdLogMessage(CUPSD_LOG_ERROR
,
2326 "Unable to allocate BrowseAddress at line %d - %s.",
2327 linenum
, strerror(errno
));
2332 dira
+= NumBrowsers
;
2334 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2336 if (!strcasecmp(value
, "@LOCAL"))
2339 * Send browse data to all local interfaces...
2342 strcpy(dira
->iface
, "*");
2345 else if (!strncasecmp(value
, "@IF(", 4))
2348 * Send browse data to the named interface...
2351 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2353 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2359 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2362 * Only IPv4 addresses are supported...
2365 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2366 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2371 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2372 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2374 cupsdLogMessage(CUPSD_LOG_INFO
,
2375 "Sending browsing info to %s:%d (IPv4)",
2376 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2381 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2384 httpAddrFreeList(addrlist
);
2387 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2390 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2393 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2396 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2397 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2399 if (location
== NULL
)
2400 cupsdLogMessage(CUPSD_LOG_ERROR
,
2401 "Unable to initialize browse access control list!");
2402 else if (!strncasecmp(value
, "deny", 4))
2403 location
->order_type
= CUPSD_AUTH_ALLOW
;
2404 else if (!strncasecmp(value
, "allow", 5))
2405 location
->order_type
= CUPSD_AUTH_DENY
;
2407 cupsdLogMessage(CUPSD_LOG_ERROR
,
2408 "Unknown BrowseOrder value %s on line %d.",
2411 else if (!strcasecmp(line
, "BrowseProtocols") ||
2412 !strcasecmp(line
, "BrowseLocalProtocols") ||
2413 !strcasecmp(line
, "BrowseRemoteProtocols"))
2416 * "BrowseProtocols name [... name]"
2417 * "BrowseLocalProtocols name [... name]"
2418 * "BrowseRemoteProtocols name [... name]"
2421 int protocols
= parse_protocols(value
);
2425 cupsdLogMessage(CUPSD_LOG_ERROR
,
2426 "Unknown browse protocol \"%s\" on line %d.",
2431 if (strcasecmp(line
, "BrowseLocalProtocols"))
2432 BrowseRemoteProtocols
= protocols
;
2433 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2434 BrowseLocalProtocols
= protocols
;
2436 else if ((!strcasecmp(line
, "BrowseAllow") ||
2437 !strcasecmp(line
, "BrowseDeny")) && value
)
2440 * BrowseAllow [From] host/ip...
2441 * BrowseDeny [From] host/ip...
2444 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2445 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2447 if (location
== NULL
)
2448 cupsdLogMessage(CUPSD_LOG_ERROR
,
2449 "Unable to initialize browse access control list!");
2452 if (!strncasecmp(value
, "from ", 5))
2455 * Strip leading "from"...
2460 while (isspace(*value
))
2465 * Figure out what form the allow/deny address takes:
2476 * nnn.nnn.nnn.nnn/mm
2477 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2480 if (!strcasecmp(value
, "all"))
2486 if (!strcasecmp(line
, "BrowseAllow"))
2487 cupsdAllowIP(location
, zeros
, zeros
);
2489 cupsdDenyIP(location
, zeros
, zeros
);
2491 else if (!strcasecmp(value
, "none"))
2497 if (!strcasecmp(line
, "BrowseAllow"))
2498 cupsdAllowIP(location
, ones
, zeros
);
2500 cupsdDenyIP(location
, ones
, zeros
);
2503 else if (value
[0] == '*' || value
[0] == '.' ||
2504 (!isdigit(value
[0] & 255) && value
[0] != '['))
2506 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2507 #endif /* AF_INET6 */
2510 * Host or domain name...
2513 if (value
[0] == '*')
2516 if (!strcasecmp(line
, "BrowseAllow"))
2517 cupsdAllowHost(location
, value
);
2519 cupsdDenyHost(location
, value
);
2524 * One of many IP address forms...
2527 if (!get_addr_and_mask(value
, ip
, mask
))
2529 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2534 if (!strcasecmp(line
, "BrowseAllow"))
2535 cupsdAllowIP(location
, ip
, mask
);
2537 cupsdDenyIP(location
, ip
, mask
);
2541 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2544 * BrowseRelay [from] source [to] destination
2548 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2550 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2554 cupsdLogMessage(CUPSD_LOG_ERROR
,
2555 "Unable to allocate BrowseRelay at line %d - %s.",
2556 linenum
, strerror(errno
));
2563 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2565 if (!strncasecmp(value
, "from ", 5))
2568 * Strip leading "from"...
2573 while (isspace(*value
))
2578 * Figure out what form the from address takes:
2587 * nnn.nnn.nnn.nnn/mm
2588 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2592 if (value
[0] == '*' || value
[0] == '.' ||
2593 (!isdigit(value
[0] & 255) && value
[0] != '['))
2595 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2596 #endif /* AF_INET6 */
2599 * Host or domain name...
2602 if (value
[0] == '*')
2605 strlcpy(temp
, value
, sizeof(temp
));
2606 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2609 relay
->from
.type
= CUPSD_AUTH_NAME
;
2611 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2613 cupsdLogMessage(CUPSD_LOG_ERROR
,
2614 "Unable to allocate BrowseRelay name at line %d - %s.",
2615 linenum
, strerror(errno
));
2619 relay
->from
.mask
.name
.length
= strlen(temp
);
2624 * One of many IP address forms...
2627 if (!get_addr_and_mask(value
, ip
, mask
))
2629 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2634 relay
->from
.type
= CUPSD_AUTH_IP
;
2635 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2636 sizeof(relay
->from
.mask
.ip
.address
));
2637 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2638 sizeof(relay
->from
.mask
.ip
.netmask
));
2642 * Skip value and trailing whitespace...
2645 for (; *value
; value
++)
2646 if (isspace(*value
))
2649 while (isspace(*value
))
2652 if (!strncasecmp(value
, "to ", 3))
2655 * Strip leading "to"...
2660 while (isspace(*value
))
2665 * Get "to" address and port...
2668 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2671 * Only IPv4 addresses are supported...
2674 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2675 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2680 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2682 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2684 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2685 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2686 relay
->from
.mask
.ip
.address
[0] >> 24,
2687 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2688 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2689 relay
->from
.mask
.ip
.address
[0] & 255,
2690 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2691 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2692 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2693 relay
->from
.mask
.ip
.netmask
[0] & 255);
2695 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2697 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2698 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2703 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2706 httpAddrFreeList(addrlist
);
2710 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2711 free(relay
->from
.mask
.name
.name
);
2713 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2717 else if (!strcasecmp(line
, "BrowsePoll") && value
)
2720 * BrowsePoll address[:port]
2723 char *portname
; /* Port name */
2724 int portnum
; /* Port number */
2725 struct servent
*service
; /* Service */
2729 * Extract the port name from the address...
2732 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2736 if (isdigit(*portname
& 255))
2737 portnum
= atoi(portname
);
2738 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2739 portnum
= ntohs(service
->s_port
);
2742 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2748 portnum
= ippPort();
2751 * Add the poll entry...
2755 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2757 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2761 cupsdLogMessage(CUPSD_LOG_ERROR
,
2762 "Unable to allocate BrowsePoll at line %d - %s.",
2763 linenum
, strerror(errno
));
2771 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2773 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2774 pollp
->port
= portnum
;
2776 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2779 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
2782 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2785 if (!strcasecmp(value
, "none"))
2786 DefaultAuthType
= CUPSD_AUTH_NONE
;
2787 else if (!strcasecmp(value
, "basic"))
2788 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2789 else if (!strcasecmp(value
, "digest"))
2790 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2791 else if (!strcasecmp(value
, "basicdigest"))
2792 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2794 else if (!strcasecmp(value
, "negotiate"))
2795 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2796 #endif /* HAVE_GSSAPI */
2799 cupsdLogMessage(CUPSD_LOG_WARN
,
2800 "Unknown default authorization type %s on line %d.",
2806 else if (!strcasecmp(line
, "DefaultEncryption"))
2809 * DefaultEncryption {Never,IfRequested,Required}
2812 if (!value
|| !strcasecmp(value
, "never"))
2813 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2814 else if (!strcasecmp(value
, "required"))
2815 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2816 else if (!strcasecmp(value
, "ifrequested"))
2817 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2820 cupsdLogMessage(CUPSD_LOG_WARN
,
2821 "Unknown default encryption %s on line %d.",
2826 #endif /* HAVE_SSL */
2828 else if (!strcasecmp(line
, "Krb5Keytab") && value
)
2830 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2833 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2834 gsskrb5_register_acceptor_identity(value
);
2836 cupsdSetEnv("KRB5_KTNAME", value
);
2837 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2839 #endif /* HAVE_GSSAPI */
2840 else if (!strcasecmp(line
, "User") && value
)
2843 * User ID to run as...
2846 if (isdigit(value
[0] & 255))
2848 int uid
= atoi(value
);
2851 cupsdLogMessage(CUPSD_LOG_ERROR
,
2852 "Will not use User 0 as specified on line %d "
2853 "for security reasons. You must use a non-"
2854 "privileged account instead.",
2861 struct passwd
*p
; /* Password information */
2864 p
= getpwnam(value
);
2869 cupsdLogMessage(CUPSD_LOG_ERROR
,
2870 "Will not use User %s (UID=0) as specified on line "
2871 "%d for security reasons. You must use a non-"
2872 "privileged account instead.",
2878 cupsdLogMessage(CUPSD_LOG_ERROR
,
2879 "Unknown User \"%s\" on line %d, ignoring!",
2883 else if (!strcasecmp(line
, "Group") && value
)
2886 * Group ID to run as...
2889 if (isdigit(value
[0]))
2890 Group
= atoi(value
);
2894 group
= getgrnam(value
);
2897 Group
= group
->gr_gid
;
2899 cupsdLogMessage(CUPSD_LOG_ERROR
,
2900 "Unknown Group \"%s\" on line %d, ignoring!",
2904 else if (!strcasecmp(line
, "SystemGroup") && value
)
2907 * SystemGroup (admin) group(s)...
2910 if (!parse_groups(value
))
2911 cupsdLogMessage(CUPSD_LOG_ERROR
,
2912 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2915 else if (!strcasecmp(line
, "HostNameLookups") && value
)
2918 * Do hostname lookups?
2921 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
2922 !strcasecmp(value
, "false"))
2923 HostNameLookups
= 0;
2924 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
2925 !strcasecmp(value
, "true"))
2926 HostNameLookups
= 1;
2927 else if (!strcasecmp(value
, "double"))
2928 HostNameLookups
= 2;
2930 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2933 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
2936 * Amount of logging to do to access log...
2939 if (!strcasecmp(value
, "all"))
2940 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
2941 else if (!strcasecmp(value
, "actions"))
2942 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
2943 else if (!strcasecmp(value
, "config"))
2944 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
2946 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
2949 else if (!strcasecmp(line
, "LogLevel") && value
)
2952 * Amount of logging to do to error log...
2955 if (!strcasecmp(value
, "debug2"))
2956 LogLevel
= CUPSD_LOG_DEBUG2
;
2957 else if (!strcasecmp(value
, "debug"))
2958 LogLevel
= CUPSD_LOG_DEBUG
;
2959 else if (!strcasecmp(value
, "info"))
2960 LogLevel
= CUPSD_LOG_INFO
;
2961 else if (!strcasecmp(value
, "notice"))
2962 LogLevel
= CUPSD_LOG_NOTICE
;
2963 else if (!strcasecmp(value
, "warn"))
2964 LogLevel
= CUPSD_LOG_WARN
;
2965 else if (!strcasecmp(value
, "error"))
2966 LogLevel
= CUPSD_LOG_ERROR
;
2967 else if (!strcasecmp(value
, "crit"))
2968 LogLevel
= CUPSD_LOG_CRIT
;
2969 else if (!strcasecmp(value
, "alert"))
2970 LogLevel
= CUPSD_LOG_ALERT
;
2971 else if (!strcasecmp(value
, "emerg"))
2972 LogLevel
= CUPSD_LOG_EMERG
;
2973 else if (!strcasecmp(value
, "none"))
2974 LogLevel
= CUPSD_LOG_NONE
;
2976 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2979 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
2982 * Format of printcap file?
2985 if (!strcasecmp(value
, "bsd"))
2986 PrintcapFormat
= PRINTCAP_BSD
;
2987 else if (!strcasecmp(value
, "solaris"))
2988 PrintcapFormat
= PRINTCAP_SOLARIS
;
2990 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2993 else if (!strcasecmp(line
, "ServerTokens") && value
)
2996 * Set the string used for the Server header...
2999 struct utsname plat
; /* Platform info */
3004 if (!strcasecmp(value
, "ProductOnly"))
3005 cupsdSetString(&ServerHeader
, "CUPS");
3006 else if (!strcasecmp(value
, "Major"))
3007 cupsdSetString(&ServerHeader
, "CUPS/1");
3008 else if (!strcasecmp(value
, "Minor"))
3009 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3010 else if (!strcasecmp(value
, "Minimal"))
3011 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3012 else if (!strcasecmp(value
, "OS"))
3013 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3014 else if (!strcasecmp(value
, "Full"))
3015 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3017 else if (!strcasecmp(value
, "None"))
3018 cupsdClearString(&ServerHeader
);
3020 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3023 else if (!strcasecmp(line
, "PassEnv") && value
)
3026 * PassEnv variable [... variable]
3031 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3032 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3035 if (value
[valuelen
])
3037 value
[valuelen
] = '\0';
3041 cupsdSetEnv(value
, NULL
);
3043 for (value
+= valuelen
; *value
; value
++)
3044 if (!isspace(*value
) || *value
!= ',')
3048 else if (!strcasecmp(line
, "SetEnv") && value
)
3051 * SetEnv variable value
3054 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3062 while (isspace(*valueptr
& 255))
3065 cupsdSetEnv(value
, valueptr
);
3068 cupsdLogMessage(CUPSD_LOG_ERROR
,
3069 "Missing value for SetEnv directive on line %d.",
3075 * Find a simple variable in the list...
3078 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3079 if (!strcasecmp(line
, var
->name
))
3085 * Unknown directive! Output an error message and continue...
3089 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3092 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3099 case CUPSD_VARTYPE_INTEGER
:
3101 cupsdLogMessage(CUPSD_LOG_ERROR
,
3102 "Missing integer value for %s on line %d!",
3107 char *units
; /* Units */
3110 n
= strtol(value
, &units
, 0);
3112 if (units
&& *units
)
3114 if (tolower(units
[0] & 255) == 'g')
3115 n
*= 1024 * 1024 * 1024;
3116 else if (tolower(units
[0] & 255) == 'm')
3118 else if (tolower(units
[0] & 255) == 'k')
3120 else if (tolower(units
[0] & 255) == 't')
3125 cupsdLogMessage(CUPSD_LOG_ERROR
,
3126 "Bad negative integer value for %s on line %d!",
3129 *((int *)var
->ptr
) = n
;
3133 case CUPSD_VARTYPE_BOOLEAN
:
3135 cupsdLogMessage(CUPSD_LOG_ERROR
,
3136 "Missing boolean value for %s on line %d!",
3138 else if (!strcasecmp(value
, "true") ||
3139 !strcasecmp(value
, "on") ||
3140 !strcasecmp(value
, "enabled") ||
3141 !strcasecmp(value
, "yes") ||
3143 *((int *)var
->ptr
) = TRUE
;
3144 else if (!strcasecmp(value
, "false") ||
3145 !strcasecmp(value
, "off") ||
3146 !strcasecmp(value
, "disabled") ||
3147 !strcasecmp(value
, "no") ||
3148 !strcasecmp(value
, "0"))
3149 *((int *)var
->ptr
) = FALSE
;
3151 cupsdLogMessage(CUPSD_LOG_ERROR
,
3152 "Unknown boolean value %s on line %d.",
3156 case CUPSD_VARTYPE_PATHNAME
:
3159 cupsdLogMessage(CUPSD_LOG_ERROR
,
3160 "Missing pathname value for %s on line %d!",
3165 if (value
[0] == '/')
3166 strlcpy(temp
, value
, sizeof(temp
));
3168 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3170 if (access(temp
, 0))
3172 cupsdLogMessage(CUPSD_LOG_ERROR
,
3173 "File or directory for \"%s %s\" on line %d "
3174 "does not exist!", line
, value
, linenum
);
3178 case CUPSD_VARTYPE_STRING
:
3179 cupsdSetString((char **)var
->ptr
, value
);
3190 * 'read_location()' - Read a <Location path> definition.
3193 static int /* O - New line number or 0 on error */
3194 read_location(cups_file_t
*fp
, /* I - Configuration file */
3195 char *location
, /* I - Location name/path */
3196 int linenum
) /* I - Current line number */
3198 cupsd_location_t
*loc
, /* New location */
3199 *parent
; /* Parent location */
3200 char line
[HTTP_MAX_BUFFER
],
3202 *value
, /* Value for directive */
3203 *valptr
; /* Pointer into value */
3206 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3209 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3212 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3215 * Decode the directive...
3218 if (!strcasecmp(line
, "</Location>"))
3220 else if (!strcasecmp(line
, "<Limit") ||
3221 !strcasecmp(line
, "<LimitExcept"))
3225 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3229 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3235 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3240 if (!strcmp(value
, "ALL"))
3241 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3242 else if (!strcmp(value
, "GET"))
3243 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3244 else if (!strcmp(value
, "HEAD"))
3245 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3246 else if (!strcmp(value
, "OPTIONS"))
3247 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3248 else if (!strcmp(value
, "POST"))
3249 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3250 else if (!strcmp(value
, "PUT"))
3251 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3252 else if (!strcmp(value
, "TRACE"))
3253 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3255 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3258 for (value
= valptr
; isspace(*value
& 255); value
++);
3261 if (!strcasecmp(line
, "<LimitExcept"))
3262 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3264 parent
->limit
&= ~loc
->limit
;
3266 else if (!strcasecmp(line
, "</Limit>") ||
3267 !strcasecmp(line
, "</LimitExcept>"))
3269 else if (!parse_aaa(loc
, line
, value
, linenum
))
3271 cupsdLogMessage(CUPSD_LOG_ERROR
,
3272 "Unknown Location directive %s on line %d.",
3278 cupsdLogMessage(CUPSD_LOG_ERROR
,
3279 "Unexpected end-of-file at line %d while reading location!",
3287 * 'read_policy()' - Read a <Policy name> definition.
3290 static int /* O - New line number or 0 on error */
3291 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3292 char *policy
, /* I - Location name/path */
3293 int linenum
) /* I - Current line number */
3295 int i
; /* Looping var */
3296 cupsd_policy_t
*pol
; /* Policy */
3297 cupsd_location_t
*op
; /* Policy operation */
3298 int num_ops
; /* Number of IPP operations */
3299 ipp_op_t ops
[100]; /* Operations */
3300 char line
[HTTP_MAX_BUFFER
],
3302 *value
, /* Value for directive */
3303 *valptr
; /* Pointer into value */
3307 * Create the policy...
3310 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3314 * Read from the file...
3320 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3323 * Decode the directive...
3326 if (!strcasecmp(line
, "</Policy>"))
3329 cupsdLogMessage(CUPSD_LOG_WARN
,
3330 "Missing </Limit> before </Policy> on line %d!",
3334 * Verify that we have an explicit policy for CUPS-Get-Document
3335 * (ensures that upgrades do not introduce new security issues...)
3338 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3339 op
->op
== IPP_ANY_OPERATION
)
3341 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3342 op
->op
!= IPP_ANY_OPERATION
)
3345 * Add a new limit for CUPS-Get-Document using the Send-Document
3346 * limit as a template...
3349 cupsdLogMessage(CUPSD_LOG_WARN
,
3350 "No limit for CUPS-Get-Document defined in policy %s "
3351 "- using Send-Document's policy", pol
->name
);
3353 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3359 else if (!strcasecmp(line
, "<Limit") && !op
)
3363 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3368 * Scan for IPP operation names...
3375 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3380 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3382 if (!strcasecmp(value
, "All"))
3383 ops
[num_ops
] = IPP_ANY_OPERATION
;
3384 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3385 cupsdLogMessage(CUPSD_LOG_ERROR
,
3386 "Bad IPP operation name \"%s\" on line %d!",
3392 cupsdLogMessage(CUPSD_LOG_ERROR
,
3393 "Too many operations listed on line %d!",
3396 for (value
= valptr
; isspace(*value
& 255); value
++);
3400 * If none are specified, apply the policy to all operations...
3405 ops
[0] = IPP_ANY_OPERATION
;
3410 * Add a new policy for the first operation...
3413 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3415 else if (!strcasecmp(line
, "</Limit>") && op
)
3418 * Finish the current operation limit...
3424 * Copy the policy to the other operations...
3427 for (i
= 1; i
< num_ops
; i
++)
3428 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3435 cupsdLogMessage(CUPSD_LOG_ERROR
,
3436 "Missing <Limit ops> directive before %s on line %d.",
3440 else if (!parse_aaa(op
, line
, value
, linenum
))
3443 cupsdLogMessage(CUPSD_LOG_ERROR
,
3444 "Unknown Policy Limit directive %s on line %d.",
3447 cupsdLogMessage(CUPSD_LOG_ERROR
,
3448 "Unknown Policy directive %s on line %d.",
3455 cupsdLogMessage(CUPSD_LOG_ERROR
,
3456 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3464 * End of "$Id: conf.c 7694 2008-06-26 00:23:20Z mike $".