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 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
150 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
151 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
152 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
153 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
154 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
155 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
156 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
157 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
158 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
159 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
161 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
162 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
163 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
164 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
165 #endif /* HAVE_SSL */
166 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
167 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
168 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
169 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
170 #ifdef HAVE_AUTHORIZATION_H
171 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
172 #endif /* HAVE_AUTHORIZATION_H */
173 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
174 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
175 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
177 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
180 static const unsigned ones
[4] =
182 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
184 static const unsigned zeros
[4] =
186 0x00000000, 0x00000000, 0x00000000, 0x00000000
193 static http_addrlist_t
*get_address(const char *value
, int defport
);
194 static int get_addr_and_mask(const char *value
, unsigned *ip
,
196 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
197 char *value
, int linenum
);
198 static int parse_groups(const char *s
);
199 static int parse_protocols(const char *s
);
200 static int read_configuration(cups_file_t
*fp
);
201 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
202 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
206 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
209 int /* O - 0 on success, -1 on error, 1 on warning */
210 cupsdCheckPermissions(
211 const char *filename
, /* I - File/directory name */
212 const char *suffix
, /* I - Additional file/directory name */
213 int mode
, /* I - Permissions */
214 int user
, /* I - Owner */
215 int group
, /* I - Group */
216 int is_dir
, /* I - 1 = directory, 0 = file */
217 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
219 int dir_created
= 0; /* Did we create a directory? */
220 char pathname
[1024]; /* File name with prefix */
221 struct stat fileinfo
; /* Stat buffer */
225 * Prepend the given root to the filename before testing it...
230 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
235 * See if we can stat the file/directory...
238 if (stat(filename
, &fileinfo
))
240 if (errno
== ENOENT
&& create_dir
)
243 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
246 if (mkdir(filename
, mode
))
249 cupsdLogMessage(CUPSD_LOG_ERROR
,
250 "Unable to create directory \"%s\" - %s", filename
,
253 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
262 return (create_dir
? -1 : 1);
266 * Make sure it's a regular file...
269 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
271 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
275 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
278 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
280 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
286 * Fix owner, group, and mode as needed...
289 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
292 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
295 if (chown(filename
, user
, group
) && !getuid())
298 cupsdLogMessage(CUPSD_LOG_ERROR
,
299 "Unable to change ownership of \"%s\" - %s", filename
,
302 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
309 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
312 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
315 if (chmod(filename
, mode
))
318 cupsdLogMessage(CUPSD_LOG_ERROR
,
319 "Unable to change permissions of \"%s\" - %s", filename
,
322 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
330 * Everything is OK...
338 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
341 int /* O - 1 on success, 0 otherwise */
342 cupsdReadConfiguration(void)
344 int i
; /* Looping var */
345 cups_file_t
*fp
; /* Configuration file */
346 int status
; /* Return status */
347 char temp
[1024], /* Temporary buffer */
348 *slash
; /* Directory separator */
349 cups_lang_t
*language
; /* Language */
350 struct passwd
*user
; /* Default user */
351 struct group
*group
; /* Default group */
352 char *old_serverroot
, /* Old ServerRoot */
353 *old_requestroot
; /* Old RequestRoot */
354 const char *tmpdir
; /* TMPDIR environment variable */
355 struct stat tmpinfo
; /* Temporary directory info */
356 cupsd_policy_t
*p
; /* Policy */
360 * Save the old root paths...
363 old_serverroot
= NULL
;
364 cupsdSetString(&old_serverroot
, ServerRoot
);
365 old_requestroot
= NULL
;
366 cupsdSetString(&old_requestroot
, RequestRoot
);
369 * Reset the server configuration data...
372 cupsdDeleteAllLocations();
391 for (i
= 0; i
< NumRelays
; i
++)
392 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
393 free(Relays
[i
].from
.mask
.name
.name
);
400 cupsdDeleteAllListeners();
406 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
407 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
408 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
409 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
410 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
411 cupsdSetString(&DataDir
, CUPS_DATADIR
);
412 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
413 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
414 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
415 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
416 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
417 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
418 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
419 cupsdSetString(&RemoteRoot
, "remroot");
420 cupsdSetString(&ServerHeader
, "CUPS/1.4");
421 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
423 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
424 #endif /* HAVE_GSSAPI */
426 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
427 PrintcapFormat
= PRINTCAP_SOLARIS
;
429 PrintcapFormat
= PRINTCAP_BSD
;
431 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
432 if ((slash
= strrchr(temp
, '/')) != NULL
)
435 cupsdSetString(&ServerRoot
, temp
);
437 cupsdClearString(&Classification
);
438 ClassifyOverride
= 0;
442 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
444 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
445 cupsdSetString(&ServerKey
, "ssl/server.key");
446 # endif /* HAVE_CDSASSL */
447 #endif /* HAVE_SSL */
449 language
= cupsLangDefault();
451 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
452 cupsdSetString(&DefaultLanguage
, "en");
454 cupsdSetString(&DefaultLanguage
, language
->language
);
456 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
458 cupsdSetString(&RIPCache
, "8m");
460 cupsdSetString(&TempDir
, NULL
);
463 * Find the default user...
466 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
471 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
472 * complement number...)
481 * Find the default group...
484 group
= getgrnam(CUPS_DEFAULT_GROUP
);
488 Group
= group
->gr_gid
;
492 * Fallback to group "nobody"...
495 group
= getgrnam("nobody");
499 Group
= group
->gr_gid
;
503 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
504 * complement number...)
515 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
516 DefaultAuthType
= CUPSD_AUTH_BASIC
;
518 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
519 #endif /* HAVE_SSL */
520 DirtyCleanInterval
= 60;
522 JobRetryInterval
= 300;
527 HostNameLookups
= FALSE
;
528 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
529 ImplicitAnyClasses
= FALSE
;
530 HideImplicitMembers
= TRUE
;
532 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
533 ListenBackLog
= SOMAXCONN
;
534 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
535 LogLevel
= CUPSD_LOG_ERROR
;
537 MaxClientsPerHost
= 0;
538 MaxLogSize
= 1024 * 1024;
539 MaxPrinterHistory
= 10;
542 RootCertDuration
= 300;
543 Timeout
= DEFAULT_TIMEOUT
;
546 BrowseInterval
= DEFAULT_INTERVAL
;
547 BrowsePort
= ippPort();
548 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
549 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
550 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
551 BrowseTimeout
= DEFAULT_TIMEOUT
;
552 Browsing
= CUPS_DEFAULT_BROWSING
;
553 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
555 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
556 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
558 cupsdClearString(&BrowseLocalOptions
);
559 cupsdClearString(&BrowseRemoteOptions
);
561 cupsdSetString(&ErrorPolicy
, "stop-printer");
564 cupsdClearString(&BrowseLDAPBindDN
);
565 cupsdClearString(&BrowseLDAPDN
);
566 cupsdClearString(&BrowseLDAPPassword
);
567 cupsdClearString(&BrowseLDAPServer
);
568 cupsdClearString(&BrowseLDAPCACertFile
);
569 #endif /* HAVE_LDAP */
571 JobHistory
= DEFAULT_HISTORY
;
572 JobFiles
= DEFAULT_FILES
;
577 MaxJobsPerPrinter
= 0;
578 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
580 cupsdDeleteAllPolicies();
581 cupsdClearString(&DefaultPolicy
);
583 #ifdef HAVE_AUTHORIZATION_H
584 cupsdClearString(&SystemGroupAuthKey
);
585 #endif /* HAVE_AUTHORIZATION_H */
587 MaxSubscriptions
= 100;
588 MaxSubscriptionsPerJob
= 0;
589 MaxSubscriptionsPerPrinter
= 0;
590 MaxSubscriptionsPerUser
= 0;
591 DefaultLeaseDuration
= 86400;
592 MaxLeaseDuration
= 0;
595 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
596 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
597 #endif /* HAVE_LAUNCHD */
601 #endif /* __APPLE__ */
604 * Read the configuration file...
607 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
610 status
= read_configuration(fp
);
620 * See if the ServerName is an IP address...
623 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
625 ServerNameIsIP
= !*slash
;
628 * Use the default system group if none was supplied in cupsd.conf...
631 if (NumSystemGroups
== 0)
633 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
636 * Find the group associated with GID 0...
643 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
645 cupsdSetString(&SystemGroups
[0], "unknown");
647 SystemGroupIDs
[0] = 0;
653 * Get the access control list for browsing...
656 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
659 * Open the system log for cupsd if necessary...
663 if (!strcmp(AccessLog
, "syslog") ||
664 !strcmp(ErrorLog
, "syslog") ||
665 !strcmp(PageLog
, "syslog"))
666 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
667 #endif /* HAVE_VSYSLOG */
670 * Log the configuration file that was used...
673 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
677 * Validate the Group and SystemGroup settings - they cannot be the same,
678 * otherwise the CGI programs will be able to authenticate as root without
684 for (i
= 0; i
< NumSystemGroups
; i
++)
685 if (Group
== SystemGroupIDs
[i
])
688 if (i
< NumSystemGroups
)
691 * Log the error and reset the group to a safe value...
694 cupsdLogMessage(CUPSD_LOG_NOTICE
,
695 "Group and SystemGroup cannot use the same groups!");
696 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
698 group
= getgrnam("nobody");
702 Group
= group
->gr_gid
;
706 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
707 * complement number...)
716 * Check that we have at least one listen/port line; if not, report this
717 * as an error and exit!
720 if (cupsArrayCount(Listeners
) == 0)
726 cupsdLogMessage(CUPSD_LOG_EMERG
,
727 "No valid Listen or Port lines were found in the configuration file!");
733 cupsdEndProcess(getpid(), 0);
737 * Set the default locale using the language and charset...
740 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
743 * Update all relative filenames to include the full path from ServerRoot...
746 if (DocumentRoot
[0] != '/')
747 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
749 if (RequestRoot
[0] != '/')
750 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
752 if (ServerBin
[0] != '/')
753 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
755 if (StateDir
[0] != '/')
756 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
758 if (CacheDir
[0] != '/')
759 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
762 if (ServerCertificate
[0] != '/')
763 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
765 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
767 chown(ServerCertificate
, RunUser
, Group
);
768 chmod(ServerCertificate
, 0600);
771 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
772 if (ServerKey
[0] != '/')
773 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
775 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
777 chown(ServerKey
, RunUser
, Group
);
778 chmod(ServerKey
, 0600);
780 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
781 #endif /* HAVE_SSL */
784 * Make sure that directories and config files are owned and
785 * writable by the user and group in the cupsd.conf file...
788 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
790 if (cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
792 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
794 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
796 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
798 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
799 SystemGroupIDs
[0], 1, 1) < 0 ||
800 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
802 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
804 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
806 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
808 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
810 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
812 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
817 * Update TempDir to the default if it hasn't been set already...
822 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
825 * TMPDIR is defined, see if it is OK for us to use...
828 if (stat(tmpdir
, &tmpinfo
))
829 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
830 tmpdir
, strerror(errno
));
831 else if (!S_ISDIR(tmpinfo
.st_mode
))
832 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
834 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
835 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
836 !(tmpinfo
.st_mode
& S_IWOTH
))
837 cupsdLogMessage(CUPSD_LOG_ERROR
,
838 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
840 cupsdSetString(&TempDir
, tmpdir
);
845 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
847 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
852 * Make sure the temporary directory has the right permissions...
855 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
859 * Update ownership and permissions if the CUPS temp directory
860 * is under the spool directory or does not exist...
863 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
868 * Setup environment variables...
874 * Check the MaxClients setting, and then allocate memory for it...
877 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
880 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
883 MaxClients
= MaxFDs
/ 3;
886 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
890 * Check the MaxActiveJobs setting; limit to 1/3 the available
891 * file descriptors, since we need a pipe for each job...
894 if (MaxActiveJobs
> (MaxFDs
/ 3))
895 MaxActiveJobs
= MaxFDs
/ 3;
897 if (Classification
&& !strcasecmp(Classification
, "none"))
898 cupsdClearString(&Classification
);
901 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
904 * Update the MaxClientsPerHost value, as needed...
907 if (MaxClientsPerHost
<= 0)
908 MaxClientsPerHost
= MaxClients
;
910 if (MaxClientsPerHost
> MaxClients
)
911 MaxClientsPerHost
= MaxClients
;
913 cupsdLogMessage(CUPSD_LOG_INFO
,
914 "Allowing up to %d client connections per host.",
918 * Make sure that BrowseTimeout is at least twice the interval...
921 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
923 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
927 BrowseTimeout
= BrowseInterval
* 2;
929 BrowseTimeout
= DEFAULT_TIMEOUT
;
931 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
936 * Update the default policy, as needed...
940 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
942 DefaultPolicyPtr
= NULL
;
944 if (!DefaultPolicyPtr
)
946 cupsd_location_t
*po
; /* New policy operation */
950 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
953 cupsdSetString(&DefaultPolicy
, "default");
955 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
956 cupsdLogMessage(CUPSD_LOG_INFO
,
957 "Using policy \"default\" as the default!");
960 cupsdLogMessage(CUPSD_LOG_INFO
,
961 "Creating CUPS default administrative policy:");
963 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
965 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
966 cupsdLogMessage(CUPSD_LOG_INFO
,
967 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
968 "Release-Job Restart-Job Purge-Jobs "
969 "Set-Job-Attributes Create-Job-Subscription "
970 "Renew-Subscription Cancel-Subscription "
971 "Get-Notifications Reprocess-Job Cancel-Current-Job "
972 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
973 "CUPS-Authenticate-Job CUPS-Get-Document>");
974 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
976 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
977 po
->order_type
= CUPSD_AUTH_ALLOW
;
978 po
->level
= CUPSD_AUTH_USER
;
980 cupsdAddName(po
, "@OWNER");
981 cupsdAddName(po
, "@SYSTEM");
982 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
984 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
985 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
986 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
987 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
988 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
989 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
990 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
991 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
992 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
993 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
994 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
995 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
996 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
997 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
998 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
999 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1000 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1001 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1003 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1005 cupsdLogMessage(CUPSD_LOG_INFO
,
1006 "<Limit Pause-Printer Resume-Printer "
1007 "Set-Printer-Attributes Enable-Printer "
1008 "Disable-Printer Pause-Printer-After-Current-Job "
1009 "Hold-New-Jobs Release-Held-New-Jobs "
1010 "Deactivate-Printer Activate-Printer Restart-Printer "
1011 "Shutdown-Printer Startup-Printer Promote-Job "
1012 "Schedule-Job-After CUPS-Add-Printer "
1013 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1014 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1015 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1016 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1018 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1019 po
->order_type
= CUPSD_AUTH_ALLOW
;
1020 po
->type
= CUPSD_AUTH_DEFAULT
;
1021 po
->level
= CUPSD_AUTH_USER
;
1023 cupsdAddName(po
, "@SYSTEM");
1024 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1026 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1027 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1028 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1029 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1030 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1031 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1032 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1033 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1034 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1035 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1036 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1037 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1038 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1039 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1040 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1041 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1042 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1043 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1044 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1045 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1046 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1048 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1050 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1051 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1053 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1054 po
->order_type
= CUPSD_AUTH_ALLOW
;
1056 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1057 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1061 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1062 cupsArrayCount(Policies
));
1063 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1065 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1066 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1067 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1070 * If we are doing a full reload or the server root has changed, flush
1071 * the jobs, printers, etc. and start from scratch...
1074 if (NeedReload
== RELOAD_ALL
||
1075 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1076 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1078 mime_type_t
*type
; /* Current type */
1079 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1080 /* MIME type name */
1083 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1086 * Free all memory...
1089 cupsdDeleteAllSubscriptions();
1091 cupsdDeleteAllClasses();
1092 cupsdDeleteAllPrinters();
1094 DefaultPrinter
= NULL
;
1096 if (MimeDatabase
!= NULL
)
1097 mimeDelete(MimeDatabase
);
1101 for (i
= 0; i
< NumMimeTypes
; i
++)
1102 _cupsStrFree(MimeTypes
[i
]);
1108 * Read the MIME type and conversion database...
1111 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1113 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
1117 cupsdLogMessage(CUPSD_LOG_EMERG
,
1118 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1122 cupsdLogMessage(CUPSD_LOG_INFO
,
1123 "Loaded MIME database from \'%s\': %d types, %d filters...",
1124 ServerRoot
, mimeNumTypes(MimeDatabase
),
1125 mimeNumFilters(MimeDatabase
));
1128 * Create a list of MIME types for the document-format-supported
1132 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1133 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1136 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1138 cupsdLogMessage(CUPSD_LOG_ERROR
,
1139 "Unable to allocate memory for %d MIME types!",
1145 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1147 i
++, type
= mimeNextType(MimeDatabase
))
1149 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1151 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1154 if (i
< NumMimeTypes
)
1155 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1158 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1160 mime_filter_t
*filter
; /* Current filter */
1163 for (type
= mimeFirstType(MimeDatabase
);
1165 type
= mimeNextType(MimeDatabase
))
1166 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1167 type
->super
, type
->type
);
1169 for (filter
= mimeFirstFilter(MimeDatabase
);
1171 filter
= mimeNextFilter(MimeDatabase
))
1172 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1173 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1174 filter
->src
->super
, filter
->src
->type
,
1175 filter
->dst
->super
, filter
->dst
->type
,
1176 filter
->cost
, filter
->filter
);
1183 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1184 cupsdLoadBanners(temp
);
1187 * Load printers and classes...
1190 cupsdLoadAllPrinters();
1191 cupsdLoadAllClasses();
1192 cupsdLoadRemoteCache();
1193 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1195 cupsdCreateCommonData();
1198 * Load queued jobs...
1204 * Load subscriptions...
1207 cupsdLoadAllSubscriptions();
1209 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1214 * Not a full reload, so recreate the common printer attributes...
1217 cupsdCreateCommonData();
1220 * Update all printers as needed...
1223 cupsdUpdatePrinters();
1224 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1226 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1230 * Reset the reload state...
1233 NeedReload
= RELOAD_NONE
;
1235 cupsdClearString(&old_serverroot
);
1236 cupsdClearString(&old_requestroot
);
1243 * 'get_address()' - Get an address + port number from a line.
1246 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1247 get_address(const char *value
, /* I - Value string */
1248 int defport
) /* I - Default port */
1250 char buffer
[1024], /* Hostname + port number buffer */
1251 defpname
[255], /* Default port name */
1252 *hostname
, /* Hostname or IP */
1253 *portname
; /* Port number or name */
1254 http_addrlist_t
*addrlist
; /* Address list */
1258 * Check for an empty value...
1263 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1268 * Grab a hostname and port number; if there is no colon and the port name
1269 * is only digits, then we have a port number by itself...
1272 strlcpy(buffer
, value
, sizeof(buffer
));
1274 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1281 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1286 * Use the default port...
1289 sprintf(defpname
, "%d", defport
);
1290 portname
= defpname
;
1296 * The buffer contains just a port number...
1304 if (hostname
&& !strcmp(hostname
, "*"))
1308 * Now lookup the address using httpAddrGetList()...
1311 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1312 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1313 hostname
? hostname
: "(nil)");
1320 * 'get_addr_and_mask()' - Get an IP address and netmask.
1323 static int /* O - 1 on success, 0 on failure */
1324 get_addr_and_mask(const char *value
, /* I - String from config file */
1325 unsigned *ip
, /* O - Address value */
1326 unsigned *mask
) /* O - Mask value */
1328 int i
, j
, /* Looping vars */
1329 family
, /* Address family */
1330 ipcount
; /* Count of fields in address */
1331 unsigned ipval
; /* Value */
1332 const char *maskval
, /* Pointer to start of mask value */
1333 *ptr
, /* Pointer into value */
1338 * Get the address...
1341 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1342 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1344 if ((maskval
= strchr(value
, '/')) != NULL
)
1347 maskval
= value
+ strlen(value
);
1351 * Check for an IPv6 address...
1357 * Parse hexadecimal IPv6 address...
1362 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1366 else if (!strncmp(ptr
, "::", 2))
1368 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1370 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1375 else if (isxdigit(*ptr
& 255))
1377 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1385 ip
[i
/ 2] |= ipval
<< 16;
1399 if (*ptr
&& *ptr
!= '/')
1403 #endif /* AF_INET6 */
1406 * Parse dotted-decimal IPv4 address...
1409 unsigned val
[4]; /* IPv4 address values */
1413 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1416 * Range check the IP numbers...
1419 for (i
= 0; i
< ipcount
; i
++)
1424 * Make sure the trailing values are zeroed, as some C libraries like
1425 * glibc apparently like to fill the unused arguments with garbage...
1428 for (i
= ipcount
; i
< 4; i
++)
1432 * Merge everything into a 32-bit IPv4 address in ip[3]...
1435 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1438 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1444 * Get the netmask value(s)...
1447 memset(mask
, 0, sizeof(unsigned) * 4);
1449 if (strchr(maskval
, '.'))
1452 * Get dotted-decimal mask...
1455 if (family
!= AF_INET
)
1458 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1461 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1462 mask
[0] = mask
[1] = mask
[2] = 0;
1467 * Get address/bits format...
1473 if (family
== AF_INET6
)
1481 mask
[0] = 0xffffffff;
1483 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1486 mask
[1] = 0xffffffff;
1490 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1493 mask
[2] = 0xffffffff;
1497 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1500 mask
[3] = 0xffffffff;
1504 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1507 #endif /* AF_INET6 */
1512 mask
[0] = 0xffffffff;
1513 mask
[1] = 0xffffffff;
1514 mask
[2] = 0xffffffff;
1517 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1519 mask
[3] = 0xffffffff;
1524 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1525 "get_addr_and_mask(value=\"%s\", "
1526 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1527 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1531 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1534 if ((ip
[0] & ~mask
[0]) != 0 ||
1535 (ip
[1] & ~mask
[1]) != 0 ||
1536 (ip
[2] & ~mask
[2]) != 0 ||
1537 (ip
[3] & ~mask
[3]) != 0)
1545 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1548 static int /* O - 1 on success, 0 on failure */
1549 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1550 char *line
, /* I - Line from file */
1551 char *value
, /* I - Start of value data */
1552 int linenum
) /* I - Current line number */
1554 char *valptr
; /* Pointer into value */
1555 unsigned ip
[4], /* IP address components */
1556 mask
[4]; /* IP netmask components */
1559 if (!strcasecmp(line
, "Encryption"))
1562 * "Encryption xxx" - set required encryption level...
1565 if (!strcasecmp(value
, "never"))
1566 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1567 else if (!strcasecmp(value
, "always"))
1569 cupsdLogMessage(CUPSD_LOG_ERROR
,
1570 "Encryption value \"%s\" on line %d is invalid in this "
1571 "context. Using \"required\" instead.", value
, linenum
);
1573 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1575 else if (!strcasecmp(value
, "required"))
1576 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1577 else if (!strcasecmp(value
, "ifrequested"))
1578 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1581 cupsdLogMessage(CUPSD_LOG_ERROR
,
1582 "Unknown Encryption value %s on line %d.", value
, linenum
);
1586 else if (!strcasecmp(line
, "Order"))
1589 * "Order Deny,Allow" or "Order Allow,Deny"...
1592 if (!strncasecmp(value
, "deny", 4))
1593 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1594 else if (!strncasecmp(value
, "allow", 5))
1595 loc
->order_type
= CUPSD_AUTH_DENY
;
1598 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1603 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1606 * Allow [From] host/ip...
1607 * Deny [From] host/ip...
1610 if (!strncasecmp(value
, "from", 4))
1613 * Strip leading "from"...
1618 while (isspace(*value
& 255))
1623 * Figure out what form the allow/deny address takes:
1634 * nnn.nnn.nnn.nnn/mm
1635 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1638 if (!strcasecmp(value
, "all"))
1644 if (!strcasecmp(line
, "Allow"))
1645 cupsdAllowIP(loc
, zeros
, zeros
);
1647 cupsdDenyIP(loc
, zeros
, zeros
);
1649 else if (!strcasecmp(value
, "none"))
1655 if (!strcasecmp(line
, "Allow"))
1656 cupsdAllowIP(loc
, ones
, zeros
);
1658 cupsdDenyIP(loc
, ones
, zeros
);
1661 else if (value
[0] == '*' || value
[0] == '.' ||
1662 (!isdigit(value
[0] & 255) && value
[0] != '['))
1664 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1665 #endif /* AF_INET6 */
1668 * Host or domain name...
1671 if (value
[0] == '*')
1674 if (!strcasecmp(line
, "Allow"))
1675 cupsdAllowHost(loc
, value
);
1677 cupsdDenyHost(loc
, value
);
1682 * One of many IP address forms...
1685 if (!get_addr_and_mask(value
, ip
, mask
))
1687 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1692 if (!strcasecmp(line
, "Allow"))
1693 cupsdAllowIP(loc
, ip
, mask
);
1695 cupsdDenyIP(loc
, ip
, mask
);
1698 else if (!strcasecmp(line
, "AuthType"))
1701 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1704 if (!strcasecmp(value
, "none"))
1706 loc
->type
= CUPSD_AUTH_NONE
;
1707 loc
->level
= CUPSD_AUTH_ANON
;
1709 else if (!strcasecmp(value
, "basic"))
1711 loc
->type
= CUPSD_AUTH_BASIC
;
1713 if (loc
->level
== CUPSD_AUTH_ANON
)
1714 loc
->level
= CUPSD_AUTH_USER
;
1716 else if (!strcasecmp(value
, "digest"))
1718 loc
->type
= CUPSD_AUTH_DIGEST
;
1720 if (loc
->level
== CUPSD_AUTH_ANON
)
1721 loc
->level
= CUPSD_AUTH_USER
;
1723 else if (!strcasecmp(value
, "basicdigest"))
1725 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1727 if (loc
->level
== CUPSD_AUTH_ANON
)
1728 loc
->level
= CUPSD_AUTH_USER
;
1730 else if (!strcasecmp(value
, "default"))
1732 loc
->type
= CUPSD_AUTH_DEFAULT
;
1734 if (loc
->level
== CUPSD_AUTH_ANON
)
1735 loc
->level
= CUPSD_AUTH_USER
;
1738 else if (!strcasecmp(value
, "negotiate"))
1740 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1742 if (loc
->level
== CUPSD_AUTH_ANON
)
1743 loc
->level
= CUPSD_AUTH_USER
;
1745 #endif /* HAVE_GSSAPI */
1748 cupsdLogMessage(CUPSD_LOG_WARN
,
1749 "Unknown authorization type %s on line %d.",
1754 else if (!strcasecmp(line
, "AuthClass"))
1757 * AuthClass anonymous, user, system, group
1760 if (!strcasecmp(value
, "anonymous"))
1762 loc
->type
= CUPSD_AUTH_NONE
;
1763 loc
->level
= CUPSD_AUTH_ANON
;
1765 cupsdLogMessage(CUPSD_LOG_WARN
,
1766 "\"AuthClass %s\" is deprecated; consider removing "
1770 else if (!strcasecmp(value
, "user"))
1772 loc
->level
= CUPSD_AUTH_USER
;
1774 cupsdLogMessage(CUPSD_LOG_WARN
,
1775 "\"AuthClass %s\" is deprecated; consider using "
1776 "\"Require valid-user\" on line %d.",
1779 else if (!strcasecmp(value
, "group"))
1781 loc
->level
= CUPSD_AUTH_GROUP
;
1783 cupsdLogMessage(CUPSD_LOG_WARN
,
1784 "\"AuthClass %s\" is deprecated; consider using "
1785 "\"Require user @groupname\" on line %d.",
1788 else if (!strcasecmp(value
, "system"))
1790 loc
->level
= CUPSD_AUTH_GROUP
;
1792 cupsdAddName(loc
, "@SYSTEM");
1794 cupsdLogMessage(CUPSD_LOG_WARN
,
1795 "\"AuthClass %s\" is deprecated; consider using "
1796 "\"Require user @SYSTEM\" on line %d.",
1801 cupsdLogMessage(CUPSD_LOG_WARN
,
1802 "Unknown authorization class %s on line %d.",
1807 else if (!strcasecmp(line
, "AuthGroupName"))
1809 cupsdAddName(loc
, value
);
1811 cupsdLogMessage(CUPSD_LOG_WARN
,
1812 "\"AuthGroupName %s\" directive is deprecated; consider "
1813 "using \"Require user @%s\" on line %d.",
1814 value
, value
, linenum
);
1816 else if (!strcasecmp(line
, "Require"))
1819 * Apache synonym for AuthClass and AuthGroupName...
1823 * Require valid-user
1824 * Require group names
1825 * Require user names
1828 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1833 if (!strcasecmp(value
, "valid-user") ||
1834 !strcasecmp(value
, "user"))
1835 loc
->level
= CUPSD_AUTH_USER
;
1836 else if (!strcasecmp(value
, "group"))
1837 loc
->level
= CUPSD_AUTH_GROUP
;
1840 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1846 * Get the list of names from the line...
1849 for (value
= valptr
; *value
;)
1851 while (isspace(*value
& 255))
1854 #ifdef HAVE_AUTHORIZATION_H
1855 if (!strncmp(value
, "@AUTHKEY(", 9))
1858 * Grab "@AUTHKEY(name)" value...
1861 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1867 #endif /* HAVE_AUTHORIZATION_H */
1868 if (*value
== '\"' || *value
== '\'')
1871 * Grab quoted name...
1874 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1881 * Grab literal name.
1884 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1890 cupsdAddName(loc
, value
);
1892 for (value
= valptr
; isspace(*value
& 255); value
++);
1895 else if (!strcasecmp(line
, "Satisfy"))
1897 if (!strcasecmp(value
, "all"))
1898 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
1899 else if (!strcasecmp(value
, "any"))
1900 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
1903 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1916 * 'parse_groups()' - Parse system group names in a string.
1919 static int /* O - 1 on success, 0 on failure */
1920 parse_groups(const char *s
) /* I - Space-delimited groups */
1922 int status
; /* Return status */
1923 char value
[1024], /* Value string */
1924 *valstart
, /* Pointer into value */
1925 *valend
, /* End of value */
1926 quote
; /* Quote character */
1927 struct group
*group
; /* Group */
1931 * Make a copy of the string and parse out the groups...
1934 strlcpy(value
, s
, sizeof(value
));
1939 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1941 if (*valstart
== '\'' || *valstart
== '\"')
1944 * Scan quoted name...
1947 quote
= *valstart
++;
1949 for (valend
= valstart
; *valend
; valend
++)
1950 if (*valend
== quote
)
1956 * Scan space or comma-delimited name...
1959 for (valend
= valstart
; *valend
; valend
++)
1960 if (isspace(*valend
) || *valend
== ',')
1967 group
= getgrnam(valstart
);
1970 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1971 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1982 while (*valstart
== ',' || isspace(*valstart
))
1991 * 'parse_protocols()' - Parse browse protocols in a string.
1994 static int /* O - Browse protocol bits */
1995 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1997 int protocols
; /* Browse protocol bits */
1998 char value
[1024], /* Value string */
1999 *valstart
, /* Pointer into value */
2000 *valend
; /* End of value */
2004 * Empty protocol line yields NULL pointer...
2011 * Loop through the value string,...
2014 strlcpy(value
, s
, sizeof(value
));
2018 for (valstart
= value
; *valstart
;)
2021 * Get the current space/comma-delimited protocol name...
2024 for (valend
= valstart
; *valend
; valend
++)
2025 if (isspace(*valend
& 255) || *valend
== ',')
2032 * Add the protocol to the bitmask...
2035 if (!strcasecmp(valstart
, "cups"))
2036 protocols
|= BROWSE_CUPS
;
2037 else if (!strcasecmp(valstart
, "slp"))
2038 protocols
|= BROWSE_SLP
;
2039 else if (!strcasecmp(valstart
, "ldap"))
2040 protocols
|= BROWSE_LDAP
;
2041 else if (!strcasecmp(valstart
, "dnssd") ||
2042 !strcasecmp(valstart
, "dns-sd") ||
2043 !strcasecmp(valstart
, "bonjour"))
2044 protocols
|= BROWSE_DNSSD
;
2045 else if (!strcasecmp(valstart
, "lpd"))
2046 protocols
|= BROWSE_LPD
;
2047 else if (!strcasecmp(valstart
, "smb"))
2048 protocols
|= BROWSE_SMB
;
2049 else if (!strcasecmp(valstart
, "all"))
2050 protocols
|= BROWSE_ALL
;
2051 else if (strcasecmp(valstart
, "none"))
2052 cupsdLogMessage(CUPSD_LOG_ERROR
,
2053 "Unknown browse protocol \"%s\" ignored!", valstart
);
2055 for (valstart
= valend
; *valstart
; valstart
++)
2056 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2065 * 'read_configuration()' - Read a configuration file.
2068 static int /* O - 1 on success, 0 on failure */
2069 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2071 int i
; /* Looping var */
2072 int linenum
; /* Current line number */
2073 char line
[HTTP_MAX_BUFFER
],
2074 /* Line from file */
2075 temp
[HTTP_MAX_BUFFER
],
2076 /* Temporary buffer for value */
2077 temp2
[HTTP_MAX_BUFFER
],
2078 /* Temporary buffer 2 for value */
2079 *ptr
, /* Pointer into line/temp */
2080 *value
, /* Pointer to value */
2081 *valueptr
; /* Pointer into value */
2082 int valuelen
; /* Length of value */
2083 cupsd_var_t
const *var
; /* Current variable */
2084 http_addrlist_t
*addrlist
, /* Address list */
2085 *addr
; /* Current address */
2086 unsigned ip
[4], /* Address value */
2087 mask
[4]; /* Netmask value */
2088 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2089 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2090 cupsd_location_t
*location
; /* Browse location */
2091 cups_file_t
*incfile
; /* Include file */
2092 char incname
[1024]; /* Include filename */
2093 struct group
*group
; /* Group */
2097 * Loop through each line in the file...
2102 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2105 * Decode the directive...
2108 if (!strcasecmp(line
, "Include"))
2114 if (value
[0] == '/')
2115 strlcpy(incname
, value
, sizeof(incname
));
2117 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2119 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2120 cupsdLogMessage(CUPSD_LOG_ERROR
,
2121 "Unable to include config file \"%s\" - %s",
2122 incname
, strerror(errno
));
2125 read_configuration(incfile
);
2126 cupsFileClose(incfile
);
2129 else if (!strcasecmp(line
, "<Location"))
2137 linenum
= read_location(fp
, value
, linenum
);
2143 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2148 else if (!strcasecmp(line
, "<Policy"))
2156 linenum
= read_policy(fp
, value
, linenum
);
2162 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2166 else if (!strcasecmp(line
, "FaxRetryInterval"))
2170 JobRetryInterval
= atoi(value
);
2171 cupsdLogMessage(CUPSD_LOG_WARN
,
2172 "FaxRetryInterval is deprecated; use "
2173 "JobRetryInterval on line %d.", linenum
);
2177 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2181 else if (!strcasecmp(line
, "FaxRetryLimit"))
2185 JobRetryLimit
= atoi(value
);
2186 cupsdLogMessage(CUPSD_LOG_WARN
,
2187 "FaxRetryLimit is deprecated; use "
2188 "JobRetryLimit on line %d.", linenum
);
2192 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2196 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2198 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2199 #endif /* HAVE_SSL */
2203 * Add listening address(es) to the list...
2206 cupsd_listener_t
*lis
; /* New listeners array */
2210 * Get the address list...
2213 addrlist
= get_address(value
, IPP_PORT
);
2217 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2223 * Add each address...
2226 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2229 * Allocate another listener...
2233 Listeners
= cupsArrayNew(NULL
, NULL
);
2237 cupsdLogMessage(CUPSD_LOG_ERROR
,
2238 "Unable to allocate %s at line %d - %s.",
2239 line
, linenum
, strerror(errno
));
2243 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2245 cupsdLogMessage(CUPSD_LOG_ERROR
,
2246 "Unable to allocate %s at line %d - %s.",
2247 line
, linenum
, strerror(errno
));
2251 cupsArrayAdd(Listeners
, lis
);
2254 * Copy the current address and log it...
2257 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2261 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2262 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2263 #endif /* HAVE_SSL */
2265 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2268 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2269 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2270 ntohs(lis
->address
.ipv6
.sin6_port
));
2272 #endif /* AF_INET6 */
2274 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2275 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2277 #endif /* AF_LOCAL */
2278 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2279 ntohs(lis
->address
.ipv4
.sin_port
));
2286 httpAddrFreeList(addrlist
);
2288 else if (!strcasecmp(line
, "BrowseAddress"))
2291 * Add a browse address to the list...
2294 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2297 if (NumBrowsers
== 0)
2298 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2300 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2304 cupsdLogMessage(CUPSD_LOG_ERROR
,
2305 "Unable to allocate BrowseAddress at line %d - %s.",
2306 linenum
, strerror(errno
));
2311 dira
+= NumBrowsers
;
2313 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2315 if (!strcasecmp(value
, "@LOCAL"))
2318 * Send browse data to all local interfaces...
2321 strcpy(dira
->iface
, "*");
2324 else if (!strncasecmp(value
, "@IF(", 4))
2327 * Send browse data to the named interface...
2330 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2332 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2338 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2341 * Only IPv4 addresses are supported...
2344 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2345 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2350 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2351 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2353 cupsdLogMessage(CUPSD_LOG_INFO
,
2354 "Sending browsing info to %s:%d (IPv4)",
2355 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2360 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2363 httpAddrFreeList(addrlist
);
2366 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2369 else if (!strcasecmp(line
, "BrowseOrder"))
2372 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2375 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2376 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2378 if (location
== NULL
)
2379 cupsdLogMessage(CUPSD_LOG_ERROR
,
2380 "Unable to initialize browse access control list!");
2381 else if (!strncasecmp(value
, "deny", 4))
2382 location
->order_type
= CUPSD_AUTH_ALLOW
;
2383 else if (!strncasecmp(value
, "allow", 5))
2384 location
->order_type
= CUPSD_AUTH_DENY
;
2386 cupsdLogMessage(CUPSD_LOG_ERROR
,
2387 "Unknown BrowseOrder value %s on line %d.",
2390 else if (!strcasecmp(line
, "BrowseProtocols") ||
2391 !strcasecmp(line
, "BrowseLocalProtocols") ||
2392 !strcasecmp(line
, "BrowseRemoteProtocols"))
2395 * "BrowseProtocols name [... name]"
2396 * "BrowseLocalProtocols name [... name]"
2397 * "BrowseRemoteProtocols name [... name]"
2400 int protocols
= parse_protocols(value
);
2404 cupsdLogMessage(CUPSD_LOG_ERROR
,
2405 "Unknown browse protocol \"%s\" on line %d.",
2410 if (strcasecmp(line
, "BrowseLocalProtocols"))
2411 BrowseRemoteProtocols
= protocols
;
2412 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2413 BrowseLocalProtocols
= protocols
;
2415 else if (!strcasecmp(line
, "BrowseAllow") ||
2416 !strcasecmp(line
, "BrowseDeny"))
2419 * BrowseAllow [From] host/ip...
2420 * BrowseDeny [From] host/ip...
2423 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2424 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2426 if (location
== NULL
)
2427 cupsdLogMessage(CUPSD_LOG_ERROR
,
2428 "Unable to initialize browse access control list!");
2431 if (!strncasecmp(value
, "from ", 5))
2434 * Strip leading "from"...
2439 while (isspace(*value
))
2444 * Figure out what form the allow/deny address takes:
2455 * nnn.nnn.nnn.nnn/mm
2456 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2459 if (!strcasecmp(value
, "all"))
2465 if (!strcasecmp(line
, "BrowseAllow"))
2466 cupsdAllowIP(location
, zeros
, zeros
);
2468 cupsdDenyIP(location
, zeros
, zeros
);
2470 else if (!strcasecmp(value
, "none"))
2476 if (!strcasecmp(line
, "BrowseAllow"))
2477 cupsdAllowIP(location
, ones
, zeros
);
2479 cupsdDenyIP(location
, ones
, zeros
);
2482 else if (value
[0] == '*' || value
[0] == '.' ||
2483 (!isdigit(value
[0] & 255) && value
[0] != '['))
2485 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2486 #endif /* AF_INET6 */
2489 * Host or domain name...
2492 if (value
[0] == '*')
2495 if (!strcasecmp(line
, "BrowseAllow"))
2496 cupsdAllowHost(location
, value
);
2498 cupsdDenyHost(location
, value
);
2503 * One of many IP address forms...
2506 if (!get_addr_and_mask(value
, ip
, mask
))
2508 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2513 if (!strcasecmp(line
, "BrowseAllow"))
2514 cupsdAllowIP(location
, ip
, mask
);
2516 cupsdDenyIP(location
, ip
, mask
);
2520 else if (!strcasecmp(line
, "BrowseRelay"))
2523 * BrowseRelay [from] source [to] destination
2527 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2529 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2533 cupsdLogMessage(CUPSD_LOG_ERROR
,
2534 "Unable to allocate BrowseRelay at line %d - %s.",
2535 linenum
, strerror(errno
));
2542 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2544 if (!strncasecmp(value
, "from ", 5))
2547 * Strip leading "from"...
2552 while (isspace(*value
))
2557 * Figure out what form the from address takes:
2566 * nnn.nnn.nnn.nnn/mm
2567 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2571 if (value
[0] == '*' || value
[0] == '.' ||
2572 (!isdigit(value
[0] & 255) && value
[0] != '['))
2574 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2575 #endif /* AF_INET6 */
2578 * Host or domain name...
2581 if (value
[0] == '*')
2584 strlcpy(temp
, value
, sizeof(temp
));
2585 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2588 relay
->from
.type
= CUPSD_AUTH_NAME
;
2590 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2592 cupsdLogMessage(CUPSD_LOG_ERROR
,
2593 "Unable to allocate BrowseRelay name at line %d - %s.",
2594 linenum
, strerror(errno
));
2598 relay
->from
.mask
.name
.length
= strlen(temp
);
2603 * One of many IP address forms...
2606 if (!get_addr_and_mask(value
, ip
, mask
))
2608 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2613 relay
->from
.type
= CUPSD_AUTH_IP
;
2614 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2615 sizeof(relay
->from
.mask
.ip
.address
));
2616 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2617 sizeof(relay
->from
.mask
.ip
.netmask
));
2621 * Skip value and trailing whitespace...
2624 for (; *value
; value
++)
2625 if (isspace(*value
))
2628 while (isspace(*value
))
2631 if (!strncasecmp(value
, "to ", 3))
2634 * Strip leading "to"...
2639 while (isspace(*value
))
2644 * Get "to" address and port...
2647 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2650 * Only IPv4 addresses are supported...
2653 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2654 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2659 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2661 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2663 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2664 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2665 relay
->from
.mask
.ip
.address
[0] >> 24,
2666 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2667 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2668 relay
->from
.mask
.ip
.address
[0] & 255,
2669 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2670 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2671 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2672 relay
->from
.mask
.ip
.netmask
[0] & 255);
2674 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2676 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2677 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2682 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2685 httpAddrFreeList(addrlist
);
2689 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2690 free(relay
->from
.mask
.name
.name
);
2692 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2696 else if (!strcasecmp(line
, "BrowsePoll"))
2699 * BrowsePoll address[:port]
2702 char *portname
; /* Port name */
2703 int portnum
; /* Port number */
2704 struct servent
*service
; /* Service */
2708 * Extract the port name from the address...
2711 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2715 if (isdigit(*portname
& 255))
2716 portnum
= atoi(portname
);
2717 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2718 portnum
= ntohs(service
->s_port
);
2721 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2727 portnum
= ippPort();
2730 * Add the poll entry...
2734 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2736 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2740 cupsdLogMessage(CUPSD_LOG_ERROR
,
2741 "Unable to allocate BrowsePoll at line %d - %s.",
2742 linenum
, strerror(errno
));
2750 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2752 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2753 pollp
->port
= portnum
;
2755 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2758 else if (!strcasecmp(line
, "DefaultAuthType"))
2761 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2764 if (!strcasecmp(value
, "none"))
2765 DefaultAuthType
= CUPSD_AUTH_NONE
;
2766 else if (!strcasecmp(value
, "basic"))
2767 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2768 else if (!strcasecmp(value
, "digest"))
2769 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2770 else if (!strcasecmp(value
, "basicdigest"))
2771 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2773 else if (!strcasecmp(value
, "negotiate"))
2774 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2775 #endif /* HAVE_GSSAPI */
2778 cupsdLogMessage(CUPSD_LOG_WARN
,
2779 "Unknown default authorization type %s on line %d.",
2785 else if (!strcasecmp(line
, "DefaultEncryption"))
2788 * DefaultEncryption {Never,IfRequested,Required}
2791 if (!value
|| !strcasecmp(value
, "never"))
2792 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2793 else if (!strcasecmp(value
, "required"))
2794 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2795 else if (!strcasecmp(value
, "ifrequested"))
2796 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2799 cupsdLogMessage(CUPSD_LOG_WARN
,
2800 "Unknown default encryption %s on line %d.",
2805 #endif /* HAVE_SSL */
2807 else if (!strcasecmp(line
, "Krb5Keytab"))
2809 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2812 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2813 gsskrb5_register_acceptor_identity(value
);
2815 cupsdSetEnv("KRB5_KTNAME", value
);
2816 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2818 #endif /* HAVE_GSSAPI */
2819 else if (!strcasecmp(line
, "User"))
2822 * User ID to run as...
2825 if (value
&& isdigit(value
[0] & 255))
2827 int uid
= atoi(value
);
2830 cupsdLogMessage(CUPSD_LOG_ERROR
,
2831 "Will not use User 0 as specified on line %d "
2832 "for security reasons. You must use a non-"
2833 "privileged account instead.",
2840 struct passwd
*p
; /* Password information */
2843 p
= getpwnam(value
);
2848 cupsdLogMessage(CUPSD_LOG_ERROR
,
2849 "Will not use User %s (UID=0) as specified on line "
2850 "%d for security reasons. You must use a non-"
2851 "privileged account instead.",
2857 cupsdLogMessage(CUPSD_LOG_ERROR
,
2858 "Unknown User \"%s\" on line %d, ignoring!",
2862 cupsdLogMessage(CUPSD_LOG_ERROR
,
2863 "User directive on line %d missing the username!",
2866 else if (!strcasecmp(line
, "Group"))
2869 * Group ID to run as...
2872 if (isdigit(value
[0]))
2873 Group
= atoi(value
);
2877 group
= getgrnam(value
);
2880 Group
= group
->gr_gid
;
2882 cupsdLogMessage(CUPSD_LOG_ERROR
,
2883 "Unknown Group \"%s\" on line %d, ignoring!",
2887 else if (!strcasecmp(line
, "SystemGroup"))
2890 * SystemGroup (admin) group(s)...
2893 if (!parse_groups(value
))
2894 cupsdLogMessage(CUPSD_LOG_ERROR
,
2895 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2898 else if (!strcasecmp(line
, "HostNameLookups"))
2901 * Do hostname lookups?
2904 if (!strcasecmp(value
, "off"))
2905 HostNameLookups
= 0;
2906 else if (!strcasecmp(value
, "on"))
2907 HostNameLookups
= 1;
2908 else if (!strcasecmp(value
, "double"))
2909 HostNameLookups
= 2;
2911 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2914 else if (!strcasecmp(line
, "LogLevel"))
2917 * Amount of logging to do...
2920 if (!strcasecmp(value
, "debug2"))
2921 LogLevel
= CUPSD_LOG_DEBUG2
;
2922 else if (!strcasecmp(value
, "debug"))
2923 LogLevel
= CUPSD_LOG_DEBUG
;
2924 else if (!strcasecmp(value
, "info"))
2925 LogLevel
= CUPSD_LOG_INFO
;
2926 else if (!strcasecmp(value
, "notice"))
2927 LogLevel
= CUPSD_LOG_NOTICE
;
2928 else if (!strcasecmp(value
, "warn"))
2929 LogLevel
= CUPSD_LOG_WARN
;
2930 else if (!strcasecmp(value
, "error"))
2931 LogLevel
= CUPSD_LOG_ERROR
;
2932 else if (!strcasecmp(value
, "crit"))
2933 LogLevel
= CUPSD_LOG_CRIT
;
2934 else if (!strcasecmp(value
, "alert"))
2935 LogLevel
= CUPSD_LOG_ALERT
;
2936 else if (!strcasecmp(value
, "emerg"))
2937 LogLevel
= CUPSD_LOG_EMERG
;
2938 else if (!strcasecmp(value
, "none"))
2939 LogLevel
= CUPSD_LOG_NONE
;
2941 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2944 else if (!strcasecmp(line
, "PrintcapFormat"))
2947 * Format of printcap file?
2950 if (!strcasecmp(value
, "bsd"))
2951 PrintcapFormat
= PRINTCAP_BSD
;
2952 else if (!strcasecmp(value
, "solaris"))
2953 PrintcapFormat
= PRINTCAP_SOLARIS
;
2955 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2958 else if (!strcasecmp(line
, "ServerTokens"))
2961 * Set the string used for the Server header...
2964 struct utsname plat
; /* Platform info */
2969 if (!strcasecmp(value
, "ProductOnly"))
2970 cupsdSetString(&ServerHeader
, "CUPS");
2971 else if (!strcasecmp(value
, "Major"))
2972 cupsdSetString(&ServerHeader
, "CUPS/1");
2973 else if (!strcasecmp(value
, "Minor"))
2974 cupsdSetString(&ServerHeader
, "CUPS/1.4");
2975 else if (!strcasecmp(value
, "Minimal"))
2976 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2977 else if (!strcasecmp(value
, "OS"))
2978 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2979 else if (!strcasecmp(value
, "Full"))
2980 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2982 else if (!strcasecmp(value
, "None"))
2983 cupsdClearString(&ServerHeader
);
2985 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2988 else if (!strcasecmp(line
, "PassEnv"))
2991 * PassEnv variable [... variable]
2996 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2997 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3000 if (value
[valuelen
])
3002 value
[valuelen
] = '\0';
3006 cupsdSetEnv(value
, NULL
);
3008 for (value
+= valuelen
; *value
; value
++)
3009 if (!isspace(*value
) || *value
!= ',')
3013 else if (!strcasecmp(line
, "SetEnv"))
3016 * SetEnv variable value
3019 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3027 while (isspace(*valueptr
& 255))
3030 cupsdSetEnv(value
, valueptr
);
3033 cupsdLogMessage(CUPSD_LOG_ERROR
,
3034 "Missing value for SetEnv directive on line %d.",
3040 * Find a simple variable in the list...
3043 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3044 if (!strcasecmp(line
, var
->name
))
3050 * Unknown directive! Output an error message and continue...
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
:
3118 if (value
[0] == '/')
3119 strlcpy(temp
, value
, sizeof(temp
));
3121 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3123 if (access(temp
, 0))
3125 cupsdLogMessage(CUPSD_LOG_ERROR
,
3126 "File or directory for \"%s %s\" on line %d "
3127 "does not exist!", line
, value
, linenum
);
3131 case CUPSD_VARTYPE_STRING
:
3132 cupsdSetString((char **)var
->ptr
, value
);
3143 * 'read_location()' - Read a <Location path> definition.
3146 static int /* O - New line number or 0 on error */
3147 read_location(cups_file_t
*fp
, /* I - Configuration file */
3148 char *location
, /* I - Location name/path */
3149 int linenum
) /* I - Current line number */
3151 cupsd_location_t
*loc
, /* New location */
3152 *parent
; /* Parent location */
3153 char line
[HTTP_MAX_BUFFER
],
3155 *value
, /* Value for directive */
3156 *valptr
; /* Pointer into value */
3159 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3162 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3165 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3168 * Decode the directive...
3171 if (!strcasecmp(line
, "</Location>"))
3173 else if (!strcasecmp(line
, "<Limit") ||
3174 !strcasecmp(line
, "<LimitExcept"))
3178 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3182 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3188 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3193 if (!strcmp(value
, "ALL"))
3194 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3195 else if (!strcmp(value
, "GET"))
3196 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3197 else if (!strcmp(value
, "HEAD"))
3198 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3199 else if (!strcmp(value
, "OPTIONS"))
3200 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3201 else if (!strcmp(value
, "POST"))
3202 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3203 else if (!strcmp(value
, "PUT"))
3204 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3205 else if (!strcmp(value
, "TRACE"))
3206 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3208 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3211 for (value
= valptr
; isspace(*value
& 255); value
++);
3214 if (!strcasecmp(line
, "<LimitExcept"))
3215 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3217 parent
->limit
&= ~loc
->limit
;
3219 else if (!strcasecmp(line
, "</Limit>") ||
3220 !strcasecmp(line
, "</LimitExcept>"))
3222 else if (!parse_aaa(loc
, line
, value
, linenum
))
3224 cupsdLogMessage(CUPSD_LOG_ERROR
,
3225 "Unknown Location directive %s on line %d.",
3231 cupsdLogMessage(CUPSD_LOG_ERROR
,
3232 "Unexpected end-of-file at line %d while reading location!",
3240 * 'read_policy()' - Read a <Policy name> definition.
3243 static int /* O - New line number or 0 on error */
3244 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3245 char *policy
, /* I - Location name/path */
3246 int linenum
) /* I - Current line number */
3248 int i
; /* Looping var */
3249 cupsd_policy_t
*pol
; /* Policy */
3250 cupsd_location_t
*op
; /* Policy operation */
3251 int num_ops
; /* Number of IPP operations */
3252 ipp_op_t ops
[100]; /* Operations */
3253 char line
[HTTP_MAX_BUFFER
],
3255 *value
, /* Value for directive */
3256 *valptr
; /* Pointer into value */
3260 * Create the policy...
3263 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3267 * Read from the file...
3273 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3276 * Decode the directive...
3279 if (!strcasecmp(line
, "</Policy>"))
3282 cupsdLogMessage(CUPSD_LOG_WARN
,
3283 "Missing </Limit> before </Policy> on line %d!",
3287 * Verify that we have an explicit policy for CUPS-Get-Document
3288 * (ensures that upgrades do not introduce new security issues...)
3291 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3292 op
->op
== IPP_ANY_OPERATION
)
3294 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3295 op
->op
!= IPP_ANY_OPERATION
)
3298 * Add a new limit for CUPS-Get-Document using the Send-Document
3299 * limit as a template...
3302 cupsdLogMessage(CUPSD_LOG_WARN
,
3303 "No limit for CUPS-Get-Document defined in policy %s "
3304 "- using Send-Document's policy", pol
->name
);
3306 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3312 else if (!strcasecmp(line
, "<Limit") && !op
)
3316 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3321 * Scan for IPP operation names...
3328 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3333 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3335 if (!strcasecmp(value
, "All"))
3336 ops
[num_ops
] = IPP_ANY_OPERATION
;
3337 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3338 cupsdLogMessage(CUPSD_LOG_ERROR
,
3339 "Bad IPP operation name \"%s\" on line %d!",
3345 cupsdLogMessage(CUPSD_LOG_ERROR
,
3346 "Too many operations listed on line %d!",
3349 for (value
= valptr
; isspace(*value
& 255); value
++);
3353 * If none are specified, apply the policy to all operations...
3358 ops
[0] = IPP_ANY_OPERATION
;
3363 * Add a new policy for the first operation...
3366 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3368 else if (!strcasecmp(line
, "</Limit>") && op
)
3371 * Finish the current operation limit...
3377 * Copy the policy to the other operations...
3380 for (i
= 1; i
< num_ops
; i
++)
3381 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3388 cupsdLogMessage(CUPSD_LOG_ERROR
,
3389 "Missing <Limit ops> directive before %s on line %d.",
3393 else if (!parse_aaa(op
, line
, value
, linenum
))
3396 cupsdLogMessage(CUPSD_LOG_ERROR
,
3397 "Unknown Policy Limit directive %s on line %d.",
3400 cupsdLogMessage(CUPSD_LOG_ERROR
,
3401 "Unknown Policy directive %s on line %d.",
3408 cupsdLogMessage(CUPSD_LOG_ERROR
,
3409 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3417 * End of "$Id: conf.c 6930 2007-09-08 00:28:06Z mike $".