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 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
107 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
108 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
109 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
110 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
111 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
112 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
113 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
114 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
115 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
117 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
118 #endif /* HAVE_GSSAPI */
119 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
120 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
121 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
122 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
123 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
124 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
125 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
127 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
128 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
129 #endif /* HAVE_LAUNCHD */
130 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
131 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
132 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
133 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
134 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
150 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
151 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
152 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
153 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
154 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
155 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
156 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
157 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
158 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
159 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
160 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
161 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
162 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
164 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
165 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
166 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
167 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
168 #endif /* HAVE_SSL */
169 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
170 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
171 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
172 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
173 #ifdef HAVE_AUTHORIZATION_H
174 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
175 #endif /* HAVE_AUTHORIZATION_H */
176 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
177 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
178 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
180 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
183 static const unsigned ones
[4] =
185 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
187 static const unsigned zeros
[4] =
189 0x00000000, 0x00000000, 0x00000000, 0x00000000
196 static http_addrlist_t
*get_address(const char *value
, int defport
);
197 static int get_addr_and_mask(const char *value
, unsigned *ip
,
199 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
200 char *value
, int linenum
);
201 static int parse_groups(const char *s
);
202 static int parse_protocols(const char *s
);
203 static int read_configuration(cups_file_t
*fp
);
204 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
205 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
209 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
212 int /* O - 0 on success, -1 on error, 1 on warning */
213 cupsdCheckPermissions(
214 const char *filename
, /* I - File/directory name */
215 const char *suffix
, /* I - Additional file/directory name */
216 int mode
, /* I - Permissions */
217 int user
, /* I - Owner */
218 int group
, /* I - Group */
219 int is_dir
, /* I - 1 = directory, 0 = file */
220 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
222 int dir_created
= 0; /* Did we create a directory? */
223 char pathname
[1024]; /* File name with prefix */
224 struct stat fileinfo
; /* Stat buffer */
228 * Prepend the given root to the filename before testing it...
233 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
238 * See if we can stat the file/directory...
241 if (stat(filename
, &fileinfo
))
243 if (errno
== ENOENT
&& create_dir
)
246 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
249 if (mkdir(filename
, mode
))
252 cupsdLogMessage(CUPSD_LOG_ERROR
,
253 "Unable to create directory \"%s\" - %s", filename
,
256 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
265 return (create_dir
? -1 : 1);
269 * Make sure it's a regular file...
272 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
274 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
278 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
281 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
283 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
289 * Fix owner, group, and mode as needed...
292 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
295 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
298 if (chown(filename
, user
, group
) && !getuid())
301 cupsdLogMessage(CUPSD_LOG_ERROR
,
302 "Unable to change ownership of \"%s\" - %s", filename
,
305 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
312 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
315 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
318 if (chmod(filename
, mode
))
321 cupsdLogMessage(CUPSD_LOG_ERROR
,
322 "Unable to change permissions of \"%s\" - %s", filename
,
325 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
333 * Everything is OK...
341 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
344 int /* O - 1 on success, 0 otherwise */
345 cupsdReadConfiguration(void)
347 int i
; /* Looping var */
348 cups_file_t
*fp
; /* Configuration file */
349 int status
; /* Return status */
350 char temp
[1024], /* Temporary buffer */
351 mimedir
[1024], /* MIME directory */
352 *slash
; /* Directory separator */
353 cups_lang_t
*language
; /* Language */
354 struct passwd
*user
; /* Default user */
355 struct group
*group
; /* Default group */
356 char *old_serverroot
, /* Old ServerRoot */
357 *old_requestroot
; /* Old RequestRoot */
358 const char *tmpdir
; /* TMPDIR environment variable */
359 struct stat tmpinfo
; /* Temporary directory info */
360 cupsd_policy_t
*p
; /* Policy */
364 * Save the old root paths...
367 old_serverroot
= NULL
;
368 cupsdSetString(&old_serverroot
, ServerRoot
);
369 old_requestroot
= NULL
;
370 cupsdSetString(&old_requestroot
, RequestRoot
);
373 * Reset the server configuration data...
376 cupsdDeleteAllLocations();
395 for (i
= 0; i
< NumRelays
; i
++)
396 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
397 free(Relays
[i
].from
.mask
.name
.name
);
404 cupsdDeleteAllListeners();
410 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
411 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
412 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
413 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
414 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
415 cupsdSetString(&DataDir
, CUPS_DATADIR
);
416 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
417 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
418 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
419 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
420 cupsdSetString(&PageLogFormat
,
421 "%p %j %u %T %P %C %{job-billing} "
422 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
423 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
424 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
425 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
426 cupsdSetString(&RemoteRoot
, "remroot");
427 cupsdSetString(&ServerHeader
, "CUPS/1.4");
428 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
430 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
431 #endif /* HAVE_GSSAPI */
433 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
434 PrintcapFormat
= PRINTCAP_SOLARIS
;
436 PrintcapFormat
= PRINTCAP_BSD
;
438 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
439 if ((slash
= strrchr(temp
, '/')) != NULL
)
442 cupsdSetString(&ServerRoot
, temp
);
444 cupsdClearString(&Classification
);
445 ClassifyOverride
= 0;
449 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
451 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
452 cupsdSetString(&ServerKey
, "ssl/server.key");
453 # endif /* HAVE_CDSASSL */
454 #endif /* HAVE_SSL */
456 language
= cupsLangDefault();
458 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
459 cupsdSetString(&DefaultLanguage
, "en");
461 cupsdSetString(&DefaultLanguage
, language
->language
);
463 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
465 cupsdSetString(&RIPCache
, "8m");
467 cupsdSetString(&TempDir
, NULL
);
470 * Find the default user...
473 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
478 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
479 * complement number...)
488 * Find the default group...
491 group
= getgrnam(CUPS_DEFAULT_GROUP
);
495 Group
= group
->gr_gid
;
499 * Fallback to group "nobody"...
502 group
= getgrnam("nobody");
506 Group
= group
->gr_gid
;
510 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
511 * complement number...)
522 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
523 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
524 DefaultAuthType
= CUPSD_AUTH_BASIC
;
526 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
527 #endif /* HAVE_SSL */
528 DirtyCleanInterval
= 60;
530 JobRetryInterval
= 300;
535 HostNameLookups
= FALSE
;
536 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
537 ImplicitAnyClasses
= FALSE
;
538 HideImplicitMembers
= TRUE
;
540 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
541 ListenBackLog
= SOMAXCONN
;
542 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
543 LogLevel
= CUPSD_LOG_WARN
;
545 MaxClientsPerHost
= 0;
546 MaxLogSize
= 1024 * 1024;
547 MaxPrinterHistory
= 10;
550 RootCertDuration
= 300;
551 Timeout
= DEFAULT_TIMEOUT
;
554 BrowseInterval
= DEFAULT_INTERVAL
;
555 BrowsePort
= ippPort();
556 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
557 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
558 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
559 BrowseTimeout
= DEFAULT_TIMEOUT
;
560 Browsing
= CUPS_DEFAULT_BROWSING
;
561 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
563 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
564 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
566 cupsdClearString(&BrowseLocalOptions
);
567 cupsdClearString(&BrowseRemoteOptions
);
569 cupsdSetString(&ErrorPolicy
, "stop-printer");
572 cupsdClearString(&BrowseLDAPBindDN
);
573 cupsdClearString(&BrowseLDAPDN
);
574 cupsdClearString(&BrowseLDAPPassword
);
575 cupsdClearString(&BrowseLDAPServer
);
576 # ifdef HAVE_LDAP_SSL
577 cupsdClearString(&BrowseLDAPCACertFile
);
578 # endif /* HAVE_LDAP_SSL */
579 #endif /* HAVE_LDAP */
581 JobHistory
= DEFAULT_HISTORY
;
582 JobFiles
= DEFAULT_FILES
;
587 MaxJobsPerPrinter
= 0;
588 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
590 cupsdDeleteAllPolicies();
591 cupsdClearString(&DefaultPolicy
);
593 #ifdef HAVE_AUTHORIZATION_H
594 cupsdClearString(&SystemGroupAuthKey
);
595 #endif /* HAVE_AUTHORIZATION_H */
597 MaxSubscriptions
= 100;
598 MaxSubscriptionsPerJob
= 0;
599 MaxSubscriptionsPerPrinter
= 0;
600 MaxSubscriptionsPerUser
= 0;
601 DefaultLeaseDuration
= 86400;
602 MaxLeaseDuration
= 0;
605 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
606 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
607 #endif /* HAVE_LAUNCHD */
611 #endif /* __APPLE__ */
614 * Read the configuration file...
617 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
620 status
= read_configuration(fp
);
630 * See if the ServerName is an IP address...
633 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
635 ServerNameIsIP
= !*slash
;
638 * Use the default system group if none was supplied in cupsd.conf...
641 if (NumSystemGroups
== 0)
643 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
646 * Find the group associated with GID 0...
653 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
655 cupsdSetString(&SystemGroups
[0], "unknown");
657 SystemGroupIDs
[0] = 0;
663 * Get the access control list for browsing...
666 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
669 * Open the system log for cupsd if necessary...
673 if (!strcmp(AccessLog
, "syslog") ||
674 !strcmp(ErrorLog
, "syslog") ||
675 !strcmp(PageLog
, "syslog"))
676 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
677 #endif /* HAVE_VSYSLOG */
680 * Log the configuration file that was used...
683 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
687 * Validate the Group and SystemGroup settings - they cannot be the same,
688 * otherwise the CGI programs will be able to authenticate as root without
694 for (i
= 0; i
< NumSystemGroups
; i
++)
695 if (Group
== SystemGroupIDs
[i
])
698 if (i
< NumSystemGroups
)
701 * Log the error and reset the group to a safe value...
704 cupsdLogMessage(CUPSD_LOG_NOTICE
,
705 "Group and SystemGroup cannot use the same groups!");
706 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
708 group
= getgrnam("nobody");
712 Group
= group
->gr_gid
;
716 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
717 * complement number...)
726 * Check that we have at least one listen/port line; if not, report this
727 * as an error and exit!
730 if (cupsArrayCount(Listeners
) == 0)
736 cupsdLogMessage(CUPSD_LOG_EMERG
,
737 "No valid Listen or Port lines were found in the configuration file!");
743 cupsdEndProcess(getpid(), 0);
747 * Set the default locale using the language and charset...
750 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
753 * Update all relative filenames to include the full path from ServerRoot...
756 if (DocumentRoot
[0] != '/')
757 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
759 if (RequestRoot
[0] != '/')
760 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
762 if (ServerBin
[0] != '/')
763 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
765 if (StateDir
[0] != '/')
766 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
768 if (CacheDir
[0] != '/')
769 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
772 if (ServerCertificate
[0] != '/')
773 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
775 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
777 chown(ServerCertificate
, RunUser
, Group
);
778 chmod(ServerCertificate
, 0600);
781 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
782 if (ServerKey
[0] != '/')
783 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
785 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
787 chown(ServerKey
, RunUser
, Group
);
788 chmod(ServerKey
, 0600);
790 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
791 #endif /* HAVE_SSL */
794 * Make sure that directories and config files are owned and
795 * writable by the user and group in the cupsd.conf file...
798 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
800 if (cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
802 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
804 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
806 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
808 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
809 SystemGroupIDs
[0], 1, 1) < 0 ||
810 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
812 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
814 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
816 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
818 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
820 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
822 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
827 * Update TempDir to the default if it hasn't been set already...
832 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
835 * TMPDIR is defined, see if it is OK for us to use...
838 if (stat(tmpdir
, &tmpinfo
))
839 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
840 tmpdir
, strerror(errno
));
841 else if (!S_ISDIR(tmpinfo
.st_mode
))
842 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
844 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
845 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
846 !(tmpinfo
.st_mode
& S_IWOTH
))
847 cupsdLogMessage(CUPSD_LOG_ERROR
,
848 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
850 cupsdSetString(&TempDir
, tmpdir
);
855 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
857 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
862 * Make sure the temporary directory has the right permissions...
865 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
869 * Update ownership and permissions if the CUPS temp directory
870 * is under the spool directory or does not exist...
873 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
878 * Setup environment variables...
884 * Check the MaxClients setting, and then allocate memory for it...
887 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
890 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
893 MaxClients
= MaxFDs
/ 3;
896 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
900 * Check the MaxActiveJobs setting; limit to 1/3 the available
901 * file descriptors, since we need a pipe for each job...
904 if (MaxActiveJobs
> (MaxFDs
/ 3))
905 MaxActiveJobs
= MaxFDs
/ 3;
907 if (Classification
&& !strcasecmp(Classification
, "none"))
908 cupsdClearString(&Classification
);
911 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
914 * Update the MaxClientsPerHost value, as needed...
917 if (MaxClientsPerHost
<= 0)
918 MaxClientsPerHost
= MaxClients
;
920 if (MaxClientsPerHost
> MaxClients
)
921 MaxClientsPerHost
= MaxClients
;
923 cupsdLogMessage(CUPSD_LOG_INFO
,
924 "Allowing up to %d client connections per host.",
928 * Make sure that BrowseTimeout is at least twice the interval...
931 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
933 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
937 BrowseTimeout
= BrowseInterval
* 2;
939 BrowseTimeout
= DEFAULT_TIMEOUT
;
941 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
946 * Update the default policy, as needed...
950 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
952 DefaultPolicyPtr
= NULL
;
954 if (!DefaultPolicyPtr
)
956 cupsd_location_t
*po
; /* New policy operation */
960 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
963 cupsdSetString(&DefaultPolicy
, "default");
965 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
966 cupsdLogMessage(CUPSD_LOG_INFO
,
967 "Using policy \"default\" as the default!");
970 cupsdLogMessage(CUPSD_LOG_INFO
,
971 "Creating CUPS default administrative policy:");
973 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
975 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
976 cupsdLogMessage(CUPSD_LOG_INFO
,
977 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
978 "Release-Job Restart-Job Purge-Jobs "
979 "Set-Job-Attributes Create-Job-Subscription "
980 "Renew-Subscription Cancel-Subscription "
981 "Get-Notifications Reprocess-Job Cancel-Current-Job "
982 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
983 "CUPS-Authenticate-Job CUPS-Get-Document>");
984 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
986 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
987 po
->order_type
= CUPSD_AUTH_ALLOW
;
988 po
->level
= CUPSD_AUTH_USER
;
990 cupsdAddName(po
, "@OWNER");
991 cupsdAddName(po
, "@SYSTEM");
992 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
994 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
995 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
996 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
997 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
998 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
999 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1000 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1001 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1002 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1003 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1004 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1005 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1006 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1007 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1008 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1009 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1010 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1011 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1013 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1015 cupsdLogMessage(CUPSD_LOG_INFO
,
1016 "<Limit Pause-Printer Resume-Printer "
1017 "Set-Printer-Attributes Enable-Printer "
1018 "Disable-Printer Pause-Printer-After-Current-Job "
1019 "Hold-New-Jobs Release-Held-New-Jobs "
1020 "Deactivate-Printer Activate-Printer Restart-Printer "
1021 "Shutdown-Printer Startup-Printer Promote-Job "
1022 "Schedule-Job-After CUPS-Add-Printer "
1023 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1024 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1025 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1026 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1028 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1029 po
->order_type
= CUPSD_AUTH_ALLOW
;
1030 po
->type
= CUPSD_AUTH_DEFAULT
;
1031 po
->level
= CUPSD_AUTH_USER
;
1033 cupsdAddName(po
, "@SYSTEM");
1034 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1036 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1037 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1038 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1039 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1040 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1041 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1042 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1043 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1044 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1045 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1046 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1047 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1048 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1049 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1050 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1051 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1052 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1053 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1054 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1055 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1056 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1058 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1060 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1061 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1063 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1064 po
->order_type
= CUPSD_AUTH_ALLOW
;
1066 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1067 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1071 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1072 cupsArrayCount(Policies
));
1073 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1075 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1076 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1077 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1080 * If we are doing a full reload or the server root has changed, flush
1081 * the jobs, printers, etc. and start from scratch...
1084 if (NeedReload
== RELOAD_ALL
||
1085 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1086 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1088 mime_type_t
*type
; /* Current type */
1089 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1090 /* MIME type name */
1093 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1096 * Free all memory...
1099 cupsdDeleteAllSubscriptions();
1101 cupsdDeleteAllClasses();
1102 cupsdDeleteAllPrinters();
1104 DefaultPrinter
= NULL
;
1106 if (MimeDatabase
!= NULL
)
1107 mimeDelete(MimeDatabase
);
1111 for (i
= 0; i
< NumMimeTypes
; i
++)
1112 _cupsStrFree(MimeTypes
[i
]);
1118 * Read the MIME type and conversion database...
1121 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1122 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1124 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1125 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1126 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1127 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1131 cupsdLogMessage(CUPSD_LOG_EMERG
,
1132 "Unable to load MIME database from \"%s\" or \"%s\"!",
1133 mimedir
, ServerRoot
);
1137 cupsdLogMessage(CUPSD_LOG_INFO
,
1138 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1139 "%d filters...", mimedir
, ServerRoot
,
1140 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1143 * Create a list of MIME types for the document-format-supported
1147 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1148 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1151 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1153 cupsdLogMessage(CUPSD_LOG_ERROR
,
1154 "Unable to allocate memory for %d MIME types!",
1160 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1162 i
++, type
= mimeNextType(MimeDatabase
))
1164 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1166 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1169 if (i
< NumMimeTypes
)
1170 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1173 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1175 mime_filter_t
*filter
; /* Current filter */
1178 for (type
= mimeFirstType(MimeDatabase
);
1180 type
= mimeNextType(MimeDatabase
))
1181 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1182 type
->super
, type
->type
);
1184 for (filter
= mimeFirstFilter(MimeDatabase
);
1186 filter
= mimeNextFilter(MimeDatabase
))
1187 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1188 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1189 filter
->src
->super
, filter
->src
->type
,
1190 filter
->dst
->super
, filter
->dst
->type
,
1191 filter
->cost
, filter
->filter
);
1198 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1199 cupsdLoadBanners(temp
);
1202 * Load printers and classes...
1205 cupsdLoadAllPrinters();
1206 cupsdLoadAllClasses();
1207 cupsdLoadRemoteCache();
1208 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1210 cupsdCreateCommonData();
1213 * Load queued jobs...
1219 * Load subscriptions...
1222 cupsdLoadAllSubscriptions();
1224 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1229 * Not a full reload, so recreate the common printer attributes...
1232 cupsdCreateCommonData();
1235 * Update all printers as needed...
1238 cupsdUpdatePrinters();
1239 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1241 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1245 * Reset the reload state...
1248 NeedReload
= RELOAD_NONE
;
1250 cupsdClearString(&old_serverroot
);
1251 cupsdClearString(&old_requestroot
);
1258 * 'get_address()' - Get an address + port number from a line.
1261 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1262 get_address(const char *value
, /* I - Value string */
1263 int defport
) /* I - Default port */
1265 char buffer
[1024], /* Hostname + port number buffer */
1266 defpname
[255], /* Default port name */
1267 *hostname
, /* Hostname or IP */
1268 *portname
; /* Port number or name */
1269 http_addrlist_t
*addrlist
; /* Address list */
1273 * Check for an empty value...
1278 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1283 * Grab a hostname and port number; if there is no colon and the port name
1284 * is only digits, then we have a port number by itself...
1287 strlcpy(buffer
, value
, sizeof(buffer
));
1289 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1296 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1301 * Use the default port...
1304 sprintf(defpname
, "%d", defport
);
1305 portname
= defpname
;
1311 * The buffer contains just a port number...
1319 if (hostname
&& !strcmp(hostname
, "*"))
1323 * Now lookup the address using httpAddrGetList()...
1326 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1327 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1328 hostname
? hostname
: "(nil)");
1335 * 'get_addr_and_mask()' - Get an IP address and netmask.
1338 static int /* O - 1 on success, 0 on failure */
1339 get_addr_and_mask(const char *value
, /* I - String from config file */
1340 unsigned *ip
, /* O - Address value */
1341 unsigned *mask
) /* O - Mask value */
1343 int i
, j
, /* Looping vars */
1344 family
, /* Address family */
1345 ipcount
; /* Count of fields in address */
1346 unsigned ipval
; /* Value */
1347 const char *maskval
, /* Pointer to start of mask value */
1348 *ptr
, /* Pointer into value */
1353 * Get the address...
1356 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1357 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1359 if ((maskval
= strchr(value
, '/')) != NULL
)
1362 maskval
= value
+ strlen(value
);
1366 * Check for an IPv6 address...
1372 * Parse hexadecimal IPv6 address...
1377 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1381 else if (!strncmp(ptr
, "::", 2))
1383 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1385 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1390 else if (isxdigit(*ptr
& 255))
1392 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1400 ip
[i
/ 2] |= ipval
<< 16;
1414 if (*ptr
&& *ptr
!= '/')
1418 #endif /* AF_INET6 */
1421 * Parse dotted-decimal IPv4 address...
1424 unsigned val
[4]; /* IPv4 address values */
1428 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1431 * Range check the IP numbers...
1434 for (i
= 0; i
< ipcount
; i
++)
1439 * Make sure the trailing values are zeroed, as some C libraries like
1440 * glibc apparently like to fill the unused arguments with garbage...
1443 for (i
= ipcount
; i
< 4; i
++)
1447 * Merge everything into a 32-bit IPv4 address in ip[3]...
1450 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1453 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1459 * Get the netmask value(s)...
1462 memset(mask
, 0, sizeof(unsigned) * 4);
1464 if (strchr(maskval
, '.'))
1467 * Get dotted-decimal mask...
1470 if (family
!= AF_INET
)
1473 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1476 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1477 mask
[0] = mask
[1] = mask
[2] = 0;
1482 * Get address/bits format...
1488 if (family
== AF_INET6
)
1496 mask
[0] = 0xffffffff;
1498 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1501 mask
[1] = 0xffffffff;
1505 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1508 mask
[2] = 0xffffffff;
1512 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1515 mask
[3] = 0xffffffff;
1519 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1522 #endif /* AF_INET6 */
1527 mask
[0] = 0xffffffff;
1528 mask
[1] = 0xffffffff;
1529 mask
[2] = 0xffffffff;
1532 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1534 mask
[3] = 0xffffffff;
1539 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1540 "get_addr_and_mask(value=\"%s\", "
1541 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1542 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1546 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1549 if ((ip
[0] & ~mask
[0]) != 0 ||
1550 (ip
[1] & ~mask
[1]) != 0 ||
1551 (ip
[2] & ~mask
[2]) != 0 ||
1552 (ip
[3] & ~mask
[3]) != 0)
1560 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1563 static int /* O - 1 on success, 0 on failure */
1564 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1565 char *line
, /* I - Line from file */
1566 char *value
, /* I - Start of value data */
1567 int linenum
) /* I - Current line number */
1569 char *valptr
; /* Pointer into value */
1570 unsigned ip
[4], /* IP address components */
1571 mask
[4]; /* IP netmask components */
1574 if (!strcasecmp(line
, "Encryption"))
1577 * "Encryption xxx" - set required encryption level...
1580 if (!strcasecmp(value
, "never"))
1581 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1582 else if (!strcasecmp(value
, "always"))
1584 cupsdLogMessage(CUPSD_LOG_ERROR
,
1585 "Encryption value \"%s\" on line %d is invalid in this "
1586 "context. Using \"required\" instead.", value
, linenum
);
1588 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1590 else if (!strcasecmp(value
, "required"))
1591 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1592 else if (!strcasecmp(value
, "ifrequested"))
1593 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1596 cupsdLogMessage(CUPSD_LOG_ERROR
,
1597 "Unknown Encryption value %s on line %d.", value
, linenum
);
1601 else if (!strcasecmp(line
, "Order"))
1604 * "Order Deny,Allow" or "Order Allow,Deny"...
1607 if (!strncasecmp(value
, "deny", 4))
1608 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1609 else if (!strncasecmp(value
, "allow", 5))
1610 loc
->order_type
= CUPSD_AUTH_DENY
;
1613 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1618 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1621 * Allow [From] host/ip...
1622 * Deny [From] host/ip...
1625 if (!strncasecmp(value
, "from", 4))
1628 * Strip leading "from"...
1633 while (isspace(*value
& 255))
1638 * Figure out what form the allow/deny address takes:
1649 * nnn.nnn.nnn.nnn/mm
1650 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1653 if (!strcasecmp(value
, "all"))
1659 if (!strcasecmp(line
, "Allow"))
1660 cupsdAllowIP(loc
, zeros
, zeros
);
1662 cupsdDenyIP(loc
, zeros
, zeros
);
1664 else if (!strcasecmp(value
, "none"))
1670 if (!strcasecmp(line
, "Allow"))
1671 cupsdAllowIP(loc
, ones
, zeros
);
1673 cupsdDenyIP(loc
, ones
, zeros
);
1676 else if (value
[0] == '*' || value
[0] == '.' ||
1677 (!isdigit(value
[0] & 255) && value
[0] != '['))
1679 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1680 #endif /* AF_INET6 */
1683 * Host or domain name...
1686 if (value
[0] == '*')
1689 if (!strcasecmp(line
, "Allow"))
1690 cupsdAllowHost(loc
, value
);
1692 cupsdDenyHost(loc
, value
);
1697 * One of many IP address forms...
1700 if (!get_addr_and_mask(value
, ip
, mask
))
1702 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1707 if (!strcasecmp(line
, "Allow"))
1708 cupsdAllowIP(loc
, ip
, mask
);
1710 cupsdDenyIP(loc
, ip
, mask
);
1713 else if (!strcasecmp(line
, "AuthType"))
1716 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1719 if (!strcasecmp(value
, "none"))
1721 loc
->type
= CUPSD_AUTH_NONE
;
1722 loc
->level
= CUPSD_AUTH_ANON
;
1724 else if (!strcasecmp(value
, "basic"))
1726 loc
->type
= CUPSD_AUTH_BASIC
;
1728 if (loc
->level
== CUPSD_AUTH_ANON
)
1729 loc
->level
= CUPSD_AUTH_USER
;
1731 else if (!strcasecmp(value
, "digest"))
1733 loc
->type
= CUPSD_AUTH_DIGEST
;
1735 if (loc
->level
== CUPSD_AUTH_ANON
)
1736 loc
->level
= CUPSD_AUTH_USER
;
1738 else if (!strcasecmp(value
, "basicdigest"))
1740 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1742 if (loc
->level
== CUPSD_AUTH_ANON
)
1743 loc
->level
= CUPSD_AUTH_USER
;
1745 else if (!strcasecmp(value
, "default"))
1747 loc
->type
= CUPSD_AUTH_DEFAULT
;
1749 if (loc
->level
== CUPSD_AUTH_ANON
)
1750 loc
->level
= CUPSD_AUTH_USER
;
1753 else if (!strcasecmp(value
, "negotiate"))
1755 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1757 if (loc
->level
== CUPSD_AUTH_ANON
)
1758 loc
->level
= CUPSD_AUTH_USER
;
1760 #endif /* HAVE_GSSAPI */
1763 cupsdLogMessage(CUPSD_LOG_WARN
,
1764 "Unknown authorization type %s on line %d.",
1769 else if (!strcasecmp(line
, "AuthClass"))
1772 * AuthClass anonymous, user, system, group
1775 if (!strcasecmp(value
, "anonymous"))
1777 loc
->type
= CUPSD_AUTH_NONE
;
1778 loc
->level
= CUPSD_AUTH_ANON
;
1780 cupsdLogMessage(CUPSD_LOG_WARN
,
1781 "\"AuthClass %s\" is deprecated; consider removing "
1785 else if (!strcasecmp(value
, "user"))
1787 loc
->level
= CUPSD_AUTH_USER
;
1789 cupsdLogMessage(CUPSD_LOG_WARN
,
1790 "\"AuthClass %s\" is deprecated; consider using "
1791 "\"Require valid-user\" on line %d.",
1794 else if (!strcasecmp(value
, "group"))
1796 loc
->level
= CUPSD_AUTH_GROUP
;
1798 cupsdLogMessage(CUPSD_LOG_WARN
,
1799 "\"AuthClass %s\" is deprecated; consider using "
1800 "\"Require user @groupname\" on line %d.",
1803 else if (!strcasecmp(value
, "system"))
1805 loc
->level
= CUPSD_AUTH_GROUP
;
1807 cupsdAddName(loc
, "@SYSTEM");
1809 cupsdLogMessage(CUPSD_LOG_WARN
,
1810 "\"AuthClass %s\" is deprecated; consider using "
1811 "\"Require user @SYSTEM\" on line %d.",
1816 cupsdLogMessage(CUPSD_LOG_WARN
,
1817 "Unknown authorization class %s on line %d.",
1822 else if (!strcasecmp(line
, "AuthGroupName"))
1824 cupsdAddName(loc
, value
);
1826 cupsdLogMessage(CUPSD_LOG_WARN
,
1827 "\"AuthGroupName %s\" directive is deprecated; consider "
1828 "using \"Require user @%s\" on line %d.",
1829 value
, value
, linenum
);
1831 else if (!strcasecmp(line
, "Require"))
1834 * Apache synonym for AuthClass and AuthGroupName...
1838 * Require valid-user
1839 * Require group names
1840 * Require user names
1843 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1848 if (!strcasecmp(value
, "valid-user") ||
1849 !strcasecmp(value
, "user"))
1850 loc
->level
= CUPSD_AUTH_USER
;
1851 else if (!strcasecmp(value
, "group"))
1852 loc
->level
= CUPSD_AUTH_GROUP
;
1855 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1861 * Get the list of names from the line...
1864 for (value
= valptr
; *value
;)
1866 while (isspace(*value
& 255))
1869 #ifdef HAVE_AUTHORIZATION_H
1870 if (!strncmp(value
, "@AUTHKEY(", 9))
1873 * Grab "@AUTHKEY(name)" value...
1876 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1882 #endif /* HAVE_AUTHORIZATION_H */
1883 if (*value
== '\"' || *value
== '\'')
1886 * Grab quoted name...
1889 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1896 * Grab literal name.
1899 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1905 cupsdAddName(loc
, value
);
1907 for (value
= valptr
; isspace(*value
& 255); value
++);
1910 else if (!strcasecmp(line
, "Satisfy"))
1912 if (!strcasecmp(value
, "all"))
1913 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
1914 else if (!strcasecmp(value
, "any"))
1915 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
1918 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1931 * 'parse_groups()' - Parse system group names in a string.
1934 static int /* O - 1 on success, 0 on failure */
1935 parse_groups(const char *s
) /* I - Space-delimited groups */
1937 int status
; /* Return status */
1938 char value
[1024], /* Value string */
1939 *valstart
, /* Pointer into value */
1940 *valend
, /* End of value */
1941 quote
; /* Quote character */
1942 struct group
*group
; /* Group */
1946 * Make a copy of the string and parse out the groups...
1949 strlcpy(value
, s
, sizeof(value
));
1954 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1956 if (*valstart
== '\'' || *valstart
== '\"')
1959 * Scan quoted name...
1962 quote
= *valstart
++;
1964 for (valend
= valstart
; *valend
; valend
++)
1965 if (*valend
== quote
)
1971 * Scan space or comma-delimited name...
1974 for (valend
= valstart
; *valend
; valend
++)
1975 if (isspace(*valend
) || *valend
== ',')
1982 group
= getgrnam(valstart
);
1985 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1986 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1997 while (*valstart
== ',' || isspace(*valstart
))
2006 * 'parse_protocols()' - Parse browse protocols in a string.
2009 static int /* O - Browse protocol bits */
2010 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2012 int protocols
; /* Browse protocol bits */
2013 char value
[1024], /* Value string */
2014 *valstart
, /* Pointer into value */
2015 *valend
; /* End of value */
2019 * Empty protocol line yields NULL pointer...
2026 * Loop through the value string,...
2029 strlcpy(value
, s
, sizeof(value
));
2033 for (valstart
= value
; *valstart
;)
2036 * Get the current space/comma-delimited protocol name...
2039 for (valend
= valstart
; *valend
; valend
++)
2040 if (isspace(*valend
& 255) || *valend
== ',')
2047 * Add the protocol to the bitmask...
2050 if (!strcasecmp(valstart
, "cups"))
2051 protocols
|= BROWSE_CUPS
;
2052 else if (!strcasecmp(valstart
, "slp"))
2053 protocols
|= BROWSE_SLP
;
2054 else if (!strcasecmp(valstart
, "ldap"))
2055 protocols
|= BROWSE_LDAP
;
2056 else if (!strcasecmp(valstart
, "dnssd") ||
2057 !strcasecmp(valstart
, "dns-sd") ||
2058 !strcasecmp(valstart
, "bonjour"))
2059 protocols
|= BROWSE_DNSSD
;
2060 else if (!strcasecmp(valstart
, "lpd"))
2061 protocols
|= BROWSE_LPD
;
2062 else if (!strcasecmp(valstart
, "smb"))
2063 protocols
|= BROWSE_SMB
;
2064 else if (!strcasecmp(valstart
, "all"))
2065 protocols
|= BROWSE_ALL
;
2066 else if (strcasecmp(valstart
, "none"))
2067 cupsdLogMessage(CUPSD_LOG_ERROR
,
2068 "Unknown browse protocol \"%s\" ignored!", valstart
);
2070 for (valstart
= valend
; *valstart
; valstart
++)
2071 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2080 * 'read_configuration()' - Read a configuration file.
2083 static int /* O - 1 on success, 0 on failure */
2084 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2086 int i
; /* Looping var */
2087 int linenum
; /* Current line number */
2088 char line
[HTTP_MAX_BUFFER
],
2089 /* Line from file */
2090 temp
[HTTP_MAX_BUFFER
],
2091 /* Temporary buffer for value */
2092 temp2
[HTTP_MAX_BUFFER
],
2093 /* Temporary buffer 2 for value */
2094 *ptr
, /* Pointer into line/temp */
2095 *value
, /* Pointer to value */
2096 *valueptr
; /* Pointer into value */
2097 int valuelen
; /* Length of value */
2098 cupsd_var_t
const *var
; /* Current variable */
2099 http_addrlist_t
*addrlist
, /* Address list */
2100 *addr
; /* Current address */
2101 unsigned ip
[4], /* Address value */
2102 mask
[4]; /* Netmask value */
2103 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2104 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2105 cupsd_location_t
*location
; /* Browse location */
2106 cups_file_t
*incfile
; /* Include file */
2107 char incname
[1024]; /* Include filename */
2108 struct group
*group
; /* Group */
2112 * Loop through each line in the file...
2117 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2120 * Decode the directive...
2123 if (!strcasecmp(line
, "Include") && value
)
2129 if (value
[0] == '/')
2130 strlcpy(incname
, value
, sizeof(incname
));
2132 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2134 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2135 cupsdLogMessage(CUPSD_LOG_ERROR
,
2136 "Unable to include config file \"%s\" - %s",
2137 incname
, strerror(errno
));
2140 read_configuration(incfile
);
2141 cupsFileClose(incfile
);
2144 else if (!strcasecmp(line
, "<Location") && value
)
2150 linenum
= read_location(fp
, value
, linenum
);
2154 else if (!strcasecmp(line
, "<Policy") && value
)
2160 linenum
= read_policy(fp
, value
, linenum
);
2164 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2166 JobRetryInterval
= atoi(value
);
2167 cupsdLogMessage(CUPSD_LOG_WARN
,
2168 "FaxRetryInterval is deprecated; use "
2169 "JobRetryInterval on line %d.", linenum
);
2171 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2173 JobRetryLimit
= atoi(value
);
2174 cupsdLogMessage(CUPSD_LOG_WARN
,
2175 "FaxRetryLimit is deprecated; use "
2176 "JobRetryLimit on line %d.", linenum
);
2178 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2180 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2181 #endif /* HAVE_SSL */
2185 * Add listening address(es) to the list...
2188 cupsd_listener_t
*lis
; /* New listeners array */
2192 * Get the address list...
2195 addrlist
= get_address(value
, IPP_PORT
);
2199 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2205 * Add each address...
2208 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2211 * Allocate another listener...
2215 Listeners
= cupsArrayNew(NULL
, NULL
);
2219 cupsdLogMessage(CUPSD_LOG_ERROR
,
2220 "Unable to allocate %s at line %d - %s.",
2221 line
, linenum
, strerror(errno
));
2225 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2227 cupsdLogMessage(CUPSD_LOG_ERROR
,
2228 "Unable to allocate %s at line %d - %s.",
2229 line
, linenum
, strerror(errno
));
2233 cupsArrayAdd(Listeners
, lis
);
2236 * Copy the current address and log it...
2239 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2243 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2244 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2245 #endif /* HAVE_SSL */
2247 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2250 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2251 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2252 ntohs(lis
->address
.ipv6
.sin6_port
));
2254 #endif /* AF_INET6 */
2256 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2257 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2259 #endif /* AF_LOCAL */
2260 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2261 ntohs(lis
->address
.ipv4
.sin_port
));
2268 httpAddrFreeList(addrlist
);
2270 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2273 * Add a browse address to the list...
2276 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2279 if (NumBrowsers
== 0)
2280 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2282 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2286 cupsdLogMessage(CUPSD_LOG_ERROR
,
2287 "Unable to allocate BrowseAddress at line %d - %s.",
2288 linenum
, strerror(errno
));
2293 dira
+= NumBrowsers
;
2295 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2297 if (!strcasecmp(value
, "@LOCAL"))
2300 * Send browse data to all local interfaces...
2303 strcpy(dira
->iface
, "*");
2306 else if (!strncasecmp(value
, "@IF(", 4))
2309 * Send browse data to the named interface...
2312 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2314 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2320 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2323 * Only IPv4 addresses are supported...
2326 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2327 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2332 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2333 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2335 cupsdLogMessage(CUPSD_LOG_INFO
,
2336 "Sending browsing info to %s:%d (IPv4)",
2337 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2342 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2345 httpAddrFreeList(addrlist
);
2348 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2351 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2354 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2357 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2358 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2360 if (location
== NULL
)
2361 cupsdLogMessage(CUPSD_LOG_ERROR
,
2362 "Unable to initialize browse access control list!");
2363 else if (!strncasecmp(value
, "deny", 4))
2364 location
->order_type
= CUPSD_AUTH_ALLOW
;
2365 else if (!strncasecmp(value
, "allow", 5))
2366 location
->order_type
= CUPSD_AUTH_DENY
;
2368 cupsdLogMessage(CUPSD_LOG_ERROR
,
2369 "Unknown BrowseOrder value %s on line %d.",
2372 else if (!strcasecmp(line
, "BrowseProtocols") ||
2373 !strcasecmp(line
, "BrowseLocalProtocols") ||
2374 !strcasecmp(line
, "BrowseRemoteProtocols"))
2377 * "BrowseProtocols name [... name]"
2378 * "BrowseLocalProtocols name [... name]"
2379 * "BrowseRemoteProtocols name [... name]"
2382 int protocols
= parse_protocols(value
);
2386 cupsdLogMessage(CUPSD_LOG_ERROR
,
2387 "Unknown browse protocol \"%s\" on line %d.",
2392 if (strcasecmp(line
, "BrowseLocalProtocols"))
2393 BrowseRemoteProtocols
= protocols
;
2394 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2395 BrowseLocalProtocols
= protocols
;
2397 else if ((!strcasecmp(line
, "BrowseAllow") ||
2398 !strcasecmp(line
, "BrowseDeny")) && value
)
2401 * BrowseAllow [From] host/ip...
2402 * BrowseDeny [From] host/ip...
2405 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2406 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2408 if (location
== NULL
)
2409 cupsdLogMessage(CUPSD_LOG_ERROR
,
2410 "Unable to initialize browse access control list!");
2413 if (!strncasecmp(value
, "from ", 5))
2416 * Strip leading "from"...
2421 while (isspace(*value
))
2426 * Figure out what form the allow/deny address takes:
2437 * nnn.nnn.nnn.nnn/mm
2438 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2441 if (!strcasecmp(value
, "all"))
2447 if (!strcasecmp(line
, "BrowseAllow"))
2448 cupsdAllowIP(location
, zeros
, zeros
);
2450 cupsdDenyIP(location
, zeros
, zeros
);
2452 else if (!strcasecmp(value
, "none"))
2458 if (!strcasecmp(line
, "BrowseAllow"))
2459 cupsdAllowIP(location
, ones
, zeros
);
2461 cupsdDenyIP(location
, ones
, zeros
);
2464 else if (value
[0] == '*' || value
[0] == '.' ||
2465 (!isdigit(value
[0] & 255) && value
[0] != '['))
2467 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2468 #endif /* AF_INET6 */
2471 * Host or domain name...
2474 if (value
[0] == '*')
2477 if (!strcasecmp(line
, "BrowseAllow"))
2478 cupsdAllowHost(location
, value
);
2480 cupsdDenyHost(location
, value
);
2485 * One of many IP address forms...
2488 if (!get_addr_and_mask(value
, ip
, mask
))
2490 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2495 if (!strcasecmp(line
, "BrowseAllow"))
2496 cupsdAllowIP(location
, ip
, mask
);
2498 cupsdDenyIP(location
, ip
, mask
);
2502 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2505 * BrowseRelay [from] source [to] destination
2509 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2511 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2515 cupsdLogMessage(CUPSD_LOG_ERROR
,
2516 "Unable to allocate BrowseRelay at line %d - %s.",
2517 linenum
, strerror(errno
));
2524 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2526 if (!strncasecmp(value
, "from ", 5))
2529 * Strip leading "from"...
2534 while (isspace(*value
))
2539 * Figure out what form the from address takes:
2548 * nnn.nnn.nnn.nnn/mm
2549 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2553 if (value
[0] == '*' || value
[0] == '.' ||
2554 (!isdigit(value
[0] & 255) && value
[0] != '['))
2556 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2557 #endif /* AF_INET6 */
2560 * Host or domain name...
2563 if (value
[0] == '*')
2566 strlcpy(temp
, value
, sizeof(temp
));
2567 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2570 relay
->from
.type
= CUPSD_AUTH_NAME
;
2572 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2574 cupsdLogMessage(CUPSD_LOG_ERROR
,
2575 "Unable to allocate BrowseRelay name at line %d - %s.",
2576 linenum
, strerror(errno
));
2580 relay
->from
.mask
.name
.length
= strlen(temp
);
2585 * One of many IP address forms...
2588 if (!get_addr_and_mask(value
, ip
, mask
))
2590 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2595 relay
->from
.type
= CUPSD_AUTH_IP
;
2596 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2597 sizeof(relay
->from
.mask
.ip
.address
));
2598 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2599 sizeof(relay
->from
.mask
.ip
.netmask
));
2603 * Skip value and trailing whitespace...
2606 for (; *value
; value
++)
2607 if (isspace(*value
))
2610 while (isspace(*value
))
2613 if (!strncasecmp(value
, "to ", 3))
2616 * Strip leading "to"...
2621 while (isspace(*value
))
2626 * Get "to" address and port...
2629 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2632 * Only IPv4 addresses are supported...
2635 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2636 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2641 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2643 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2645 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2646 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2647 relay
->from
.mask
.ip
.address
[0] >> 24,
2648 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2649 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2650 relay
->from
.mask
.ip
.address
[0] & 255,
2651 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2652 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2653 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2654 relay
->from
.mask
.ip
.netmask
[0] & 255);
2656 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2658 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2659 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2664 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2667 httpAddrFreeList(addrlist
);
2671 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2672 free(relay
->from
.mask
.name
.name
);
2674 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2678 else if (!strcasecmp(line
, "BrowsePoll") && value
)
2681 * BrowsePoll address[:port]
2684 char *portname
; /* Port name */
2685 int portnum
; /* Port number */
2686 struct servent
*service
; /* Service */
2690 * Extract the port name from the address...
2693 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2697 if (isdigit(*portname
& 255))
2698 portnum
= atoi(portname
);
2699 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2700 portnum
= ntohs(service
->s_port
);
2703 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2709 portnum
= ippPort();
2712 * Add the poll entry...
2716 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2718 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2722 cupsdLogMessage(CUPSD_LOG_ERROR
,
2723 "Unable to allocate BrowsePoll at line %d - %s.",
2724 linenum
, strerror(errno
));
2732 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2734 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2735 pollp
->port
= portnum
;
2737 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2740 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
2743 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2746 if (!strcasecmp(value
, "none"))
2747 DefaultAuthType
= CUPSD_AUTH_NONE
;
2748 else if (!strcasecmp(value
, "basic"))
2749 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2750 else if (!strcasecmp(value
, "digest"))
2751 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2752 else if (!strcasecmp(value
, "basicdigest"))
2753 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2755 else if (!strcasecmp(value
, "negotiate"))
2756 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2757 #endif /* HAVE_GSSAPI */
2760 cupsdLogMessage(CUPSD_LOG_WARN
,
2761 "Unknown default authorization type %s on line %d.",
2767 else if (!strcasecmp(line
, "DefaultEncryption"))
2770 * DefaultEncryption {Never,IfRequested,Required}
2773 if (!value
|| !strcasecmp(value
, "never"))
2774 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2775 else if (!strcasecmp(value
, "required"))
2776 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2777 else if (!strcasecmp(value
, "ifrequested"))
2778 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2781 cupsdLogMessage(CUPSD_LOG_WARN
,
2782 "Unknown default encryption %s on line %d.",
2787 #endif /* HAVE_SSL */
2789 else if (!strcasecmp(line
, "Krb5Keytab") && value
)
2791 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2794 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2795 gsskrb5_register_acceptor_identity(value
);
2797 cupsdSetEnv("KRB5_KTNAME", value
);
2798 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2800 #endif /* HAVE_GSSAPI */
2801 else if (!strcasecmp(line
, "User") && value
)
2804 * User ID to run as...
2807 if (isdigit(value
[0] & 255))
2809 int uid
= atoi(value
);
2812 cupsdLogMessage(CUPSD_LOG_ERROR
,
2813 "Will not use User 0 as specified on line %d "
2814 "for security reasons. You must use a non-"
2815 "privileged account instead.",
2822 struct passwd
*p
; /* Password information */
2825 p
= getpwnam(value
);
2830 cupsdLogMessage(CUPSD_LOG_ERROR
,
2831 "Will not use User %s (UID=0) as specified on line "
2832 "%d for security reasons. You must use a non-"
2833 "privileged account instead.",
2839 cupsdLogMessage(CUPSD_LOG_ERROR
,
2840 "Unknown User \"%s\" on line %d, ignoring!",
2844 else if (!strcasecmp(line
, "Group") && value
)
2847 * Group ID to run as...
2850 if (isdigit(value
[0]))
2851 Group
= atoi(value
);
2855 group
= getgrnam(value
);
2858 Group
= group
->gr_gid
;
2860 cupsdLogMessage(CUPSD_LOG_ERROR
,
2861 "Unknown Group \"%s\" on line %d, ignoring!",
2865 else if (!strcasecmp(line
, "SystemGroup") && value
)
2868 * SystemGroup (admin) group(s)...
2871 if (!parse_groups(value
))
2872 cupsdLogMessage(CUPSD_LOG_ERROR
,
2873 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2876 else if (!strcasecmp(line
, "HostNameLookups") && value
)
2879 * Do hostname lookups?
2882 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
2883 !strcasecmp(value
, "false"))
2884 HostNameLookups
= 0;
2885 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
2886 !strcasecmp(value
, "true"))
2887 HostNameLookups
= 1;
2888 else if (!strcasecmp(value
, "double"))
2889 HostNameLookups
= 2;
2891 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2894 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
2897 * Amount of logging to do to access log...
2900 if (!strcasecmp(value
, "all"))
2901 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
2902 else if (!strcasecmp(value
, "actions"))
2903 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
2904 else if (!strcasecmp(value
, "config"))
2905 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
2907 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
2910 else if (!strcasecmp(line
, "LogLevel") && value
)
2913 * Amount of logging to do to error log...
2916 if (!strcasecmp(value
, "debug2"))
2917 LogLevel
= CUPSD_LOG_DEBUG2
;
2918 else if (!strcasecmp(value
, "debug"))
2919 LogLevel
= CUPSD_LOG_DEBUG
;
2920 else if (!strcasecmp(value
, "info"))
2921 LogLevel
= CUPSD_LOG_INFO
;
2922 else if (!strcasecmp(value
, "notice"))
2923 LogLevel
= CUPSD_LOG_NOTICE
;
2924 else if (!strcasecmp(value
, "warn"))
2925 LogLevel
= CUPSD_LOG_WARN
;
2926 else if (!strcasecmp(value
, "error"))
2927 LogLevel
= CUPSD_LOG_ERROR
;
2928 else if (!strcasecmp(value
, "crit"))
2929 LogLevel
= CUPSD_LOG_CRIT
;
2930 else if (!strcasecmp(value
, "alert"))
2931 LogLevel
= CUPSD_LOG_ALERT
;
2932 else if (!strcasecmp(value
, "emerg"))
2933 LogLevel
= CUPSD_LOG_EMERG
;
2934 else if (!strcasecmp(value
, "none"))
2935 LogLevel
= CUPSD_LOG_NONE
;
2937 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2940 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
2943 * Format of printcap file?
2946 if (!strcasecmp(value
, "bsd"))
2947 PrintcapFormat
= PRINTCAP_BSD
;
2948 else if (!strcasecmp(value
, "solaris"))
2949 PrintcapFormat
= PRINTCAP_SOLARIS
;
2951 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2954 else if (!strcasecmp(line
, "ServerTokens") && value
)
2957 * Set the string used for the Server header...
2960 struct utsname plat
; /* Platform info */
2965 if (!strcasecmp(value
, "ProductOnly"))
2966 cupsdSetString(&ServerHeader
, "CUPS");
2967 else if (!strcasecmp(value
, "Major"))
2968 cupsdSetString(&ServerHeader
, "CUPS/1");
2969 else if (!strcasecmp(value
, "Minor"))
2970 cupsdSetString(&ServerHeader
, "CUPS/1.4");
2971 else if (!strcasecmp(value
, "Minimal"))
2972 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2973 else if (!strcasecmp(value
, "OS"))
2974 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2975 else if (!strcasecmp(value
, "Full"))
2976 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2978 else if (!strcasecmp(value
, "None"))
2979 cupsdClearString(&ServerHeader
);
2981 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2984 else if (!strcasecmp(line
, "PassEnv") && value
)
2987 * PassEnv variable [... variable]
2992 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2993 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2996 if (value
[valuelen
])
2998 value
[valuelen
] = '\0';
3002 cupsdSetEnv(value
, NULL
);
3004 for (value
+= valuelen
; *value
; value
++)
3005 if (!isspace(*value
) || *value
!= ',')
3009 else if (!strcasecmp(line
, "SetEnv") && value
)
3012 * SetEnv variable value
3015 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3023 while (isspace(*valueptr
& 255))
3026 cupsdSetEnv(value
, valueptr
);
3029 cupsdLogMessage(CUPSD_LOG_ERROR
,
3030 "Missing value for SetEnv directive on line %d.",
3036 * Find a simple variable in the list...
3039 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3040 if (!strcasecmp(line
, var
->name
))
3046 * Unknown directive! Output an error message and continue...
3050 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3053 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3060 case CUPSD_VARTYPE_INTEGER
:
3062 cupsdLogMessage(CUPSD_LOG_ERROR
,
3063 "Missing integer value for %s on line %d!",
3068 char *units
; /* Units */
3071 n
= strtol(value
, &units
, 0);
3073 if (units
&& *units
)
3075 if (tolower(units
[0] & 255) == 'g')
3076 n
*= 1024 * 1024 * 1024;
3077 else if (tolower(units
[0] & 255) == 'm')
3079 else if (tolower(units
[0] & 255) == 'k')
3081 else if (tolower(units
[0] & 255) == 't')
3086 cupsdLogMessage(CUPSD_LOG_ERROR
,
3087 "Bad negative integer value for %s on line %d!",
3090 *((int *)var
->ptr
) = n
;
3094 case CUPSD_VARTYPE_BOOLEAN
:
3096 cupsdLogMessage(CUPSD_LOG_ERROR
,
3097 "Missing boolean value for %s on line %d!",
3099 else if (!strcasecmp(value
, "true") ||
3100 !strcasecmp(value
, "on") ||
3101 !strcasecmp(value
, "enabled") ||
3102 !strcasecmp(value
, "yes") ||
3104 *((int *)var
->ptr
) = TRUE
;
3105 else if (!strcasecmp(value
, "false") ||
3106 !strcasecmp(value
, "off") ||
3107 !strcasecmp(value
, "disabled") ||
3108 !strcasecmp(value
, "no") ||
3109 !strcasecmp(value
, "0"))
3110 *((int *)var
->ptr
) = FALSE
;
3112 cupsdLogMessage(CUPSD_LOG_ERROR
,
3113 "Unknown boolean value %s on line %d.",
3117 case CUPSD_VARTYPE_PATHNAME
:
3120 cupsdLogMessage(CUPSD_LOG_ERROR
,
3121 "Missing pathname value for %s on line %d!",
3126 if (value
[0] == '/')
3127 strlcpy(temp
, value
, sizeof(temp
));
3129 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3131 if (access(temp
, 0))
3133 cupsdLogMessage(CUPSD_LOG_ERROR
,
3134 "File or directory for \"%s %s\" on line %d "
3135 "does not exist!", line
, value
, linenum
);
3139 case CUPSD_VARTYPE_STRING
:
3140 cupsdSetString((char **)var
->ptr
, value
);
3151 * 'read_location()' - Read a <Location path> definition.
3154 static int /* O - New line number or 0 on error */
3155 read_location(cups_file_t
*fp
, /* I - Configuration file */
3156 char *location
, /* I - Location name/path */
3157 int linenum
) /* I - Current line number */
3159 cupsd_location_t
*loc
, /* New location */
3160 *parent
; /* Parent location */
3161 char line
[HTTP_MAX_BUFFER
],
3163 *value
, /* Value for directive */
3164 *valptr
; /* Pointer into value */
3167 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3170 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3173 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3176 * Decode the directive...
3179 if (!strcasecmp(line
, "</Location>"))
3181 else if (!strcasecmp(line
, "<Limit") ||
3182 !strcasecmp(line
, "<LimitExcept"))
3186 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3190 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3196 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3201 if (!strcmp(value
, "ALL"))
3202 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3203 else if (!strcmp(value
, "GET"))
3204 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3205 else if (!strcmp(value
, "HEAD"))
3206 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3207 else if (!strcmp(value
, "OPTIONS"))
3208 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3209 else if (!strcmp(value
, "POST"))
3210 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3211 else if (!strcmp(value
, "PUT"))
3212 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3213 else if (!strcmp(value
, "TRACE"))
3214 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3216 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3219 for (value
= valptr
; isspace(*value
& 255); value
++);
3222 if (!strcasecmp(line
, "<LimitExcept"))
3223 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3225 parent
->limit
&= ~loc
->limit
;
3227 else if (!strcasecmp(line
, "</Limit>") ||
3228 !strcasecmp(line
, "</LimitExcept>"))
3230 else if (!parse_aaa(loc
, line
, value
, linenum
))
3232 cupsdLogMessage(CUPSD_LOG_ERROR
,
3233 "Unknown Location directive %s on line %d.",
3239 cupsdLogMessage(CUPSD_LOG_ERROR
,
3240 "Unexpected end-of-file at line %d while reading location!",
3248 * 'read_policy()' - Read a <Policy name> definition.
3251 static int /* O - New line number or 0 on error */
3252 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3253 char *policy
, /* I - Location name/path */
3254 int linenum
) /* I - Current line number */
3256 int i
; /* Looping var */
3257 cupsd_policy_t
*pol
; /* Policy */
3258 cupsd_location_t
*op
; /* Policy operation */
3259 int num_ops
; /* Number of IPP operations */
3260 ipp_op_t ops
[100]; /* Operations */
3261 char line
[HTTP_MAX_BUFFER
],
3263 *value
, /* Value for directive */
3264 *valptr
; /* Pointer into value */
3268 * Create the policy...
3271 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3275 * Read from the file...
3281 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3284 * Decode the directive...
3287 if (!strcasecmp(line
, "</Policy>"))
3290 cupsdLogMessage(CUPSD_LOG_WARN
,
3291 "Missing </Limit> before </Policy> on line %d!",
3295 * Verify that we have an explicit policy for CUPS-Get-Document
3296 * (ensures that upgrades do not introduce new security issues...)
3299 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3300 op
->op
== IPP_ANY_OPERATION
)
3302 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3303 op
->op
!= IPP_ANY_OPERATION
)
3306 * Add a new limit for CUPS-Get-Document using the Send-Document
3307 * limit as a template...
3310 cupsdLogMessage(CUPSD_LOG_WARN
,
3311 "No limit for CUPS-Get-Document defined in policy %s "
3312 "- using Send-Document's policy", pol
->name
);
3314 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3320 else if (!strcasecmp(line
, "<Limit") && !op
)
3324 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3329 * Scan for IPP operation names...
3336 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3341 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3343 if (!strcasecmp(value
, "All"))
3344 ops
[num_ops
] = IPP_ANY_OPERATION
;
3345 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3346 cupsdLogMessage(CUPSD_LOG_ERROR
,
3347 "Bad IPP operation name \"%s\" on line %d!",
3353 cupsdLogMessage(CUPSD_LOG_ERROR
,
3354 "Too many operations listed on line %d!",
3357 for (value
= valptr
; isspace(*value
& 255); value
++);
3361 * If none are specified, apply the policy to all operations...
3366 ops
[0] = IPP_ANY_OPERATION
;
3371 * Add a new policy for the first operation...
3374 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3376 else if (!strcasecmp(line
, "</Limit>") && op
)
3379 * Finish the current operation limit...
3385 * Copy the policy to the other operations...
3388 for (i
= 1; i
< num_ops
; i
++)
3389 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3396 cupsdLogMessage(CUPSD_LOG_ERROR
,
3397 "Missing <Limit ops> directive before %s on line %d.",
3401 else if (!parse_aaa(op
, line
, value
, linenum
))
3404 cupsdLogMessage(CUPSD_LOG_ERROR
,
3405 "Unknown Policy Limit directive %s on line %d.",
3408 cupsdLogMessage(CUPSD_LOG_ERROR
,
3409 "Unknown Policy directive %s on line %d.",
3416 cupsdLogMessage(CUPSD_LOG_ERROR
,
3417 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3425 * End of "$Id: conf.c 7694 2008-06-26 00:23:20Z mike $".