2 * "$Id: conf.c 5116 2006-02-16 12:52:32Z 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 * parse_groups() - Parse system group names in a string.
34 * parse_protocols() - Parse browse protocols in a string.
35 * read_configuration() - Read a configuration file.
36 * read_location() - Read a <Location path> definition.
37 * read_policy() - Read a <Policy name> definition.
41 * Include necessary headers...
47 #include <sys/utsname.h>
52 #endif /* HAVE_VSYSLOG */
56 * Possibly missing network definitions...
60 # define INADDR_NONE 0xffffffff
61 #endif /* !INADDR_NONE */
65 * Configuration variable structure...
70 CUPSD_VARTYPE_INTEGER
, /* Integer option */
71 CUPSD_VARTYPE_STRING
, /* String option */
72 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
77 char *name
; /* Name of variable */
78 void *ptr
; /* Pointer to variable */
79 cupsd_vartype_t type
; /* Type (int, string, address) */
87 static cupsd_var_t variables
[] =
89 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
90 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
91 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
92 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
93 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
94 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
95 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
96 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
97 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
98 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
99 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
100 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
101 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
102 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
103 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
104 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
105 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
106 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
107 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
108 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
109 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
110 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
111 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
112 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
113 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
114 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
115 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
116 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
117 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
118 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
119 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
120 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
121 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
122 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
123 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
124 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
127 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
140 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
141 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
142 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
143 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
144 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
145 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
146 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
147 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
148 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
149 { "RunAsUser", &RunAsUser
, CUPSD_VARTYPE_BOOLEAN
},
150 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
151 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
152 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
154 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
155 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
156 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
157 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
158 #endif /* HAVE_SSL */
160 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
161 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
162 #endif /* HAVE_LAUNCHD */
163 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
164 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
165 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
166 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
167 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
168 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
170 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
173 static unsigned ones
[4] =
175 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
177 static unsigned zeros
[4] =
179 0x00000000, 0x00000000, 0x00000000, 0x00000000
186 static int check_permissions(const char *filename
,
187 const char *suffix
, int mode
,
188 int user
, int group
, int is_dir
,
190 static http_addrlist_t
*get_address(const char *value
, int defport
);
191 static int get_addr_and_mask(const char *value
, unsigned *ip
,
193 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
194 char *value
, int linenum
);
195 static int parse_groups(const char *s
);
196 static int parse_protocols(const char *s
);
197 static int read_configuration(cups_file_t
*fp
);
198 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
199 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
203 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
206 int /* O - 1 on success, 0 otherwise */
207 cupsdReadConfiguration(void)
209 int i
; /* Looping var */
210 cups_file_t
*fp
; /* Configuration file */
211 int status
; /* Return status */
212 char temp
[1024], /* Temporary buffer */
213 *slash
; /* Directory separator */
214 cups_lang_t
*language
; /* Language */
215 struct passwd
*user
; /* Default user */
216 struct group
*group
; /* Default group */
217 char *old_serverroot
, /* Old ServerRoot */
218 *old_requestroot
; /* Old RequestRoot */
221 * Save the old root paths...
224 old_serverroot
= NULL
;
225 cupsdSetString(&old_serverroot
, ServerRoot
);
226 old_requestroot
= NULL
;
227 cupsdSetString(&old_requestroot
, RequestRoot
);
230 * Reset the server configuration data...
233 cupsdDeleteAllLocations();
251 for (i
= 0; i
< NumRelays
; i
++)
252 if (Relays
[i
].from
.type
== AUTH_NAME
)
253 free(Relays
[i
].from
.mask
.name
.name
);
260 cupsdDeleteAllListeners();
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.2");
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 user...
321 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
326 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
327 * complement number...)
336 * Find the default group (nobody)...
339 group
= getgrnam("nobody");
343 Group
= group
->gr_gid
;
347 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
348 * complement number...)
358 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
359 DefaultAuthType
= AUTH_BASIC
;
361 JobRetryInterval
= 300;
366 HostNameLookups
= FALSE
;
367 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
368 ImplicitAnyClasses
= FALSE
;
369 HideImplicitMembers
= TRUE
;
371 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
372 ListenBackLog
= SOMAXCONN
;
373 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
374 LogLevel
= CUPSD_LOG_ERROR
;
376 MaxClientsPerHost
= 0;
377 MaxLogSize
= 1024 * 1024;
378 MaxPrinterHistory
= 10;
381 RootCertDuration
= 300;
383 Timeout
= DEFAULT_TIMEOUT
;
386 BrowseInterval
= DEFAULT_INTERVAL
;
387 BrowsePort
= ippPort();
388 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
389 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
390 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
391 BrowseTimeout
= DEFAULT_TIMEOUT
;
392 Browsing
= CUPS_DEFAULT_BROWSING
;
393 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
395 cupsdClearString(&BrowseLocalOptions
);
396 cupsdClearString(&BrowseRemoteOptions
);
398 JobHistory
= DEFAULT_HISTORY
;
399 JobFiles
= DEFAULT_FILES
;
404 MaxJobsPerPrinter
= 0;
407 cupsdDeleteAllPolicies();
408 cupsdClearString(&DefaultPolicy
);
410 MaxSubscriptions
= 100;
411 MaxSubscriptionsPerJob
= 0;
412 MaxSubscriptionsPerPrinter
= 0;
413 MaxSubscriptionsPerUser
= 0;
414 DefaultLeaseDuration
= 86400;
415 MaxLeaseDuration
= 0;
418 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
419 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
420 #endif /* HAVE_LAUNCHD */
423 * Read the configuration file...
426 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
429 status
= read_configuration(fp
);
442 * Use the default system group if none was supplied in cupsd.conf...
445 if (NumSystemGroups
== 0)
447 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
450 * Find the group associated with GID 0...
457 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
459 cupsdSetString(&SystemGroups
[0], "unknown");
461 SystemGroupIDs
[0] = 0;
467 * Get the access control list for browsing...
470 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
473 * Open the system log for cupsd if necessary...
477 if (!strcmp(AccessLog
, "syslog") ||
478 !strcmp(ErrorLog
, "syslog") ||
479 !strcmp(PageLog
, "syslog"))
480 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
481 #endif /* HAVE_VSYSLOG */
484 * Log the configuration file that was used...
487 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
491 * Validate the Group and SystemGroup settings - they cannot be the same,
492 * otherwise the CGI programs will be able to authenticate as root without
498 for (i
= 0; i
< NumSystemGroups
; i
++)
499 if (Group
== SystemGroupIDs
[i
])
502 if (i
< NumSystemGroups
)
505 * Log the error and reset the group to a safe value...
508 cupsdLogMessage(CUPSD_LOG_NOTICE
,
509 "Group and SystemGroup cannot use the same groups!");
510 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
512 group
= getgrnam("nobody");
516 Group
= group
->gr_gid
;
520 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
521 * complement number...)
530 * Check that we have at least one listen/port line; if not, report this
531 * as an error and exit!
534 if (cupsArrayCount(Listeners
) == 0)
540 cupsdLogMessage(CUPSD_LOG_EMERG
,
541 "No valid Listen or Port lines were found in the configuration file!");
547 cupsdEndProcess(getpid(), 0);
551 * Set the default locale using the language and charset...
554 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
557 * Update all relative filenames to include the full path from ServerRoot...
560 if (DocumentRoot
[0] != '/')
561 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
563 if (RequestRoot
[0] != '/')
564 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
566 if (ServerBin
[0] != '/')
567 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
569 if (StateDir
[0] != '/')
570 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
572 if (CacheDir
[0] != '/')
573 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
576 if (ServerCertificate
[0] != '/')
577 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
579 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
581 chown(ServerCertificate
, RunUser
, Group
);
582 chmod(ServerCertificate
, 0600);
585 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
586 if (ServerKey
[0] != '/')
587 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
589 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
591 chown(ServerKey
, RunUser
, Group
);
592 chmod(ServerKey
, 0600);
594 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
595 #endif /* HAVE_SSL */
598 * Make sure that directories and config files are owned and
599 * writable by the user and group in the cupsd.conf file...
602 check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1);
603 /* check_permissions(CacheDir, "ppd", 0755, RunUser, Group, 1, 1);*/
605 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1);
606 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
607 SystemGroupIDs
[0], 1, 1);
609 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0);
610 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1);
611 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0);
612 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
, Group
,
614 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
, 0, 0);
615 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
, 0, 0);
616 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0);
619 * Make sure the request and temporary directories have the right
623 check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1);
625 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
629 * Update ownership and permissions if the CUPS temp directory
630 * is under the spool directory or does not exist...
633 check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1);
636 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
639 * Clean out the temporary directory...
642 cups_dir_t
*dir
; /* Temporary directory */
643 cups_dentry_t
*dent
; /* Directory entry */
644 char tempfile
[1024]; /* Temporary filename */
647 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
649 cupsdLogMessage(CUPSD_LOG_INFO
,
650 "Cleaning out old temporary files in \"%s\"...", TempDir
);
652 while ((dent
= cupsDirRead(dir
)) != NULL
)
654 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
656 if (unlink(tempfile
))
657 cupsdLogMessage(CUPSD_LOG_ERROR
,
658 "Unable to remove temporary file \"%s\" - %s",
659 tempfile
, strerror(errno
));
661 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
668 cupsdLogMessage(CUPSD_LOG_ERROR
,
669 "Unable to open temporary directory \"%s\" - %s",
670 TempDir
, strerror(errno
));
674 * Setup environment variables...
680 * Check the MaxClients setting, and then allocate memory for it...
683 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
686 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
689 MaxClients
= MaxFDs
/ 3;
692 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
696 * Check the MaxActiveJobs setting; limit to 1/3 the available
697 * file descriptors, since we need a pipe for each job...
700 if (MaxActiveJobs
> (MaxFDs
/ 3))
701 MaxActiveJobs
= MaxFDs
/ 3;
703 if (Classification
&& strcasecmp(Classification
, "none") == 0)
704 cupsdClearString(&Classification
);
707 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
710 * Update the MaxClientsPerHost value, as needed...
713 if (MaxClientsPerHost
<= 0)
714 MaxClientsPerHost
= MaxClients
;
716 if (MaxClientsPerHost
> MaxClients
)
717 MaxClientsPerHost
= MaxClients
;
719 cupsdLogMessage(CUPSD_LOG_INFO
,
720 "Allowing up to %d client connections per host.",
724 * Update the default policy, as needed...
728 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
730 DefaultPolicyPtr
= NULL
;
732 if (!DefaultPolicyPtr
)
734 cupsd_policy_t
*p
; /* New policy */
735 cupsd_location_t
*po
; /* New policy operation */
739 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
742 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
743 cupsdLogMessage(CUPSD_LOG_INFO
,
744 "Using policy \"default\" as the default!");
747 cupsdLogMessage(CUPSD_LOG_INFO
,
748 "Creating CUPS default administrative policy:");
750 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
752 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
753 cupsdLogMessage(CUPSD_LOG_INFO
,
754 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
755 "Release-Job Restart-Job Purge-Jobs "
756 "Set-Job-Attributes Create-Job-Subscription "
757 "Renew-Subscription Cancel-Subscription "
758 "Get-Notifications Reprocess-Job Cancel-Current-Job "
759 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
760 "CUPS-Authenticate-Job>");
761 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
763 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
764 po
->order_type
= AUTH_ALLOW
;
765 po
->level
= AUTH_USER
;
767 cupsdAddName(po
, "@OWNER");
768 cupsdAddName(po
, "@SYSTEM");
769 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
771 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
772 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
773 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
774 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
775 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
776 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
777 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
778 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
779 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
780 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
781 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
782 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
783 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
784 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
785 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
786 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
787 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
789 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
791 cupsdLogMessage(CUPSD_LOG_INFO
,
792 "<Limit Pause-Printer Resume-Printer "
793 "Set-Printer-Attributes Enable-Printer "
794 "Disable-Printer Pause-Printer-After-Current-Job "
795 "Hold-New-Jobs Release-Held-New-Jobs "
796 "Deactivate-Printer Activate-Printer Restart-Printer "
797 "Shutdown-Printer Startup-Printer Promote-Job "
798 "Schedule-Job-After CUPS-Add-Printer "
799 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
800 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
801 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
802 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
804 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
805 po
->order_type
= AUTH_ALLOW
;
806 po
->type
= AUTH_BASIC
;
807 po
->level
= AUTH_USER
;
809 cupsdAddName(po
, "@SYSTEM");
810 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
812 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
813 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
814 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
815 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
816 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
817 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
818 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
819 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
820 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
821 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
822 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
823 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
824 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
825 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
826 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
827 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
828 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
829 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
830 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
831 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
832 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
834 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
836 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
837 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
839 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
840 po
->order_type
= AUTH_ALLOW
;
842 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
843 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
847 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
849 for (i
= 0; i
< NumPolicies
; i
++)
850 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
851 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
855 * If we are doing a full reload or the server root has changed, flush
856 * the jobs, printers, etc. and start from scratch...
859 if (NeedReload
== RELOAD_ALL
||
860 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
861 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
863 mime_type_t
*type
; /* Current type */
864 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
868 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
874 cupsdDeleteAllSubscriptions();
876 cupsdDeleteAllClasses();
877 cupsdDeleteAllPrinters();
879 DefaultPrinter
= NULL
;
881 if (MimeDatabase
!= NULL
)
882 mimeDelete(MimeDatabase
);
886 for (i
= 0; i
< NumMimeTypes
; i
++)
887 _cups_sp_free(MimeTypes
[i
]);
893 * Read the MIME type and conversion database...
896 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
898 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
902 cupsdLogMessage(CUPSD_LOG_EMERG
,
903 "Unable to load MIME database from \'%s\'!", ServerRoot
);
907 cupsdLogMessage(CUPSD_LOG_INFO
,
908 "Loaded MIME database from \'%s\': %d types, %d filters...",
909 ServerRoot
, mimeNumTypes(MimeDatabase
),
910 mimeNumFilters(MimeDatabase
));
913 * Create a list of MIME types for the document-format-supported
917 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
918 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
921 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
923 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
925 i
++, type
= mimeNextType(MimeDatabase
))
927 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
929 MimeTypes
[i
] = _cups_sp_alloc(mimetype
);
932 if (i
< NumMimeTypes
)
933 MimeTypes
[i
] = _cups_sp_alloc("application/octet-stream");
935 if (LogLevel
== CUPSD_LOG_DEBUG2
)
937 mime_filter_t
*filter
; /* Current filter */
940 for (type
= mimeFirstType(MimeDatabase
);
942 type
= mimeNextType(MimeDatabase
))
943 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
944 type
->super
, type
->type
);
946 for (filter
= mimeFirstFilter(MimeDatabase
);
948 filter
= mimeNextFilter(MimeDatabase
))
949 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
950 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
951 filter
->src
->super
, filter
->src
->type
,
952 filter
->dst
->super
, filter
->dst
->type
,
953 filter
->cost
, filter
->filter
);
960 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
961 cupsdLoadBanners(temp
);
964 * Load printers and classes...
967 cupsdLoadAllPrinters();
968 cupsdLoadAllClasses();
969 cupsdLoadRemoteCache();
970 cupsdWritePrintcap();
972 cupsdCreateCommonData();
975 * Load queued jobs...
981 * Load subscriptions...
984 cupsdLoadAllSubscriptions();
986 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
991 * Not a full reload, so recreate the common printer attributes...
994 cupsdCreateCommonData();
997 * Update all printers as needed...
1000 cupsdUpdatePrinters();
1001 cupsdWritePrintcap();
1003 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1007 * Reset the reload state...
1010 NeedReload
= RELOAD_NONE
;
1012 cupsdClearString(&old_serverroot
);
1013 cupsdClearString(&old_requestroot
);
1020 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1023 static int /* O - 0 on success, -1 on error */
1024 check_permissions(const char *filename
, /* I - File/directory name */
1025 const char *suffix
, /* I - Additional file/directory name */
1026 int mode
, /* I - Permissions */
1027 int user
, /* I - Owner */
1028 int group
, /* I - Group */
1029 int is_dir
, /* I - 1 = directory, 0 = file */
1030 int create_dir
)/* I - 1 = create directory, 0 = not */
1032 int dir_created
= 0; /* Did we create a directory? */
1033 char pathname
[1024]; /* File name with prefix */
1034 struct stat fileinfo
; /* Stat buffer */
1038 * Prepend the given root to the filename before testing it...
1043 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1044 filename
= pathname
;
1048 * See if we can stat the file/directory...
1051 if (stat(filename
, &fileinfo
))
1053 if (errno
== ENOENT
&& create_dir
)
1055 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1058 if (mkdir(filename
, mode
))
1060 cupsdLogMessage(CUPSD_LOG_ERROR
,
1061 "Unable to create directory \"%s\" - %s", filename
,
1073 * Make sure it's a regular file...
1076 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1078 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1082 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1084 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1089 * Fix owner, group, and mode as needed...
1092 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1094 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1096 if (chown(filename
, user
, group
))
1098 cupsdLogMessage(CUPSD_LOG_ERROR
,
1099 "Unable to change ownership of \"%s\" - %s", filename
,
1105 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
1107 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1109 if (chmod(filename
, mode
))
1111 cupsdLogMessage(CUPSD_LOG_ERROR
,
1112 "Unable to change permissions of \"%s\" - %s", filename
,
1119 * Everything is OK...
1127 * 'get_address()' - Get an address + port number from a line.
1130 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1131 get_address(const char *value
, /* I - Value string */
1132 int defport
) /* I - Default port */
1134 char buffer
[1024], /* Hostname + port number buffer */
1135 defpname
[255], /* Default port name */
1136 *hostname
, /* Hostname or IP */
1137 *portname
; /* Port number or name */
1138 http_addrlist_t
*addrlist
; /* Address list */
1142 * Check for an empty value...
1147 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1152 * Grab a hostname and port number; if there is no colon and the port name
1153 * is only digits, then we have a port number by itself...
1156 strlcpy(buffer
, value
, sizeof(buffer
));
1158 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1165 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1170 * Use the default port...
1173 sprintf(defpname
, "%d", defport
);
1174 portname
= defpname
;
1180 * The buffer contains just a port number...
1188 if (hostname
&& !strcmp(hostname
, "*"))
1192 * Now lookup the address using httpAddrGetList()...
1195 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1196 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1197 hostname
? hostname
: "(nil)");
1204 * 'get_addr_and_mask()' - Get an IP address and netmask.
1207 static int /* O - 1 on success, 0 on failure */
1208 get_addr_and_mask(const char *value
, /* I - String from config file */
1209 unsigned *ip
, /* O - Address value */
1210 unsigned *mask
) /* O - Mask value */
1212 int i
, j
, /* Looping vars */
1213 family
, /* Address family */
1214 ipcount
; /* Count of fields in address */
1215 unsigned ipval
; /* Value */
1216 const char *maskval
, /* Pointer to start of mask value */
1217 *ptr
, /* Pointer into value */
1219 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1221 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1222 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1223 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1224 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1227 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1229 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1230 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1231 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1232 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1233 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1234 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1235 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1236 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1238 #endif /* AF_INET6 */
1242 * Get the address...
1245 memset(ip
, 0, sizeof(unsigned) * 4);
1247 if ((maskval
= strchr(value
, '/')) != NULL
)
1250 maskval
= value
+ strlen(value
);
1254 * Check for an IPv6 address...
1260 * Parse hexadecimal IPv6 address...
1265 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1269 else if (!strncmp(ptr
, "::", 2))
1271 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1273 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1277 else if (isxdigit(*ptr
& 255))
1279 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1287 ip
[i
] |= ipval
<< 16;
1298 if (*ptr
&& *ptr
!= '/')
1302 #endif /* AF_INET6 */
1305 * Parse dotted-decimal IPv4 address...
1309 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1311 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1312 ip
[0] = ip
[1] = ip
[2] = 0;
1318 * Get the netmask value(s)...
1321 memset(mask
, 0, sizeof(unsigned) * 4);
1324 if (*maskval
== '[')
1327 * Get hexadecimal mask value...
1330 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1334 else if (!strncmp(ptr
, "::", 2))
1336 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1338 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1342 else if (isxdigit(*ptr
& 255))
1344 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1352 mask
[i
] |= ipval
<< 16;
1365 #endif /* AF_INET6 */
1366 if (strchr(maskval
, '.'))
1369 * Get dotted-decimal mask...
1372 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1375 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1376 mask
[0] = mask
[1] = mask
[2] = 0;
1381 * Get address/bits format...
1387 if (family
== AF_INET6
)
1392 mask
[0] = 0xffffffff;
1394 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1397 mask
[1] = 0xffffffff;
1401 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1404 mask
[2] = 0xffffffff;
1408 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1411 mask
[3] = 0xffffffff;
1415 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1418 #endif /* AF_INET6 */
1422 mask
[0] = 0xffffffff;
1423 mask
[1] = 0xffffffff;
1424 mask
[2] = 0xffffffff;
1427 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1429 mask
[3] = 0xffffffff;
1434 else if (family
== AF_INET6
)
1435 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1436 #endif /* AF_INET6 */
1438 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1440 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1441 "get_addr_and_mask(value=\"%s\", "
1442 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1443 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1447 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1450 if ((ip
[0] & ~mask
[0]) != 0 ||
1451 (ip
[1] & ~mask
[1]) != 0 ||
1452 (ip
[2] & ~mask
[2]) != 0 ||
1453 (ip
[3] & ~mask
[3]) != 0)
1461 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1464 static int /* O - 1 on success, 0 on failure */
1465 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1466 char *line
, /* I - Line from file */
1467 char *value
, /* I - Start of value data */
1468 int linenum
) /* I - Current line number */
1470 char *valptr
; /* Pointer into value */
1471 unsigned ip
[4], /* IP address components */
1472 mask
[4]; /* IP netmask components */
1475 if (!strcasecmp(line
, "Encryption"))
1478 * "Encryption xxx" - set required encryption level...
1481 if (!strcasecmp(value
, "never"))
1482 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1483 else if (!strcasecmp(value
, "always"))
1485 cupsdLogMessage(CUPSD_LOG_ERROR
,
1486 "Encryption value \"%s\" on line %d is invalid in this "
1487 "context. Using \"required\" instead.", value
, linenum
);
1489 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1491 else if (!strcasecmp(value
, "required"))
1492 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1493 else if (!strcasecmp(value
, "ifrequested"))
1494 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1497 cupsdLogMessage(CUPSD_LOG_ERROR
,
1498 "Unknown Encryption value %s on line %d.", value
, linenum
);
1502 else if (!strcasecmp(line
, "Order"))
1505 * "Order Deny,Allow" or "Order Allow,Deny"...
1508 if (!strncasecmp(value
, "deny", 4))
1509 loc
->order_type
= AUTH_ALLOW
;
1510 else if (!strncasecmp(value
, "allow", 5))
1511 loc
->order_type
= AUTH_DENY
;
1514 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1519 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1522 * Allow [From] host/ip...
1523 * Deny [From] host/ip...
1526 if (!strncasecmp(value
, "from", 4))
1529 * Strip leading "from"...
1534 while (isspace(*value
& 255))
1539 * Figure out what form the allow/deny address takes:
1550 * nnn.nnn.nnn.nnn/mm
1551 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1554 if (!strcasecmp(value
, "all"))
1560 if (!strcasecmp(line
, "Allow"))
1561 cupsdAllowIP(loc
, zeros
, zeros
);
1563 cupsdDenyIP(loc
, zeros
, zeros
);
1565 else if (!strcasecmp(value
, "none"))
1571 if (!strcasecmp(line
, "Allow"))
1572 cupsdAllowIP(loc
, ones
, zeros
);
1574 cupsdDenyIP(loc
, ones
, zeros
);
1576 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1579 * Host or domain name...
1582 if (value
[0] == '*')
1585 if (!strcasecmp(line
, "Allow"))
1586 cupsdAllowHost(loc
, value
);
1588 cupsdDenyHost(loc
, value
);
1593 * One of many IP address forms...
1596 if (!get_addr_and_mask(value
, ip
, mask
))
1598 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1603 if (!strcasecmp(line
, "Allow"))
1604 cupsdAllowIP(loc
, ip
, mask
);
1606 cupsdDenyIP(loc
, ip
, mask
);
1609 else if (!strcasecmp(line
, "AuthType"))
1612 * AuthType {none,basic,digest,basicdigest}
1615 if (!strcasecmp(value
, "none"))
1617 loc
->type
= AUTH_NONE
;
1618 loc
->level
= AUTH_ANON
;
1620 else if (!strcasecmp(value
, "basic"))
1622 loc
->type
= AUTH_BASIC
;
1624 if (loc
->level
== AUTH_ANON
)
1625 loc
->level
= AUTH_USER
;
1627 else if (!strcasecmp(value
, "digest"))
1629 loc
->type
= AUTH_DIGEST
;
1631 if (loc
->level
== AUTH_ANON
)
1632 loc
->level
= AUTH_USER
;
1634 else if (!strcasecmp(value
, "basicdigest"))
1636 loc
->type
= AUTH_BASICDIGEST
;
1638 if (loc
->level
== AUTH_ANON
)
1639 loc
->level
= AUTH_USER
;
1643 cupsdLogMessage(CUPSD_LOG_WARN
,
1644 "Unknown authorization type %s on line %d.",
1649 else if (!strcasecmp(line
, "AuthClass"))
1652 * AuthClass anonymous, user, system, group
1655 if (!strcasecmp(value
, "anonymous"))
1657 loc
->type
= AUTH_NONE
;
1658 loc
->level
= AUTH_ANON
;
1660 cupsdLogMessage(CUPSD_LOG_WARN
,
1661 "\"AuthClass %s\" is deprecated; consider removing "
1665 else if (!strcasecmp(value
, "user"))
1667 loc
->level
= AUTH_USER
;
1669 cupsdLogMessage(CUPSD_LOG_WARN
,
1670 "\"AuthClass %s\" is deprecated; consider using "
1671 "\"Require valid-user\" on line %d.",
1674 else if (!strcasecmp(value
, "group"))
1676 loc
->level
= AUTH_GROUP
;
1678 cupsdLogMessage(CUPSD_LOG_WARN
,
1679 "\"AuthClass %s\" is deprecated; consider using "
1680 "\"Require @groupname\" on line %d.",
1683 else if (!strcasecmp(value
, "system"))
1685 loc
->level
= AUTH_GROUP
;
1687 cupsdAddName(loc
, "@SYSTEM");
1689 cupsdLogMessage(CUPSD_LOG_WARN
,
1690 "\"AuthClass %s\" is deprecated; consider using "
1691 "\"Require @SYSTEM\" on line %d.",
1696 cupsdLogMessage(CUPSD_LOG_WARN
,
1697 "Unknown authorization class %s on line %d.",
1702 else if (!strcasecmp(line
, "AuthGroupName"))
1704 cupsdAddName(loc
, value
);
1706 cupsdLogMessage(CUPSD_LOG_WARN
,
1707 "\"AuthGroupName %s\" directive is deprecated; consider "
1708 "using \"Require @%s\" on line %d.",
1709 value
, value
, linenum
);
1711 else if (!strcasecmp(line
, "Require"))
1714 * Apache synonym for AuthClass and AuthGroupName...
1718 * Require valid-user
1719 * Require group names
1720 * Require user names
1723 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1728 if (!strcasecmp(value
, "valid-user") ||
1729 !strcasecmp(value
, "user"))
1730 loc
->level
= AUTH_USER
;
1731 else if (!strcasecmp(value
, "group"))
1732 loc
->level
= AUTH_GROUP
;
1735 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1741 * Get the list of names from the line...
1744 for (value
= valptr
; *value
;)
1746 while (isspace(*value
& 255))
1749 if (*value
== '\"' || *value
== '\'')
1752 * Grab quoted name...
1755 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1762 * Grab literal name.
1765 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1771 cupsdAddName(loc
, value
);
1773 for (value
= valptr
; isspace(*value
& 255); value
++);
1776 else if (!strcasecmp(line
, "Satisfy"))
1778 if (!strcasecmp(value
, "all"))
1779 loc
->satisfy
= AUTH_SATISFY_ALL
;
1780 else if (!strcasecmp(value
, "any"))
1781 loc
->satisfy
= AUTH_SATISFY_ANY
;
1784 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1797 * 'parse_groups()' - Parse system group names in a string.
1800 static int /* O - 1 on success, 0 on failure */
1801 parse_groups(const char *s
) /* I - Space-delimited groups */
1803 int status
; /* Return status */
1804 char value
[1024], /* Value string */
1805 *valstart
, /* Pointer into value */
1806 *valend
, /* End of value */
1807 quote
; /* Quote character */
1808 struct group
*group
; /* Group */
1812 * Make a copy of the string and parse out the groups...
1815 strlcpy(value
, s
, sizeof(value
));
1820 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1822 if (*valstart
== '\'' || *valstart
== '\"')
1825 * Scan quoted name...
1828 quote
= *valstart
++;
1830 for (valend
= valstart
; *valend
; valend
++)
1831 if (*valend
== quote
)
1837 * Scan space or comma-delimited name...
1840 for (valend
= valstart
; *valend
; valend
++)
1841 if (isspace(*valend
) || *valend
== ',')
1848 group
= getgrnam(valstart
);
1851 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1852 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1863 while (*valstart
== ',' || isspace(*valstart
))
1872 * 'parse_protocols()' - Parse browse protocols in a string.
1875 static int /* O - Browse protocol bits */
1876 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1878 int protocols
; /* Browse protocol bits */
1879 char value
[1024], /* Value string */
1880 *valstart
, /* Pointer into value */
1881 *valend
; /* End of value */
1885 * Loop through the value string,...
1888 strlcpy(value
, s
, sizeof(value
));
1892 for (valstart
= value
; *valstart
;)
1895 * Get the current space/comma-delimited protocol name...
1898 for (valend
= valstart
; *valend
; valend
++)
1899 if (isspace(*valend
& 255) || *valend
== ',')
1906 * Add the protocol to the bitmask...
1909 if (!strcasecmp(valstart
, "cups"))
1910 protocols
|= BROWSE_CUPS
;
1911 else if (!strcasecmp(valstart
, "slp"))
1912 protocols
|= BROWSE_SLP
;
1913 else if (!strcasecmp(valstart
, "ldap"))
1914 protocols
|= BROWSE_LDAP
;
1915 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
1916 protocols
|= BROWSE_DNSSD
;
1917 else if (!strcasecmp(valstart
, "all"))
1918 protocols
|= BROWSE_ALL
;
1922 for (valstart
= valend
; *valstart
; valstart
++)
1923 if (!isspace(*valstart
& 255) || *valstart
!= ',')
1932 * 'read_configuration()' - Read a configuration file.
1935 static int /* O - 1 on success, 0 on failure */
1936 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1938 int i
; /* Looping var */
1939 int linenum
; /* Current line number */
1940 char line
[HTTP_MAX_BUFFER
],
1941 /* Line from file */
1942 temp
[HTTP_MAX_BUFFER
],
1943 /* Temporary buffer for value */
1944 temp2
[HTTP_MAX_BUFFER
],
1945 /* Temporary buffer 2 for value */
1946 *ptr
, /* Pointer into line/temp */
1947 *value
, /* Pointer to value */
1948 *valueptr
; /* Pointer into value */
1949 int valuelen
; /* Length of value */
1950 cupsd_var_t
*var
; /* Current variable */
1951 http_addrlist_t
*addrlist
, /* Address list */
1952 *addr
; /* Current address */
1953 unsigned ip
[4], /* Address value */
1954 mask
[4]; /* Netmask value */
1955 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1956 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1957 cupsd_location_t
*location
; /* Browse location */
1958 cups_file_t
*incfile
; /* Include file */
1959 char incname
[1024]; /* Include filename */
1960 struct group
*group
; /* Group */
1964 * Loop through each line in the file...
1969 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1972 * Decode the directive...
1975 if (!strcasecmp(line
, "Include"))
1981 if (value
[0] == '/')
1982 strlcpy(incname
, value
, sizeof(incname
));
1984 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1986 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1987 cupsdLogMessage(CUPSD_LOG_ERROR
,
1988 "Unable to include config file \"%s\" - %s",
1989 incname
, strerror(errno
));
1992 read_configuration(incfile
);
1993 cupsFileClose(incfile
);
1996 else if (!strcasecmp(line
, "<Location"))
2004 linenum
= read_location(fp
, value
, linenum
);
2010 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2015 else if (!strcasecmp(line
, "<Policy"))
2023 linenum
= read_policy(fp
, value
, linenum
);
2029 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2033 else if (!strcasecmp(line
, "FaxRetryInterval"))
2037 JobRetryInterval
= atoi(value
);
2038 cupsdLogMessage(CUPSD_LOG_WARN
,
2039 "FaxRetryInterval is deprecated; use "
2040 "JobRetryInterval on line %d.", linenum
);
2044 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2048 else if (!strcasecmp(line
, "FaxRetryLimit"))
2052 JobRetryLimit
= atoi(value
);
2053 cupsdLogMessage(CUPSD_LOG_WARN
,
2054 "FaxRetryLimit is deprecated; use "
2055 "JobRetryLimit on line %d.", linenum
);
2059 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2063 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2065 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2066 #endif /* HAVE_SSL */
2070 * Add listening address(es) to the list...
2073 cupsd_listener_t
*lis
; /* New listeners array */
2077 * Get the address list...
2080 addrlist
= get_address(value
, IPP_PORT
);
2084 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2090 * Add each address...
2093 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2096 * Allocate another listener...
2100 Listeners
= cupsArrayNew(NULL
, NULL
);
2104 cupsdLogMessage(CUPSD_LOG_ERROR
,
2105 "Unable to allocate %s at line %d - %s.",
2106 line
, linenum
, strerror(errno
));
2110 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2112 cupsdLogMessage(CUPSD_LOG_ERROR
,
2113 "Unable to allocate %s at line %d - %s.",
2114 line
, linenum
, strerror(errno
));
2118 cupsArrayAdd(Listeners
, lis
);
2121 * Copy the current address and log it...
2124 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2128 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2129 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2130 #endif /* HAVE_SSL */
2132 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2135 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2136 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2137 ntohs(lis
->address
.ipv6
.sin6_port
));
2139 #endif /* AF_INET6 */
2141 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2142 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2144 #endif /* AF_LOCAL */
2145 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2146 ntohs(lis
->address
.ipv4
.sin_port
));
2153 httpAddrFreeList(addrlist
);
2155 else if (!strcasecmp(line
, "BrowseAddress"))
2158 * Add a browse address to the list...
2161 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2164 if (NumBrowsers
== 0)
2165 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2167 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2171 cupsdLogMessage(CUPSD_LOG_ERROR
,
2172 "Unable to allocate BrowseAddress at line %d - %s.",
2173 linenum
, strerror(errno
));
2178 dira
+= NumBrowsers
;
2180 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2182 if (!strcasecmp(value
, "@LOCAL"))
2185 * Send browse data to all local interfaces...
2188 strcpy(dira
->iface
, "*");
2191 else if (!strncasecmp(value
, "@IF(", 4))
2194 * Send browse data to the named interface...
2197 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2199 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2205 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2208 * Only IPv4 addresses are supported...
2211 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2212 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2217 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2218 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2220 cupsdLogMessage(CUPSD_LOG_INFO
,
2221 "Sending browsing info to %s:%d (IPv4)",
2222 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2227 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2230 httpAddrFreeList(addrlist
);
2233 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2236 else if (!strcasecmp(line
, "BrowseOrder"))
2239 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2242 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2243 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2245 if (location
== NULL
)
2246 cupsdLogMessage(CUPSD_LOG_ERROR
,
2247 "Unable to initialize browse access control list!");
2248 else if (!strncasecmp(value
, "deny", 4))
2249 location
->order_type
= AUTH_ALLOW
;
2250 else if (!strncasecmp(value
, "allow", 5))
2251 location
->order_type
= AUTH_DENY
;
2253 cupsdLogMessage(CUPSD_LOG_ERROR
,
2254 "Unknown BrowseOrder value %s on line %d.",
2257 else if (!strcasecmp(line
, "BrowseProtocols") ||
2258 !strcasecmp(line
, "BrowseLocalProtocols") ||
2259 !strcasecmp(line
, "BrowseRemoteProtocols"))
2262 * "BrowseProtocols name [... name]"
2263 * "BrowseLocalProtocols name [... name]"
2264 * "BrowseRemoteProtocols name [... name]"
2267 int protocols
= parse_protocols(value
);
2271 cupsdLogMessage(CUPSD_LOG_ERROR
,
2272 "Unknown browse protocol \"%s\" on line %d.",
2277 if (strcasecmp(line
, "BrowseLocalProtocols"))
2278 BrowseRemoteProtocols
= protocols
;
2279 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2280 BrowseLocalProtocols
= protocols
;
2282 else if (!strcasecmp(line
, "BrowseAllow") ||
2283 !strcasecmp(line
, "BrowseDeny"))
2286 * BrowseAllow [From] host/ip...
2287 * BrowseDeny [From] host/ip...
2290 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2291 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2293 if (location
== NULL
)
2294 cupsdLogMessage(CUPSD_LOG_ERROR
,
2295 "Unable to initialize browse access control list!");
2298 if (!strncasecmp(value
, "from ", 5))
2301 * Strip leading "from"...
2306 while (isspace(*value
))
2311 * Figure out what form the allow/deny address takes:
2322 * nnn.nnn.nnn.nnn/mm
2323 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2326 if (!strcasecmp(value
, "all"))
2332 if (!strcasecmp(line
, "BrowseAllow"))
2333 cupsdAllowIP(location
, zeros
, zeros
);
2335 cupsdDenyIP(location
, zeros
, zeros
);
2337 else if (!strcasecmp(value
, "none"))
2343 if (!strcasecmp(line
, "BrowseAllow"))
2344 cupsdAllowIP(location
, ones
, zeros
);
2346 cupsdDenyIP(location
, ones
, zeros
);
2348 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2351 * Host or domain name...
2354 if (value
[0] == '*')
2357 if (!strcasecmp(line
, "BrowseAllow"))
2358 cupsdAllowHost(location
, value
);
2360 cupsdDenyHost(location
, value
);
2365 * One of many IP address forms...
2368 if (!get_addr_and_mask(value
, ip
, mask
))
2370 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2375 if (!strcasecmp(line
, "BrowseAllow"))
2376 cupsdAllowIP(location
, ip
, mask
);
2378 cupsdDenyIP(location
, ip
, mask
);
2382 else if (!strcasecmp(line
, "BrowseRelay"))
2385 * BrowseRelay [from] source [to] destination
2389 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2391 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2395 cupsdLogMessage(CUPSD_LOG_ERROR
,
2396 "Unable to allocate BrowseRelay at line %d - %s.",
2397 linenum
, strerror(errno
));
2404 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2406 if (!strncasecmp(value
, "from ", 5))
2409 * Strip leading "from"...
2414 while (isspace(*value
))
2419 * Figure out what form the from address takes:
2428 * nnn.nnn.nnn.nnn/mm
2429 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2432 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2435 * Host or domain name...
2438 if (value
[0] == '*')
2441 strlcpy(temp
, value
, sizeof(temp
));
2442 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2445 relay
->from
.type
= AUTH_NAME
;
2446 relay
->from
.mask
.name
.name
= strdup(temp
);
2447 relay
->from
.mask
.name
.length
= strlen(temp
);
2452 * One of many IP address forms...
2455 if (!get_addr_and_mask(value
, ip
, mask
))
2457 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2462 relay
->from
.type
= AUTH_IP
;
2463 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2464 sizeof(relay
->from
.mask
.ip
.address
));
2465 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2466 sizeof(relay
->from
.mask
.ip
.netmask
));
2470 * Skip value and trailing whitespace...
2473 for (; *value
; value
++)
2474 if (isspace(*value
))
2477 while (isspace(*value
))
2480 if (!strncasecmp(value
, "to ", 3))
2483 * Strip leading "to"...
2488 while (isspace(*value
))
2493 * Get "to" address and port...
2496 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2499 * Only IPv4 addresses are supported...
2502 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2503 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2508 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2510 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2512 if (relay
->from
.type
== AUTH_IP
)
2513 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2514 relay
->from
.mask
.ip
.address
[0],
2515 relay
->from
.mask
.ip
.address
[1],
2516 relay
->from
.mask
.ip
.address
[2],
2517 relay
->from
.mask
.ip
.address
[3],
2518 relay
->from
.mask
.ip
.netmask
[0],
2519 relay
->from
.mask
.ip
.netmask
[1],
2520 relay
->from
.mask
.ip
.netmask
[2],
2521 relay
->from
.mask
.ip
.netmask
[3]);
2523 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2525 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2526 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2531 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2534 httpAddrFreeList(addrlist
);
2538 if (relay
->from
.type
== AUTH_NAME
)
2539 free(relay
->from
.mask
.name
.name
);
2541 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2545 else if (!strcasecmp(line
, "BrowsePoll"))
2548 * BrowsePoll address[:port]
2551 char *portname
; /* Port name */
2552 int portnum
; /* Port number */
2553 struct servent
*service
; /* Service */
2557 * Extract the port name from the address...
2560 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2564 if (isdigit(*portname
& 255))
2565 portnum
= atoi(portname
);
2566 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2567 portnum
= ntohs(service
->s_port
);
2570 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2576 portnum
= ippPort();
2579 * Add the poll entry...
2583 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2585 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2589 cupsdLogMessage(CUPSD_LOG_ERROR
,
2590 "Unable to allocate BrowsePoll at line %d - %s.",
2591 linenum
, strerror(errno
));
2599 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2601 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2602 pollp
->port
= portnum
;
2604 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2607 else if (!strcasecmp(line
, "DefaultAuthType"))
2610 * DefaultAuthType {basic,digest,basicdigest}
2613 if (!strcasecmp(value
, "basic"))
2614 DefaultAuthType
= AUTH_BASIC
;
2615 else if (!strcasecmp(value
, "digest"))
2616 DefaultAuthType
= AUTH_DIGEST
;
2617 else if (!strcasecmp(value
, "basicdigest"))
2618 DefaultAuthType
= AUTH_BASICDIGEST
;
2621 cupsdLogMessage(CUPSD_LOG_WARN
,
2622 "Unknown default authorization type %s on line %d.",
2627 else if (!strcasecmp(line
, "User"))
2630 * User ID to run as...
2633 if (value
&& isdigit(value
[0] & 255))
2635 int uid
= atoi(value
);
2638 cupsdLogMessage(CUPSD_LOG_ERROR
,
2639 "Will not use User 0 as specified on line %d "
2640 "for security reasons. You must use a non-"
2641 "privileged account instead.",
2648 struct passwd
*p
; /* Password information */
2651 p
= getpwnam(value
);
2656 cupsdLogMessage(CUPSD_LOG_ERROR
,
2657 "Will not use User %s (UID=0) as specified on line "
2658 "%d for security reasons. You must use a non-"
2659 "privileged account instead.",
2665 cupsdLogMessage(CUPSD_LOG_ERROR
,
2666 "Unknown User \"%s\" on line %d, ignoring!",
2670 cupsdLogMessage(CUPSD_LOG_ERROR
,
2671 "User directive on line %d missing the username!",
2674 else if (!strcasecmp(line
, "Group"))
2677 * Group ID to run as...
2680 if (isdigit(value
[0]))
2681 Group
= atoi(value
);
2685 group
= getgrnam(value
);
2688 Group
= group
->gr_gid
;
2690 cupsdLogMessage(CUPSD_LOG_ERROR
,
2691 "Unknown Group \"%s\" on line %d, ignoring!",
2695 else if (!strcasecmp(line
, "SystemGroup"))
2698 * SystemGroup (admin) group(s)...
2701 if (!parse_groups(value
))
2702 cupsdLogMessage(CUPSD_LOG_ERROR
,
2703 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2706 else if (!strcasecmp(line
, "HostNameLookups"))
2709 * Do hostname lookups?
2712 if (!strcasecmp(value
, "off"))
2713 HostNameLookups
= 0;
2714 else if (!strcasecmp(value
, "on"))
2715 HostNameLookups
= 1;
2716 else if (!strcasecmp(value
, "double"))
2717 HostNameLookups
= 2;
2719 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2722 else if (!strcasecmp(line
, "LogLevel"))
2725 * Amount of logging to do...
2728 if (!strcasecmp(value
, "debug2"))
2729 LogLevel
= CUPSD_LOG_DEBUG2
;
2730 else if (!strcasecmp(value
, "debug"))
2731 LogLevel
= CUPSD_LOG_DEBUG
;
2732 else if (!strcasecmp(value
, "info"))
2733 LogLevel
= CUPSD_LOG_INFO
;
2734 else if (!strcasecmp(value
, "notice"))
2735 LogLevel
= CUPSD_LOG_NOTICE
;
2736 else if (!strcasecmp(value
, "warn"))
2737 LogLevel
= CUPSD_LOG_WARN
;
2738 else if (!strcasecmp(value
, "error"))
2739 LogLevel
= CUPSD_LOG_ERROR
;
2740 else if (!strcasecmp(value
, "crit"))
2741 LogLevel
= CUPSD_LOG_CRIT
;
2742 else if (!strcasecmp(value
, "alert"))
2743 LogLevel
= CUPSD_LOG_ALERT
;
2744 else if (!strcasecmp(value
, "emerg"))
2745 LogLevel
= CUPSD_LOG_EMERG
;
2746 else if (!strcasecmp(value
, "none"))
2747 LogLevel
= CUPSD_LOG_NONE
;
2749 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2752 else if (!strcasecmp(line
, "PrintcapFormat"))
2755 * Format of printcap file?
2758 if (!strcasecmp(value
, "bsd"))
2759 PrintcapFormat
= PRINTCAP_BSD
;
2760 else if (!strcasecmp(value
, "solaris"))
2761 PrintcapFormat
= PRINTCAP_SOLARIS
;
2763 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2766 else if (!strcasecmp(line
, "ServerTokens"))
2769 * Set the string used for the Server header...
2772 struct utsname plat
; /* Platform info */
2777 if (!strcasecmp(value
, "ProductOnly"))
2778 cupsdSetString(&ServerHeader
, "CUPS");
2779 else if (!strcasecmp(value
, "Major"))
2780 cupsdSetString(&ServerHeader
, "CUPS/1");
2781 else if (!strcasecmp(value
, "Minor"))
2782 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2783 else if (!strcasecmp(value
, "Minimal"))
2784 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2785 else if (!strcasecmp(value
, "OS"))
2786 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2787 else if (!strcasecmp(value
, "Full"))
2788 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2790 else if (!strcasecmp(value
, "None"))
2791 cupsdClearString(&ServerHeader
);
2793 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2796 else if (!strcasecmp(line
, "PassEnv"))
2799 * PassEnv variable [... variable]
2804 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2805 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2808 if (value
[valuelen
])
2810 value
[valuelen
] = '\0';
2814 cupsdSetEnv(value
, NULL
);
2816 for (value
+= valuelen
; *value
; value
++)
2817 if (!isspace(*value
) || *value
!= ',')
2821 else if (!strcasecmp(line
, "SetEnv"))
2824 * SetEnv variable value
2827 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2835 while (isspace(*valueptr
& 255))
2838 cupsdSetEnv(value
, valueptr
);
2841 cupsdLogMessage(CUPSD_LOG_ERROR
,
2842 "Missing value for SetEnv directive on line %d.",
2848 * Find a simple variable in the list...
2851 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2852 if (!strcasecmp(line
, var
->name
))
2858 * Unknown directive! Output an error message and continue...
2861 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2868 case CUPSD_VARTYPE_INTEGER
:
2871 char *units
; /* Units */
2874 n
= strtol(value
, &units
, 0);
2876 if (units
&& *units
)
2878 if (tolower(units
[0] & 255) == 'g')
2879 n
*= 1024 * 1024 * 1024;
2880 else if (tolower(units
[0] & 255) == 'm')
2882 else if (tolower(units
[0] & 255) == 'k')
2884 else if (tolower(units
[0] & 255) == 't')
2888 *((int *)var
->ptr
) = n
;
2892 case CUPSD_VARTYPE_BOOLEAN
:
2893 if (!strcasecmp(value
, "true") ||
2894 !strcasecmp(value
, "on") ||
2895 !strcasecmp(value
, "enabled") ||
2896 !strcasecmp(value
, "yes") ||
2898 *((int *)var
->ptr
) = TRUE
;
2899 else if (!strcasecmp(value
, "false") ||
2900 !strcasecmp(value
, "off") ||
2901 !strcasecmp(value
, "disabled") ||
2902 !strcasecmp(value
, "no") ||
2903 !strcasecmp(value
, "0"))
2904 *((int *)var
->ptr
) = FALSE
;
2906 cupsdLogMessage(CUPSD_LOG_ERROR
,
2907 "Unknown boolean value %s on line %d.",
2911 case CUPSD_VARTYPE_STRING
:
2912 cupsdSetString((char **)var
->ptr
, value
);
2923 * 'read_location()' - Read a <Location path> definition.
2926 static int /* O - New line number or 0 on error */
2927 read_location(cups_file_t
*fp
, /* I - Configuration file */
2928 char *location
, /* I - Location name/path */
2929 int linenum
) /* I - Current line number */
2931 cupsd_location_t
*loc
, /* New location */
2932 *parent
; /* Parent location */
2933 char line
[HTTP_MAX_BUFFER
],
2935 *value
, /* Value for directive */
2936 *valptr
; /* Pointer into value */
2939 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2942 parent
->limit
= AUTH_LIMIT_ALL
;
2945 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2948 * Decode the directive...
2951 if (!strcasecmp(line
, "</Location>"))
2953 else if (!strcasecmp(line
, "<Limit") ||
2954 !strcasecmp(line
, "<LimitExcept"))
2958 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2962 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2968 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2973 if (!strcmp(value
, "ALL"))
2974 loc
->limit
= AUTH_LIMIT_ALL
;
2975 else if (!strcmp(value
, "GET"))
2976 loc
->limit
|= AUTH_LIMIT_GET
;
2977 else if (!strcmp(value
, "HEAD"))
2978 loc
->limit
|= AUTH_LIMIT_HEAD
;
2979 else if (!strcmp(value
, "OPTIONS"))
2980 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2981 else if (!strcmp(value
, "POST"))
2982 loc
->limit
|= AUTH_LIMIT_POST
;
2983 else if (!strcmp(value
, "PUT"))
2984 loc
->limit
|= AUTH_LIMIT_PUT
;
2985 else if (!strcmp(value
, "TRACE"))
2986 loc
->limit
|= AUTH_LIMIT_TRACE
;
2988 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2991 for (value
= valptr
; isspace(*value
& 255); value
++);
2994 if (!strcasecmp(line
, "<LimitExcept"))
2995 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2997 parent
->limit
&= ~loc
->limit
;
2999 else if (!strcasecmp(line
, "</Limit>"))
3001 else if (!parse_aaa(loc
, line
, value
, linenum
))
3003 cupsdLogMessage(CUPSD_LOG_ERROR
,
3004 "Unknown Location directive %s on line %d.",
3010 cupsdLogMessage(CUPSD_LOG_ERROR
,
3011 "Unexpected end-of-file at line %d while reading location!",
3019 * 'read_policy()' - Read a <Policy name> definition.
3022 static int /* O - New line number or 0 on error */
3023 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3024 char *policy
, /* I - Location name/path */
3025 int linenum
) /* I - Current line number */
3027 int i
; /* Looping var */
3028 cupsd_policy_t
*pol
; /* Policy */
3029 cupsd_location_t
*op
; /* Policy operation */
3030 int num_ops
; /* Number of IPP operations */
3031 ipp_op_t ops
[100]; /* Operations */
3032 char line
[HTTP_MAX_BUFFER
],
3034 *value
, /* Value for directive */
3035 *valptr
; /* Pointer into value */
3039 * Create the policy...
3042 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3046 * Read from the file...
3052 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3055 * Decode the directive...
3058 if (!strcasecmp(line
, "</Policy>"))
3061 cupsdLogMessage(CUPSD_LOG_WARN
,
3062 "Missing </Limit> before </Policy> on line %d!",
3067 else if (!strcasecmp(line
, "<Limit") && !op
)
3071 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3076 * Scan for IPP operation names...
3083 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3088 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3090 if (!strcasecmp(value
, "All"))
3091 ops
[num_ops
] = IPP_ANY_OPERATION
;
3092 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3093 cupsdLogMessage(CUPSD_LOG_ERROR
,
3094 "Bad IPP operation name \"%s\" on line %d!",
3100 cupsdLogMessage(CUPSD_LOG_ERROR
,
3101 "Too many operations listed on line %d!",
3104 for (value
= valptr
; isspace(*value
& 255); value
++);
3108 * If none are specified, apply the policy to all operations...
3113 ops
[0] = IPP_ANY_OPERATION
;
3118 * Add a new policy for the first operation...
3121 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3123 else if (!strcasecmp(line
, "</Limit>") && op
)
3126 * Finish the current operation limit...
3132 * Copy the policy to the other operations...
3135 for (i
= 1; i
< num_ops
; i
++)
3136 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3143 cupsdLogMessage(CUPSD_LOG_ERROR
,
3144 "Missing <Limit ops> directive before %s on line %d.",
3148 else if (!parse_aaa(op
, line
, value
, linenum
))
3151 cupsdLogMessage(CUPSD_LOG_ERROR
,
3152 "Unknown Policy Limit directive %s on line %d.",
3155 cupsdLogMessage(CUPSD_LOG_ERROR
,
3156 "Unknown Policy directive %s on line %d.",
3163 cupsdLogMessage(CUPSD_LOG_ERROR
,
3164 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3172 * End of "$Id: conf.c 5116 2006-02-16 12:52:32Z mike $".