2 * "$Id: conf.c 5028 2006-01-31 01:16:43Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdReadConfiguration() - Read the cupsd.conf file.
27 * check_permissions() - Fix the mode and ownership of a file or
29 * get_address() - Get an address + port number from a line.
30 * get_addr_and_mask() - Get an IP address and netmask.
31 * parse_aaa() - Parse authentication, authorization, and
32 * access control lines.
33 * read_configuration() - Read a configuration file.
34 * read_location() - Read a <Location path> definition.
35 * read_policy() - Read a <Policy name> definition.
39 * Include necessary headers...
45 #include <sys/utsname.h>
50 #endif /* HAVE_VSYSLOG */
54 * Possibly missing network definitions...
58 # define INADDR_NONE 0xffffffff
59 #endif /* !INADDR_NONE */
63 * Configuration variable structure...
68 CUPSD_VARTYPE_INTEGER
, /* Integer option */
69 CUPSD_VARTYPE_STRING
, /* String option */
70 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
75 char *name
; /* Name of variable */
76 void *ptr
; /* Pointer to variable */
77 cupsd_vartype_t type
; /* Type (int, string, address) */
85 static cupsd_var_t variables
[] =
87 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
88 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
89 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
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 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
109 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
110 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
111 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
112 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
113 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
114 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
115 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
116 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
117 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
118 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
119 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
120 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
121 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
123 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
124 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
127 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
138 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
139 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
140 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
141 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
142 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
143 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
144 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
145 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
146 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
147 { "RunAsUser", &RunAsUser
, CUPSD_VARTYPE_BOOLEAN
},
148 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
149 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
150 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
152 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
153 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
154 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
155 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
156 #endif /* HAVE_SSL */
158 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
159 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
160 #endif /* HAVE_LAUNCHD */
161 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
162 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
163 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
164 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
165 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
166 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
168 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
171 static unsigned ones
[4] =
173 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
175 static unsigned zeros
[4] =
177 0x00000000, 0x00000000, 0x00000000, 0x00000000
184 static int check_permissions(const char *filename
,
185 const char *suffix
, int mode
,
186 int user
, int group
, int is_dir
,
188 static http_addrlist_t
*get_address(const char *value
, int defport
);
189 static int get_addr_and_mask(const char *value
, unsigned *ip
,
191 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
192 char *value
, int linenum
);
193 static int read_configuration(cups_file_t
*fp
);
194 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
195 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
199 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
202 int /* O - 1 on success, 0 otherwise */
203 cupsdReadConfiguration(void)
205 int i
; /* Looping var */
206 cups_file_t
*fp
; /* Configuration file */
207 int status
; /* Return status */
208 char temp
[1024], /* Temporary buffer */
209 *slash
; /* Directory separator */
210 cups_lang_t
*language
; /* Language */
211 struct passwd
*user
; /* Default user */
212 struct group
*group
; /* Default group */
213 char *old_serverroot
, /* Old ServerRoot */
214 *old_requestroot
; /* Old RequestRoot */
217 * Save the old root paths...
220 old_serverroot
= NULL
;
221 cupsdSetString(&old_serverroot
, ServerRoot
);
222 old_requestroot
= NULL
;
223 cupsdSetString(&old_requestroot
, RequestRoot
);
226 * Reset the server configuration data...
229 cupsdDeleteAllLocations();
247 for (i
= 0; i
< NumRelays
; i
++)
248 if (Relays
[i
].from
.type
== AUTH_NAME
)
249 free(Relays
[i
].from
.mask
.name
.name
);
256 if (NumListeners
> 0)
266 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
267 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
268 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
269 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
270 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
271 cupsdSetString(&DataDir
, CUPS_DATADIR
);
272 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
273 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
274 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
275 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
276 cupsdSetString(&Printcap
, "/etc/printcap");
277 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
278 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
279 cupsdSetString(&RemoteRoot
, "remroot");
280 cupsdSetString(&ServerHeader
, "CUPS/1.1");
281 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
283 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
284 if ((slash
= strrchr(temp
, '/')) != NULL
)
287 cupsdSetString(&ServerRoot
, temp
);
289 cupsdClearString(&Classification
);
290 ClassifyOverride
= 0;
294 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
296 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
297 cupsdSetString(&ServerKey
, "ssl/server.key");
298 # endif /* HAVE_CDSASSL */
299 #endif /* HAVE_SSL */
301 language
= cupsLangDefault();
303 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
304 cupsdSetString(&DefaultLanguage
, "en");
306 cupsdSetString(&DefaultLanguage
, language
->language
);
308 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
310 cupsdSetString(&RIPCache
, "8m");
312 if (getenv("TMPDIR") == NULL
)
313 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
315 cupsdSetString(&TempDir
, getenv("TMPDIR"));
318 * Find the default system group: "sys", "system", or "root"...
321 group
= getgrnam(CUPS_DEFAULT_GROUP
);
329 * Found the group, use it!
332 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
334 SystemGroupIDs
[0] = group
->gr_gid
;
339 * Find the group associated with GID 0...
346 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
348 cupsdSetString(&SystemGroups
[0], "unknown");
350 SystemGroupIDs
[0] = 0;
354 * Find the default user...
357 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
362 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
363 * complement number...)
372 * Find the default group (nobody)...
375 group
= getgrnam("nobody");
379 Group
= group
->gr_gid
;
383 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
384 * complement number...)
394 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
395 DefaultAuthType
= AUTH_BASIC
;
397 JobRetryInterval
= 300;
402 HostNameLookups
= FALSE
;
403 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
404 ImplicitAnyClasses
= FALSE
;
405 HideImplicitMembers
= TRUE
;
407 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
408 ListenBackLog
= SOMAXCONN
;
409 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
410 LogLevel
= CUPSD_LOG_ERROR
;
412 MaxClientsPerHost
= 0;
413 MaxLogSize
= 1024 * 1024;
414 MaxPrinterHistory
= 10;
417 RootCertDuration
= 300;
419 Timeout
= DEFAULT_TIMEOUT
;
421 BrowseInterval
= DEFAULT_INTERVAL
;
422 BrowsePort
= ippPort();
423 BrowseLocalProtocols
= BROWSE_CUPS
; /* TODO: Use configure option */
424 BrowseRemoteProtocols
= BROWSE_CUPS
; /* TODO: Use configure option */
425 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
426 BrowseTimeout
= DEFAULT_TIMEOUT
;
427 Browsing
= CUPS_DEFAULT_BROWSING
;
428 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
430 cupsdClearString(&BrowseLocalOptions
);
431 cupsdClearString(&BrowseRemoteOptions
);
433 JobHistory
= DEFAULT_HISTORY
;
434 JobFiles
= DEFAULT_FILES
;
439 MaxJobsPerPrinter
= 0;
442 cupsdDeleteAllPolicies();
443 cupsdClearString(&DefaultPolicy
);
445 MaxSubscriptions
= 100;
446 MaxSubscriptionsPerJob
= 0;
447 MaxSubscriptionsPerPrinter
= 0;
448 MaxSubscriptionsPerUser
= 0;
449 DefaultLeaseDuration
= 86400;
450 MaxLeaseDuration
= 0;
453 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
454 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
455 #endif /* HAVE_LAUNCHD */
458 * Read the configuration file...
461 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
464 status
= read_configuration(fp
);
477 * Use the default system group if none was supplied in cupsd.conf...
480 if (NumSystemGroups
== 0)
484 * Get the access control list for browsing...
487 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
490 * Open the system log for cupsd if necessary...
494 if (!strcmp(AccessLog
, "syslog") ||
495 !strcmp(ErrorLog
, "syslog") ||
496 !strcmp(PageLog
, "syslog"))
497 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
498 #endif /* HAVE_VSYSLOG */
501 * Log the configuration file that was used...
504 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
508 * Validate the Group and SystemGroup settings - they cannot be the same,
509 * otherwise the CGI programs will be able to authenticate as root without
515 for (i
= 0; i
< NumSystemGroups
; i
++)
516 if (Group
== SystemGroupIDs
[i
])
519 if (i
< NumSystemGroups
)
522 * Log the error and reset the group to a safe value...
525 cupsdLogMessage(CUPSD_LOG_NOTICE
,
526 "Group and SystemGroup cannot use the same groups!");
527 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
529 group
= getgrnam("nobody");
533 Group
= group
->gr_gid
;
537 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
538 * complement number...)
547 * Check that we have at least one listen/port line; if not, report this
548 * as an error and exit!
551 if (NumListeners
== 0)
557 cupsdLogMessage(CUPSD_LOG_EMERG
,
558 "No valid Listen or Port lines were found in the configuration file!");
564 cupsdEndProcess(getpid(), 0);
568 * Set the default locale using the language and charset...
571 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
574 * Update all relative filenames to include the full path from ServerRoot...
577 if (DocumentRoot
[0] != '/')
578 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
580 if (RequestRoot
[0] != '/')
581 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
583 if (ServerBin
[0] != '/')
584 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
586 if (StateDir
[0] != '/')
587 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
589 if (CacheDir
[0] != '/')
590 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
593 if (ServerCertificate
[0] != '/')
594 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
596 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
598 chown(ServerCertificate
, RunUser
, Group
);
599 chmod(ServerCertificate
, 0600);
602 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
603 if (ServerKey
[0] != '/')
604 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
606 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
608 chown(ServerKey
, RunUser
, Group
);
609 chmod(ServerKey
, 0600);
611 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
612 #endif /* HAVE_SSL */
615 * Make sure that directories and config files are owned and
616 * writable by the user and group in the cupsd.conf file...
619 check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1);
620 check_permissions(CacheDir
, "ppd", 0755, RunUser
, Group
, 1, 1);
622 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1);
623 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
624 SystemGroupIDs
[0], 1, 1);
626 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0);
627 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1);
628 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0);
629 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
, Group
,
631 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
, 0, 0);
632 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
, 0, 0);
633 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0);
636 * Make sure the request and temporary directories have the right
640 check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1);
642 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
646 * Update ownership and permissions if the CUPS temp directory
647 * is under the spool directory or does not exist...
650 check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1);
653 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
656 * Clean out the temporary directory...
659 cups_dir_t
*dir
; /* Temporary directory */
660 cups_dentry_t
*dent
; /* Directory entry */
661 char tempfile
[1024]; /* Temporary filename */
664 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
666 cupsdLogMessage(CUPSD_LOG_INFO
,
667 "Cleaning out old temporary files in \"%s\"...", TempDir
);
669 while ((dent
= cupsDirRead(dir
)) != NULL
)
671 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
673 if (unlink(tempfile
))
674 cupsdLogMessage(CUPSD_LOG_ERROR
,
675 "Unable to remove temporary file \"%s\" - %s",
676 tempfile
, strerror(errno
));
678 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
685 cupsdLogMessage(CUPSD_LOG_ERROR
,
686 "Unable to open temporary directory \"%s\" - %s",
687 TempDir
, strerror(errno
));
691 * Setup environment variables...
697 * Check the MaxClients setting, and then allocate memory for it...
700 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
703 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
706 MaxClients
= MaxFDs
/ 3;
709 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
711 cupsdLogMessage(CUPSD_LOG_ERROR
,
712 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
713 MaxClients
, strerror(errno
));
717 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
721 * Check the MaxActiveJobs setting; limit to 1/3 the available
722 * file descriptors, since we need a pipe for each job...
725 if (MaxActiveJobs
> (MaxFDs
/ 3))
726 MaxActiveJobs
= MaxFDs
/ 3;
728 if (Classification
&& strcasecmp(Classification
, "none") == 0)
729 cupsdClearString(&Classification
);
732 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
735 * Update the MaxClientsPerHost value, as needed...
738 if (MaxClientsPerHost
<= 0)
739 MaxClientsPerHost
= MaxClients
;
741 if (MaxClientsPerHost
> MaxClients
)
742 MaxClientsPerHost
= MaxClients
;
744 cupsdLogMessage(CUPSD_LOG_INFO
,
745 "Allowing up to %d client connections per host.",
749 * Update the default policy, as needed...
753 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
755 DefaultPolicyPtr
= NULL
;
757 if (!DefaultPolicyPtr
)
759 cupsd_policy_t
*p
; /* New policy */
760 cupsd_location_t
*po
; /* New policy operation */
764 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
767 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
768 cupsdLogMessage(CUPSD_LOG_INFO
,
769 "Using policy \"default\" as the default!");
772 cupsdLogMessage(CUPSD_LOG_INFO
,
773 "Creating CUPS default administrative policy:");
775 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
777 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
778 cupsdLogMessage(CUPSD_LOG_INFO
,
779 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
780 "Release-Job Restart-Job Purge-Jobs "
781 "Set-Job-Attributes Create-Job-Subscription "
782 "Renew-Subscription Cancel-Subscription "
783 "Get-Notifications Reprocess-Job Cancel-Current-Job "
784 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
785 "CUPS-Authenticate-Job>");
786 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
788 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
789 po
->order_type
= AUTH_ALLOW
;
790 po
->level
= AUTH_USER
;
792 cupsdAddName(po
, "@OWNER");
793 cupsdAddName(po
, "@SYSTEM");
794 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
796 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
797 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
798 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
799 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
800 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
801 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
802 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
803 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
804 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
805 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
806 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
807 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
808 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
809 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
810 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
811 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
812 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
814 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
816 cupsdLogMessage(CUPSD_LOG_INFO
,
817 "<Limit Pause-Printer Resume-Printer "
818 "Set-Printer-Attributes Enable-Printer "
819 "Disable-Printer Pause-Printer-After-Current-Job "
820 "Hold-New-Jobs Release-Held-New-Jobs "
821 "Deactivate-Printer Activate-Printer Restart-Printer "
822 "Shutdown-Printer Startup-Printer Promote-Job "
823 "Schedule-Job-After CUPS-Add-Printer "
824 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
825 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
826 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
827 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
829 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
830 po
->order_type
= AUTH_ALLOW
;
831 po
->type
= AUTH_BASIC
;
832 po
->level
= AUTH_USER
;
834 cupsdAddName(po
, "@SYSTEM");
835 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
837 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
838 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
839 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
840 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
841 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
842 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
843 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
844 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
845 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
846 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
847 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
848 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
849 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
850 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
851 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
852 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
853 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
854 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
855 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
856 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
857 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
859 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
861 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
862 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
864 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
865 po
->order_type
= AUTH_ALLOW
;
867 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
868 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
872 cupsdLogMessage(CUPSD_LOG_DEBUG
,"NumPolicies=%d", NumPolicies
);
873 for (i
= 0; i
< NumPolicies
; i
++)
874 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Policies[%d]=\"%s\"", i
,
878 * If we are doing a full reload or the server root has changed, flush
879 * the jobs, printers, etc. and start from scratch...
882 if (NeedReload
== RELOAD_ALL
||
883 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
884 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
886 mime_type_t
*type
; /* Current type */
887 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
891 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
897 cupsdDeleteAllSubscriptions();
899 cupsdDeleteAllClasses();
900 cupsdDeleteAllPrinters();
902 DefaultPrinter
= NULL
;
904 if (MimeDatabase
!= NULL
)
905 mimeDelete(MimeDatabase
);
909 for (i
= 0; i
< NumMimeTypes
; i
++)
910 free((void *)MimeTypes
[i
]);
916 * Read the MIME type and conversion database...
919 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
921 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
925 cupsdLogMessage(CUPSD_LOG_EMERG
,
926 "Unable to load MIME database from \'%s\'!", ServerRoot
);
930 cupsdLogMessage(CUPSD_LOG_INFO
,
931 "Loaded MIME database from \'%s\': %d types, %d filters...",
932 ServerRoot
, mimeNumTypes(MimeDatabase
),
933 mimeNumFilters(MimeDatabase
));
936 * Create a list of MIME types for the document-format-supported
940 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
941 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
944 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
946 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
948 i
++, type
= mimeNextType(MimeDatabase
))
950 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
952 MimeTypes
[i
] = strdup(mimetype
);
955 if (i
< NumMimeTypes
)
956 MimeTypes
[i
] = strdup("application/octet-stream");
962 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
963 cupsdLoadBanners(temp
);
966 * Load printers and classes...
969 cupsdLoadAllPrinters();
970 cupsdLoadAllClasses();
971 cupsdLoadRemoteCache();
972 cupsdWritePrintcap();
974 cupsdCreateCommonData();
977 * Load queued jobs...
983 * Load subscriptions...
986 cupsdLoadAllSubscriptions();
988 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
993 * Not a full reload, so recreate the common printer attributes...
996 cupsdCreateCommonData();
999 * Update all printers as needed...
1002 cupsdUpdatePrinters();
1003 cupsdWritePrintcap();
1005 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1009 * Reset the reload state...
1012 NeedReload
= RELOAD_NONE
;
1014 cupsdClearString(&old_serverroot
);
1015 cupsdClearString(&old_requestroot
);
1022 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1025 static int /* O - 0 on success, -1 on error */
1026 check_permissions(const char *filename
, /* I - File/directory name */
1027 const char *suffix
, /* I - Additional file/directory name */
1028 int mode
, /* I - Permissions */
1029 int user
, /* I - Owner */
1030 int group
, /* I - Group */
1031 int is_dir
, /* I - 1 = directory, 0 = file */
1032 int create_dir
)/* I - 1 = create directory, 0 = not */
1034 int dir_created
= 0; /* Did we create a directory? */
1035 char pathname
[1024]; /* File name with prefix */
1036 struct stat fileinfo
; /* Stat buffer */
1040 * Prepend the given root to the filename before testing it...
1045 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1046 filename
= pathname
;
1050 * See if we can stat the file/directory...
1053 if (stat(filename
, &fileinfo
))
1055 if (errno
== ENOENT
&& create_dir
)
1057 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1060 if (mkdir(filename
, mode
))
1062 cupsdLogMessage(CUPSD_LOG_ERROR
,
1063 "Unable to create directory \"%s\" - %s", filename
,
1075 * Make sure it's a regular file...
1078 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1080 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1084 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1086 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1091 * Fix owner, group, and mode as needed...
1094 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1096 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1098 if (chown(filename
, user
, group
))
1100 cupsdLogMessage(CUPSD_LOG_ERROR
,
1101 "Unable to change ownership of \"%s\" - %s", filename
,
1107 if (dir_created
|| (fileinfo
.st_mode
& 0777) != mode
)
1109 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1111 if (chmod(filename
, mode
))
1113 cupsdLogMessage(CUPSD_LOG_ERROR
,
1114 "Unable to change permissions of \"%s\" - %s", filename
,
1121 * Everything is OK...
1129 * 'get_address()' - Get an address + port number from a line.
1132 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1133 get_address(const char *value
, /* I - Value string */
1134 int defport
) /* I - Default port */
1136 char buffer
[1024], /* Hostname + port number buffer */
1137 defpname
[255], /* Default port name */
1138 *hostname
, /* Hostname or IP */
1139 *portname
; /* Port number or name */
1140 http_addrlist_t
*addrlist
; /* Address list */
1144 * Check for an empty value...
1149 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1154 * Grab a hostname and port number; if there is no colon and the port name
1155 * is only digits, then we have a port number by itself...
1158 strlcpy(buffer
, value
, sizeof(buffer
));
1160 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1167 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1172 * Use the default port...
1175 sprintf(defpname
, "%d", defport
);
1176 portname
= defpname
;
1182 * The buffer contains just a port number...
1190 if (hostname
&& !strcmp(hostname
, "*"))
1194 * Now lookup the address using httpAddrGetList()...
1197 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1198 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1199 hostname
? hostname
: "(nil)");
1206 * 'get_addr_and_mask()' - Get an IP address and netmask.
1209 static int /* O - 1 on success, 0 on failure */
1210 get_addr_and_mask(const char *value
, /* I - String from config file */
1211 unsigned *ip
, /* O - Address value */
1212 unsigned *mask
) /* O - Mask value */
1214 int i
, j
, /* Looping vars */
1215 family
, /* Address family */
1216 ipcount
; /* Count of fields in address */
1217 unsigned ipval
; /* Value */
1218 const char *maskval
, /* Pointer to start of mask value */
1219 *ptr
, /* Pointer into value */
1221 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1223 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1224 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1225 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1226 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1229 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1231 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1232 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1233 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1234 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1235 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1236 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1237 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1238 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1240 #endif /* AF_INET6 */
1244 * Get the address...
1247 memset(ip
, 0, sizeof(unsigned) * 4);
1249 if ((maskval
= strchr(value
, '/')) != NULL
)
1252 maskval
= value
+ strlen(value
);
1256 * Check for an IPv6 address...
1262 * Parse hexadecimal IPv6 address...
1267 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1271 else if (!strncmp(ptr
, "::", 2))
1273 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1275 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1279 else if (isxdigit(*ptr
& 255))
1281 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1289 ip
[i
] |= ipval
<< 16;
1300 if (*ptr
&& *ptr
!= '/')
1304 #endif /* AF_INET6 */
1307 * Parse dotted-decimal IPv4 address...
1311 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1313 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1314 ip
[0] = ip
[1] = ip
[2] = 0;
1320 * Get the netmask value(s)...
1323 memset(mask
, 0, sizeof(unsigned) * 4);
1326 if (*maskval
== '[')
1329 * Get hexadecimal mask value...
1332 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1336 else if (!strncmp(ptr
, "::", 2))
1338 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1340 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1344 else if (isxdigit(*ptr
& 255))
1346 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1354 mask
[i
] |= ipval
<< 16;
1367 #endif /* AF_INET6 */
1368 if (strchr(maskval
, '.'))
1371 * Get dotted-decimal mask...
1374 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1377 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1378 mask
[0] = mask
[1] = mask
[2] = 0;
1383 * Get address/bits format...
1389 if (family
== AF_INET6
)
1394 mask
[0] = 0xffffffff;
1396 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1399 mask
[1] = 0xffffffff;
1403 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1406 mask
[2] = 0xffffffff;
1410 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1413 mask
[3] = 0xffffffff;
1417 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1420 #endif /* AF_INET6 */
1424 mask
[0] = 0xffffffff;
1425 mask
[1] = 0xffffffff;
1426 mask
[2] = 0xffffffff;
1429 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1431 mask
[3] = 0xffffffff;
1436 else if (family
== AF_INET6
)
1437 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1438 #endif /* AF_INET6 */
1440 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1442 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1443 "get_addr_and_mask(value=\"%s\", "
1444 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1445 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1449 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1452 if ((ip
[0] & ~mask
[0]) != 0 ||
1453 (ip
[1] & ~mask
[1]) != 0 ||
1454 (ip
[2] & ~mask
[2]) != 0 ||
1455 (ip
[3] & ~mask
[3]) != 0)
1463 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1466 static int /* O - 1 on success, 0 on failure */
1467 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1468 char *line
, /* I - Line from file */
1469 char *value
, /* I - Start of value data */
1470 int linenum
) /* I - Current line number */
1472 char *valptr
; /* Pointer into value */
1473 unsigned ip
[4], /* IP address components */
1474 mask
[4]; /* IP netmask components */
1477 if (!strcasecmp(line
, "Encryption"))
1480 * "Encryption xxx" - set required encryption level...
1483 if (!strcasecmp(value
, "never"))
1484 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1485 else if (!strcasecmp(value
, "always"))
1487 cupsdLogMessage(CUPSD_LOG_ERROR
,
1488 "Encryption value \"%s\" on line %d is invalid in this "
1489 "context. Using \"required\" instead.", value
, linenum
);
1491 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1493 else if (!strcasecmp(value
, "required"))
1494 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1495 else if (!strcasecmp(value
, "ifrequested"))
1496 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1499 cupsdLogMessage(CUPSD_LOG_ERROR
,
1500 "Unknown Encryption value %s on line %d.", value
, linenum
);
1504 else if (!strcasecmp(line
, "Order"))
1507 * "Order Deny,Allow" or "Order Allow,Deny"...
1510 if (!strncasecmp(value
, "deny", 4))
1511 loc
->order_type
= AUTH_ALLOW
;
1512 else if (!strncasecmp(value
, "allow", 5))
1513 loc
->order_type
= AUTH_DENY
;
1516 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1521 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1524 * Allow [From] host/ip...
1525 * Deny [From] host/ip...
1528 if (!strncasecmp(value
, "from", 4))
1531 * Strip leading "from"...
1536 while (isspace(*value
& 255))
1541 * Figure out what form the allow/deny address takes:
1552 * nnn.nnn.nnn.nnn/mm
1553 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1556 if (!strcasecmp(value
, "all"))
1562 if (!strcasecmp(line
, "Allow"))
1563 cupsdAllowIP(loc
, zeros
, zeros
);
1565 cupsdDenyIP(loc
, zeros
, zeros
);
1567 else if (!strcasecmp(value
, "none"))
1573 if (!strcasecmp(line
, "Allow"))
1574 cupsdAllowIP(loc
, ones
, zeros
);
1576 cupsdDenyIP(loc
, ones
, zeros
);
1578 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1581 * Host or domain name...
1584 if (value
[0] == '*')
1587 if (!strcasecmp(line
, "Allow"))
1588 cupsdAllowHost(loc
, value
);
1590 cupsdDenyHost(loc
, value
);
1595 * One of many IP address forms...
1598 if (!get_addr_and_mask(value
, ip
, mask
))
1600 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1605 if (!strcasecmp(line
, "Allow"))
1606 cupsdAllowIP(loc
, ip
, mask
);
1608 cupsdDenyIP(loc
, ip
, mask
);
1611 else if (!strcasecmp(line
, "AuthType"))
1614 * AuthType {none,basic,digest,basicdigest}
1617 if (!strcasecmp(value
, "none"))
1619 loc
->type
= AUTH_NONE
;
1620 loc
->level
= AUTH_ANON
;
1622 else if (!strcasecmp(value
, "basic"))
1624 loc
->type
= AUTH_BASIC
;
1626 if (loc
->level
== AUTH_ANON
)
1627 loc
->level
= AUTH_USER
;
1629 else if (!strcasecmp(value
, "digest"))
1631 loc
->type
= AUTH_DIGEST
;
1633 if (loc
->level
== AUTH_ANON
)
1634 loc
->level
= AUTH_USER
;
1636 else if (!strcasecmp(value
, "basicdigest"))
1638 loc
->type
= AUTH_BASICDIGEST
;
1640 if (loc
->level
== AUTH_ANON
)
1641 loc
->level
= AUTH_USER
;
1645 cupsdLogMessage(CUPSD_LOG_WARN
,
1646 "Unknown authorization type %s on line %d.",
1651 else if (!strcasecmp(line
, "AuthClass"))
1654 * AuthClass anonymous, user, system, group
1657 if (!strcasecmp(value
, "anonymous"))
1659 loc
->type
= AUTH_NONE
;
1660 loc
->level
= AUTH_ANON
;
1662 cupsdLogMessage(CUPSD_LOG_WARN
,
1663 "\"AuthClass %s\" is deprecated; consider removing "
1667 else if (!strcasecmp(value
, "user"))
1669 loc
->level
= AUTH_USER
;
1671 cupsdLogMessage(CUPSD_LOG_WARN
,
1672 "\"AuthClass %s\" is deprecated; consider using "
1673 "\"Require valid-user\" on line %d.",
1676 else if (!strcasecmp(value
, "group"))
1678 loc
->level
= AUTH_GROUP
;
1680 cupsdLogMessage(CUPSD_LOG_WARN
,
1681 "\"AuthClass %s\" is deprecated; consider using "
1682 "\"Require @groupname\" on line %d.",
1685 else if (!strcasecmp(value
, "system"))
1687 loc
->level
= AUTH_GROUP
;
1689 cupsdAddName(loc
, "@SYSTEM");
1691 cupsdLogMessage(CUPSD_LOG_WARN
,
1692 "\"AuthClass %s\" is deprecated; consider using "
1693 "\"Require @SYSTEM\" on line %d.",
1698 cupsdLogMessage(CUPSD_LOG_WARN
,
1699 "Unknown authorization class %s on line %d.",
1704 else if (!strcasecmp(line
, "AuthGroupName"))
1706 cupsdAddName(loc
, value
);
1708 cupsdLogMessage(CUPSD_LOG_WARN
,
1709 "\"AuthGroupName %s\" directive is deprecated; consider "
1710 "using \"Require @%s\" on line %d.",
1711 value
, value
, linenum
);
1713 else if (!strcasecmp(line
, "Require"))
1716 * Apache synonym for AuthClass and AuthGroupName...
1720 * Require valid-user
1721 * Require group names
1722 * Require user names
1725 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1730 if (!strcasecmp(value
, "valid-user") ||
1731 !strcasecmp(value
, "user"))
1732 loc
->level
= AUTH_USER
;
1733 else if (!strcasecmp(value
, "group"))
1734 loc
->level
= AUTH_GROUP
;
1737 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1743 * Get the list of names from the line...
1746 for (value
= valptr
; *value
;)
1748 while (isspace(*value
& 255))
1751 if (*value
== '\"' || *value
== '\'')
1754 * Grab quoted name...
1757 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1764 * Grab literal name.
1767 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1773 cupsdAddName(loc
, value
);
1775 for (value
= valptr
; isspace(*value
& 255); value
++);
1778 else if (!strcasecmp(line
, "Satisfy"))
1780 if (!strcasecmp(value
, "all"))
1781 loc
->satisfy
= AUTH_SATISFY_ALL
;
1782 else if (!strcasecmp(value
, "any"))
1783 loc
->satisfy
= AUTH_SATISFY_ANY
;
1786 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1799 * 'read_configuration()' - Read a configuration file.
1802 static int /* O - 1 on success, 0 on failure */
1803 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1805 int i
; /* Looping var */
1806 int linenum
; /* Current line number */
1807 char line
[HTTP_MAX_BUFFER
],
1808 /* Line from file */
1809 temp
[HTTP_MAX_BUFFER
],
1810 /* Temporary buffer for value */
1811 temp2
[HTTP_MAX_BUFFER
],
1812 /* Temporary buffer 2 for value */
1813 *ptr
, /* Pointer into line/temp */
1814 *value
, /* Pointer to value */
1815 *valueptr
, /* Pointer into value */
1816 quote
; /* Quote character */
1817 int valuelen
; /* Length of value */
1818 cupsd_var_t
*var
; /* Current variable */
1819 http_addrlist_t
*addrlist
, /* Address list */
1820 *addr
; /* Current address */
1821 unsigned ip
[4], /* Address value */
1822 mask
[4]; /* Netmask value */
1823 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1824 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1825 cupsd_location_t
*location
; /* Browse location */
1826 cups_file_t
*incfile
; /* Include file */
1827 char incname
[1024]; /* Include filename */
1828 struct group
*group
; /* Group */
1832 * Loop through each line in the file...
1837 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1840 * Decode the directive...
1843 if (!strcasecmp(line
, "Include"))
1849 if (value
[0] == '/')
1850 strlcpy(incname
, value
, sizeof(incname
));
1852 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1854 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1855 cupsdLogMessage(CUPSD_LOG_ERROR
,
1856 "Unable to include config file \"%s\" - %s",
1857 incname
, strerror(errno
));
1860 read_configuration(incfile
);
1861 cupsFileClose(incfile
);
1864 else if (!strcasecmp(line
, "<Location"))
1872 linenum
= read_location(fp
, value
, linenum
);
1878 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1883 else if (!strcasecmp(line
, "<Policy"))
1891 linenum
= read_policy(fp
, value
, linenum
);
1897 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1901 else if (!strcasecmp(line
, "FaxRetryInterval"))
1905 JobRetryInterval
= atoi(value
);
1906 cupsdLogMessage(CUPSD_LOG_WARN
,
1907 "FaxRetryInterval is deprecated; use "
1908 "JobRetryInterval on line %d.", linenum
);
1912 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1916 else if (!strcasecmp(line
, "FaxRetryLimit"))
1920 JobRetryLimit
= atoi(value
);
1921 cupsdLogMessage(CUPSD_LOG_WARN
,
1922 "FaxRetryLimit is deprecated; use "
1923 "JobRetryLimit on line %d.", linenum
);
1927 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1931 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
1933 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
1934 #endif /* HAVE_SSL */
1938 * Add listening address(es) to the list...
1941 cupsd_listener_t
*lis
; /* New listeners array */
1945 * Get the address list...
1948 addrlist
= get_address(value
, IPP_PORT
);
1952 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1958 * Add each address...
1961 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1964 * Allocate another listener...
1967 if (NumListeners
== 0)
1968 lis
= malloc(sizeof(cupsd_listener_t
));
1970 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1974 cupsdLogMessage(CUPSD_LOG_ERROR
,
1975 "Unable to allocate %s at line %d - %s.",
1976 line
, linenum
, strerror(errno
));
1981 lis
+= NumListeners
;
1984 * Copy the current address and log it...
1987 memset(lis
, 0, sizeof(cupsd_listener_t
));
1988 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
1992 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1993 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1994 #endif /* HAVE_SSL */
1997 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2000 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2001 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2002 ntohs(lis
->address
.ipv6
.sin6_port
));
2004 #endif /* AF_INET6 */
2006 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2007 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2009 #endif /* AF_LOCAL */
2010 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2011 ntohs(lis
->address
.ipv4
.sin_port
));
2020 httpAddrFreeList(addrlist
);
2022 else if (!strcasecmp(line
, "BrowseAddress"))
2025 * Add a browse address to the list...
2028 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2031 if (NumBrowsers
== 0)
2032 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2034 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2038 cupsdLogMessage(CUPSD_LOG_ERROR
,
2039 "Unable to allocate BrowseAddress at line %d - %s.",
2040 linenum
, strerror(errno
));
2045 dira
+= NumBrowsers
;
2047 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2049 if (!strcasecmp(value
, "@LOCAL"))
2052 * Send browse data to all local interfaces...
2055 strcpy(dira
->iface
, "*");
2058 else if (!strncasecmp(value
, "@IF(", 4))
2061 * Send browse data to the named interface...
2064 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2066 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2072 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2075 * Only IPv4 addresses are supported...
2078 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2079 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2084 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2085 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2087 cupsdLogMessage(CUPSD_LOG_INFO
,
2088 "Sending browsing info to %s:%d (IPv4)",
2089 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2094 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2097 httpAddrFreeList(addrlist
);
2100 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2103 else if (!strcasecmp(line
, "BrowseOrder"))
2106 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2109 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2110 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2112 if (location
== NULL
)
2113 cupsdLogMessage(CUPSD_LOG_ERROR
,
2114 "Unable to initialize browse access control list!");
2115 else if (!strncasecmp(value
, "deny", 4))
2116 location
->order_type
= AUTH_ALLOW
;
2117 else if (!strncasecmp(value
, "allow", 5))
2118 location
->order_type
= AUTH_DENY
;
2120 cupsdLogMessage(CUPSD_LOG_ERROR
,
2121 "Unknown BrowseOrder value %s on line %d.",
2124 else if (!strcasecmp(line
, "BrowseProtocols") ||
2125 !strcasecmp(line
, "BrowseLocalProtocols") ||
2126 !strcasecmp(line
, "BrowseRemoteProtocols"))
2129 * "BrowseProtocol name [... name]"
2132 if (strcasecmp(line
, "BrowseLocalProtocols"))
2133 BrowseRemoteProtocols
= 0;
2134 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2135 BrowseLocalProtocols
= 0;
2139 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2140 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2143 if (value
[valuelen
])
2145 value
[valuelen
] = '\0';
2149 if (!strcasecmp(value
, "cups"))
2151 if (strcasecmp(line
, "BrowseLocalProtocols"))
2152 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2153 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2154 BrowseLocalProtocols
|= BROWSE_CUPS
;
2156 else if (!strcasecmp(value
, "slp"))
2158 if (strcasecmp(line
, "BrowseLocalProtocols"))
2159 BrowseRemoteProtocols
|= BROWSE_SLP
;
2160 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2161 BrowseLocalProtocols
|= BROWSE_SLP
;
2163 else if (!strcasecmp(value
, "ldap"))
2165 if (strcasecmp(line
, "BrowseLocalProtocols"))
2166 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2167 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2168 BrowseLocalProtocols
|= BROWSE_LDAP
;
2170 else if (!strcasecmp(value
, "all"))
2172 if (strcasecmp(line
, "BrowseLocalProtocols"))
2173 BrowseRemoteProtocols
|= BROWSE_ALL
;
2174 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2175 BrowseLocalProtocols
|= BROWSE_ALL
;
2179 cupsdLogMessage(CUPSD_LOG_ERROR
,
2180 "Unknown browse protocol \"%s\" on line %d.",
2185 for (value
+= valuelen
; *value
; value
++)
2186 if (!isspace(*value
) || *value
!= ',')
2190 else if (!strcasecmp(line
, "BrowseAllow") ||
2191 !strcasecmp(line
, "BrowseDeny"))
2194 * BrowseAllow [From] host/ip...
2195 * BrowseDeny [From] host/ip...
2198 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2199 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2201 if (location
== NULL
)
2202 cupsdLogMessage(CUPSD_LOG_ERROR
,
2203 "Unable to initialize browse access control list!");
2206 if (!strncasecmp(value
, "from ", 5))
2209 * Strip leading "from"...
2214 while (isspace(*value
))
2219 * Figure out what form the allow/deny address takes:
2230 * nnn.nnn.nnn.nnn/mm
2231 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2234 if (!strcasecmp(value
, "all"))
2240 if (!strcasecmp(line
, "BrowseAllow"))
2241 cupsdAllowIP(location
, zeros
, zeros
);
2243 cupsdDenyIP(location
, zeros
, zeros
);
2245 else if (!strcasecmp(value
, "none"))
2251 if (!strcasecmp(line
, "BrowseAllow"))
2252 cupsdAllowIP(location
, ones
, zeros
);
2254 cupsdDenyIP(location
, ones
, zeros
);
2256 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2259 * Host or domain name...
2262 if (value
[0] == '*')
2265 if (!strcasecmp(line
, "BrowseAllow"))
2266 cupsdAllowHost(location
, value
);
2268 cupsdDenyHost(location
, value
);
2273 * One of many IP address forms...
2276 if (!get_addr_and_mask(value
, ip
, mask
))
2278 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2283 if (!strcasecmp(line
, "BrowseAllow"))
2284 cupsdAllowIP(location
, ip
, mask
);
2286 cupsdDenyIP(location
, ip
, mask
);
2290 else if (!strcasecmp(line
, "BrowseRelay"))
2293 * BrowseRelay [from] source [to] destination
2297 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2299 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2303 cupsdLogMessage(CUPSD_LOG_ERROR
,
2304 "Unable to allocate BrowseRelay at line %d - %s.",
2305 linenum
, strerror(errno
));
2312 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2314 if (!strncasecmp(value
, "from ", 5))
2317 * Strip leading "from"...
2322 while (isspace(*value
))
2327 * Figure out what form the from address takes:
2336 * nnn.nnn.nnn.nnn/mm
2337 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2340 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2343 * Host or domain name...
2346 if (value
[0] == '*')
2349 strlcpy(temp
, value
, sizeof(temp
));
2350 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2353 relay
->from
.type
= AUTH_NAME
;
2354 relay
->from
.mask
.name
.name
= strdup(temp
);
2355 relay
->from
.mask
.name
.length
= strlen(temp
);
2360 * One of many IP address forms...
2363 if (!get_addr_and_mask(value
, ip
, mask
))
2365 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2370 relay
->from
.type
= AUTH_IP
;
2371 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2372 sizeof(relay
->from
.mask
.ip
.address
));
2373 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2374 sizeof(relay
->from
.mask
.ip
.netmask
));
2378 * Skip value and trailing whitespace...
2381 for (; *value
; value
++)
2382 if (isspace(*value
))
2385 while (isspace(*value
))
2388 if (!strncasecmp(value
, "to ", 3))
2391 * Strip leading "to"...
2396 while (isspace(*value
))
2401 * Get "to" address and port...
2404 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2407 * Only IPv4 addresses are supported...
2410 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2411 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2416 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2418 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2420 if (relay
->from
.type
== AUTH_IP
)
2421 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2422 relay
->from
.mask
.ip
.address
[0],
2423 relay
->from
.mask
.ip
.address
[1],
2424 relay
->from
.mask
.ip
.address
[2],
2425 relay
->from
.mask
.ip
.address
[3],
2426 relay
->from
.mask
.ip
.netmask
[0],
2427 relay
->from
.mask
.ip
.netmask
[1],
2428 relay
->from
.mask
.ip
.netmask
[2],
2429 relay
->from
.mask
.ip
.netmask
[3]);
2431 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2433 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2434 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2439 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2442 httpAddrFreeList(addrlist
);
2446 if (relay
->from
.type
== AUTH_NAME
)
2447 free(relay
->from
.mask
.name
.name
);
2449 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2453 else if (!strcasecmp(line
, "BrowsePoll"))
2456 * BrowsePoll address[:port]
2459 char *portname
; /* Port name */
2460 int portnum
; /* Port number */
2461 struct servent
*service
; /* Service */
2465 * Extract the port name from the address...
2468 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2472 if (isdigit(*portname
& 255))
2473 portnum
= atoi(portname
);
2474 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2475 portnum
= ntohs(service
->s_port
);
2478 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2484 portnum
= ippPort();
2487 * Add the poll entry...
2491 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2493 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2497 cupsdLogMessage(CUPSD_LOG_ERROR
,
2498 "Unable to allocate BrowsePoll at line %d - %s.",
2499 linenum
, strerror(errno
));
2507 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2509 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2510 pollp
->port
= portnum
;
2512 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2515 else if (!strcasecmp(line
, "DefaultAuthType"))
2518 * DefaultAuthType {basic,digest,basicdigest}
2521 if (!strcasecmp(value
, "basic"))
2522 DefaultAuthType
= AUTH_BASIC
;
2523 else if (!strcasecmp(value
, "digest"))
2524 DefaultAuthType
= AUTH_DIGEST
;
2525 else if (!strcasecmp(value
, "basicdigest"))
2526 DefaultAuthType
= AUTH_BASICDIGEST
;
2529 cupsdLogMessage(CUPSD_LOG_WARN
,
2530 "Unknown default authorization type %s on line %d.",
2535 else if (!strcasecmp(line
, "User"))
2538 * User ID to run as...
2541 if (value
&& isdigit(value
[0] & 255))
2543 int uid
= atoi(value
);
2546 cupsdLogMessage(CUPSD_LOG_ERROR
,
2547 "Will not use User 0 as specified on line %d "
2548 "for security reasons. You must use a non-"
2549 "privileged account instead.",
2556 struct passwd
*p
; /* Password information */
2559 p
= getpwnam(value
);
2564 cupsdLogMessage(CUPSD_LOG_ERROR
,
2565 "Will not use User %s (UID=0) as specified on line "
2566 "%d for security reasons. You must use a non-"
2567 "privileged account instead.",
2573 cupsdLogMessage(CUPSD_LOG_ERROR
,
2574 "Unknown User \"%s\" on line %d, ignoring!",
2578 cupsdLogMessage(CUPSD_LOG_ERROR
,
2579 "User directive on line %d missing the username!",
2582 else if (!strcasecmp(line
, "Group"))
2585 * Group ID to run as...
2588 if (isdigit(value
[0]))
2589 Group
= atoi(value
);
2593 group
= getgrnam(value
);
2596 Group
= group
->gr_gid
;
2598 cupsdLogMessage(CUPSD_LOG_ERROR
,
2599 "Unknown Group \"%s\" on line %d, ignoring!",
2603 else if (!strcasecmp(line
, "SystemGroup"))
2606 * System (admin) group(s)...
2609 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2611 if (*value
== '\'' || *value
== '\"')
2614 * Scan quoted name...
2619 for (valueptr
= value
; *valueptr
; valueptr
++)
2620 if (*valueptr
== quote
)
2626 * Scan space or comma-delimited name...
2629 for (valueptr
= value
; *valueptr
; valueptr
++)
2630 if (isspace(*valueptr
) || *valueptr
== ',')
2637 group
= getgrnam(value
);
2640 cupsdSetString(SystemGroups
+ i
, value
);
2641 SystemGroupIDs
[i
] = group
->gr_gid
;
2646 cupsdLogMessage(CUPSD_LOG_ERROR
,
2647 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2654 while (*value
== ',' || isspace(*value
))
2659 NumSystemGroups
= i
;
2661 else if (!strcasecmp(line
, "HostNameLookups"))
2664 * Do hostname lookups?
2667 if (!strcasecmp(value
, "off"))
2668 HostNameLookups
= 0;
2669 else if (!strcasecmp(value
, "on"))
2670 HostNameLookups
= 1;
2671 else if (!strcasecmp(value
, "double"))
2672 HostNameLookups
= 2;
2674 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2677 else if (!strcasecmp(line
, "LogLevel"))
2680 * Amount of logging to do...
2683 if (!strcasecmp(value
, "debug2"))
2684 LogLevel
= CUPSD_LOG_DEBUG2
;
2685 else if (!strcasecmp(value
, "debug"))
2686 LogLevel
= CUPSD_LOG_DEBUG
;
2687 else if (!strcasecmp(value
, "info"))
2688 LogLevel
= CUPSD_LOG_INFO
;
2689 else if (!strcasecmp(value
, "notice"))
2690 LogLevel
= CUPSD_LOG_NOTICE
;
2691 else if (!strcasecmp(value
, "warn"))
2692 LogLevel
= CUPSD_LOG_WARN
;
2693 else if (!strcasecmp(value
, "error"))
2694 LogLevel
= CUPSD_LOG_ERROR
;
2695 else if (!strcasecmp(value
, "crit"))
2696 LogLevel
= CUPSD_LOG_CRIT
;
2697 else if (!strcasecmp(value
, "alert"))
2698 LogLevel
= CUPSD_LOG_ALERT
;
2699 else if (!strcasecmp(value
, "emerg"))
2700 LogLevel
= CUPSD_LOG_EMERG
;
2701 else if (!strcasecmp(value
, "none"))
2702 LogLevel
= CUPSD_LOG_NONE
;
2704 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2707 else if (!strcasecmp(line
, "PrintcapFormat"))
2710 * Format of printcap file?
2713 if (!strcasecmp(value
, "bsd"))
2714 PrintcapFormat
= PRINTCAP_BSD
;
2715 else if (!strcasecmp(value
, "solaris"))
2716 PrintcapFormat
= PRINTCAP_SOLARIS
;
2718 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2721 else if (!strcasecmp(line
, "ServerTokens"))
2724 * Set the string used for the Server header...
2727 struct utsname plat
; /* Platform info */
2732 if (!strcasecmp(value
, "ProductOnly"))
2733 cupsdSetString(&ServerHeader
, "CUPS");
2734 else if (!strcasecmp(value
, "Major"))
2735 cupsdSetString(&ServerHeader
, "CUPS/1");
2736 else if (!strcasecmp(value
, "Minor"))
2737 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2738 else if (!strcasecmp(value
, "Minimal"))
2739 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2740 else if (!strcasecmp(value
, "OS"))
2741 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2742 else if (!strcasecmp(value
, "Full"))
2743 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2745 else if (!strcasecmp(value
, "None"))
2746 cupsdClearString(&ServerHeader
);
2748 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2751 else if (!strcasecmp(line
, "PassEnv"))
2754 * PassEnv variable [... variable]
2759 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2760 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2763 if (value
[valuelen
])
2765 value
[valuelen
] = '\0';
2769 cupsdSetEnv(value
, NULL
);
2771 for (value
+= valuelen
; *value
; value
++)
2772 if (!isspace(*value
) || *value
!= ',')
2776 else if (!strcasecmp(line
, "SetEnv"))
2779 * SetEnv variable value
2782 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2790 while (isspace(*valueptr
& 255))
2793 cupsdSetEnv(value
, valueptr
);
2796 cupsdLogMessage(CUPSD_LOG_ERROR
,
2797 "Missing value for SetEnv directive on line %d.",
2803 * Find a simple variable in the list...
2806 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2807 if (!strcasecmp(line
, var
->name
))
2813 * Unknown directive! Output an error message and continue...
2816 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2823 case CUPSD_VARTYPE_INTEGER
:
2826 char *units
; /* Units */
2829 n
= strtol(value
, &units
, 0);
2831 if (units
&& *units
)
2833 if (tolower(units
[0] & 255) == 'g')
2834 n
*= 1024 * 1024 * 1024;
2835 else if (tolower(units
[0] & 255) == 'm')
2837 else if (tolower(units
[0] & 255) == 'k')
2839 else if (tolower(units
[0] & 255) == 't')
2843 *((int *)var
->ptr
) = n
;
2847 case CUPSD_VARTYPE_BOOLEAN
:
2848 if (!strcasecmp(value
, "true") ||
2849 !strcasecmp(value
, "on") ||
2850 !strcasecmp(value
, "enabled") ||
2851 !strcasecmp(value
, "yes") ||
2853 *((int *)var
->ptr
) = TRUE
;
2854 else if (!strcasecmp(value
, "false") ||
2855 !strcasecmp(value
, "off") ||
2856 !strcasecmp(value
, "disabled") ||
2857 !strcasecmp(value
, "no") ||
2858 !strcasecmp(value
, "0"))
2859 *((int *)var
->ptr
) = FALSE
;
2861 cupsdLogMessage(CUPSD_LOG_ERROR
,
2862 "Unknown boolean value %s on line %d.",
2866 case CUPSD_VARTYPE_STRING
:
2867 cupsdSetString((char **)var
->ptr
, value
);
2878 * 'read_location()' - Read a <Location path> definition.
2881 static int /* O - New line number or 0 on error */
2882 read_location(cups_file_t
*fp
, /* I - Configuration file */
2883 char *location
, /* I - Location name/path */
2884 int linenum
) /* I - Current line number */
2886 cupsd_location_t
*loc
, /* New location */
2887 *parent
; /* Parent location */
2888 char line
[HTTP_MAX_BUFFER
],
2890 *value
, /* Value for directive */
2891 *valptr
; /* Pointer into value */
2894 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2897 parent
->limit
= AUTH_LIMIT_ALL
;
2900 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2903 * Decode the directive...
2906 if (!strcasecmp(line
, "</Location>"))
2908 else if (!strcasecmp(line
, "<Limit") ||
2909 !strcasecmp(line
, "<LimitExcept"))
2913 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2917 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2923 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2928 if (!strcmp(value
, "ALL"))
2929 loc
->limit
= AUTH_LIMIT_ALL
;
2930 else if (!strcmp(value
, "GET"))
2931 loc
->limit
|= AUTH_LIMIT_GET
;
2932 else if (!strcmp(value
, "HEAD"))
2933 loc
->limit
|= AUTH_LIMIT_HEAD
;
2934 else if (!strcmp(value
, "OPTIONS"))
2935 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2936 else if (!strcmp(value
, "POST"))
2937 loc
->limit
|= AUTH_LIMIT_POST
;
2938 else if (!strcmp(value
, "PUT"))
2939 loc
->limit
|= AUTH_LIMIT_PUT
;
2940 else if (!strcmp(value
, "TRACE"))
2941 loc
->limit
|= AUTH_LIMIT_TRACE
;
2943 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2946 for (value
= valptr
; isspace(*value
& 255); value
++);
2949 if (!strcasecmp(line
, "<LimitExcept"))
2950 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2952 parent
->limit
&= ~loc
->limit
;
2954 else if (!strcasecmp(line
, "</Limit>"))
2956 else if (!parse_aaa(loc
, line
, value
, linenum
))
2958 cupsdLogMessage(CUPSD_LOG_ERROR
,
2959 "Unknown Location directive %s on line %d.",
2965 cupsdLogMessage(CUPSD_LOG_ERROR
,
2966 "Unexpected end-of-file at line %d while reading location!",
2974 * 'read_policy()' - Read a <Policy name> definition.
2977 static int /* O - New line number or 0 on error */
2978 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2979 char *policy
, /* I - Location name/path */
2980 int linenum
) /* I - Current line number */
2982 int i
; /* Looping var */
2983 cupsd_policy_t
*pol
; /* Policy */
2984 cupsd_location_t
*op
; /* Policy operation */
2985 int num_ops
; /* Number of IPP operations */
2986 ipp_op_t ops
[100]; /* Operations */
2987 char line
[HTTP_MAX_BUFFER
],
2989 *value
, /* Value for directive */
2990 *valptr
; /* Pointer into value */
2994 * Create the policy...
2997 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3001 * Read from the file...
3007 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3010 * Decode the directive...
3013 if (!strcasecmp(line
, "</Policy>"))
3016 cupsdLogMessage(CUPSD_LOG_WARN
,
3017 "Missing </Limit> before </Policy> on line %d!",
3022 else if (!strcasecmp(line
, "<Limit") && !op
)
3026 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3031 * Scan for IPP operation names...
3038 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3043 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3045 if (!strcasecmp(value
, "All"))
3046 ops
[num_ops
] = IPP_ANY_OPERATION
;
3047 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3048 cupsdLogMessage(CUPSD_LOG_ERROR
,
3049 "Bad IPP operation name \"%s\" on line %d!",
3055 cupsdLogMessage(CUPSD_LOG_ERROR
,
3056 "Too many operations listed on line %d!",
3059 for (value
= valptr
; isspace(*value
& 255); value
++);
3063 * If none are specified, apply the policy to all operations...
3068 ops
[0] = IPP_ANY_OPERATION
;
3073 * Add a new policy for the first operation...
3076 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3078 else if (!strcasecmp(line
, "</Limit>") && op
)
3081 * Finish the current operation limit...
3087 * Copy the policy to the other operations...
3090 for (i
= 1; i
< num_ops
; i
++)
3091 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3098 cupsdLogMessage(CUPSD_LOG_ERROR
,
3099 "Missing <Limit ops> directive before %s on line %d.",
3103 else if (!parse_aaa(op
, line
, value
, linenum
))
3106 cupsdLogMessage(CUPSD_LOG_ERROR
,
3107 "Unknown Policy Limit directive %s on line %d.",
3110 cupsdLogMessage(CUPSD_LOG_ERROR
,
3111 "Unknown Policy directive %s on line %d.",
3118 cupsdLogMessage(CUPSD_LOG_ERROR
,
3119 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3127 * End of "$Id: conf.c 5028 2006-01-31 01:16:43Z mike $".