2 * "$Id: conf.c 6930 2007-09-08 00:28:06Z 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
},
85 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
86 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
87 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
88 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
89 #endif /* HAVE_LDAP */
90 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
91 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
92 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
93 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
94 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
95 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
96 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
97 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
98 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
99 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
100 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
101 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
102 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
103 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
104 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
105 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
106 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
107 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
108 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
109 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
110 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
111 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
112 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
113 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
115 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
116 #endif /* HAVE_GSSAPI */
117 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
118 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
119 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
120 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
121 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
122 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
123 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
125 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
126 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
127 #endif /* HAVE_LAUNCHD */
128 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
129 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
130 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
131 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
132 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
148 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
149 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
150 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
151 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
152 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
153 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
154 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
155 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
156 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
157 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
158 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
159 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
160 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
162 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
163 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
164 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
165 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
166 #endif /* HAVE_SSL */
167 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
168 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
169 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
170 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
171 #ifdef HAVE_AUTHORIZATION_H
172 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
173 #endif /* HAVE_AUTHORIZATION_H */
174 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
175 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
176 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
178 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
181 static const unsigned ones
[4] =
183 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
185 static const unsigned zeros
[4] =
187 0x00000000, 0x00000000, 0x00000000, 0x00000000
194 static http_addrlist_t
*get_address(const char *value
, int defport
);
195 static int get_addr_and_mask(const char *value
, unsigned *ip
,
197 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
198 char *value
, int linenum
);
199 static int parse_groups(const char *s
);
200 static int parse_protocols(const char *s
);
201 static int read_configuration(cups_file_t
*fp
);
202 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
203 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
207 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
210 int /* O - 0 on success, -1 on error, 1 on warning */
211 cupsdCheckPermissions(
212 const char *filename
, /* I - File/directory name */
213 const char *suffix
, /* I - Additional file/directory name */
214 int mode
, /* I - Permissions */
215 int user
, /* I - Owner */
216 int group
, /* I - Group */
217 int is_dir
, /* I - 1 = directory, 0 = file */
218 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
220 int dir_created
= 0; /* Did we create a directory? */
221 char pathname
[1024]; /* File name with prefix */
222 struct stat fileinfo
; /* Stat buffer */
226 * Prepend the given root to the filename before testing it...
231 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
236 * See if we can stat the file/directory...
239 if (stat(filename
, &fileinfo
))
241 if (errno
== ENOENT
&& create_dir
)
244 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
247 if (mkdir(filename
, mode
))
250 cupsdLogMessage(CUPSD_LOG_ERROR
,
251 "Unable to create directory \"%s\" - %s", filename
,
254 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
263 return (create_dir
? -1 : 1);
267 * Make sure it's a regular file...
270 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
272 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
276 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
279 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
281 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
287 * Fix owner, group, and mode as needed...
290 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
293 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
296 if (chown(filename
, user
, group
) && !getuid())
299 cupsdLogMessage(CUPSD_LOG_ERROR
,
300 "Unable to change ownership of \"%s\" - %s", filename
,
303 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
310 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
313 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
316 if (chmod(filename
, mode
))
319 cupsdLogMessage(CUPSD_LOG_ERROR
,
320 "Unable to change permissions of \"%s\" - %s", filename
,
323 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
331 * Everything is OK...
339 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
342 int /* O - 1 on success, 0 otherwise */
343 cupsdReadConfiguration(void)
345 int i
; /* Looping var */
346 cups_file_t
*fp
; /* Configuration file */
347 int status
; /* Return status */
348 char temp
[1024], /* Temporary buffer */
349 mimedir
[1024], /* MIME directory */
350 *slash
; /* Directory separator */
351 cups_lang_t
*language
; /* Language */
352 struct passwd
*user
; /* Default user */
353 struct group
*group
; /* Default group */
354 char *old_serverroot
, /* Old ServerRoot */
355 *old_requestroot
; /* Old RequestRoot */
356 const char *tmpdir
; /* TMPDIR environment variable */
357 struct stat tmpinfo
; /* Temporary directory info */
358 cupsd_policy_t
*p
; /* Policy */
362 * Save the old root paths...
365 old_serverroot
= NULL
;
366 cupsdSetString(&old_serverroot
, ServerRoot
);
367 old_requestroot
= NULL
;
368 cupsdSetString(&old_requestroot
, RequestRoot
);
371 * Reset the server configuration data...
374 cupsdDeleteAllLocations();
393 for (i
= 0; i
< NumRelays
; i
++)
394 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
395 free(Relays
[i
].from
.mask
.name
.name
);
402 cupsdDeleteAllListeners();
408 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
409 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
410 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
411 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
412 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
413 cupsdSetString(&DataDir
, CUPS_DATADIR
);
414 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
415 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
416 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
417 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
418 cupsdSetString(&PageLogFormat
,
419 "%p %j %u %T %P %C %{job-billing} "
420 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
421 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
422 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
423 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
424 cupsdSetString(&RemoteRoot
, "remroot");
425 cupsdSetString(&ServerHeader
, "CUPS/1.4");
426 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
428 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
429 #endif /* HAVE_GSSAPI */
431 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
432 PrintcapFormat
= PRINTCAP_SOLARIS
;
434 PrintcapFormat
= PRINTCAP_BSD
;
436 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
437 if ((slash
= strrchr(temp
, '/')) != NULL
)
440 cupsdSetString(&ServerRoot
, temp
);
442 cupsdClearString(&Classification
);
443 ClassifyOverride
= 0;
447 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
449 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
450 cupsdSetString(&ServerKey
, "ssl/server.key");
451 # endif /* HAVE_CDSASSL */
452 #endif /* HAVE_SSL */
454 language
= cupsLangDefault();
456 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
457 cupsdSetString(&DefaultLanguage
, "en");
459 cupsdSetString(&DefaultLanguage
, language
->language
);
461 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
463 cupsdSetString(&RIPCache
, "8m");
465 cupsdSetString(&TempDir
, NULL
);
468 * Find the default user...
471 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
476 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
477 * complement number...)
486 * Find the default group...
489 group
= getgrnam(CUPS_DEFAULT_GROUP
);
493 Group
= group
->gr_gid
;
497 * Fallback to group "nobody"...
500 group
= getgrnam("nobody");
504 Group
= group
->gr_gid
;
508 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
509 * complement number...)
520 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
521 DefaultAuthType
= CUPSD_AUTH_BASIC
;
523 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
524 #endif /* HAVE_SSL */
525 DirtyCleanInterval
= 60;
527 JobRetryInterval
= 300;
532 HostNameLookups
= FALSE
;
533 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
534 ImplicitAnyClasses
= FALSE
;
535 HideImplicitMembers
= TRUE
;
537 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
538 ListenBackLog
= SOMAXCONN
;
539 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
540 LogLevel
= CUPSD_LOG_ERROR
;
542 MaxClientsPerHost
= 0;
543 MaxLogSize
= 1024 * 1024;
544 MaxPrinterHistory
= 10;
547 RootCertDuration
= 300;
548 Timeout
= DEFAULT_TIMEOUT
;
551 BrowseInterval
= DEFAULT_INTERVAL
;
552 BrowsePort
= ippPort();
553 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
554 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
555 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
556 BrowseTimeout
= DEFAULT_TIMEOUT
;
557 Browsing
= CUPS_DEFAULT_BROWSING
;
558 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
560 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
561 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
563 cupsdClearString(&BrowseLocalOptions
);
564 cupsdClearString(&BrowseRemoteOptions
);
566 cupsdSetString(&ErrorPolicy
, "stop-printer");
569 cupsdClearString(&BrowseLDAPBindDN
);
570 cupsdClearString(&BrowseLDAPDN
);
571 cupsdClearString(&BrowseLDAPPassword
);
572 cupsdClearString(&BrowseLDAPServer
);
573 cupsdClearString(&BrowseLDAPCACertFile
);
574 #endif /* HAVE_LDAP */
576 JobHistory
= DEFAULT_HISTORY
;
577 JobFiles
= DEFAULT_FILES
;
582 MaxJobsPerPrinter
= 0;
583 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
585 cupsdDeleteAllPolicies();
586 cupsdClearString(&DefaultPolicy
);
588 #ifdef HAVE_AUTHORIZATION_H
589 cupsdClearString(&SystemGroupAuthKey
);
590 #endif /* HAVE_AUTHORIZATION_H */
592 MaxSubscriptions
= 100;
593 MaxSubscriptionsPerJob
= 0;
594 MaxSubscriptionsPerPrinter
= 0;
595 MaxSubscriptionsPerUser
= 0;
596 DefaultLeaseDuration
= 86400;
597 MaxLeaseDuration
= 0;
600 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
601 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
602 #endif /* HAVE_LAUNCHD */
606 #endif /* __APPLE__ */
609 * Read the configuration file...
612 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
615 status
= read_configuration(fp
);
625 * See if the ServerName is an IP address...
628 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
630 ServerNameIsIP
= !*slash
;
633 * Use the default system group if none was supplied in cupsd.conf...
636 if (NumSystemGroups
== 0)
638 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
641 * Find the group associated with GID 0...
648 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
650 cupsdSetString(&SystemGroups
[0], "unknown");
652 SystemGroupIDs
[0] = 0;
658 * Get the access control list for browsing...
661 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
664 * Open the system log for cupsd if necessary...
668 if (!strcmp(AccessLog
, "syslog") ||
669 !strcmp(ErrorLog
, "syslog") ||
670 !strcmp(PageLog
, "syslog"))
671 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
672 #endif /* HAVE_VSYSLOG */
675 * Log the configuration file that was used...
678 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
682 * Validate the Group and SystemGroup settings - they cannot be the same,
683 * otherwise the CGI programs will be able to authenticate as root without
689 for (i
= 0; i
< NumSystemGroups
; i
++)
690 if (Group
== SystemGroupIDs
[i
])
693 if (i
< NumSystemGroups
)
696 * Log the error and reset the group to a safe value...
699 cupsdLogMessage(CUPSD_LOG_NOTICE
,
700 "Group and SystemGroup cannot use the same groups!");
701 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
703 group
= getgrnam("nobody");
707 Group
= group
->gr_gid
;
711 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
712 * complement number...)
721 * Check that we have at least one listen/port line; if not, report this
722 * as an error and exit!
725 if (cupsArrayCount(Listeners
) == 0)
731 cupsdLogMessage(CUPSD_LOG_EMERG
,
732 "No valid Listen or Port lines were found in the configuration file!");
738 cupsdEndProcess(getpid(), 0);
742 * Set the default locale using the language and charset...
745 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
748 * Update all relative filenames to include the full path from ServerRoot...
751 if (DocumentRoot
[0] != '/')
752 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
754 if (RequestRoot
[0] != '/')
755 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
757 if (ServerBin
[0] != '/')
758 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
760 if (StateDir
[0] != '/')
761 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
763 if (CacheDir
[0] != '/')
764 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
767 if (ServerCertificate
[0] != '/')
768 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
770 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
772 chown(ServerCertificate
, RunUser
, Group
);
773 chmod(ServerCertificate
, 0600);
776 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
777 if (ServerKey
[0] != '/')
778 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
780 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
782 chown(ServerKey
, RunUser
, Group
);
783 chmod(ServerKey
, 0600);
785 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
786 #endif /* HAVE_SSL */
789 * Make sure that directories and config files are owned and
790 * writable by the user and group in the cupsd.conf file...
793 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
795 if (cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
797 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
799 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
801 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
803 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
804 SystemGroupIDs
[0], 1, 1) < 0 ||
805 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
807 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
809 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
811 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
813 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
815 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
817 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
822 * Update TempDir to the default if it hasn't been set already...
827 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
830 * TMPDIR is defined, see if it is OK for us to use...
833 if (stat(tmpdir
, &tmpinfo
))
834 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
835 tmpdir
, strerror(errno
));
836 else if (!S_ISDIR(tmpinfo
.st_mode
))
837 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
839 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
840 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
841 !(tmpinfo
.st_mode
& S_IWOTH
))
842 cupsdLogMessage(CUPSD_LOG_ERROR
,
843 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
845 cupsdSetString(&TempDir
, tmpdir
);
850 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
852 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
857 * Make sure the temporary directory has the right permissions...
860 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
864 * Update ownership and permissions if the CUPS temp directory
865 * is under the spool directory or does not exist...
868 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
873 * Setup environment variables...
879 * Check the MaxClients setting, and then allocate memory for it...
882 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
885 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
888 MaxClients
= MaxFDs
/ 3;
891 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
895 * Check the MaxActiveJobs setting; limit to 1/3 the available
896 * file descriptors, since we need a pipe for each job...
899 if (MaxActiveJobs
> (MaxFDs
/ 3))
900 MaxActiveJobs
= MaxFDs
/ 3;
902 if (Classification
&& !strcasecmp(Classification
, "none"))
903 cupsdClearString(&Classification
);
906 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
909 * Update the MaxClientsPerHost value, as needed...
912 if (MaxClientsPerHost
<= 0)
913 MaxClientsPerHost
= MaxClients
;
915 if (MaxClientsPerHost
> MaxClients
)
916 MaxClientsPerHost
= MaxClients
;
918 cupsdLogMessage(CUPSD_LOG_INFO
,
919 "Allowing up to %d client connections per host.",
923 * Make sure that BrowseTimeout is at least twice the interval...
926 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
928 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
932 BrowseTimeout
= BrowseInterval
* 2;
934 BrowseTimeout
= DEFAULT_TIMEOUT
;
936 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
941 * Update the default policy, as needed...
945 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
947 DefaultPolicyPtr
= NULL
;
949 if (!DefaultPolicyPtr
)
951 cupsd_location_t
*po
; /* New policy operation */
955 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
958 cupsdSetString(&DefaultPolicy
, "default");
960 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
961 cupsdLogMessage(CUPSD_LOG_INFO
,
962 "Using policy \"default\" as the default!");
965 cupsdLogMessage(CUPSD_LOG_INFO
,
966 "Creating CUPS default administrative policy:");
968 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
970 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
971 cupsdLogMessage(CUPSD_LOG_INFO
,
972 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
973 "Release-Job Restart-Job Purge-Jobs "
974 "Set-Job-Attributes Create-Job-Subscription "
975 "Renew-Subscription Cancel-Subscription "
976 "Get-Notifications Reprocess-Job Cancel-Current-Job "
977 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
978 "CUPS-Authenticate-Job CUPS-Get-Document>");
979 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
981 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
982 po
->order_type
= CUPSD_AUTH_ALLOW
;
983 po
->level
= CUPSD_AUTH_USER
;
985 cupsdAddName(po
, "@OWNER");
986 cupsdAddName(po
, "@SYSTEM");
987 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
989 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
990 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
991 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
992 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
993 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
994 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
995 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
996 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
997 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
998 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
999 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1000 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1001 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1002 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1003 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1004 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1005 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1006 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1008 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1010 cupsdLogMessage(CUPSD_LOG_INFO
,
1011 "<Limit Pause-Printer Resume-Printer "
1012 "Set-Printer-Attributes Enable-Printer "
1013 "Disable-Printer Pause-Printer-After-Current-Job "
1014 "Hold-New-Jobs Release-Held-New-Jobs "
1015 "Deactivate-Printer Activate-Printer Restart-Printer "
1016 "Shutdown-Printer Startup-Printer Promote-Job "
1017 "Schedule-Job-After CUPS-Add-Printer "
1018 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1019 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1020 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1021 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1023 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1024 po
->order_type
= CUPSD_AUTH_ALLOW
;
1025 po
->type
= CUPSD_AUTH_DEFAULT
;
1026 po
->level
= CUPSD_AUTH_USER
;
1028 cupsdAddName(po
, "@SYSTEM");
1029 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1031 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1032 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1033 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1034 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1035 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1036 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1037 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1038 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1039 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1040 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1041 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1042 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1043 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1044 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1045 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1046 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1047 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1048 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1049 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1050 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1051 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1053 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1055 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1056 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1058 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1059 po
->order_type
= CUPSD_AUTH_ALLOW
;
1061 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1062 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1066 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1067 cupsArrayCount(Policies
));
1068 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1070 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1071 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1072 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1075 * If we are doing a full reload or the server root has changed, flush
1076 * the jobs, printers, etc. and start from scratch...
1079 if (NeedReload
== RELOAD_ALL
||
1080 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1081 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1083 mime_type_t
*type
; /* Current type */
1084 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1085 /* MIME type name */
1088 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1091 * Free all memory...
1094 cupsdDeleteAllSubscriptions();
1096 cupsdDeleteAllClasses();
1097 cupsdDeleteAllPrinters();
1099 DefaultPrinter
= NULL
;
1101 if (MimeDatabase
!= NULL
)
1102 mimeDelete(MimeDatabase
);
1106 for (i
= 0; i
< NumMimeTypes
; i
++)
1107 _cupsStrFree(MimeTypes
[i
]);
1113 * Read the MIME type and conversion database...
1116 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1117 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1119 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
1123 cupsdLogMessage(CUPSD_LOG_EMERG
,
1124 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1128 if (!access(mimedir
, 0))
1129 MimeDatabase
= mimeMerge(MimeDatabase
, mimedir
, temp
);
1131 cupsdLogMessage(CUPSD_LOG_INFO
,
1132 "Loaded MIME database from \'%s\': %d types, %d filters...",
1133 ServerRoot
, mimeNumTypes(MimeDatabase
),
1134 mimeNumFilters(MimeDatabase
));
1137 * Create a list of MIME types for the document-format-supported
1141 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1142 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1145 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1147 cupsdLogMessage(CUPSD_LOG_ERROR
,
1148 "Unable to allocate memory for %d MIME types!",
1154 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1156 i
++, type
= mimeNextType(MimeDatabase
))
1158 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1160 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1163 if (i
< NumMimeTypes
)
1164 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1167 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1169 mime_filter_t
*filter
; /* Current filter */
1172 for (type
= mimeFirstType(MimeDatabase
);
1174 type
= mimeNextType(MimeDatabase
))
1175 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1176 type
->super
, type
->type
);
1178 for (filter
= mimeFirstFilter(MimeDatabase
);
1180 filter
= mimeNextFilter(MimeDatabase
))
1181 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1182 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1183 filter
->src
->super
, filter
->src
->type
,
1184 filter
->dst
->super
, filter
->dst
->type
,
1185 filter
->cost
, filter
->filter
);
1192 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1193 cupsdLoadBanners(temp
);
1196 * Load printers and classes...
1199 cupsdLoadAllPrinters();
1200 cupsdLoadAllClasses();
1201 cupsdLoadRemoteCache();
1202 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1204 cupsdCreateCommonData();
1207 * Load queued jobs...
1213 * Load subscriptions...
1216 cupsdLoadAllSubscriptions();
1218 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1223 * Not a full reload, so recreate the common printer attributes...
1226 cupsdCreateCommonData();
1229 * Update all printers as needed...
1232 cupsdUpdatePrinters();
1233 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1235 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1239 * Reset the reload state...
1242 NeedReload
= RELOAD_NONE
;
1244 cupsdClearString(&old_serverroot
);
1245 cupsdClearString(&old_requestroot
);
1252 * 'get_address()' - Get an address + port number from a line.
1255 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1256 get_address(const char *value
, /* I - Value string */
1257 int defport
) /* I - Default port */
1259 char buffer
[1024], /* Hostname + port number buffer */
1260 defpname
[255], /* Default port name */
1261 *hostname
, /* Hostname or IP */
1262 *portname
; /* Port number or name */
1263 http_addrlist_t
*addrlist
; /* Address list */
1267 * Check for an empty value...
1272 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1277 * Grab a hostname and port number; if there is no colon and the port name
1278 * is only digits, then we have a port number by itself...
1281 strlcpy(buffer
, value
, sizeof(buffer
));
1283 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1290 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1295 * Use the default port...
1298 sprintf(defpname
, "%d", defport
);
1299 portname
= defpname
;
1305 * The buffer contains just a port number...
1313 if (hostname
&& !strcmp(hostname
, "*"))
1317 * Now lookup the address using httpAddrGetList()...
1320 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1321 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1322 hostname
? hostname
: "(nil)");
1329 * 'get_addr_and_mask()' - Get an IP address and netmask.
1332 static int /* O - 1 on success, 0 on failure */
1333 get_addr_and_mask(const char *value
, /* I - String from config file */
1334 unsigned *ip
, /* O - Address value */
1335 unsigned *mask
) /* O - Mask value */
1337 int i
, j
, /* Looping vars */
1338 family
, /* Address family */
1339 ipcount
; /* Count of fields in address */
1340 unsigned ipval
; /* Value */
1341 const char *maskval
, /* Pointer to start of mask value */
1342 *ptr
, /* Pointer into value */
1347 * Get the address...
1350 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1351 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1353 if ((maskval
= strchr(value
, '/')) != NULL
)
1356 maskval
= value
+ strlen(value
);
1360 * Check for an IPv6 address...
1366 * Parse hexadecimal IPv6 address...
1371 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1375 else if (!strncmp(ptr
, "::", 2))
1377 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1379 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1384 else if (isxdigit(*ptr
& 255))
1386 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1394 ip
[i
/ 2] |= ipval
<< 16;
1408 if (*ptr
&& *ptr
!= '/')
1412 #endif /* AF_INET6 */
1415 * Parse dotted-decimal IPv4 address...
1418 unsigned val
[4]; /* IPv4 address values */
1422 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1425 * Range check the IP numbers...
1428 for (i
= 0; i
< ipcount
; i
++)
1433 * Make sure the trailing values are zeroed, as some C libraries like
1434 * glibc apparently like to fill the unused arguments with garbage...
1437 for (i
= ipcount
; i
< 4; i
++)
1441 * Merge everything into a 32-bit IPv4 address in ip[3]...
1444 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1447 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1453 * Get the netmask value(s)...
1456 memset(mask
, 0, sizeof(unsigned) * 4);
1458 if (strchr(maskval
, '.'))
1461 * Get dotted-decimal mask...
1464 if (family
!= AF_INET
)
1467 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1470 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1471 mask
[0] = mask
[1] = mask
[2] = 0;
1476 * Get address/bits format...
1482 if (family
== AF_INET6
)
1490 mask
[0] = 0xffffffff;
1492 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1495 mask
[1] = 0xffffffff;
1499 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1502 mask
[2] = 0xffffffff;
1506 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1509 mask
[3] = 0xffffffff;
1513 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1516 #endif /* AF_INET6 */
1521 mask
[0] = 0xffffffff;
1522 mask
[1] = 0xffffffff;
1523 mask
[2] = 0xffffffff;
1526 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1528 mask
[3] = 0xffffffff;
1533 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1534 "get_addr_and_mask(value=\"%s\", "
1535 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1536 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1540 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1543 if ((ip
[0] & ~mask
[0]) != 0 ||
1544 (ip
[1] & ~mask
[1]) != 0 ||
1545 (ip
[2] & ~mask
[2]) != 0 ||
1546 (ip
[3] & ~mask
[3]) != 0)
1554 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1557 static int /* O - 1 on success, 0 on failure */
1558 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1559 char *line
, /* I - Line from file */
1560 char *value
, /* I - Start of value data */
1561 int linenum
) /* I - Current line number */
1563 char *valptr
; /* Pointer into value */
1564 unsigned ip
[4], /* IP address components */
1565 mask
[4]; /* IP netmask components */
1568 if (!strcasecmp(line
, "Encryption"))
1571 * "Encryption xxx" - set required encryption level...
1574 if (!strcasecmp(value
, "never"))
1575 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1576 else if (!strcasecmp(value
, "always"))
1578 cupsdLogMessage(CUPSD_LOG_ERROR
,
1579 "Encryption value \"%s\" on line %d is invalid in this "
1580 "context. Using \"required\" instead.", value
, linenum
);
1582 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1584 else if (!strcasecmp(value
, "required"))
1585 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1586 else if (!strcasecmp(value
, "ifrequested"))
1587 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1590 cupsdLogMessage(CUPSD_LOG_ERROR
,
1591 "Unknown Encryption value %s on line %d.", value
, linenum
);
1595 else if (!strcasecmp(line
, "Order"))
1598 * "Order Deny,Allow" or "Order Allow,Deny"...
1601 if (!strncasecmp(value
, "deny", 4))
1602 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1603 else if (!strncasecmp(value
, "allow", 5))
1604 loc
->order_type
= CUPSD_AUTH_DENY
;
1607 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1612 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1615 * Allow [From] host/ip...
1616 * Deny [From] host/ip...
1619 if (!strncasecmp(value
, "from", 4))
1622 * Strip leading "from"...
1627 while (isspace(*value
& 255))
1632 * Figure out what form the allow/deny address takes:
1643 * nnn.nnn.nnn.nnn/mm
1644 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1647 if (!strcasecmp(value
, "all"))
1653 if (!strcasecmp(line
, "Allow"))
1654 cupsdAllowIP(loc
, zeros
, zeros
);
1656 cupsdDenyIP(loc
, zeros
, zeros
);
1658 else if (!strcasecmp(value
, "none"))
1664 if (!strcasecmp(line
, "Allow"))
1665 cupsdAllowIP(loc
, ones
, zeros
);
1667 cupsdDenyIP(loc
, ones
, zeros
);
1670 else if (value
[0] == '*' || value
[0] == '.' ||
1671 (!isdigit(value
[0] & 255) && value
[0] != '['))
1673 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1674 #endif /* AF_INET6 */
1677 * Host or domain name...
1680 if (value
[0] == '*')
1683 if (!strcasecmp(line
, "Allow"))
1684 cupsdAllowHost(loc
, value
);
1686 cupsdDenyHost(loc
, value
);
1691 * One of many IP address forms...
1694 if (!get_addr_and_mask(value
, ip
, mask
))
1696 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1701 if (!strcasecmp(line
, "Allow"))
1702 cupsdAllowIP(loc
, ip
, mask
);
1704 cupsdDenyIP(loc
, ip
, mask
);
1707 else if (!strcasecmp(line
, "AuthType"))
1710 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1713 if (!strcasecmp(value
, "none"))
1715 loc
->type
= CUPSD_AUTH_NONE
;
1716 loc
->level
= CUPSD_AUTH_ANON
;
1718 else if (!strcasecmp(value
, "basic"))
1720 loc
->type
= CUPSD_AUTH_BASIC
;
1722 if (loc
->level
== CUPSD_AUTH_ANON
)
1723 loc
->level
= CUPSD_AUTH_USER
;
1725 else if (!strcasecmp(value
, "digest"))
1727 loc
->type
= CUPSD_AUTH_DIGEST
;
1729 if (loc
->level
== CUPSD_AUTH_ANON
)
1730 loc
->level
= CUPSD_AUTH_USER
;
1732 else if (!strcasecmp(value
, "basicdigest"))
1734 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1736 if (loc
->level
== CUPSD_AUTH_ANON
)
1737 loc
->level
= CUPSD_AUTH_USER
;
1739 else if (!strcasecmp(value
, "default"))
1741 loc
->type
= CUPSD_AUTH_DEFAULT
;
1743 if (loc
->level
== CUPSD_AUTH_ANON
)
1744 loc
->level
= CUPSD_AUTH_USER
;
1747 else if (!strcasecmp(value
, "negotiate"))
1749 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1751 if (loc
->level
== CUPSD_AUTH_ANON
)
1752 loc
->level
= CUPSD_AUTH_USER
;
1754 #endif /* HAVE_GSSAPI */
1757 cupsdLogMessage(CUPSD_LOG_WARN
,
1758 "Unknown authorization type %s on line %d.",
1763 else if (!strcasecmp(line
, "AuthClass"))
1766 * AuthClass anonymous, user, system, group
1769 if (!strcasecmp(value
, "anonymous"))
1771 loc
->type
= CUPSD_AUTH_NONE
;
1772 loc
->level
= CUPSD_AUTH_ANON
;
1774 cupsdLogMessage(CUPSD_LOG_WARN
,
1775 "\"AuthClass %s\" is deprecated; consider removing "
1779 else if (!strcasecmp(value
, "user"))
1781 loc
->level
= CUPSD_AUTH_USER
;
1783 cupsdLogMessage(CUPSD_LOG_WARN
,
1784 "\"AuthClass %s\" is deprecated; consider using "
1785 "\"Require valid-user\" on line %d.",
1788 else if (!strcasecmp(value
, "group"))
1790 loc
->level
= CUPSD_AUTH_GROUP
;
1792 cupsdLogMessage(CUPSD_LOG_WARN
,
1793 "\"AuthClass %s\" is deprecated; consider using "
1794 "\"Require user @groupname\" on line %d.",
1797 else if (!strcasecmp(value
, "system"))
1799 loc
->level
= CUPSD_AUTH_GROUP
;
1801 cupsdAddName(loc
, "@SYSTEM");
1803 cupsdLogMessage(CUPSD_LOG_WARN
,
1804 "\"AuthClass %s\" is deprecated; consider using "
1805 "\"Require user @SYSTEM\" on line %d.",
1810 cupsdLogMessage(CUPSD_LOG_WARN
,
1811 "Unknown authorization class %s on line %d.",
1816 else if (!strcasecmp(line
, "AuthGroupName"))
1818 cupsdAddName(loc
, value
);
1820 cupsdLogMessage(CUPSD_LOG_WARN
,
1821 "\"AuthGroupName %s\" directive is deprecated; consider "
1822 "using \"Require user @%s\" on line %d.",
1823 value
, value
, linenum
);
1825 else if (!strcasecmp(line
, "Require"))
1828 * Apache synonym for AuthClass and AuthGroupName...
1832 * Require valid-user
1833 * Require group names
1834 * Require user names
1837 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1842 if (!strcasecmp(value
, "valid-user") ||
1843 !strcasecmp(value
, "user"))
1844 loc
->level
= CUPSD_AUTH_USER
;
1845 else if (!strcasecmp(value
, "group"))
1846 loc
->level
= CUPSD_AUTH_GROUP
;
1849 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1855 * Get the list of names from the line...
1858 for (value
= valptr
; *value
;)
1860 while (isspace(*value
& 255))
1863 #ifdef HAVE_AUTHORIZATION_H
1864 if (!strncmp(value
, "@AUTHKEY(", 9))
1867 * Grab "@AUTHKEY(name)" value...
1870 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1876 #endif /* HAVE_AUTHORIZATION_H */
1877 if (*value
== '\"' || *value
== '\'')
1880 * Grab quoted name...
1883 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1890 * Grab literal name.
1893 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1899 cupsdAddName(loc
, value
);
1901 for (value
= valptr
; isspace(*value
& 255); value
++);
1904 else if (!strcasecmp(line
, "Satisfy"))
1906 if (!strcasecmp(value
, "all"))
1907 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
1908 else if (!strcasecmp(value
, "any"))
1909 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
1912 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1925 * 'parse_groups()' - Parse system group names in a string.
1928 static int /* O - 1 on success, 0 on failure */
1929 parse_groups(const char *s
) /* I - Space-delimited groups */
1931 int status
; /* Return status */
1932 char value
[1024], /* Value string */
1933 *valstart
, /* Pointer into value */
1934 *valend
, /* End of value */
1935 quote
; /* Quote character */
1936 struct group
*group
; /* Group */
1940 * Make a copy of the string and parse out the groups...
1943 strlcpy(value
, s
, sizeof(value
));
1948 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1950 if (*valstart
== '\'' || *valstart
== '\"')
1953 * Scan quoted name...
1956 quote
= *valstart
++;
1958 for (valend
= valstart
; *valend
; valend
++)
1959 if (*valend
== quote
)
1965 * Scan space or comma-delimited name...
1968 for (valend
= valstart
; *valend
; valend
++)
1969 if (isspace(*valend
) || *valend
== ',')
1976 group
= getgrnam(valstart
);
1979 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1980 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1991 while (*valstart
== ',' || isspace(*valstart
))
2000 * 'parse_protocols()' - Parse browse protocols in a string.
2003 static int /* O - Browse protocol bits */
2004 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2006 int protocols
; /* Browse protocol bits */
2007 char value
[1024], /* Value string */
2008 *valstart
, /* Pointer into value */
2009 *valend
; /* End of value */
2013 * Empty protocol line yields NULL pointer...
2020 * Loop through the value string,...
2023 strlcpy(value
, s
, sizeof(value
));
2027 for (valstart
= value
; *valstart
;)
2030 * Get the current space/comma-delimited protocol name...
2033 for (valend
= valstart
; *valend
; valend
++)
2034 if (isspace(*valend
& 255) || *valend
== ',')
2041 * Add the protocol to the bitmask...
2044 if (!strcasecmp(valstart
, "cups"))
2045 protocols
|= BROWSE_CUPS
;
2046 else if (!strcasecmp(valstart
, "slp"))
2047 protocols
|= BROWSE_SLP
;
2048 else if (!strcasecmp(valstart
, "ldap"))
2049 protocols
|= BROWSE_LDAP
;
2050 else if (!strcasecmp(valstart
, "dnssd") ||
2051 !strcasecmp(valstart
, "dns-sd") ||
2052 !strcasecmp(valstart
, "bonjour"))
2053 protocols
|= BROWSE_DNSSD
;
2054 else if (!strcasecmp(valstart
, "lpd"))
2055 protocols
|= BROWSE_LPD
;
2056 else if (!strcasecmp(valstart
, "smb"))
2057 protocols
|= BROWSE_SMB
;
2058 else if (!strcasecmp(valstart
, "all"))
2059 protocols
|= BROWSE_ALL
;
2060 else if (strcasecmp(valstart
, "none"))
2061 cupsdLogMessage(CUPSD_LOG_ERROR
,
2062 "Unknown browse protocol \"%s\" ignored!", valstart
);
2064 for (valstart
= valend
; *valstart
; valstart
++)
2065 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2074 * 'read_configuration()' - Read a configuration file.
2077 static int /* O - 1 on success, 0 on failure */
2078 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2080 int i
; /* Looping var */
2081 int linenum
; /* Current line number */
2082 char line
[HTTP_MAX_BUFFER
],
2083 /* Line from file */
2084 temp
[HTTP_MAX_BUFFER
],
2085 /* Temporary buffer for value */
2086 temp2
[HTTP_MAX_BUFFER
],
2087 /* Temporary buffer 2 for value */
2088 *ptr
, /* Pointer into line/temp */
2089 *value
, /* Pointer to value */
2090 *valueptr
; /* Pointer into value */
2091 int valuelen
; /* Length of value */
2092 cupsd_var_t
const *var
; /* Current variable */
2093 http_addrlist_t
*addrlist
, /* Address list */
2094 *addr
; /* Current address */
2095 unsigned ip
[4], /* Address value */
2096 mask
[4]; /* Netmask value */
2097 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2098 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2099 cupsd_location_t
*location
; /* Browse location */
2100 cups_file_t
*incfile
; /* Include file */
2101 char incname
[1024]; /* Include filename */
2102 struct group
*group
; /* Group */
2106 * Loop through each line in the file...
2111 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2114 * Decode the directive...
2117 if (!strcasecmp(line
, "Include") && value
)
2123 if (value
[0] == '/')
2124 strlcpy(incname
, value
, sizeof(incname
));
2126 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2128 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2129 cupsdLogMessage(CUPSD_LOG_ERROR
,
2130 "Unable to include config file \"%s\" - %s",
2131 incname
, strerror(errno
));
2134 read_configuration(incfile
);
2135 cupsFileClose(incfile
);
2138 else if (!strcasecmp(line
, "<Location") && value
)
2144 linenum
= read_location(fp
, value
, linenum
);
2148 else if (!strcasecmp(line
, "<Policy") && value
)
2154 linenum
= read_policy(fp
, value
, linenum
);
2158 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2160 JobRetryInterval
= atoi(value
);
2161 cupsdLogMessage(CUPSD_LOG_WARN
,
2162 "FaxRetryInterval is deprecated; use "
2163 "JobRetryInterval on line %d.", linenum
);
2165 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2167 JobRetryLimit
= atoi(value
);
2168 cupsdLogMessage(CUPSD_LOG_WARN
,
2169 "FaxRetryLimit is deprecated; use "
2170 "JobRetryLimit on line %d.", linenum
);
2172 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2174 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2175 #endif /* HAVE_SSL */
2179 * Add listening address(es) to the list...
2182 cupsd_listener_t
*lis
; /* New listeners array */
2186 * Get the address list...
2189 addrlist
= get_address(value
, IPP_PORT
);
2193 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2199 * Add each address...
2202 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2205 * Allocate another listener...
2209 Listeners
= cupsArrayNew(NULL
, NULL
);
2213 cupsdLogMessage(CUPSD_LOG_ERROR
,
2214 "Unable to allocate %s at line %d - %s.",
2215 line
, linenum
, strerror(errno
));
2219 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2221 cupsdLogMessage(CUPSD_LOG_ERROR
,
2222 "Unable to allocate %s at line %d - %s.",
2223 line
, linenum
, strerror(errno
));
2227 cupsArrayAdd(Listeners
, lis
);
2230 * Copy the current address and log it...
2233 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2237 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2238 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2239 #endif /* HAVE_SSL */
2241 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2244 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2245 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2246 ntohs(lis
->address
.ipv6
.sin6_port
));
2248 #endif /* AF_INET6 */
2250 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2251 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2253 #endif /* AF_LOCAL */
2254 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2255 ntohs(lis
->address
.ipv4
.sin_port
));
2262 httpAddrFreeList(addrlist
);
2264 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2267 * Add a browse address to the list...
2270 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2273 if (NumBrowsers
== 0)
2274 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2276 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2280 cupsdLogMessage(CUPSD_LOG_ERROR
,
2281 "Unable to allocate BrowseAddress at line %d - %s.",
2282 linenum
, strerror(errno
));
2287 dira
+= NumBrowsers
;
2289 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2291 if (!strcasecmp(value
, "@LOCAL"))
2294 * Send browse data to all local interfaces...
2297 strcpy(dira
->iface
, "*");
2300 else if (!strncasecmp(value
, "@IF(", 4))
2303 * Send browse data to the named interface...
2306 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2308 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2314 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2317 * Only IPv4 addresses are supported...
2320 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2321 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2326 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2327 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2329 cupsdLogMessage(CUPSD_LOG_INFO
,
2330 "Sending browsing info to %s:%d (IPv4)",
2331 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2336 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2339 httpAddrFreeList(addrlist
);
2342 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2345 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2348 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2351 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2352 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2354 if (location
== NULL
)
2355 cupsdLogMessage(CUPSD_LOG_ERROR
,
2356 "Unable to initialize browse access control list!");
2357 else if (!strncasecmp(value
, "deny", 4))
2358 location
->order_type
= CUPSD_AUTH_ALLOW
;
2359 else if (!strncasecmp(value
, "allow", 5))
2360 location
->order_type
= CUPSD_AUTH_DENY
;
2362 cupsdLogMessage(CUPSD_LOG_ERROR
,
2363 "Unknown BrowseOrder value %s on line %d.",
2366 else if (!strcasecmp(line
, "BrowseProtocols") ||
2367 !strcasecmp(line
, "BrowseLocalProtocols") ||
2368 !strcasecmp(line
, "BrowseRemoteProtocols"))
2371 * "BrowseProtocols name [... name]"
2372 * "BrowseLocalProtocols name [... name]"
2373 * "BrowseRemoteProtocols name [... name]"
2376 int protocols
= parse_protocols(value
);
2380 cupsdLogMessage(CUPSD_LOG_ERROR
,
2381 "Unknown browse protocol \"%s\" on line %d.",
2386 if (strcasecmp(line
, "BrowseLocalProtocols"))
2387 BrowseRemoteProtocols
= protocols
;
2388 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2389 BrowseLocalProtocols
= protocols
;
2391 else if ((!strcasecmp(line
, "BrowseAllow") ||
2392 !strcasecmp(line
, "BrowseDeny")) && value
)
2395 * BrowseAllow [From] host/ip...
2396 * BrowseDeny [From] host/ip...
2399 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2400 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2402 if (location
== NULL
)
2403 cupsdLogMessage(CUPSD_LOG_ERROR
,
2404 "Unable to initialize browse access control list!");
2407 if (!strncasecmp(value
, "from ", 5))
2410 * Strip leading "from"...
2415 while (isspace(*value
))
2420 * Figure out what form the allow/deny address takes:
2431 * nnn.nnn.nnn.nnn/mm
2432 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2435 if (!strcasecmp(value
, "all"))
2441 if (!strcasecmp(line
, "BrowseAllow"))
2442 cupsdAllowIP(location
, zeros
, zeros
);
2444 cupsdDenyIP(location
, zeros
, zeros
);
2446 else if (!strcasecmp(value
, "none"))
2452 if (!strcasecmp(line
, "BrowseAllow"))
2453 cupsdAllowIP(location
, ones
, zeros
);
2455 cupsdDenyIP(location
, ones
, zeros
);
2458 else if (value
[0] == '*' || value
[0] == '.' ||
2459 (!isdigit(value
[0] & 255) && value
[0] != '['))
2461 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2462 #endif /* AF_INET6 */
2465 * Host or domain name...
2468 if (value
[0] == '*')
2471 if (!strcasecmp(line
, "BrowseAllow"))
2472 cupsdAllowHost(location
, value
);
2474 cupsdDenyHost(location
, value
);
2479 * One of many IP address forms...
2482 if (!get_addr_and_mask(value
, ip
, mask
))
2484 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2489 if (!strcasecmp(line
, "BrowseAllow"))
2490 cupsdAllowIP(location
, ip
, mask
);
2492 cupsdDenyIP(location
, ip
, mask
);
2496 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2499 * BrowseRelay [from] source [to] destination
2503 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2505 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2509 cupsdLogMessage(CUPSD_LOG_ERROR
,
2510 "Unable to allocate BrowseRelay at line %d - %s.",
2511 linenum
, strerror(errno
));
2518 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2520 if (!strncasecmp(value
, "from ", 5))
2523 * Strip leading "from"...
2528 while (isspace(*value
))
2533 * Figure out what form the from address takes:
2542 * nnn.nnn.nnn.nnn/mm
2543 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2547 if (value
[0] == '*' || value
[0] == '.' ||
2548 (!isdigit(value
[0] & 255) && value
[0] != '['))
2550 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2551 #endif /* AF_INET6 */
2554 * Host or domain name...
2557 if (value
[0] == '*')
2560 strlcpy(temp
, value
, sizeof(temp
));
2561 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2564 relay
->from
.type
= CUPSD_AUTH_NAME
;
2566 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2568 cupsdLogMessage(CUPSD_LOG_ERROR
,
2569 "Unable to allocate BrowseRelay name at line %d - %s.",
2570 linenum
, strerror(errno
));
2574 relay
->from
.mask
.name
.length
= strlen(temp
);
2579 * One of many IP address forms...
2582 if (!get_addr_and_mask(value
, ip
, mask
))
2584 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2589 relay
->from
.type
= CUPSD_AUTH_IP
;
2590 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2591 sizeof(relay
->from
.mask
.ip
.address
));
2592 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2593 sizeof(relay
->from
.mask
.ip
.netmask
));
2597 * Skip value and trailing whitespace...
2600 for (; *value
; value
++)
2601 if (isspace(*value
))
2604 while (isspace(*value
))
2607 if (!strncasecmp(value
, "to ", 3))
2610 * Strip leading "to"...
2615 while (isspace(*value
))
2620 * Get "to" address and port...
2623 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2626 * Only IPv4 addresses are supported...
2629 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2630 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2635 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2637 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2639 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2640 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2641 relay
->from
.mask
.ip
.address
[0] >> 24,
2642 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2643 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2644 relay
->from
.mask
.ip
.address
[0] & 255,
2645 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2646 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2647 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2648 relay
->from
.mask
.ip
.netmask
[0] & 255);
2650 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2652 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2653 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2658 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2661 httpAddrFreeList(addrlist
);
2665 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2666 free(relay
->from
.mask
.name
.name
);
2668 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2672 else if (!strcasecmp(line
, "BrowsePoll") && value
)
2675 * BrowsePoll address[:port]
2678 char *portname
; /* Port name */
2679 int portnum
; /* Port number */
2680 struct servent
*service
; /* Service */
2684 * Extract the port name from the address...
2687 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2691 if (isdigit(*portname
& 255))
2692 portnum
= atoi(portname
);
2693 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2694 portnum
= ntohs(service
->s_port
);
2697 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2703 portnum
= ippPort();
2706 * Add the poll entry...
2710 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2712 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2716 cupsdLogMessage(CUPSD_LOG_ERROR
,
2717 "Unable to allocate BrowsePoll at line %d - %s.",
2718 linenum
, strerror(errno
));
2726 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2728 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2729 pollp
->port
= portnum
;
2731 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2734 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
2737 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2740 if (!strcasecmp(value
, "none"))
2741 DefaultAuthType
= CUPSD_AUTH_NONE
;
2742 else if (!strcasecmp(value
, "basic"))
2743 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2744 else if (!strcasecmp(value
, "digest"))
2745 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2746 else if (!strcasecmp(value
, "basicdigest"))
2747 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2749 else if (!strcasecmp(value
, "negotiate"))
2750 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2751 #endif /* HAVE_GSSAPI */
2754 cupsdLogMessage(CUPSD_LOG_WARN
,
2755 "Unknown default authorization type %s on line %d.",
2761 else if (!strcasecmp(line
, "DefaultEncryption"))
2764 * DefaultEncryption {Never,IfRequested,Required}
2767 if (!value
|| !strcasecmp(value
, "never"))
2768 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2769 else if (!strcasecmp(value
, "required"))
2770 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2771 else if (!strcasecmp(value
, "ifrequested"))
2772 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2775 cupsdLogMessage(CUPSD_LOG_WARN
,
2776 "Unknown default encryption %s on line %d.",
2781 #endif /* HAVE_SSL */
2783 else if (!strcasecmp(line
, "Krb5Keytab") && value
)
2785 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2788 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2789 gsskrb5_register_acceptor_identity(value
);
2791 cupsdSetEnv("KRB5_KTNAME", value
);
2792 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2794 #endif /* HAVE_GSSAPI */
2795 else if (!strcasecmp(line
, "User") && value
)
2798 * User ID to run as...
2801 if (isdigit(value
[0] & 255))
2803 int uid
= atoi(value
);
2806 cupsdLogMessage(CUPSD_LOG_ERROR
,
2807 "Will not use User 0 as specified on line %d "
2808 "for security reasons. You must use a non-"
2809 "privileged account instead.",
2816 struct passwd
*p
; /* Password information */
2819 p
= getpwnam(value
);
2824 cupsdLogMessage(CUPSD_LOG_ERROR
,
2825 "Will not use User %s (UID=0) as specified on line "
2826 "%d for security reasons. You must use a non-"
2827 "privileged account instead.",
2833 cupsdLogMessage(CUPSD_LOG_ERROR
,
2834 "Unknown User \"%s\" on line %d, ignoring!",
2838 else if (!strcasecmp(line
, "Group") && value
)
2841 * Group ID to run as...
2844 if (isdigit(value
[0]))
2845 Group
= atoi(value
);
2849 group
= getgrnam(value
);
2852 Group
= group
->gr_gid
;
2854 cupsdLogMessage(CUPSD_LOG_ERROR
,
2855 "Unknown Group \"%s\" on line %d, ignoring!",
2859 else if (!strcasecmp(line
, "SystemGroup") && value
)
2862 * SystemGroup (admin) group(s)...
2865 if (!parse_groups(value
))
2866 cupsdLogMessage(CUPSD_LOG_ERROR
,
2867 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2870 else if (!strcasecmp(line
, "HostNameLookups") && value
)
2873 * Do hostname lookups?
2876 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
2877 !strcasecmp(value
, "false"))
2878 HostNameLookups
= 0;
2879 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
2880 !strcasecmp(value
, "true"))
2881 HostNameLookups
= 1;
2882 else if (!strcasecmp(value
, "double"))
2883 HostNameLookups
= 2;
2885 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2888 else if (!strcasecmp(line
, "LogLevel") && value
)
2891 * Amount of logging to do...
2894 if (!strcasecmp(value
, "debug2"))
2895 LogLevel
= CUPSD_LOG_DEBUG2
;
2896 else if (!strcasecmp(value
, "debug"))
2897 LogLevel
= CUPSD_LOG_DEBUG
;
2898 else if (!strcasecmp(value
, "info"))
2899 LogLevel
= CUPSD_LOG_INFO
;
2900 else if (!strcasecmp(value
, "notice"))
2901 LogLevel
= CUPSD_LOG_NOTICE
;
2902 else if (!strcasecmp(value
, "warn"))
2903 LogLevel
= CUPSD_LOG_WARN
;
2904 else if (!strcasecmp(value
, "error"))
2905 LogLevel
= CUPSD_LOG_ERROR
;
2906 else if (!strcasecmp(value
, "crit"))
2907 LogLevel
= CUPSD_LOG_CRIT
;
2908 else if (!strcasecmp(value
, "alert"))
2909 LogLevel
= CUPSD_LOG_ALERT
;
2910 else if (!strcasecmp(value
, "emerg"))
2911 LogLevel
= CUPSD_LOG_EMERG
;
2912 else if (!strcasecmp(value
, "none"))
2913 LogLevel
= CUPSD_LOG_NONE
;
2915 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2918 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
2921 * Format of printcap file?
2924 if (!strcasecmp(value
, "bsd"))
2925 PrintcapFormat
= PRINTCAP_BSD
;
2926 else if (!strcasecmp(value
, "solaris"))
2927 PrintcapFormat
= PRINTCAP_SOLARIS
;
2929 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2932 else if (!strcasecmp(line
, "ServerTokens") && value
)
2935 * Set the string used for the Server header...
2938 struct utsname plat
; /* Platform info */
2943 if (!strcasecmp(value
, "ProductOnly"))
2944 cupsdSetString(&ServerHeader
, "CUPS");
2945 else if (!strcasecmp(value
, "Major"))
2946 cupsdSetString(&ServerHeader
, "CUPS/1");
2947 else if (!strcasecmp(value
, "Minor"))
2948 cupsdSetString(&ServerHeader
, "CUPS/1.4");
2949 else if (!strcasecmp(value
, "Minimal"))
2950 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2951 else if (!strcasecmp(value
, "OS"))
2952 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2953 else if (!strcasecmp(value
, "Full"))
2954 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2956 else if (!strcasecmp(value
, "None"))
2957 cupsdClearString(&ServerHeader
);
2959 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2962 else if (!strcasecmp(line
, "PassEnv") && value
)
2965 * PassEnv variable [... variable]
2970 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2971 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2974 if (value
[valuelen
])
2976 value
[valuelen
] = '\0';
2980 cupsdSetEnv(value
, NULL
);
2982 for (value
+= valuelen
; *value
; value
++)
2983 if (!isspace(*value
) || *value
!= ',')
2987 else if (!strcasecmp(line
, "SetEnv") && value
)
2990 * SetEnv variable value
2993 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3001 while (isspace(*valueptr
& 255))
3004 cupsdSetEnv(value
, valueptr
);
3007 cupsdLogMessage(CUPSD_LOG_ERROR
,
3008 "Missing value for SetEnv directive on line %d.",
3014 * Find a simple variable in the list...
3017 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3018 if (!strcasecmp(line
, var
->name
))
3024 * Unknown directive! Output an error message and continue...
3028 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3031 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3038 case CUPSD_VARTYPE_INTEGER
:
3040 cupsdLogMessage(CUPSD_LOG_ERROR
,
3041 "Missing integer value for %s on line %d!",
3046 char *units
; /* Units */
3049 n
= strtol(value
, &units
, 0);
3051 if (units
&& *units
)
3053 if (tolower(units
[0] & 255) == 'g')
3054 n
*= 1024 * 1024 * 1024;
3055 else if (tolower(units
[0] & 255) == 'm')
3057 else if (tolower(units
[0] & 255) == 'k')
3059 else if (tolower(units
[0] & 255) == 't')
3064 cupsdLogMessage(CUPSD_LOG_ERROR
,
3065 "Bad negative integer value for %s on line %d!",
3068 *((int *)var
->ptr
) = n
;
3072 case CUPSD_VARTYPE_BOOLEAN
:
3074 cupsdLogMessage(CUPSD_LOG_ERROR
,
3075 "Missing boolean value for %s on line %d!",
3077 else if (!strcasecmp(value
, "true") ||
3078 !strcasecmp(value
, "on") ||
3079 !strcasecmp(value
, "enabled") ||
3080 !strcasecmp(value
, "yes") ||
3082 *((int *)var
->ptr
) = TRUE
;
3083 else if (!strcasecmp(value
, "false") ||
3084 !strcasecmp(value
, "off") ||
3085 !strcasecmp(value
, "disabled") ||
3086 !strcasecmp(value
, "no") ||
3087 !strcasecmp(value
, "0"))
3088 *((int *)var
->ptr
) = FALSE
;
3090 cupsdLogMessage(CUPSD_LOG_ERROR
,
3091 "Unknown boolean value %s on line %d.",
3095 case CUPSD_VARTYPE_PATHNAME
:
3098 cupsdLogMessage(CUPSD_LOG_ERROR
,
3099 "Missing pathname value for %s on line %d!",
3104 if (value
[0] == '/')
3105 strlcpy(temp
, value
, sizeof(temp
));
3107 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3109 if (access(temp
, 0))
3111 cupsdLogMessage(CUPSD_LOG_ERROR
,
3112 "File or directory for \"%s %s\" on line %d "
3113 "does not exist!", line
, value
, linenum
);
3117 case CUPSD_VARTYPE_STRING
:
3118 cupsdSetString((char **)var
->ptr
, value
);
3129 * 'read_location()' - Read a <Location path> definition.
3132 static int /* O - New line number or 0 on error */
3133 read_location(cups_file_t
*fp
, /* I - Configuration file */
3134 char *location
, /* I - Location name/path */
3135 int linenum
) /* I - Current line number */
3137 cupsd_location_t
*loc
, /* New location */
3138 *parent
; /* Parent location */
3139 char line
[HTTP_MAX_BUFFER
],
3141 *value
, /* Value for directive */
3142 *valptr
; /* Pointer into value */
3145 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3148 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3151 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3154 * Decode the directive...
3157 if (!strcasecmp(line
, "</Location>"))
3159 else if (!strcasecmp(line
, "<Limit") ||
3160 !strcasecmp(line
, "<LimitExcept"))
3164 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3168 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3174 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3179 if (!strcmp(value
, "ALL"))
3180 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3181 else if (!strcmp(value
, "GET"))
3182 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3183 else if (!strcmp(value
, "HEAD"))
3184 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3185 else if (!strcmp(value
, "OPTIONS"))
3186 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3187 else if (!strcmp(value
, "POST"))
3188 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3189 else if (!strcmp(value
, "PUT"))
3190 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3191 else if (!strcmp(value
, "TRACE"))
3192 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3194 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3197 for (value
= valptr
; isspace(*value
& 255); value
++);
3200 if (!strcasecmp(line
, "<LimitExcept"))
3201 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3203 parent
->limit
&= ~loc
->limit
;
3205 else if (!strcasecmp(line
, "</Limit>") ||
3206 !strcasecmp(line
, "</LimitExcept>"))
3208 else if (!parse_aaa(loc
, line
, value
, linenum
))
3210 cupsdLogMessage(CUPSD_LOG_ERROR
,
3211 "Unknown Location directive %s on line %d.",
3217 cupsdLogMessage(CUPSD_LOG_ERROR
,
3218 "Unexpected end-of-file at line %d while reading location!",
3226 * 'read_policy()' - Read a <Policy name> definition.
3229 static int /* O - New line number or 0 on error */
3230 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3231 char *policy
, /* I - Location name/path */
3232 int linenum
) /* I - Current line number */
3234 int i
; /* Looping var */
3235 cupsd_policy_t
*pol
; /* Policy */
3236 cupsd_location_t
*op
; /* Policy operation */
3237 int num_ops
; /* Number of IPP operations */
3238 ipp_op_t ops
[100]; /* Operations */
3239 char line
[HTTP_MAX_BUFFER
],
3241 *value
, /* Value for directive */
3242 *valptr
; /* Pointer into value */
3246 * Create the policy...
3249 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3253 * Read from the file...
3259 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3262 * Decode the directive...
3265 if (!strcasecmp(line
, "</Policy>"))
3268 cupsdLogMessage(CUPSD_LOG_WARN
,
3269 "Missing </Limit> before </Policy> on line %d!",
3273 * Verify that we have an explicit policy for CUPS-Get-Document
3274 * (ensures that upgrades do not introduce new security issues...)
3277 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3278 op
->op
== IPP_ANY_OPERATION
)
3280 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3281 op
->op
!= IPP_ANY_OPERATION
)
3284 * Add a new limit for CUPS-Get-Document using the Send-Document
3285 * limit as a template...
3288 cupsdLogMessage(CUPSD_LOG_WARN
,
3289 "No limit for CUPS-Get-Document defined in policy %s "
3290 "- using Send-Document's policy", pol
->name
);
3292 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3298 else if (!strcasecmp(line
, "<Limit") && !op
)
3302 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3307 * Scan for IPP operation names...
3314 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3319 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3321 if (!strcasecmp(value
, "All"))
3322 ops
[num_ops
] = IPP_ANY_OPERATION
;
3323 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3324 cupsdLogMessage(CUPSD_LOG_ERROR
,
3325 "Bad IPP operation name \"%s\" on line %d!",
3331 cupsdLogMessage(CUPSD_LOG_ERROR
,
3332 "Too many operations listed on line %d!",
3335 for (value
= valptr
; isspace(*value
& 255); value
++);
3339 * If none are specified, apply the policy to all operations...
3344 ops
[0] = IPP_ANY_OPERATION
;
3349 * Add a new policy for the first operation...
3352 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3354 else if (!strcasecmp(line
, "</Limit>") && op
)
3357 * Finish the current operation limit...
3363 * Copy the policy to the other operations...
3366 for (i
= 1; i
< num_ops
; i
++)
3367 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3374 cupsdLogMessage(CUPSD_LOG_ERROR
,
3375 "Missing <Limit ops> directive before %s on line %d.",
3379 else if (!parse_aaa(op
, line
, value
, linenum
))
3382 cupsdLogMessage(CUPSD_LOG_ERROR
,
3383 "Unknown Policy Limit directive %s on line %d.",
3386 cupsdLogMessage(CUPSD_LOG_ERROR
,
3387 "Unknown Policy directive %s on line %d.",
3394 cupsdLogMessage(CUPSD_LOG_ERROR
,
3395 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3403 * End of "$Id: conf.c 6930 2007-09-08 00:28:06Z mike $".