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 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
107 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
108 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
109 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
110 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
111 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
112 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
114 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
115 #endif /* HAVE_GSSAPI */
116 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
117 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
118 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
119 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
120 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
121 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
123 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
124 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
125 #endif /* HAVE_LAUNCHD */
126 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
127 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
128 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
129 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
130 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
146 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
147 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
148 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
149 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
150 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
151 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
152 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
153 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
154 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
155 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
156 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
157 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
159 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
160 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
161 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
162 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
163 #endif /* HAVE_SSL */
164 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
165 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
166 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
167 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
168 #ifdef HAVE_AUTHORIZATION_H
169 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
170 #endif /* HAVE_AUTHORIZATION_H */
171 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
172 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
173 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
175 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
178 static const unsigned ones
[4] =
180 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
182 static const unsigned zeros
[4] =
184 0x00000000, 0x00000000, 0x00000000, 0x00000000
191 static http_addrlist_t
*get_address(const char *value
, int defport
);
192 static int get_addr_and_mask(const char *value
, unsigned *ip
,
194 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
195 char *value
, int linenum
);
196 static int parse_groups(const char *s
);
197 static int parse_protocols(const char *s
);
198 static int read_configuration(cups_file_t
*fp
);
199 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
200 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
204 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
207 int /* O - 0 on success, -1 on error, 1 on warning */
208 cupsdCheckPermissions(
209 const char *filename
, /* I - File/directory name */
210 const char *suffix
, /* I - Additional file/directory name */
211 int mode
, /* I - Permissions */
212 int user
, /* I - Owner */
213 int group
, /* I - Group */
214 int is_dir
, /* I - 1 = directory, 0 = file */
215 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
217 int dir_created
= 0; /* Did we create a directory? */
218 char pathname
[1024]; /* File name with prefix */
219 struct stat fileinfo
; /* Stat buffer */
223 * Prepend the given root to the filename before testing it...
228 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
233 * See if we can stat the file/directory...
236 if (stat(filename
, &fileinfo
))
238 if (errno
== ENOENT
&& create_dir
)
241 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
244 if (mkdir(filename
, mode
))
247 cupsdLogMessage(CUPSD_LOG_ERROR
,
248 "Unable to create directory \"%s\" - %s", filename
,
251 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
260 return (create_dir
? -1 : 1);
264 * Make sure it's a regular file...
267 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
269 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
273 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
276 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
278 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
284 * Fix owner, group, and mode as needed...
287 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
290 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
293 if (chown(filename
, user
, group
) && !getuid())
296 cupsdLogMessage(CUPSD_LOG_ERROR
,
297 "Unable to change ownership of \"%s\" - %s", filename
,
300 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
307 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
310 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
313 if (chmod(filename
, mode
))
316 cupsdLogMessage(CUPSD_LOG_ERROR
,
317 "Unable to change permissions of \"%s\" - %s", filename
,
320 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
328 * Everything is OK...
336 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
339 int /* O - 1 on success, 0 otherwise */
340 cupsdReadConfiguration(void)
342 int i
; /* Looping var */
343 cups_file_t
*fp
; /* Configuration file */
344 int status
; /* Return status */
345 char temp
[1024], /* Temporary buffer */
346 *slash
; /* Directory separator */
347 cups_lang_t
*language
; /* Language */
348 struct passwd
*user
; /* Default user */
349 struct group
*group
; /* Default group */
350 char *old_serverroot
, /* Old ServerRoot */
351 *old_requestroot
; /* Old RequestRoot */
352 const char *tmpdir
; /* TMPDIR environment variable */
353 struct stat tmpinfo
; /* Temporary directory info */
354 cupsd_policy_t
*p
; /* Policy */
358 * Save the old root paths...
361 old_serverroot
= NULL
;
362 cupsdSetString(&old_serverroot
, ServerRoot
);
363 old_requestroot
= NULL
;
364 cupsdSetString(&old_requestroot
, RequestRoot
);
367 * Reset the server configuration data...
370 cupsdDeleteAllLocations();
389 for (i
= 0; i
< NumRelays
; i
++)
390 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
391 free(Relays
[i
].from
.mask
.name
.name
);
398 cupsdDeleteAllListeners();
404 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
405 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
406 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
407 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
408 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
409 cupsdSetString(&DataDir
, CUPS_DATADIR
);
410 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
411 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
412 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
413 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
414 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
415 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
416 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
417 cupsdSetString(&RemoteRoot
, "remroot");
418 cupsdSetString(&ServerHeader
, "CUPS/1.2");
419 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
421 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
422 #endif /* HAVE_GSSAPI */
424 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
425 PrintcapFormat
= PRINTCAP_SOLARIS
;
427 PrintcapFormat
= PRINTCAP_BSD
;
429 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
430 if ((slash
= strrchr(temp
, '/')) != NULL
)
433 cupsdSetString(&ServerRoot
, temp
);
435 cupsdClearString(&Classification
);
436 ClassifyOverride
= 0;
440 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
442 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
443 cupsdSetString(&ServerKey
, "ssl/server.key");
444 # endif /* HAVE_CDSASSL */
445 #endif /* HAVE_SSL */
447 language
= cupsLangDefault();
449 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
450 cupsdSetString(&DefaultLanguage
, "en");
452 cupsdSetString(&DefaultLanguage
, language
->language
);
454 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
456 cupsdSetString(&RIPCache
, "8m");
458 cupsdSetString(&TempDir
, NULL
);
461 * Find the default user...
464 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
469 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
470 * complement number...)
479 * Find the default group...
482 group
= getgrnam(CUPS_DEFAULT_GROUP
);
486 Group
= group
->gr_gid
;
490 * Fallback to group "nobody"...
493 group
= getgrnam("nobody");
497 Group
= group
->gr_gid
;
501 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
502 * complement number...)
513 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
514 DefaultAuthType
= CUPSD_AUTH_BASIC
;
516 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
517 #endif /* HAVE_SSL */
519 JobRetryInterval
= 300;
524 HostNameLookups
= FALSE
;
525 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
526 ImplicitAnyClasses
= FALSE
;
527 HideImplicitMembers
= TRUE
;
529 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
530 ListenBackLog
= SOMAXCONN
;
531 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
532 LogLevel
= CUPSD_LOG_ERROR
;
534 MaxClientsPerHost
= 0;
535 MaxLogSize
= 1024 * 1024;
536 MaxPrinterHistory
= 10;
539 RootCertDuration
= 300;
540 Timeout
= DEFAULT_TIMEOUT
;
543 BrowseInterval
= DEFAULT_INTERVAL
;
544 BrowsePort
= ippPort();
545 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
546 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
547 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
548 BrowseTimeout
= DEFAULT_TIMEOUT
;
549 Browsing
= CUPS_DEFAULT_BROWSING
;
550 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
552 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
553 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
555 cupsdClearString(&BrowseLocalOptions
);
556 cupsdClearString(&BrowseRemoteOptions
);
558 cupsdSetString(&ErrorPolicy
, "stop-printer");
561 cupsdClearString(&BrowseLDAPBindDN
);
562 cupsdClearString(&BrowseLDAPDN
);
563 cupsdClearString(&BrowseLDAPPassword
);
564 cupsdClearString(&BrowseLDAPServer
);
565 cupsdClearString(&BrowseLDAPCACertFile
);
566 #endif /* HAVE_LDAP */
568 JobHistory
= DEFAULT_HISTORY
;
569 JobFiles
= DEFAULT_FILES
;
574 MaxJobsPerPrinter
= 0;
575 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
577 cupsdDeleteAllPolicies();
578 cupsdClearString(&DefaultPolicy
);
580 #ifdef HAVE_AUTHORIZATION_H
581 cupsdClearString(&SystemGroupAuthKey
);
582 #endif /* HAVE_AUTHORIZATION_H */
584 MaxSubscriptions
= 100;
585 MaxSubscriptionsPerJob
= 0;
586 MaxSubscriptionsPerPrinter
= 0;
587 MaxSubscriptionsPerUser
= 0;
588 DefaultLeaseDuration
= 86400;
589 MaxLeaseDuration
= 0;
592 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
593 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
594 #endif /* HAVE_LAUNCHD */
598 #endif /* __APPLE__ */
601 * Read the configuration file...
604 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
607 status
= read_configuration(fp
);
617 * See if the ServerName is an IP address...
620 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
622 ServerNameIsIP
= !*slash
;
625 * Use the default system group if none was supplied in cupsd.conf...
628 if (NumSystemGroups
== 0)
630 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
633 * Find the group associated with GID 0...
640 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
642 cupsdSetString(&SystemGroups
[0], "unknown");
644 SystemGroupIDs
[0] = 0;
650 * Get the access control list for browsing...
653 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
656 * Open the system log for cupsd if necessary...
660 if (!strcmp(AccessLog
, "syslog") ||
661 !strcmp(ErrorLog
, "syslog") ||
662 !strcmp(PageLog
, "syslog"))
663 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
664 #endif /* HAVE_VSYSLOG */
667 * Log the configuration file that was used...
670 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
674 * Validate the Group and SystemGroup settings - they cannot be the same,
675 * otherwise the CGI programs will be able to authenticate as root without
681 for (i
= 0; i
< NumSystemGroups
; i
++)
682 if (Group
== SystemGroupIDs
[i
])
685 if (i
< NumSystemGroups
)
688 * Log the error and reset the group to a safe value...
691 cupsdLogMessage(CUPSD_LOG_NOTICE
,
692 "Group and SystemGroup cannot use the same groups!");
693 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
695 group
= getgrnam("nobody");
699 Group
= group
->gr_gid
;
703 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
704 * complement number...)
713 * Check that we have at least one listen/port line; if not, report this
714 * as an error and exit!
717 if (cupsArrayCount(Listeners
) == 0)
723 cupsdLogMessage(CUPSD_LOG_EMERG
,
724 "No valid Listen or Port lines were found in the configuration file!");
730 cupsdEndProcess(getpid(), 0);
734 * Set the default locale using the language and charset...
737 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
740 * Update all relative filenames to include the full path from ServerRoot...
743 if (DocumentRoot
[0] != '/')
744 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
746 if (RequestRoot
[0] != '/')
747 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
749 if (ServerBin
[0] != '/')
750 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
752 if (StateDir
[0] != '/')
753 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
755 if (CacheDir
[0] != '/')
756 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
759 if (ServerCertificate
[0] != '/')
760 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
762 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
764 chown(ServerCertificate
, RunUser
, Group
);
765 chmod(ServerCertificate
, 0600);
768 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
769 if (ServerKey
[0] != '/')
770 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
772 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
774 chown(ServerKey
, RunUser
, Group
);
775 chmod(ServerKey
, 0600);
777 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
778 #endif /* HAVE_SSL */
781 * Make sure that directories and config files are owned and
782 * writable by the user and group in the cupsd.conf file...
785 if (cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
787 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
789 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
791 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
792 SystemGroupIDs
[0], 1, 1) < 0 ||
793 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
795 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
797 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
799 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
801 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
803 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
805 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
810 * Update TempDir to the default if it hasn't been set already...
815 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
818 * TMPDIR is defined, see if it is OK for us to use...
821 if (stat(tmpdir
, &tmpinfo
))
822 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
823 tmpdir
, strerror(errno
));
824 else if (!S_ISDIR(tmpinfo
.st_mode
))
825 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
827 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
828 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
829 !(tmpinfo
.st_mode
& S_IWOTH
))
830 cupsdLogMessage(CUPSD_LOG_ERROR
,
831 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
833 cupsdSetString(&TempDir
, tmpdir
);
838 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
840 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
845 * Make sure the temporary directory has the right permissions...
848 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
852 * Update ownership and permissions if the CUPS temp directory
853 * is under the spool directory or does not exist...
856 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
861 * Setup environment variables...
867 * Check the MaxClients setting, and then allocate memory for it...
870 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
873 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
876 MaxClients
= MaxFDs
/ 3;
879 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
883 * Check the MaxActiveJobs setting; limit to 1/3 the available
884 * file descriptors, since we need a pipe for each job...
887 if (MaxActiveJobs
> (MaxFDs
/ 3))
888 MaxActiveJobs
= MaxFDs
/ 3;
890 if (Classification
&& !strcasecmp(Classification
, "none"))
891 cupsdClearString(&Classification
);
894 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
897 * Update the MaxClientsPerHost value, as needed...
900 if (MaxClientsPerHost
<= 0)
901 MaxClientsPerHost
= MaxClients
;
903 if (MaxClientsPerHost
> MaxClients
)
904 MaxClientsPerHost
= MaxClients
;
906 cupsdLogMessage(CUPSD_LOG_INFO
,
907 "Allowing up to %d client connections per host.",
911 * Make sure that BrowseTimeout is at least twice the interval...
914 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
916 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
920 BrowseTimeout
= BrowseInterval
* 2;
922 BrowseTimeout
= DEFAULT_TIMEOUT
;
924 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
929 * Update the default policy, as needed...
933 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
935 DefaultPolicyPtr
= NULL
;
937 if (!DefaultPolicyPtr
)
939 cupsd_location_t
*po
; /* New policy operation */
943 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
946 cupsdSetString(&DefaultPolicy
, "default");
948 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
949 cupsdLogMessage(CUPSD_LOG_INFO
,
950 "Using policy \"default\" as the default!");
953 cupsdLogMessage(CUPSD_LOG_INFO
,
954 "Creating CUPS default administrative policy:");
956 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
958 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
959 cupsdLogMessage(CUPSD_LOG_INFO
,
960 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
961 "Release-Job Restart-Job Purge-Jobs "
962 "Set-Job-Attributes Create-Job-Subscription "
963 "Renew-Subscription Cancel-Subscription "
964 "Get-Notifications Reprocess-Job Cancel-Current-Job "
965 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
966 "CUPS-Authenticate-Job CUPS-Get-Document>");
967 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
969 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
970 po
->order_type
= CUPSD_AUTH_ALLOW
;
971 po
->level
= CUPSD_AUTH_USER
;
973 cupsdAddName(po
, "@OWNER");
974 cupsdAddName(po
, "@SYSTEM");
975 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
977 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
978 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
979 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
980 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
981 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
982 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
983 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
984 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
985 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
986 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
987 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
988 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
989 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
990 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
991 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
992 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
993 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
994 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
996 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
998 cupsdLogMessage(CUPSD_LOG_INFO
,
999 "<Limit Pause-Printer Resume-Printer "
1000 "Set-Printer-Attributes Enable-Printer "
1001 "Disable-Printer Pause-Printer-After-Current-Job "
1002 "Hold-New-Jobs Release-Held-New-Jobs "
1003 "Deactivate-Printer Activate-Printer Restart-Printer "
1004 "Shutdown-Printer Startup-Printer Promote-Job "
1005 "Schedule-Job-After CUPS-Add-Printer "
1006 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1007 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1008 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1009 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1011 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1012 po
->order_type
= CUPSD_AUTH_ALLOW
;
1013 po
->type
= CUPSD_AUTH_DEFAULT
;
1014 po
->level
= CUPSD_AUTH_USER
;
1016 cupsdAddName(po
, "@SYSTEM");
1017 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1019 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1020 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1021 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1022 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1023 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1024 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1025 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1026 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1027 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1028 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1029 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1030 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1031 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1032 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1033 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1034 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1035 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1036 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1037 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1038 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1039 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1041 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1043 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1044 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1046 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1047 po
->order_type
= CUPSD_AUTH_ALLOW
;
1049 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1050 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1054 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1055 cupsArrayCount(Policies
));
1056 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1058 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1059 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1060 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1063 * If we are doing a full reload or the server root has changed, flush
1064 * the jobs, printers, etc. and start from scratch...
1067 if (NeedReload
== RELOAD_ALL
||
1068 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1069 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1071 mime_type_t
*type
; /* Current type */
1072 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1073 /* MIME type name */
1076 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1079 * Free all memory...
1082 cupsdDeleteAllSubscriptions();
1084 cupsdDeleteAllClasses();
1085 cupsdDeleteAllPrinters();
1087 DefaultPrinter
= NULL
;
1089 if (MimeDatabase
!= NULL
)
1090 mimeDelete(MimeDatabase
);
1094 for (i
= 0; i
< NumMimeTypes
; i
++)
1095 _cupsStrFree(MimeTypes
[i
]);
1101 * Read the MIME type and conversion database...
1104 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1106 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
1110 cupsdLogMessage(CUPSD_LOG_EMERG
,
1111 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1115 cupsdLogMessage(CUPSD_LOG_INFO
,
1116 "Loaded MIME database from \'%s\': %d types, %d filters...",
1117 ServerRoot
, mimeNumTypes(MimeDatabase
),
1118 mimeNumFilters(MimeDatabase
));
1121 * Create a list of MIME types for the document-format-supported
1125 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1126 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1129 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1131 cupsdLogMessage(CUPSD_LOG_ERROR
,
1132 "Unable to allocate memory for %d MIME types!",
1138 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1140 i
++, type
= mimeNextType(MimeDatabase
))
1142 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1144 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1147 if (i
< NumMimeTypes
)
1148 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1151 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1153 mime_filter_t
*filter
; /* Current filter */
1156 for (type
= mimeFirstType(MimeDatabase
);
1158 type
= mimeNextType(MimeDatabase
))
1159 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1160 type
->super
, type
->type
);
1162 for (filter
= mimeFirstFilter(MimeDatabase
);
1164 filter
= mimeNextFilter(MimeDatabase
))
1165 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1166 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1167 filter
->src
->super
, filter
->src
->type
,
1168 filter
->dst
->super
, filter
->dst
->type
,
1169 filter
->cost
, filter
->filter
);
1176 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1177 cupsdLoadBanners(temp
);
1180 * Load printers and classes...
1183 cupsdLoadAllPrinters();
1184 cupsdLoadAllClasses();
1185 cupsdLoadRemoteCache();
1186 cupsdWritePrintcap();
1188 cupsdCreateCommonData();
1191 * Load queued jobs...
1197 * Load subscriptions...
1200 cupsdLoadAllSubscriptions();
1202 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1207 * Not a full reload, so recreate the common printer attributes...
1210 cupsdCreateCommonData();
1213 * Update all printers as needed...
1216 cupsdUpdatePrinters();
1217 cupsdWritePrintcap();
1219 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1223 * Reset the reload state...
1226 NeedReload
= RELOAD_NONE
;
1228 cupsdClearString(&old_serverroot
);
1229 cupsdClearString(&old_requestroot
);
1236 * 'get_address()' - Get an address + port number from a line.
1239 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1240 get_address(const char *value
, /* I - Value string */
1241 int defport
) /* I - Default port */
1243 char buffer
[1024], /* Hostname + port number buffer */
1244 defpname
[255], /* Default port name */
1245 *hostname
, /* Hostname or IP */
1246 *portname
; /* Port number or name */
1247 http_addrlist_t
*addrlist
; /* Address list */
1251 * Check for an empty value...
1256 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1261 * Grab a hostname and port number; if there is no colon and the port name
1262 * is only digits, then we have a port number by itself...
1265 strlcpy(buffer
, value
, sizeof(buffer
));
1267 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1274 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1279 * Use the default port...
1282 sprintf(defpname
, "%d", defport
);
1283 portname
= defpname
;
1289 * The buffer contains just a port number...
1297 if (hostname
&& !strcmp(hostname
, "*"))
1301 * Now lookup the address using httpAddrGetList()...
1304 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1305 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1306 hostname
? hostname
: "(nil)");
1313 * 'get_addr_and_mask()' - Get an IP address and netmask.
1316 static int /* O - 1 on success, 0 on failure */
1317 get_addr_and_mask(const char *value
, /* I - String from config file */
1318 unsigned *ip
, /* O - Address value */
1319 unsigned *mask
) /* O - Mask value */
1321 int i
, j
, /* Looping vars */
1322 family
, /* Address family */
1323 ipcount
; /* Count of fields in address */
1324 unsigned ipval
; /* Value */
1325 const char *maskval
, /* Pointer to start of mask value */
1326 *ptr
, /* Pointer into value */
1331 * Get the address...
1334 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1335 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1337 if ((maskval
= strchr(value
, '/')) != NULL
)
1340 maskval
= value
+ strlen(value
);
1344 * Check for an IPv6 address...
1350 * Parse hexadecimal IPv6 address...
1355 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1359 else if (!strncmp(ptr
, "::", 2))
1361 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1363 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1368 else if (isxdigit(*ptr
& 255))
1370 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1378 ip
[i
/ 2] |= ipval
<< 16;
1392 if (*ptr
&& *ptr
!= '/')
1396 #endif /* AF_INET6 */
1399 * Parse dotted-decimal IPv4 address...
1402 unsigned val
[4]; /* IPv4 address values */
1406 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1409 * Range check the IP numbers...
1412 for (i
= 0; i
< ipcount
; i
++)
1417 * Make sure the trailing values are zeroed, as some C libraries like
1418 * glibc apparently like to fill the unused arguments with garbage...
1421 for (i
= ipcount
; i
< 4; i
++)
1425 * Merge everything into a 32-bit IPv4 address in ip[3]...
1428 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1431 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1437 * Get the netmask value(s)...
1440 memset(mask
, 0, sizeof(unsigned) * 4);
1442 if (strchr(maskval
, '.'))
1445 * Get dotted-decimal mask...
1448 if (family
!= AF_INET
)
1451 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1454 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1455 mask
[0] = mask
[1] = mask
[2] = 0;
1460 * Get address/bits format...
1466 if (family
== AF_INET6
)
1474 mask
[0] = 0xffffffff;
1476 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1479 mask
[1] = 0xffffffff;
1483 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1486 mask
[2] = 0xffffffff;
1490 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1493 mask
[3] = 0xffffffff;
1497 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1500 #endif /* AF_INET6 */
1505 mask
[0] = 0xffffffff;
1506 mask
[1] = 0xffffffff;
1507 mask
[2] = 0xffffffff;
1510 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1512 mask
[3] = 0xffffffff;
1517 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1518 "get_addr_and_mask(value=\"%s\", "
1519 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1520 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1524 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1527 if ((ip
[0] & ~mask
[0]) != 0 ||
1528 (ip
[1] & ~mask
[1]) != 0 ||
1529 (ip
[2] & ~mask
[2]) != 0 ||
1530 (ip
[3] & ~mask
[3]) != 0)
1538 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1541 static int /* O - 1 on success, 0 on failure */
1542 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1543 char *line
, /* I - Line from file */
1544 char *value
, /* I - Start of value data */
1545 int linenum
) /* I - Current line number */
1547 char *valptr
; /* Pointer into value */
1548 unsigned ip
[4], /* IP address components */
1549 mask
[4]; /* IP netmask components */
1552 if (!strcasecmp(line
, "Encryption"))
1555 * "Encryption xxx" - set required encryption level...
1558 if (!strcasecmp(value
, "never"))
1559 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1560 else if (!strcasecmp(value
, "always"))
1562 cupsdLogMessage(CUPSD_LOG_ERROR
,
1563 "Encryption value \"%s\" on line %d is invalid in this "
1564 "context. Using \"required\" instead.", value
, linenum
);
1566 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1568 else if (!strcasecmp(value
, "required"))
1569 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1570 else if (!strcasecmp(value
, "ifrequested"))
1571 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1574 cupsdLogMessage(CUPSD_LOG_ERROR
,
1575 "Unknown Encryption value %s on line %d.", value
, linenum
);
1579 else if (!strcasecmp(line
, "Order"))
1582 * "Order Deny,Allow" or "Order Allow,Deny"...
1585 if (!strncasecmp(value
, "deny", 4))
1586 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1587 else if (!strncasecmp(value
, "allow", 5))
1588 loc
->order_type
= CUPSD_AUTH_DENY
;
1591 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1596 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1599 * Allow [From] host/ip...
1600 * Deny [From] host/ip...
1603 if (!strncasecmp(value
, "from", 4))
1606 * Strip leading "from"...
1611 while (isspace(*value
& 255))
1616 * Figure out what form the allow/deny address takes:
1627 * nnn.nnn.nnn.nnn/mm
1628 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1631 if (!strcasecmp(value
, "all"))
1637 if (!strcasecmp(line
, "Allow"))
1638 cupsdAllowIP(loc
, zeros
, zeros
);
1640 cupsdDenyIP(loc
, zeros
, zeros
);
1642 else if (!strcasecmp(value
, "none"))
1648 if (!strcasecmp(line
, "Allow"))
1649 cupsdAllowIP(loc
, ones
, zeros
);
1651 cupsdDenyIP(loc
, ones
, zeros
);
1654 else if (value
[0] == '*' || value
[0] == '.' ||
1655 (!isdigit(value
[0] & 255) && value
[0] != '['))
1657 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1658 #endif /* AF_INET6 */
1661 * Host or domain name...
1664 if (value
[0] == '*')
1667 if (!strcasecmp(line
, "Allow"))
1668 cupsdAllowHost(loc
, value
);
1670 cupsdDenyHost(loc
, value
);
1675 * One of many IP address forms...
1678 if (!get_addr_and_mask(value
, ip
, mask
))
1680 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1685 if (!strcasecmp(line
, "Allow"))
1686 cupsdAllowIP(loc
, ip
, mask
);
1688 cupsdDenyIP(loc
, ip
, mask
);
1691 else if (!strcasecmp(line
, "AuthType"))
1694 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1697 if (!strcasecmp(value
, "none"))
1699 loc
->type
= CUPSD_AUTH_NONE
;
1700 loc
->level
= CUPSD_AUTH_ANON
;
1702 else if (!strcasecmp(value
, "basic"))
1704 loc
->type
= CUPSD_AUTH_BASIC
;
1706 if (loc
->level
== CUPSD_AUTH_ANON
)
1707 loc
->level
= CUPSD_AUTH_USER
;
1709 else if (!strcasecmp(value
, "digest"))
1711 loc
->type
= CUPSD_AUTH_DIGEST
;
1713 if (loc
->level
== CUPSD_AUTH_ANON
)
1714 loc
->level
= CUPSD_AUTH_USER
;
1716 else if (!strcasecmp(value
, "basicdigest"))
1718 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1720 if (loc
->level
== CUPSD_AUTH_ANON
)
1721 loc
->level
= CUPSD_AUTH_USER
;
1723 else if (!strcasecmp(value
, "default"))
1725 loc
->type
= CUPSD_AUTH_DEFAULT
;
1727 if (loc
->level
== CUPSD_AUTH_ANON
)
1728 loc
->level
= CUPSD_AUTH_USER
;
1731 else if (!strcasecmp(value
, "negotiate"))
1733 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1735 if (loc
->level
== CUPSD_AUTH_ANON
)
1736 loc
->level
= CUPSD_AUTH_USER
;
1738 #endif /* HAVE_GSSAPI */
1741 cupsdLogMessage(CUPSD_LOG_WARN
,
1742 "Unknown authorization type %s on line %d.",
1747 else if (!strcasecmp(line
, "AuthClass"))
1750 * AuthClass anonymous, user, system, group
1753 if (!strcasecmp(value
, "anonymous"))
1755 loc
->type
= CUPSD_AUTH_NONE
;
1756 loc
->level
= CUPSD_AUTH_ANON
;
1758 cupsdLogMessage(CUPSD_LOG_WARN
,
1759 "\"AuthClass %s\" is deprecated; consider removing "
1763 else if (!strcasecmp(value
, "user"))
1765 loc
->level
= CUPSD_AUTH_USER
;
1767 cupsdLogMessage(CUPSD_LOG_WARN
,
1768 "\"AuthClass %s\" is deprecated; consider using "
1769 "\"Require valid-user\" on line %d.",
1772 else if (!strcasecmp(value
, "group"))
1774 loc
->level
= CUPSD_AUTH_GROUP
;
1776 cupsdLogMessage(CUPSD_LOG_WARN
,
1777 "\"AuthClass %s\" is deprecated; consider using "
1778 "\"Require user @groupname\" on line %d.",
1781 else if (!strcasecmp(value
, "system"))
1783 loc
->level
= CUPSD_AUTH_GROUP
;
1785 cupsdAddName(loc
, "@SYSTEM");
1787 cupsdLogMessage(CUPSD_LOG_WARN
,
1788 "\"AuthClass %s\" is deprecated; consider using "
1789 "\"Require user @SYSTEM\" on line %d.",
1794 cupsdLogMessage(CUPSD_LOG_WARN
,
1795 "Unknown authorization class %s on line %d.",
1800 else if (!strcasecmp(line
, "AuthGroupName"))
1802 cupsdAddName(loc
, value
);
1804 cupsdLogMessage(CUPSD_LOG_WARN
,
1805 "\"AuthGroupName %s\" directive is deprecated; consider "
1806 "using \"Require user @%s\" on line %d.",
1807 value
, value
, linenum
);
1809 else if (!strcasecmp(line
, "Require"))
1812 * Apache synonym for AuthClass and AuthGroupName...
1816 * Require valid-user
1817 * Require group names
1818 * Require user names
1821 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1826 if (!strcasecmp(value
, "valid-user") ||
1827 !strcasecmp(value
, "user"))
1828 loc
->level
= CUPSD_AUTH_USER
;
1829 else if (!strcasecmp(value
, "group"))
1830 loc
->level
= CUPSD_AUTH_GROUP
;
1833 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1839 * Get the list of names from the line...
1842 for (value
= valptr
; *value
;)
1844 while (isspace(*value
& 255))
1847 #ifdef HAVE_AUTHORIZATION_H
1848 if (!strncmp(value
, "@AUTHKEY(", 9))
1851 * Grab "@AUTHKEY(name)" value...
1854 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1860 #endif /* HAVE_AUTHORIZATION_H */
1861 if (*value
== '\"' || *value
== '\'')
1864 * Grab quoted name...
1867 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1874 * Grab literal name.
1877 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1883 cupsdAddName(loc
, value
);
1885 for (value
= valptr
; isspace(*value
& 255); value
++);
1888 else if (!strcasecmp(line
, "Satisfy"))
1890 if (!strcasecmp(value
, "all"))
1891 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
1892 else if (!strcasecmp(value
, "any"))
1893 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
1896 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1909 * 'parse_groups()' - Parse system group names in a string.
1912 static int /* O - 1 on success, 0 on failure */
1913 parse_groups(const char *s
) /* I - Space-delimited groups */
1915 int status
; /* Return status */
1916 char value
[1024], /* Value string */
1917 *valstart
, /* Pointer into value */
1918 *valend
, /* End of value */
1919 quote
; /* Quote character */
1920 struct group
*group
; /* Group */
1924 * Make a copy of the string and parse out the groups...
1927 strlcpy(value
, s
, sizeof(value
));
1932 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1934 if (*valstart
== '\'' || *valstart
== '\"')
1937 * Scan quoted name...
1940 quote
= *valstart
++;
1942 for (valend
= valstart
; *valend
; valend
++)
1943 if (*valend
== quote
)
1949 * Scan space or comma-delimited name...
1952 for (valend
= valstart
; *valend
; valend
++)
1953 if (isspace(*valend
) || *valend
== ',')
1960 group
= getgrnam(valstart
);
1963 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1964 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1975 while (*valstart
== ',' || isspace(*valstart
))
1984 * 'parse_protocols()' - Parse browse protocols in a string.
1987 static int /* O - Browse protocol bits */
1988 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1990 int protocols
; /* Browse protocol bits */
1991 char value
[1024], /* Value string */
1992 *valstart
, /* Pointer into value */
1993 *valend
; /* End of value */
1997 * Empty protocol line yields NULL pointer...
2004 * Loop through the value string,...
2007 strlcpy(value
, s
, sizeof(value
));
2011 for (valstart
= value
; *valstart
;)
2014 * Get the current space/comma-delimited protocol name...
2017 for (valend
= valstart
; *valend
; valend
++)
2018 if (isspace(*valend
& 255) || *valend
== ',')
2025 * Add the protocol to the bitmask...
2028 if (!strcasecmp(valstart
, "cups"))
2029 protocols
|= BROWSE_CUPS
;
2030 else if (!strcasecmp(valstart
, "slp"))
2031 protocols
|= BROWSE_SLP
;
2032 else if (!strcasecmp(valstart
, "ldap"))
2033 protocols
|= BROWSE_LDAP
;
2034 else if (!strcasecmp(valstart
, "dnssd") ||
2035 !strcasecmp(valstart
, "dns-sd") ||
2036 !strcasecmp(valstart
, "bonjour"))
2037 protocols
|= BROWSE_DNSSD
;
2038 else if (!strcasecmp(valstart
, "lpd"))
2039 protocols
|= BROWSE_LPD
;
2040 else if (!strcasecmp(valstart
, "smb"))
2041 protocols
|= BROWSE_SMB
;
2042 else if (!strcasecmp(valstart
, "all"))
2043 protocols
|= BROWSE_ALL
;
2044 else if (strcasecmp(valstart
, "none"))
2045 cupsdLogMessage(CUPSD_LOG_ERROR
,
2046 "Unknown browse protocol \"%s\" ignored!", valstart
);
2048 for (valstart
= valend
; *valstart
; valstart
++)
2049 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2058 * 'read_configuration()' - Read a configuration file.
2061 static int /* O - 1 on success, 0 on failure */
2062 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2064 int i
; /* Looping var */
2065 int linenum
; /* Current line number */
2066 char line
[HTTP_MAX_BUFFER
],
2067 /* Line from file */
2068 temp
[HTTP_MAX_BUFFER
],
2069 /* Temporary buffer for value */
2070 temp2
[HTTP_MAX_BUFFER
],
2071 /* Temporary buffer 2 for value */
2072 *ptr
, /* Pointer into line/temp */
2073 *value
, /* Pointer to value */
2074 *valueptr
; /* Pointer into value */
2075 int valuelen
; /* Length of value */
2076 cupsd_var_t
const *var
; /* Current variable */
2077 http_addrlist_t
*addrlist
, /* Address list */
2078 *addr
; /* Current address */
2079 unsigned ip
[4], /* Address value */
2080 mask
[4]; /* Netmask value */
2081 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2082 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2083 cupsd_location_t
*location
; /* Browse location */
2084 cups_file_t
*incfile
; /* Include file */
2085 char incname
[1024]; /* Include filename */
2086 struct group
*group
; /* Group */
2090 * Loop through each line in the file...
2095 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2098 * Decode the directive...
2101 if (!strcasecmp(line
, "Include"))
2107 if (value
[0] == '/')
2108 strlcpy(incname
, value
, sizeof(incname
));
2110 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2112 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2113 cupsdLogMessage(CUPSD_LOG_ERROR
,
2114 "Unable to include config file \"%s\" - %s",
2115 incname
, strerror(errno
));
2118 read_configuration(incfile
);
2119 cupsFileClose(incfile
);
2122 else if (!strcasecmp(line
, "<Location"))
2130 linenum
= read_location(fp
, value
, linenum
);
2136 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2141 else if (!strcasecmp(line
, "<Policy"))
2149 linenum
= read_policy(fp
, value
, linenum
);
2155 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2159 else if (!strcasecmp(line
, "FaxRetryInterval"))
2163 JobRetryInterval
= atoi(value
);
2164 cupsdLogMessage(CUPSD_LOG_WARN
,
2165 "FaxRetryInterval is deprecated; use "
2166 "JobRetryInterval on line %d.", linenum
);
2170 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2174 else if (!strcasecmp(line
, "FaxRetryLimit"))
2178 JobRetryLimit
= atoi(value
);
2179 cupsdLogMessage(CUPSD_LOG_WARN
,
2180 "FaxRetryLimit is deprecated; use "
2181 "JobRetryLimit on line %d.", linenum
);
2185 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2189 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2191 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2192 #endif /* HAVE_SSL */
2196 * Add listening address(es) to the list...
2199 cupsd_listener_t
*lis
; /* New listeners array */
2203 * Get the address list...
2206 addrlist
= get_address(value
, IPP_PORT
);
2210 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2216 * Add each address...
2219 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2222 * Allocate another listener...
2226 Listeners
= cupsArrayNew(NULL
, NULL
);
2230 cupsdLogMessage(CUPSD_LOG_ERROR
,
2231 "Unable to allocate %s at line %d - %s.",
2232 line
, linenum
, strerror(errno
));
2236 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2238 cupsdLogMessage(CUPSD_LOG_ERROR
,
2239 "Unable to allocate %s at line %d - %s.",
2240 line
, linenum
, strerror(errno
));
2244 cupsArrayAdd(Listeners
, lis
);
2247 * Copy the current address and log it...
2250 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2254 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2255 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2256 #endif /* HAVE_SSL */
2258 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2261 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2262 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2263 ntohs(lis
->address
.ipv6
.sin6_port
));
2265 #endif /* AF_INET6 */
2267 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2268 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2270 #endif /* AF_LOCAL */
2271 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2272 ntohs(lis
->address
.ipv4
.sin_port
));
2279 httpAddrFreeList(addrlist
);
2281 else if (!strcasecmp(line
, "BrowseAddress"))
2284 * Add a browse address to the list...
2287 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2290 if (NumBrowsers
== 0)
2291 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2293 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2297 cupsdLogMessage(CUPSD_LOG_ERROR
,
2298 "Unable to allocate BrowseAddress at line %d - %s.",
2299 linenum
, strerror(errno
));
2304 dira
+= NumBrowsers
;
2306 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2308 if (!strcasecmp(value
, "@LOCAL"))
2311 * Send browse data to all local interfaces...
2314 strcpy(dira
->iface
, "*");
2317 else if (!strncasecmp(value
, "@IF(", 4))
2320 * Send browse data to the named interface...
2323 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2325 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2331 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2334 * Only IPv4 addresses are supported...
2337 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2338 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2343 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2344 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2346 cupsdLogMessage(CUPSD_LOG_INFO
,
2347 "Sending browsing info to %s:%d (IPv4)",
2348 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2353 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2356 httpAddrFreeList(addrlist
);
2359 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2362 else if (!strcasecmp(line
, "BrowseOrder"))
2365 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2368 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2369 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2371 if (location
== NULL
)
2372 cupsdLogMessage(CUPSD_LOG_ERROR
,
2373 "Unable to initialize browse access control list!");
2374 else if (!strncasecmp(value
, "deny", 4))
2375 location
->order_type
= CUPSD_AUTH_ALLOW
;
2376 else if (!strncasecmp(value
, "allow", 5))
2377 location
->order_type
= CUPSD_AUTH_DENY
;
2379 cupsdLogMessage(CUPSD_LOG_ERROR
,
2380 "Unknown BrowseOrder value %s on line %d.",
2383 else if (!strcasecmp(line
, "BrowseProtocols") ||
2384 !strcasecmp(line
, "BrowseLocalProtocols") ||
2385 !strcasecmp(line
, "BrowseRemoteProtocols"))
2388 * "BrowseProtocols name [... name]"
2389 * "BrowseLocalProtocols name [... name]"
2390 * "BrowseRemoteProtocols name [... name]"
2393 int protocols
= parse_protocols(value
);
2397 cupsdLogMessage(CUPSD_LOG_ERROR
,
2398 "Unknown browse protocol \"%s\" on line %d.",
2403 if (strcasecmp(line
, "BrowseLocalProtocols"))
2404 BrowseRemoteProtocols
= protocols
;
2405 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2406 BrowseLocalProtocols
= protocols
;
2408 else if (!strcasecmp(line
, "BrowseAllow") ||
2409 !strcasecmp(line
, "BrowseDeny"))
2412 * BrowseAllow [From] host/ip...
2413 * BrowseDeny [From] host/ip...
2416 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2417 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2419 if (location
== NULL
)
2420 cupsdLogMessage(CUPSD_LOG_ERROR
,
2421 "Unable to initialize browse access control list!");
2424 if (!strncasecmp(value
, "from ", 5))
2427 * Strip leading "from"...
2432 while (isspace(*value
))
2437 * Figure out what form the allow/deny address takes:
2448 * nnn.nnn.nnn.nnn/mm
2449 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2452 if (!strcasecmp(value
, "all"))
2458 if (!strcasecmp(line
, "BrowseAllow"))
2459 cupsdAllowIP(location
, zeros
, zeros
);
2461 cupsdDenyIP(location
, zeros
, zeros
);
2463 else if (!strcasecmp(value
, "none"))
2469 if (!strcasecmp(line
, "BrowseAllow"))
2470 cupsdAllowIP(location
, ones
, zeros
);
2472 cupsdDenyIP(location
, ones
, zeros
);
2475 else if (value
[0] == '*' || value
[0] == '.' ||
2476 (!isdigit(value
[0] & 255) && value
[0] != '['))
2478 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2479 #endif /* AF_INET6 */
2482 * Host or domain name...
2485 if (value
[0] == '*')
2488 if (!strcasecmp(line
, "BrowseAllow"))
2489 cupsdAllowHost(location
, value
);
2491 cupsdDenyHost(location
, value
);
2496 * One of many IP address forms...
2499 if (!get_addr_and_mask(value
, ip
, mask
))
2501 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2506 if (!strcasecmp(line
, "BrowseAllow"))
2507 cupsdAllowIP(location
, ip
, mask
);
2509 cupsdDenyIP(location
, ip
, mask
);
2513 else if (!strcasecmp(line
, "BrowseRelay"))
2516 * BrowseRelay [from] source [to] destination
2520 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2522 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2526 cupsdLogMessage(CUPSD_LOG_ERROR
,
2527 "Unable to allocate BrowseRelay at line %d - %s.",
2528 linenum
, strerror(errno
));
2535 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2537 if (!strncasecmp(value
, "from ", 5))
2540 * Strip leading "from"...
2545 while (isspace(*value
))
2550 * Figure out what form the from address takes:
2559 * nnn.nnn.nnn.nnn/mm
2560 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2564 if (value
[0] == '*' || value
[0] == '.' ||
2565 (!isdigit(value
[0] & 255) && value
[0] != '['))
2567 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2568 #endif /* AF_INET6 */
2571 * Host or domain name...
2574 if (value
[0] == '*')
2577 strlcpy(temp
, value
, sizeof(temp
));
2578 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2581 relay
->from
.type
= CUPSD_AUTH_NAME
;
2583 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2585 cupsdLogMessage(CUPSD_LOG_ERROR
,
2586 "Unable to allocate BrowseRelay name at line %d - %s.",
2587 linenum
, strerror(errno
));
2591 relay
->from
.mask
.name
.length
= strlen(temp
);
2596 * One of many IP address forms...
2599 if (!get_addr_and_mask(value
, ip
, mask
))
2601 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2606 relay
->from
.type
= CUPSD_AUTH_IP
;
2607 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2608 sizeof(relay
->from
.mask
.ip
.address
));
2609 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2610 sizeof(relay
->from
.mask
.ip
.netmask
));
2614 * Skip value and trailing whitespace...
2617 for (; *value
; value
++)
2618 if (isspace(*value
))
2621 while (isspace(*value
))
2624 if (!strncasecmp(value
, "to ", 3))
2627 * Strip leading "to"...
2632 while (isspace(*value
))
2637 * Get "to" address and port...
2640 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2643 * Only IPv4 addresses are supported...
2646 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2647 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2652 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2654 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2656 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2657 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2658 relay
->from
.mask
.ip
.address
[0] >> 24,
2659 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2660 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2661 relay
->from
.mask
.ip
.address
[0] & 255,
2662 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2663 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2664 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2665 relay
->from
.mask
.ip
.netmask
[0] & 255);
2667 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2669 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2670 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2675 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2678 httpAddrFreeList(addrlist
);
2682 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2683 free(relay
->from
.mask
.name
.name
);
2685 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2689 else if (!strcasecmp(line
, "BrowsePoll"))
2692 * BrowsePoll address[:port]
2695 char *portname
; /* Port name */
2696 int portnum
; /* Port number */
2697 struct servent
*service
; /* Service */
2701 * Extract the port name from the address...
2704 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2708 if (isdigit(*portname
& 255))
2709 portnum
= atoi(portname
);
2710 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2711 portnum
= ntohs(service
->s_port
);
2714 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2720 portnum
= ippPort();
2723 * Add the poll entry...
2727 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2729 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2733 cupsdLogMessage(CUPSD_LOG_ERROR
,
2734 "Unable to allocate BrowsePoll at line %d - %s.",
2735 linenum
, strerror(errno
));
2743 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2745 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2746 pollp
->port
= portnum
;
2748 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2751 else if (!strcasecmp(line
, "DefaultAuthType"))
2754 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2757 if (!strcasecmp(value
, "none"))
2758 DefaultAuthType
= CUPSD_AUTH_NONE
;
2759 else if (!strcasecmp(value
, "basic"))
2760 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2761 else if (!strcasecmp(value
, "digest"))
2762 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2763 else if (!strcasecmp(value
, "basicdigest"))
2764 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2766 else if (!strcasecmp(value
, "negotiate"))
2767 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2768 #endif /* HAVE_GSSAPI */
2771 cupsdLogMessage(CUPSD_LOG_WARN
,
2772 "Unknown default authorization type %s on line %d.",
2778 else if (!strcasecmp(line
, "DefaultEncryption"))
2781 * DefaultEncryption {Never,IfRequested,Required}
2784 if (!value
|| !strcasecmp(value
, "never"))
2785 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2786 else if (!strcasecmp(value
, "required"))
2787 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2788 else if (!strcasecmp(value
, "ifrequested"))
2789 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2792 cupsdLogMessage(CUPSD_LOG_WARN
,
2793 "Unknown default encryption %s on line %d.",
2798 #endif /* HAVE_SSL */
2800 else if (!strcasecmp(line
, "Krb5Keytab"))
2802 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2805 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2806 gsskrb5_register_acceptor_identity(value
);
2808 cupsdSetEnv("KRB5_KTNAME", value
);
2809 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2811 #endif /* HAVE_GSSAPI */
2812 else if (!strcasecmp(line
, "User"))
2815 * User ID to run as...
2818 if (value
&& isdigit(value
[0] & 255))
2820 int uid
= atoi(value
);
2823 cupsdLogMessage(CUPSD_LOG_ERROR
,
2824 "Will not use User 0 as specified on line %d "
2825 "for security reasons. You must use a non-"
2826 "privileged account instead.",
2833 struct passwd
*p
; /* Password information */
2836 p
= getpwnam(value
);
2841 cupsdLogMessage(CUPSD_LOG_ERROR
,
2842 "Will not use User %s (UID=0) as specified on line "
2843 "%d for security reasons. You must use a non-"
2844 "privileged account instead.",
2850 cupsdLogMessage(CUPSD_LOG_ERROR
,
2851 "Unknown User \"%s\" on line %d, ignoring!",
2855 cupsdLogMessage(CUPSD_LOG_ERROR
,
2856 "User directive on line %d missing the username!",
2859 else if (!strcasecmp(line
, "Group"))
2862 * Group ID to run as...
2865 if (isdigit(value
[0]))
2866 Group
= atoi(value
);
2870 group
= getgrnam(value
);
2873 Group
= group
->gr_gid
;
2875 cupsdLogMessage(CUPSD_LOG_ERROR
,
2876 "Unknown Group \"%s\" on line %d, ignoring!",
2880 else if (!strcasecmp(line
, "SystemGroup"))
2883 * SystemGroup (admin) group(s)...
2886 if (!parse_groups(value
))
2887 cupsdLogMessage(CUPSD_LOG_ERROR
,
2888 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2891 else if (!strcasecmp(line
, "HostNameLookups"))
2894 * Do hostname lookups?
2897 if (!strcasecmp(value
, "off"))
2898 HostNameLookups
= 0;
2899 else if (!strcasecmp(value
, "on"))
2900 HostNameLookups
= 1;
2901 else if (!strcasecmp(value
, "double"))
2902 HostNameLookups
= 2;
2904 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2907 else if (!strcasecmp(line
, "LogLevel"))
2910 * Amount of logging to do...
2913 if (!strcasecmp(value
, "debug2"))
2914 LogLevel
= CUPSD_LOG_DEBUG2
;
2915 else if (!strcasecmp(value
, "debug"))
2916 LogLevel
= CUPSD_LOG_DEBUG
;
2917 else if (!strcasecmp(value
, "info"))
2918 LogLevel
= CUPSD_LOG_INFO
;
2919 else if (!strcasecmp(value
, "notice"))
2920 LogLevel
= CUPSD_LOG_NOTICE
;
2921 else if (!strcasecmp(value
, "warn"))
2922 LogLevel
= CUPSD_LOG_WARN
;
2923 else if (!strcasecmp(value
, "error"))
2924 LogLevel
= CUPSD_LOG_ERROR
;
2925 else if (!strcasecmp(value
, "crit"))
2926 LogLevel
= CUPSD_LOG_CRIT
;
2927 else if (!strcasecmp(value
, "alert"))
2928 LogLevel
= CUPSD_LOG_ALERT
;
2929 else if (!strcasecmp(value
, "emerg"))
2930 LogLevel
= CUPSD_LOG_EMERG
;
2931 else if (!strcasecmp(value
, "none"))
2932 LogLevel
= CUPSD_LOG_NONE
;
2934 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2937 else if (!strcasecmp(line
, "PrintcapFormat"))
2940 * Format of printcap file?
2943 if (!strcasecmp(value
, "bsd"))
2944 PrintcapFormat
= PRINTCAP_BSD
;
2945 else if (!strcasecmp(value
, "solaris"))
2946 PrintcapFormat
= PRINTCAP_SOLARIS
;
2948 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2951 else if (!strcasecmp(line
, "ServerTokens"))
2954 * Set the string used for the Server header...
2957 struct utsname plat
; /* Platform info */
2962 if (!strcasecmp(value
, "ProductOnly"))
2963 cupsdSetString(&ServerHeader
, "CUPS");
2964 else if (!strcasecmp(value
, "Major"))
2965 cupsdSetString(&ServerHeader
, "CUPS/1");
2966 else if (!strcasecmp(value
, "Minor"))
2967 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2968 else if (!strcasecmp(value
, "Minimal"))
2969 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2970 else if (!strcasecmp(value
, "OS"))
2971 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2972 else if (!strcasecmp(value
, "Full"))
2973 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2975 else if (!strcasecmp(value
, "None"))
2976 cupsdClearString(&ServerHeader
);
2978 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2981 else if (!strcasecmp(line
, "PassEnv"))
2984 * PassEnv variable [... variable]
2989 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2990 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2993 if (value
[valuelen
])
2995 value
[valuelen
] = '\0';
2999 cupsdSetEnv(value
, NULL
);
3001 for (value
+= valuelen
; *value
; value
++)
3002 if (!isspace(*value
) || *value
!= ',')
3006 else if (!strcasecmp(line
, "SetEnv"))
3009 * SetEnv variable value
3012 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3020 while (isspace(*valueptr
& 255))
3023 cupsdSetEnv(value
, valueptr
);
3026 cupsdLogMessage(CUPSD_LOG_ERROR
,
3027 "Missing value for SetEnv directive on line %d.",
3033 * Find a simple variable in the list...
3036 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3037 if (!strcasecmp(line
, var
->name
))
3043 * Unknown directive! Output an error message and continue...
3046 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3053 case CUPSD_VARTYPE_INTEGER
:
3055 cupsdLogMessage(CUPSD_LOG_ERROR
,
3056 "Missing integer value for %s on line %d!",
3061 char *units
; /* Units */
3064 n
= strtol(value
, &units
, 0);
3066 if (units
&& *units
)
3068 if (tolower(units
[0] & 255) == 'g')
3069 n
*= 1024 * 1024 * 1024;
3070 else if (tolower(units
[0] & 255) == 'm')
3072 else if (tolower(units
[0] & 255) == 'k')
3074 else if (tolower(units
[0] & 255) == 't')
3079 cupsdLogMessage(CUPSD_LOG_ERROR
,
3080 "Bad negative integer value for %s on line %d!",
3083 *((int *)var
->ptr
) = n
;
3087 case CUPSD_VARTYPE_BOOLEAN
:
3089 cupsdLogMessage(CUPSD_LOG_ERROR
,
3090 "Missing boolean value for %s on line %d!",
3092 else if (!strcasecmp(value
, "true") ||
3093 !strcasecmp(value
, "on") ||
3094 !strcasecmp(value
, "enabled") ||
3095 !strcasecmp(value
, "yes") ||
3097 *((int *)var
->ptr
) = TRUE
;
3098 else if (!strcasecmp(value
, "false") ||
3099 !strcasecmp(value
, "off") ||
3100 !strcasecmp(value
, "disabled") ||
3101 !strcasecmp(value
, "no") ||
3102 !strcasecmp(value
, "0"))
3103 *((int *)var
->ptr
) = FALSE
;
3105 cupsdLogMessage(CUPSD_LOG_ERROR
,
3106 "Unknown boolean value %s on line %d.",
3110 case CUPSD_VARTYPE_PATHNAME
:
3111 if (value
[0] == '/')
3112 strlcpy(temp
, value
, sizeof(temp
));
3114 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3116 if (access(temp
, 0))
3118 cupsdLogMessage(CUPSD_LOG_ERROR
,
3119 "File or directory for \"%s %s\" on line %d "
3120 "does not exist!", line
, value
, linenum
);
3124 case CUPSD_VARTYPE_STRING
:
3125 cupsdSetString((char **)var
->ptr
, value
);
3136 * 'read_location()' - Read a <Location path> definition.
3139 static int /* O - New line number or 0 on error */
3140 read_location(cups_file_t
*fp
, /* I - Configuration file */
3141 char *location
, /* I - Location name/path */
3142 int linenum
) /* I - Current line number */
3144 cupsd_location_t
*loc
, /* New location */
3145 *parent
; /* Parent location */
3146 char line
[HTTP_MAX_BUFFER
],
3148 *value
, /* Value for directive */
3149 *valptr
; /* Pointer into value */
3152 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3155 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3158 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3161 * Decode the directive...
3164 if (!strcasecmp(line
, "</Location>"))
3166 else if (!strcasecmp(line
, "<Limit") ||
3167 !strcasecmp(line
, "<LimitExcept"))
3171 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3175 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3181 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3186 if (!strcmp(value
, "ALL"))
3187 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3188 else if (!strcmp(value
, "GET"))
3189 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3190 else if (!strcmp(value
, "HEAD"))
3191 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3192 else if (!strcmp(value
, "OPTIONS"))
3193 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3194 else if (!strcmp(value
, "POST"))
3195 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3196 else if (!strcmp(value
, "PUT"))
3197 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3198 else if (!strcmp(value
, "TRACE"))
3199 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3201 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3204 for (value
= valptr
; isspace(*value
& 255); value
++);
3207 if (!strcasecmp(line
, "<LimitExcept"))
3208 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3210 parent
->limit
&= ~loc
->limit
;
3212 else if (!strcasecmp(line
, "</Limit>") ||
3213 !strcasecmp(line
, "</LimitExcept>"))
3215 else if (!parse_aaa(loc
, line
, value
, linenum
))
3217 cupsdLogMessage(CUPSD_LOG_ERROR
,
3218 "Unknown Location directive %s on line %d.",
3224 cupsdLogMessage(CUPSD_LOG_ERROR
,
3225 "Unexpected end-of-file at line %d while reading location!",
3233 * 'read_policy()' - Read a <Policy name> definition.
3236 static int /* O - New line number or 0 on error */
3237 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3238 char *policy
, /* I - Location name/path */
3239 int linenum
) /* I - Current line number */
3241 int i
; /* Looping var */
3242 cupsd_policy_t
*pol
; /* Policy */
3243 cupsd_location_t
*op
; /* Policy operation */
3244 int num_ops
; /* Number of IPP operations */
3245 ipp_op_t ops
[100]; /* Operations */
3246 char line
[HTTP_MAX_BUFFER
],
3248 *value
, /* Value for directive */
3249 *valptr
; /* Pointer into value */
3253 * Create the policy...
3256 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3260 * Read from the file...
3266 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3269 * Decode the directive...
3272 if (!strcasecmp(line
, "</Policy>"))
3275 cupsdLogMessage(CUPSD_LOG_WARN
,
3276 "Missing </Limit> before </Policy> on line %d!",
3280 * Verify that we have an explicit policy for CUPS-Get-Document
3281 * (ensures that upgrades do not introduce new security issues...)
3284 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3285 op
->op
== IPP_ANY_OPERATION
)
3287 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3288 op
->op
!= IPP_ANY_OPERATION
)
3291 * Add a new limit for CUPS-Get-Document using the Send-Document
3292 * limit as a template...
3295 cupsdLogMessage(CUPSD_LOG_WARN
,
3296 "No limit for CUPS-Get-Document defined in policy %s "
3297 "- using Send-Document's policy", pol
->name
);
3299 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3305 else if (!strcasecmp(line
, "<Limit") && !op
)
3309 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3314 * Scan for IPP operation names...
3321 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3326 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3328 if (!strcasecmp(value
, "All"))
3329 ops
[num_ops
] = IPP_ANY_OPERATION
;
3330 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3331 cupsdLogMessage(CUPSD_LOG_ERROR
,
3332 "Bad IPP operation name \"%s\" on line %d!",
3338 cupsdLogMessage(CUPSD_LOG_ERROR
,
3339 "Too many operations listed on line %d!",
3342 for (value
= valptr
; isspace(*value
& 255); value
++);
3346 * If none are specified, apply the policy to all operations...
3351 ops
[0] = IPP_ANY_OPERATION
;
3356 * Add a new policy for the first operation...
3359 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3361 else if (!strcasecmp(line
, "</Limit>") && op
)
3364 * Finish the current operation limit...
3370 * Copy the policy to the other operations...
3373 for (i
= 1; i
< num_ops
; i
++)
3374 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3381 cupsdLogMessage(CUPSD_LOG_ERROR
,
3382 "Missing <Limit ops> directive before %s on line %d.",
3386 else if (!parse_aaa(op
, line
, value
, linenum
))
3389 cupsdLogMessage(CUPSD_LOG_ERROR
,
3390 "Unknown Policy Limit directive %s on line %d.",
3393 cupsdLogMessage(CUPSD_LOG_ERROR
,
3394 "Unknown Policy directive %s on line %d.",
3401 cupsdLogMessage(CUPSD_LOG_ERROR
,
3402 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3410 * End of "$Id: conf.c 6930 2007-09-08 00:28:06Z mike $".