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 cupsdDeleteAllListeners();
262 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
263 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
264 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
265 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
266 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
267 cupsdSetString(&DataDir
, CUPS_DATADIR
);
268 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
269 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
270 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
271 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
272 cupsdSetString(&Printcap
, "/etc/printcap");
273 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
274 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
275 cupsdSetString(&RemoteRoot
, "remroot");
276 cupsdSetString(&ServerHeader
, "CUPS/1.1");
277 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
279 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
280 if ((slash
= strrchr(temp
, '/')) != NULL
)
283 cupsdSetString(&ServerRoot
, temp
);
285 cupsdClearString(&Classification
);
286 ClassifyOverride
= 0;
290 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
292 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
293 cupsdSetString(&ServerKey
, "ssl/server.key");
294 # endif /* HAVE_CDSASSL */
295 #endif /* HAVE_SSL */
297 language
= cupsLangDefault();
299 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
300 cupsdSetString(&DefaultLanguage
, "en");
302 cupsdSetString(&DefaultLanguage
, language
->language
);
304 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
306 cupsdSetString(&RIPCache
, "8m");
308 if (getenv("TMPDIR") == NULL
)
309 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
311 cupsdSetString(&TempDir
, getenv("TMPDIR"));
314 * Find the default system group: "sys", "system", or "root"...
317 group
= getgrnam(CUPS_DEFAULT_GROUP
);
325 * Found the group, use it!
328 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
330 SystemGroupIDs
[0] = group
->gr_gid
;
335 * Find the group associated with GID 0...
342 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
344 cupsdSetString(&SystemGroups
[0], "unknown");
346 SystemGroupIDs
[0] = 0;
350 * Find the default user...
353 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
358 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
359 * complement number...)
368 * Find the default group (nobody)...
371 group
= getgrnam("nobody");
375 Group
= group
->gr_gid
;
379 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
380 * complement number...)
390 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
391 DefaultAuthType
= AUTH_BASIC
;
393 JobRetryInterval
= 300;
398 HostNameLookups
= FALSE
;
399 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
400 ImplicitAnyClasses
= FALSE
;
401 HideImplicitMembers
= TRUE
;
403 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
404 ListenBackLog
= SOMAXCONN
;
405 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
406 LogLevel
= CUPSD_LOG_ERROR
;
408 MaxClientsPerHost
= 0;
409 MaxLogSize
= 1024 * 1024;
410 MaxPrinterHistory
= 10;
413 RootCertDuration
= 300;
415 Timeout
= DEFAULT_TIMEOUT
;
417 BrowseInterval
= DEFAULT_INTERVAL
;
418 BrowsePort
= ippPort();
419 BrowseLocalProtocols
= BROWSE_CUPS
; /* TODO: Use configure option */
420 BrowseRemoteProtocols
= BROWSE_CUPS
; /* TODO: Use configure option */
421 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
422 BrowseTimeout
= DEFAULT_TIMEOUT
;
423 Browsing
= CUPS_DEFAULT_BROWSING
;
424 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
426 cupsdClearString(&BrowseLocalOptions
);
427 cupsdClearString(&BrowseRemoteOptions
);
429 JobHistory
= DEFAULT_HISTORY
;
430 JobFiles
= DEFAULT_FILES
;
435 MaxJobsPerPrinter
= 0;
438 cupsdDeleteAllPolicies();
439 cupsdClearString(&DefaultPolicy
);
441 MaxSubscriptions
= 100;
442 MaxSubscriptionsPerJob
= 0;
443 MaxSubscriptionsPerPrinter
= 0;
444 MaxSubscriptionsPerUser
= 0;
445 DefaultLeaseDuration
= 86400;
446 MaxLeaseDuration
= 0;
449 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
450 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
451 #endif /* HAVE_LAUNCHD */
454 * Read the configuration file...
457 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
460 status
= read_configuration(fp
);
473 * Use the default system group if none was supplied in cupsd.conf...
476 if (NumSystemGroups
== 0)
480 * Get the access control list for browsing...
483 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
486 * Open the system log for cupsd if necessary...
490 if (!strcmp(AccessLog
, "syslog") ||
491 !strcmp(ErrorLog
, "syslog") ||
492 !strcmp(PageLog
, "syslog"))
493 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
494 #endif /* HAVE_VSYSLOG */
497 * Log the configuration file that was used...
500 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
504 * Validate the Group and SystemGroup settings - they cannot be the same,
505 * otherwise the CGI programs will be able to authenticate as root without
511 for (i
= 0; i
< NumSystemGroups
; i
++)
512 if (Group
== SystemGroupIDs
[i
])
515 if (i
< NumSystemGroups
)
518 * Log the error and reset the group to a safe value...
521 cupsdLogMessage(CUPSD_LOG_NOTICE
,
522 "Group and SystemGroup cannot use the same groups!");
523 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
525 group
= getgrnam("nobody");
529 Group
= group
->gr_gid
;
533 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
534 * complement number...)
543 * Check that we have at least one listen/port line; if not, report this
544 * as an error and exit!
547 if (cupsArrayCount(Listeners
) == 0)
553 cupsdLogMessage(CUPSD_LOG_EMERG
,
554 "No valid Listen or Port lines were found in the configuration file!");
560 cupsdEndProcess(getpid(), 0);
564 * Set the default locale using the language and charset...
567 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
570 * Update all relative filenames to include the full path from ServerRoot...
573 if (DocumentRoot
[0] != '/')
574 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
576 if (RequestRoot
[0] != '/')
577 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
579 if (ServerBin
[0] != '/')
580 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
582 if (StateDir
[0] != '/')
583 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
585 if (CacheDir
[0] != '/')
586 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
589 if (ServerCertificate
[0] != '/')
590 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
592 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
594 chown(ServerCertificate
, RunUser
, Group
);
595 chmod(ServerCertificate
, 0600);
598 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
599 if (ServerKey
[0] != '/')
600 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
602 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
604 chown(ServerKey
, RunUser
, Group
);
605 chmod(ServerKey
, 0600);
607 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
608 #endif /* HAVE_SSL */
611 * Make sure that directories and config files are owned and
612 * writable by the user and group in the cupsd.conf file...
615 check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1);
616 check_permissions(CacheDir
, "ppd", 0755, RunUser
, Group
, 1, 1);
618 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1);
619 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
620 SystemGroupIDs
[0], 1, 1);
622 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0);
623 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1);
624 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0);
625 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
, Group
,
627 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
, 0, 0);
628 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
, 0, 0);
629 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0);
632 * Make sure the request and temporary directories have the right
636 check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1);
638 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
642 * Update ownership and permissions if the CUPS temp directory
643 * is under the spool directory or does not exist...
646 check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1);
649 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
652 * Clean out the temporary directory...
655 cups_dir_t
*dir
; /* Temporary directory */
656 cups_dentry_t
*dent
; /* Directory entry */
657 char tempfile
[1024]; /* Temporary filename */
660 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
662 cupsdLogMessage(CUPSD_LOG_INFO
,
663 "Cleaning out old temporary files in \"%s\"...", TempDir
);
665 while ((dent
= cupsDirRead(dir
)) != NULL
)
667 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
669 if (unlink(tempfile
))
670 cupsdLogMessage(CUPSD_LOG_ERROR
,
671 "Unable to remove temporary file \"%s\" - %s",
672 tempfile
, strerror(errno
));
674 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
681 cupsdLogMessage(CUPSD_LOG_ERROR
,
682 "Unable to open temporary directory \"%s\" - %s",
683 TempDir
, strerror(errno
));
687 * Setup environment variables...
693 * Check the MaxClients setting, and then allocate memory for it...
696 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
699 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
702 MaxClients
= MaxFDs
/ 3;
705 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
709 * Check the MaxActiveJobs setting; limit to 1/3 the available
710 * file descriptors, since we need a pipe for each job...
713 if (MaxActiveJobs
> (MaxFDs
/ 3))
714 MaxActiveJobs
= MaxFDs
/ 3;
716 if (Classification
&& strcasecmp(Classification
, "none") == 0)
717 cupsdClearString(&Classification
);
720 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
723 * Update the MaxClientsPerHost value, as needed...
726 if (MaxClientsPerHost
<= 0)
727 MaxClientsPerHost
= MaxClients
;
729 if (MaxClientsPerHost
> MaxClients
)
730 MaxClientsPerHost
= MaxClients
;
732 cupsdLogMessage(CUPSD_LOG_INFO
,
733 "Allowing up to %d client connections per host.",
737 * Update the default policy, as needed...
741 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
743 DefaultPolicyPtr
= NULL
;
745 if (!DefaultPolicyPtr
)
747 cupsd_policy_t
*p
; /* New policy */
748 cupsd_location_t
*po
; /* New policy operation */
752 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
755 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
756 cupsdLogMessage(CUPSD_LOG_INFO
,
757 "Using policy \"default\" as the default!");
760 cupsdLogMessage(CUPSD_LOG_INFO
,
761 "Creating CUPS default administrative policy:");
763 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
765 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
766 cupsdLogMessage(CUPSD_LOG_INFO
,
767 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
768 "Release-Job Restart-Job Purge-Jobs "
769 "Set-Job-Attributes Create-Job-Subscription "
770 "Renew-Subscription Cancel-Subscription "
771 "Get-Notifications Reprocess-Job Cancel-Current-Job "
772 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
773 "CUPS-Authenticate-Job>");
774 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
776 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
777 po
->order_type
= AUTH_ALLOW
;
778 po
->level
= AUTH_USER
;
780 cupsdAddName(po
, "@OWNER");
781 cupsdAddName(po
, "@SYSTEM");
782 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
784 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
785 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
786 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
787 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
788 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
789 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
790 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
791 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
792 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
793 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
794 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
795 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
796 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
797 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
798 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
799 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
800 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
802 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
804 cupsdLogMessage(CUPSD_LOG_INFO
,
805 "<Limit Pause-Printer Resume-Printer "
806 "Set-Printer-Attributes Enable-Printer "
807 "Disable-Printer Pause-Printer-After-Current-Job "
808 "Hold-New-Jobs Release-Held-New-Jobs "
809 "Deactivate-Printer Activate-Printer Restart-Printer "
810 "Shutdown-Printer Startup-Printer Promote-Job "
811 "Schedule-Job-After CUPS-Add-Printer "
812 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
813 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
814 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
815 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
817 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
818 po
->order_type
= AUTH_ALLOW
;
819 po
->type
= AUTH_BASIC
;
820 po
->level
= AUTH_USER
;
822 cupsdAddName(po
, "@SYSTEM");
823 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
825 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
826 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
827 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
828 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
829 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
830 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
831 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
832 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
833 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
834 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
835 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
836 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
837 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
838 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
839 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
840 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
841 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
842 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
843 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
844 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
845 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
847 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
849 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
850 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
852 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
853 po
->order_type
= AUTH_ALLOW
;
855 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
856 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
860 cupsdLogMessage(CUPSD_LOG_DEBUG
,"NumPolicies=%d", NumPolicies
);
861 for (i
= 0; i
< NumPolicies
; i
++)
862 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Policies[%d]=\"%s\"", i
,
866 * If we are doing a full reload or the server root has changed, flush
867 * the jobs, printers, etc. and start from scratch...
870 if (NeedReload
== RELOAD_ALL
||
871 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
872 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
874 mime_type_t
*type
; /* Current type */
875 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
879 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
885 cupsdDeleteAllSubscriptions();
887 cupsdDeleteAllClasses();
888 cupsdDeleteAllPrinters();
890 DefaultPrinter
= NULL
;
892 if (MimeDatabase
!= NULL
)
893 mimeDelete(MimeDatabase
);
897 for (i
= 0; i
< NumMimeTypes
; i
++)
898 free((void *)MimeTypes
[i
]);
904 * Read the MIME type and conversion database...
907 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
909 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
913 cupsdLogMessage(CUPSD_LOG_EMERG
,
914 "Unable to load MIME database from \'%s\'!", ServerRoot
);
918 cupsdLogMessage(CUPSD_LOG_INFO
,
919 "Loaded MIME database from \'%s\': %d types, %d filters...",
920 ServerRoot
, mimeNumTypes(MimeDatabase
),
921 mimeNumFilters(MimeDatabase
));
924 * Create a list of MIME types for the document-format-supported
928 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
929 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
932 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
934 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
936 i
++, type
= mimeNextType(MimeDatabase
))
938 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
940 MimeTypes
[i
] = strdup(mimetype
);
943 if (i
< NumMimeTypes
)
944 MimeTypes
[i
] = strdup("application/octet-stream");
950 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
951 cupsdLoadBanners(temp
);
954 * Load printers and classes...
957 cupsdLoadAllPrinters();
958 cupsdLoadAllClasses();
959 cupsdLoadRemoteCache();
960 cupsdWritePrintcap();
962 cupsdCreateCommonData();
965 * Load queued jobs...
971 * Load subscriptions...
974 cupsdLoadAllSubscriptions();
976 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
981 * Not a full reload, so recreate the common printer attributes...
984 cupsdCreateCommonData();
987 * Update all printers as needed...
990 cupsdUpdatePrinters();
991 cupsdWritePrintcap();
993 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
997 * Reset the reload state...
1000 NeedReload
= RELOAD_NONE
;
1002 cupsdClearString(&old_serverroot
);
1003 cupsdClearString(&old_requestroot
);
1010 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1013 static int /* O - 0 on success, -1 on error */
1014 check_permissions(const char *filename
, /* I - File/directory name */
1015 const char *suffix
, /* I - Additional file/directory name */
1016 int mode
, /* I - Permissions */
1017 int user
, /* I - Owner */
1018 int group
, /* I - Group */
1019 int is_dir
, /* I - 1 = directory, 0 = file */
1020 int create_dir
)/* I - 1 = create directory, 0 = not */
1022 int dir_created
= 0; /* Did we create a directory? */
1023 char pathname
[1024]; /* File name with prefix */
1024 struct stat fileinfo
; /* Stat buffer */
1028 * Prepend the given root to the filename before testing it...
1033 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1034 filename
= pathname
;
1038 * See if we can stat the file/directory...
1041 if (stat(filename
, &fileinfo
))
1043 if (errno
== ENOENT
&& create_dir
)
1045 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1048 if (mkdir(filename
, mode
))
1050 cupsdLogMessage(CUPSD_LOG_ERROR
,
1051 "Unable to create directory \"%s\" - %s", filename
,
1063 * Make sure it's a regular file...
1066 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1068 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1072 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1074 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1079 * Fix owner, group, and mode as needed...
1082 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1084 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1086 if (chown(filename
, user
, group
))
1088 cupsdLogMessage(CUPSD_LOG_ERROR
,
1089 "Unable to change ownership of \"%s\" - %s", filename
,
1095 if (dir_created
|| (fileinfo
.st_mode
& 0777) != mode
)
1097 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1099 if (chmod(filename
, mode
))
1101 cupsdLogMessage(CUPSD_LOG_ERROR
,
1102 "Unable to change permissions of \"%s\" - %s", filename
,
1109 * Everything is OK...
1117 * 'get_address()' - Get an address + port number from a line.
1120 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1121 get_address(const char *value
, /* I - Value string */
1122 int defport
) /* I - Default port */
1124 char buffer
[1024], /* Hostname + port number buffer */
1125 defpname
[255], /* Default port name */
1126 *hostname
, /* Hostname or IP */
1127 *portname
; /* Port number or name */
1128 http_addrlist_t
*addrlist
; /* Address list */
1132 * Check for an empty value...
1137 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1142 * Grab a hostname and port number; if there is no colon and the port name
1143 * is only digits, then we have a port number by itself...
1146 strlcpy(buffer
, value
, sizeof(buffer
));
1148 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1155 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1160 * Use the default port...
1163 sprintf(defpname
, "%d", defport
);
1164 portname
= defpname
;
1170 * The buffer contains just a port number...
1178 if (hostname
&& !strcmp(hostname
, "*"))
1182 * Now lookup the address using httpAddrGetList()...
1185 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1186 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1187 hostname
? hostname
: "(nil)");
1194 * 'get_addr_and_mask()' - Get an IP address and netmask.
1197 static int /* O - 1 on success, 0 on failure */
1198 get_addr_and_mask(const char *value
, /* I - String from config file */
1199 unsigned *ip
, /* O - Address value */
1200 unsigned *mask
) /* O - Mask value */
1202 int i
, j
, /* Looping vars */
1203 family
, /* Address family */
1204 ipcount
; /* Count of fields in address */
1205 unsigned ipval
; /* Value */
1206 const char *maskval
, /* Pointer to start of mask value */
1207 *ptr
, /* Pointer into value */
1209 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1211 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1212 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1213 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1214 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1217 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1219 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1220 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1221 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1222 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1223 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1224 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1225 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1226 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1228 #endif /* AF_INET6 */
1232 * Get the address...
1235 memset(ip
, 0, sizeof(unsigned) * 4);
1237 if ((maskval
= strchr(value
, '/')) != NULL
)
1240 maskval
= value
+ strlen(value
);
1244 * Check for an IPv6 address...
1250 * Parse hexadecimal IPv6 address...
1255 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1259 else if (!strncmp(ptr
, "::", 2))
1261 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1263 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1267 else if (isxdigit(*ptr
& 255))
1269 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1277 ip
[i
] |= ipval
<< 16;
1288 if (*ptr
&& *ptr
!= '/')
1292 #endif /* AF_INET6 */
1295 * Parse dotted-decimal IPv4 address...
1299 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1301 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1302 ip
[0] = ip
[1] = ip
[2] = 0;
1308 * Get the netmask value(s)...
1311 memset(mask
, 0, sizeof(unsigned) * 4);
1314 if (*maskval
== '[')
1317 * Get hexadecimal mask value...
1320 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1324 else if (!strncmp(ptr
, "::", 2))
1326 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1328 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1332 else if (isxdigit(*ptr
& 255))
1334 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1342 mask
[i
] |= ipval
<< 16;
1355 #endif /* AF_INET6 */
1356 if (strchr(maskval
, '.'))
1359 * Get dotted-decimal mask...
1362 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1365 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1366 mask
[0] = mask
[1] = mask
[2] = 0;
1371 * Get address/bits format...
1377 if (family
== AF_INET6
)
1382 mask
[0] = 0xffffffff;
1384 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1387 mask
[1] = 0xffffffff;
1391 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1394 mask
[2] = 0xffffffff;
1398 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1401 mask
[3] = 0xffffffff;
1405 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1408 #endif /* AF_INET6 */
1412 mask
[0] = 0xffffffff;
1413 mask
[1] = 0xffffffff;
1414 mask
[2] = 0xffffffff;
1417 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1419 mask
[3] = 0xffffffff;
1424 else if (family
== AF_INET6
)
1425 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1426 #endif /* AF_INET6 */
1428 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1430 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1431 "get_addr_and_mask(value=\"%s\", "
1432 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1433 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1437 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1440 if ((ip
[0] & ~mask
[0]) != 0 ||
1441 (ip
[1] & ~mask
[1]) != 0 ||
1442 (ip
[2] & ~mask
[2]) != 0 ||
1443 (ip
[3] & ~mask
[3]) != 0)
1451 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1454 static int /* O - 1 on success, 0 on failure */
1455 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1456 char *line
, /* I - Line from file */
1457 char *value
, /* I - Start of value data */
1458 int linenum
) /* I - Current line number */
1460 char *valptr
; /* Pointer into value */
1461 unsigned ip
[4], /* IP address components */
1462 mask
[4]; /* IP netmask components */
1465 if (!strcasecmp(line
, "Encryption"))
1468 * "Encryption xxx" - set required encryption level...
1471 if (!strcasecmp(value
, "never"))
1472 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1473 else if (!strcasecmp(value
, "always"))
1475 cupsdLogMessage(CUPSD_LOG_ERROR
,
1476 "Encryption value \"%s\" on line %d is invalid in this "
1477 "context. Using \"required\" instead.", value
, linenum
);
1479 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1481 else if (!strcasecmp(value
, "required"))
1482 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1483 else if (!strcasecmp(value
, "ifrequested"))
1484 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1487 cupsdLogMessage(CUPSD_LOG_ERROR
,
1488 "Unknown Encryption value %s on line %d.", value
, linenum
);
1492 else if (!strcasecmp(line
, "Order"))
1495 * "Order Deny,Allow" or "Order Allow,Deny"...
1498 if (!strncasecmp(value
, "deny", 4))
1499 loc
->order_type
= AUTH_ALLOW
;
1500 else if (!strncasecmp(value
, "allow", 5))
1501 loc
->order_type
= AUTH_DENY
;
1504 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1509 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1512 * Allow [From] host/ip...
1513 * Deny [From] host/ip...
1516 if (!strncasecmp(value
, "from", 4))
1519 * Strip leading "from"...
1524 while (isspace(*value
& 255))
1529 * Figure out what form the allow/deny address takes:
1540 * nnn.nnn.nnn.nnn/mm
1541 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1544 if (!strcasecmp(value
, "all"))
1550 if (!strcasecmp(line
, "Allow"))
1551 cupsdAllowIP(loc
, zeros
, zeros
);
1553 cupsdDenyIP(loc
, zeros
, zeros
);
1555 else if (!strcasecmp(value
, "none"))
1561 if (!strcasecmp(line
, "Allow"))
1562 cupsdAllowIP(loc
, ones
, zeros
);
1564 cupsdDenyIP(loc
, ones
, zeros
);
1566 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1569 * Host or domain name...
1572 if (value
[0] == '*')
1575 if (!strcasecmp(line
, "Allow"))
1576 cupsdAllowHost(loc
, value
);
1578 cupsdDenyHost(loc
, value
);
1583 * One of many IP address forms...
1586 if (!get_addr_and_mask(value
, ip
, mask
))
1588 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1593 if (!strcasecmp(line
, "Allow"))
1594 cupsdAllowIP(loc
, ip
, mask
);
1596 cupsdDenyIP(loc
, ip
, mask
);
1599 else if (!strcasecmp(line
, "AuthType"))
1602 * AuthType {none,basic,digest,basicdigest}
1605 if (!strcasecmp(value
, "none"))
1607 loc
->type
= AUTH_NONE
;
1608 loc
->level
= AUTH_ANON
;
1610 else if (!strcasecmp(value
, "basic"))
1612 loc
->type
= AUTH_BASIC
;
1614 if (loc
->level
== AUTH_ANON
)
1615 loc
->level
= AUTH_USER
;
1617 else if (!strcasecmp(value
, "digest"))
1619 loc
->type
= AUTH_DIGEST
;
1621 if (loc
->level
== AUTH_ANON
)
1622 loc
->level
= AUTH_USER
;
1624 else if (!strcasecmp(value
, "basicdigest"))
1626 loc
->type
= AUTH_BASICDIGEST
;
1628 if (loc
->level
== AUTH_ANON
)
1629 loc
->level
= AUTH_USER
;
1633 cupsdLogMessage(CUPSD_LOG_WARN
,
1634 "Unknown authorization type %s on line %d.",
1639 else if (!strcasecmp(line
, "AuthClass"))
1642 * AuthClass anonymous, user, system, group
1645 if (!strcasecmp(value
, "anonymous"))
1647 loc
->type
= AUTH_NONE
;
1648 loc
->level
= AUTH_ANON
;
1650 cupsdLogMessage(CUPSD_LOG_WARN
,
1651 "\"AuthClass %s\" is deprecated; consider removing "
1655 else if (!strcasecmp(value
, "user"))
1657 loc
->level
= AUTH_USER
;
1659 cupsdLogMessage(CUPSD_LOG_WARN
,
1660 "\"AuthClass %s\" is deprecated; consider using "
1661 "\"Require valid-user\" on line %d.",
1664 else if (!strcasecmp(value
, "group"))
1666 loc
->level
= AUTH_GROUP
;
1668 cupsdLogMessage(CUPSD_LOG_WARN
,
1669 "\"AuthClass %s\" is deprecated; consider using "
1670 "\"Require @groupname\" on line %d.",
1673 else if (!strcasecmp(value
, "system"))
1675 loc
->level
= AUTH_GROUP
;
1677 cupsdAddName(loc
, "@SYSTEM");
1679 cupsdLogMessage(CUPSD_LOG_WARN
,
1680 "\"AuthClass %s\" is deprecated; consider using "
1681 "\"Require @SYSTEM\" on line %d.",
1686 cupsdLogMessage(CUPSD_LOG_WARN
,
1687 "Unknown authorization class %s on line %d.",
1692 else if (!strcasecmp(line
, "AuthGroupName"))
1694 cupsdAddName(loc
, value
);
1696 cupsdLogMessage(CUPSD_LOG_WARN
,
1697 "\"AuthGroupName %s\" directive is deprecated; consider "
1698 "using \"Require @%s\" on line %d.",
1699 value
, value
, linenum
);
1701 else if (!strcasecmp(line
, "Require"))
1704 * Apache synonym for AuthClass and AuthGroupName...
1708 * Require valid-user
1709 * Require group names
1710 * Require user names
1713 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1718 if (!strcasecmp(value
, "valid-user") ||
1719 !strcasecmp(value
, "user"))
1720 loc
->level
= AUTH_USER
;
1721 else if (!strcasecmp(value
, "group"))
1722 loc
->level
= AUTH_GROUP
;
1725 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1731 * Get the list of names from the line...
1734 for (value
= valptr
; *value
;)
1736 while (isspace(*value
& 255))
1739 if (*value
== '\"' || *value
== '\'')
1742 * Grab quoted name...
1745 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1752 * Grab literal name.
1755 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1761 cupsdAddName(loc
, value
);
1763 for (value
= valptr
; isspace(*value
& 255); value
++);
1766 else if (!strcasecmp(line
, "Satisfy"))
1768 if (!strcasecmp(value
, "all"))
1769 loc
->satisfy
= AUTH_SATISFY_ALL
;
1770 else if (!strcasecmp(value
, "any"))
1771 loc
->satisfy
= AUTH_SATISFY_ANY
;
1774 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1787 * 'read_configuration()' - Read a configuration file.
1790 static int /* O - 1 on success, 0 on failure */
1791 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1793 int i
; /* Looping var */
1794 int linenum
; /* Current line number */
1795 char line
[HTTP_MAX_BUFFER
],
1796 /* Line from file */
1797 temp
[HTTP_MAX_BUFFER
],
1798 /* Temporary buffer for value */
1799 temp2
[HTTP_MAX_BUFFER
],
1800 /* Temporary buffer 2 for value */
1801 *ptr
, /* Pointer into line/temp */
1802 *value
, /* Pointer to value */
1803 *valueptr
, /* Pointer into value */
1804 quote
; /* Quote character */
1805 int valuelen
; /* Length of value */
1806 cupsd_var_t
*var
; /* Current variable */
1807 http_addrlist_t
*addrlist
, /* Address list */
1808 *addr
; /* Current address */
1809 unsigned ip
[4], /* Address value */
1810 mask
[4]; /* Netmask value */
1811 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1812 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1813 cupsd_location_t
*location
; /* Browse location */
1814 cups_file_t
*incfile
; /* Include file */
1815 char incname
[1024]; /* Include filename */
1816 struct group
*group
; /* Group */
1820 * Loop through each line in the file...
1825 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1828 * Decode the directive...
1831 if (!strcasecmp(line
, "Include"))
1837 if (value
[0] == '/')
1838 strlcpy(incname
, value
, sizeof(incname
));
1840 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1842 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1843 cupsdLogMessage(CUPSD_LOG_ERROR
,
1844 "Unable to include config file \"%s\" - %s",
1845 incname
, strerror(errno
));
1848 read_configuration(incfile
);
1849 cupsFileClose(incfile
);
1852 else if (!strcasecmp(line
, "<Location"))
1860 linenum
= read_location(fp
, value
, linenum
);
1866 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1871 else if (!strcasecmp(line
, "<Policy"))
1879 linenum
= read_policy(fp
, value
, linenum
);
1885 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1889 else if (!strcasecmp(line
, "FaxRetryInterval"))
1893 JobRetryInterval
= atoi(value
);
1894 cupsdLogMessage(CUPSD_LOG_WARN
,
1895 "FaxRetryInterval is deprecated; use "
1896 "JobRetryInterval on line %d.", linenum
);
1900 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1904 else if (!strcasecmp(line
, "FaxRetryLimit"))
1908 JobRetryLimit
= atoi(value
);
1909 cupsdLogMessage(CUPSD_LOG_WARN
,
1910 "FaxRetryLimit is deprecated; use "
1911 "JobRetryLimit on line %d.", linenum
);
1915 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1919 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
1921 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
1922 #endif /* HAVE_SSL */
1926 * Add listening address(es) to the list...
1929 cupsd_listener_t
*lis
; /* New listeners array */
1933 * Get the address list...
1936 addrlist
= get_address(value
, IPP_PORT
);
1940 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1946 * Add each address...
1949 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1952 * Allocate another listener...
1956 Listeners
= cupsArrayNew(NULL
, NULL
);
1960 cupsdLogMessage(CUPSD_LOG_ERROR
,
1961 "Unable to allocate %s at line %d - %s.",
1962 line
, linenum
, strerror(errno
));
1966 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
1968 cupsdLogMessage(CUPSD_LOG_ERROR
,
1969 "Unable to allocate %s at line %d - %s.",
1970 line
, linenum
, strerror(errno
));
1974 cupsArrayAdd(Listeners
, lis
);
1977 * Copy the current address and log it...
1980 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
1984 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1985 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1986 #endif /* HAVE_SSL */
1988 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
1991 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1992 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1993 ntohs(lis
->address
.ipv6
.sin6_port
));
1995 #endif /* AF_INET6 */
1997 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1998 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2000 #endif /* AF_LOCAL */
2001 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2002 ntohs(lis
->address
.ipv4
.sin_port
));
2009 httpAddrFreeList(addrlist
);
2011 else if (!strcasecmp(line
, "BrowseAddress"))
2014 * Add a browse address to the list...
2017 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2020 if (NumBrowsers
== 0)
2021 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2023 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2027 cupsdLogMessage(CUPSD_LOG_ERROR
,
2028 "Unable to allocate BrowseAddress at line %d - %s.",
2029 linenum
, strerror(errno
));
2034 dira
+= NumBrowsers
;
2036 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2038 if (!strcasecmp(value
, "@LOCAL"))
2041 * Send browse data to all local interfaces...
2044 strcpy(dira
->iface
, "*");
2047 else if (!strncasecmp(value
, "@IF(", 4))
2050 * Send browse data to the named interface...
2053 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2055 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2061 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2064 * Only IPv4 addresses are supported...
2067 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2068 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2073 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2074 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2076 cupsdLogMessage(CUPSD_LOG_INFO
,
2077 "Sending browsing info to %s:%d (IPv4)",
2078 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2083 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2086 httpAddrFreeList(addrlist
);
2089 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2092 else if (!strcasecmp(line
, "BrowseOrder"))
2095 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2098 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2099 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2101 if (location
== NULL
)
2102 cupsdLogMessage(CUPSD_LOG_ERROR
,
2103 "Unable to initialize browse access control list!");
2104 else if (!strncasecmp(value
, "deny", 4))
2105 location
->order_type
= AUTH_ALLOW
;
2106 else if (!strncasecmp(value
, "allow", 5))
2107 location
->order_type
= AUTH_DENY
;
2109 cupsdLogMessage(CUPSD_LOG_ERROR
,
2110 "Unknown BrowseOrder value %s on line %d.",
2113 else if (!strcasecmp(line
, "BrowseProtocols") ||
2114 !strcasecmp(line
, "BrowseLocalProtocols") ||
2115 !strcasecmp(line
, "BrowseRemoteProtocols"))
2118 * "BrowseProtocol name [... name]"
2121 if (strcasecmp(line
, "BrowseLocalProtocols"))
2122 BrowseRemoteProtocols
= 0;
2123 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2124 BrowseLocalProtocols
= 0;
2128 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2129 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2132 if (value
[valuelen
])
2134 value
[valuelen
] = '\0';
2138 if (!strcasecmp(value
, "cups"))
2140 if (strcasecmp(line
, "BrowseLocalProtocols"))
2141 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2142 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2143 BrowseLocalProtocols
|= BROWSE_CUPS
;
2145 else if (!strcasecmp(value
, "slp"))
2147 if (strcasecmp(line
, "BrowseLocalProtocols"))
2148 BrowseRemoteProtocols
|= BROWSE_SLP
;
2149 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2150 BrowseLocalProtocols
|= BROWSE_SLP
;
2152 else if (!strcasecmp(value
, "ldap"))
2154 if (strcasecmp(line
, "BrowseLocalProtocols"))
2155 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2156 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2157 BrowseLocalProtocols
|= BROWSE_LDAP
;
2159 else if (!strcasecmp(value
, "all"))
2161 if (strcasecmp(line
, "BrowseLocalProtocols"))
2162 BrowseRemoteProtocols
|= BROWSE_ALL
;
2163 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2164 BrowseLocalProtocols
|= BROWSE_ALL
;
2168 cupsdLogMessage(CUPSD_LOG_ERROR
,
2169 "Unknown browse protocol \"%s\" on line %d.",
2174 for (value
+= valuelen
; *value
; value
++)
2175 if (!isspace(*value
) || *value
!= ',')
2179 else if (!strcasecmp(line
, "BrowseAllow") ||
2180 !strcasecmp(line
, "BrowseDeny"))
2183 * BrowseAllow [From] host/ip...
2184 * BrowseDeny [From] host/ip...
2187 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2188 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2190 if (location
== NULL
)
2191 cupsdLogMessage(CUPSD_LOG_ERROR
,
2192 "Unable to initialize browse access control list!");
2195 if (!strncasecmp(value
, "from ", 5))
2198 * Strip leading "from"...
2203 while (isspace(*value
))
2208 * Figure out what form the allow/deny address takes:
2219 * nnn.nnn.nnn.nnn/mm
2220 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2223 if (!strcasecmp(value
, "all"))
2229 if (!strcasecmp(line
, "BrowseAllow"))
2230 cupsdAllowIP(location
, zeros
, zeros
);
2232 cupsdDenyIP(location
, zeros
, zeros
);
2234 else if (!strcasecmp(value
, "none"))
2240 if (!strcasecmp(line
, "BrowseAllow"))
2241 cupsdAllowIP(location
, ones
, zeros
);
2243 cupsdDenyIP(location
, ones
, zeros
);
2245 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2248 * Host or domain name...
2251 if (value
[0] == '*')
2254 if (!strcasecmp(line
, "BrowseAllow"))
2255 cupsdAllowHost(location
, value
);
2257 cupsdDenyHost(location
, value
);
2262 * One of many IP address forms...
2265 if (!get_addr_and_mask(value
, ip
, mask
))
2267 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2272 if (!strcasecmp(line
, "BrowseAllow"))
2273 cupsdAllowIP(location
, ip
, mask
);
2275 cupsdDenyIP(location
, ip
, mask
);
2279 else if (!strcasecmp(line
, "BrowseRelay"))
2282 * BrowseRelay [from] source [to] destination
2286 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2288 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2292 cupsdLogMessage(CUPSD_LOG_ERROR
,
2293 "Unable to allocate BrowseRelay at line %d - %s.",
2294 linenum
, strerror(errno
));
2301 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2303 if (!strncasecmp(value
, "from ", 5))
2306 * Strip leading "from"...
2311 while (isspace(*value
))
2316 * Figure out what form the from address takes:
2325 * nnn.nnn.nnn.nnn/mm
2326 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2329 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2332 * Host or domain name...
2335 if (value
[0] == '*')
2338 strlcpy(temp
, value
, sizeof(temp
));
2339 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2342 relay
->from
.type
= AUTH_NAME
;
2343 relay
->from
.mask
.name
.name
= strdup(temp
);
2344 relay
->from
.mask
.name
.length
= strlen(temp
);
2349 * One of many IP address forms...
2352 if (!get_addr_and_mask(value
, ip
, mask
))
2354 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2359 relay
->from
.type
= AUTH_IP
;
2360 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2361 sizeof(relay
->from
.mask
.ip
.address
));
2362 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2363 sizeof(relay
->from
.mask
.ip
.netmask
));
2367 * Skip value and trailing whitespace...
2370 for (; *value
; value
++)
2371 if (isspace(*value
))
2374 while (isspace(*value
))
2377 if (!strncasecmp(value
, "to ", 3))
2380 * Strip leading "to"...
2385 while (isspace(*value
))
2390 * Get "to" address and port...
2393 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2396 * Only IPv4 addresses are supported...
2399 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2400 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2405 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2407 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2409 if (relay
->from
.type
== AUTH_IP
)
2410 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2411 relay
->from
.mask
.ip
.address
[0],
2412 relay
->from
.mask
.ip
.address
[1],
2413 relay
->from
.mask
.ip
.address
[2],
2414 relay
->from
.mask
.ip
.address
[3],
2415 relay
->from
.mask
.ip
.netmask
[0],
2416 relay
->from
.mask
.ip
.netmask
[1],
2417 relay
->from
.mask
.ip
.netmask
[2],
2418 relay
->from
.mask
.ip
.netmask
[3]);
2420 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2422 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2423 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2428 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2431 httpAddrFreeList(addrlist
);
2435 if (relay
->from
.type
== AUTH_NAME
)
2436 free(relay
->from
.mask
.name
.name
);
2438 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2442 else if (!strcasecmp(line
, "BrowsePoll"))
2445 * BrowsePoll address[:port]
2448 char *portname
; /* Port name */
2449 int portnum
; /* Port number */
2450 struct servent
*service
; /* Service */
2454 * Extract the port name from the address...
2457 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2461 if (isdigit(*portname
& 255))
2462 portnum
= atoi(portname
);
2463 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2464 portnum
= ntohs(service
->s_port
);
2467 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2473 portnum
= ippPort();
2476 * Add the poll entry...
2480 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2482 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2486 cupsdLogMessage(CUPSD_LOG_ERROR
,
2487 "Unable to allocate BrowsePoll at line %d - %s.",
2488 linenum
, strerror(errno
));
2496 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2498 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2499 pollp
->port
= portnum
;
2501 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2504 else if (!strcasecmp(line
, "DefaultAuthType"))
2507 * DefaultAuthType {basic,digest,basicdigest}
2510 if (!strcasecmp(value
, "basic"))
2511 DefaultAuthType
= AUTH_BASIC
;
2512 else if (!strcasecmp(value
, "digest"))
2513 DefaultAuthType
= AUTH_DIGEST
;
2514 else if (!strcasecmp(value
, "basicdigest"))
2515 DefaultAuthType
= AUTH_BASICDIGEST
;
2518 cupsdLogMessage(CUPSD_LOG_WARN
,
2519 "Unknown default authorization type %s on line %d.",
2524 else if (!strcasecmp(line
, "User"))
2527 * User ID to run as...
2530 if (value
&& isdigit(value
[0] & 255))
2532 int uid
= atoi(value
);
2535 cupsdLogMessage(CUPSD_LOG_ERROR
,
2536 "Will not use User 0 as specified on line %d "
2537 "for security reasons. You must use a non-"
2538 "privileged account instead.",
2545 struct passwd
*p
; /* Password information */
2548 p
= getpwnam(value
);
2553 cupsdLogMessage(CUPSD_LOG_ERROR
,
2554 "Will not use User %s (UID=0) as specified on line "
2555 "%d for security reasons. You must use a non-"
2556 "privileged account instead.",
2562 cupsdLogMessage(CUPSD_LOG_ERROR
,
2563 "Unknown User \"%s\" on line %d, ignoring!",
2567 cupsdLogMessage(CUPSD_LOG_ERROR
,
2568 "User directive on line %d missing the username!",
2571 else if (!strcasecmp(line
, "Group"))
2574 * Group ID to run as...
2577 if (isdigit(value
[0]))
2578 Group
= atoi(value
);
2582 group
= getgrnam(value
);
2585 Group
= group
->gr_gid
;
2587 cupsdLogMessage(CUPSD_LOG_ERROR
,
2588 "Unknown Group \"%s\" on line %d, ignoring!",
2592 else if (!strcasecmp(line
, "SystemGroup"))
2595 * System (admin) group(s)...
2598 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2600 if (*value
== '\'' || *value
== '\"')
2603 * Scan quoted name...
2608 for (valueptr
= value
; *valueptr
; valueptr
++)
2609 if (*valueptr
== quote
)
2615 * Scan space or comma-delimited name...
2618 for (valueptr
= value
; *valueptr
; valueptr
++)
2619 if (isspace(*valueptr
) || *valueptr
== ',')
2626 group
= getgrnam(value
);
2629 cupsdSetString(SystemGroups
+ i
, value
);
2630 SystemGroupIDs
[i
] = group
->gr_gid
;
2635 cupsdLogMessage(CUPSD_LOG_ERROR
,
2636 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2643 while (*value
== ',' || isspace(*value
))
2648 NumSystemGroups
= i
;
2650 else if (!strcasecmp(line
, "HostNameLookups"))
2653 * Do hostname lookups?
2656 if (!strcasecmp(value
, "off"))
2657 HostNameLookups
= 0;
2658 else if (!strcasecmp(value
, "on"))
2659 HostNameLookups
= 1;
2660 else if (!strcasecmp(value
, "double"))
2661 HostNameLookups
= 2;
2663 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2666 else if (!strcasecmp(line
, "LogLevel"))
2669 * Amount of logging to do...
2672 if (!strcasecmp(value
, "debug2"))
2673 LogLevel
= CUPSD_LOG_DEBUG2
;
2674 else if (!strcasecmp(value
, "debug"))
2675 LogLevel
= CUPSD_LOG_DEBUG
;
2676 else if (!strcasecmp(value
, "info"))
2677 LogLevel
= CUPSD_LOG_INFO
;
2678 else if (!strcasecmp(value
, "notice"))
2679 LogLevel
= CUPSD_LOG_NOTICE
;
2680 else if (!strcasecmp(value
, "warn"))
2681 LogLevel
= CUPSD_LOG_WARN
;
2682 else if (!strcasecmp(value
, "error"))
2683 LogLevel
= CUPSD_LOG_ERROR
;
2684 else if (!strcasecmp(value
, "crit"))
2685 LogLevel
= CUPSD_LOG_CRIT
;
2686 else if (!strcasecmp(value
, "alert"))
2687 LogLevel
= CUPSD_LOG_ALERT
;
2688 else if (!strcasecmp(value
, "emerg"))
2689 LogLevel
= CUPSD_LOG_EMERG
;
2690 else if (!strcasecmp(value
, "none"))
2691 LogLevel
= CUPSD_LOG_NONE
;
2693 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2696 else if (!strcasecmp(line
, "PrintcapFormat"))
2699 * Format of printcap file?
2702 if (!strcasecmp(value
, "bsd"))
2703 PrintcapFormat
= PRINTCAP_BSD
;
2704 else if (!strcasecmp(value
, "solaris"))
2705 PrintcapFormat
= PRINTCAP_SOLARIS
;
2707 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2710 else if (!strcasecmp(line
, "ServerTokens"))
2713 * Set the string used for the Server header...
2716 struct utsname plat
; /* Platform info */
2721 if (!strcasecmp(value
, "ProductOnly"))
2722 cupsdSetString(&ServerHeader
, "CUPS");
2723 else if (!strcasecmp(value
, "Major"))
2724 cupsdSetString(&ServerHeader
, "CUPS/1");
2725 else if (!strcasecmp(value
, "Minor"))
2726 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2727 else if (!strcasecmp(value
, "Minimal"))
2728 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2729 else if (!strcasecmp(value
, "OS"))
2730 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2731 else if (!strcasecmp(value
, "Full"))
2732 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2734 else if (!strcasecmp(value
, "None"))
2735 cupsdClearString(&ServerHeader
);
2737 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2740 else if (!strcasecmp(line
, "PassEnv"))
2743 * PassEnv variable [... variable]
2748 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2749 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2752 if (value
[valuelen
])
2754 value
[valuelen
] = '\0';
2758 cupsdSetEnv(value
, NULL
);
2760 for (value
+= valuelen
; *value
; value
++)
2761 if (!isspace(*value
) || *value
!= ',')
2765 else if (!strcasecmp(line
, "SetEnv"))
2768 * SetEnv variable value
2771 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2779 while (isspace(*valueptr
& 255))
2782 cupsdSetEnv(value
, valueptr
);
2785 cupsdLogMessage(CUPSD_LOG_ERROR
,
2786 "Missing value for SetEnv directive on line %d.",
2792 * Find a simple variable in the list...
2795 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2796 if (!strcasecmp(line
, var
->name
))
2802 * Unknown directive! Output an error message and continue...
2805 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2812 case CUPSD_VARTYPE_INTEGER
:
2815 char *units
; /* Units */
2818 n
= strtol(value
, &units
, 0);
2820 if (units
&& *units
)
2822 if (tolower(units
[0] & 255) == 'g')
2823 n
*= 1024 * 1024 * 1024;
2824 else if (tolower(units
[0] & 255) == 'm')
2826 else if (tolower(units
[0] & 255) == 'k')
2828 else if (tolower(units
[0] & 255) == 't')
2832 *((int *)var
->ptr
) = n
;
2836 case CUPSD_VARTYPE_BOOLEAN
:
2837 if (!strcasecmp(value
, "true") ||
2838 !strcasecmp(value
, "on") ||
2839 !strcasecmp(value
, "enabled") ||
2840 !strcasecmp(value
, "yes") ||
2842 *((int *)var
->ptr
) = TRUE
;
2843 else if (!strcasecmp(value
, "false") ||
2844 !strcasecmp(value
, "off") ||
2845 !strcasecmp(value
, "disabled") ||
2846 !strcasecmp(value
, "no") ||
2847 !strcasecmp(value
, "0"))
2848 *((int *)var
->ptr
) = FALSE
;
2850 cupsdLogMessage(CUPSD_LOG_ERROR
,
2851 "Unknown boolean value %s on line %d.",
2855 case CUPSD_VARTYPE_STRING
:
2856 cupsdSetString((char **)var
->ptr
, value
);
2867 * 'read_location()' - Read a <Location path> definition.
2870 static int /* O - New line number or 0 on error */
2871 read_location(cups_file_t
*fp
, /* I - Configuration file */
2872 char *location
, /* I - Location name/path */
2873 int linenum
) /* I - Current line number */
2875 cupsd_location_t
*loc
, /* New location */
2876 *parent
; /* Parent location */
2877 char line
[HTTP_MAX_BUFFER
],
2879 *value
, /* Value for directive */
2880 *valptr
; /* Pointer into value */
2883 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2886 parent
->limit
= AUTH_LIMIT_ALL
;
2889 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2892 * Decode the directive...
2895 if (!strcasecmp(line
, "</Location>"))
2897 else if (!strcasecmp(line
, "<Limit") ||
2898 !strcasecmp(line
, "<LimitExcept"))
2902 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2906 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2912 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2917 if (!strcmp(value
, "ALL"))
2918 loc
->limit
= AUTH_LIMIT_ALL
;
2919 else if (!strcmp(value
, "GET"))
2920 loc
->limit
|= AUTH_LIMIT_GET
;
2921 else if (!strcmp(value
, "HEAD"))
2922 loc
->limit
|= AUTH_LIMIT_HEAD
;
2923 else if (!strcmp(value
, "OPTIONS"))
2924 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2925 else if (!strcmp(value
, "POST"))
2926 loc
->limit
|= AUTH_LIMIT_POST
;
2927 else if (!strcmp(value
, "PUT"))
2928 loc
->limit
|= AUTH_LIMIT_PUT
;
2929 else if (!strcmp(value
, "TRACE"))
2930 loc
->limit
|= AUTH_LIMIT_TRACE
;
2932 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2935 for (value
= valptr
; isspace(*value
& 255); value
++);
2938 if (!strcasecmp(line
, "<LimitExcept"))
2939 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2941 parent
->limit
&= ~loc
->limit
;
2943 else if (!strcasecmp(line
, "</Limit>"))
2945 else if (!parse_aaa(loc
, line
, value
, linenum
))
2947 cupsdLogMessage(CUPSD_LOG_ERROR
,
2948 "Unknown Location directive %s on line %d.",
2954 cupsdLogMessage(CUPSD_LOG_ERROR
,
2955 "Unexpected end-of-file at line %d while reading location!",
2963 * 'read_policy()' - Read a <Policy name> definition.
2966 static int /* O - New line number or 0 on error */
2967 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2968 char *policy
, /* I - Location name/path */
2969 int linenum
) /* I - Current line number */
2971 int i
; /* Looping var */
2972 cupsd_policy_t
*pol
; /* Policy */
2973 cupsd_location_t
*op
; /* Policy operation */
2974 int num_ops
; /* Number of IPP operations */
2975 ipp_op_t ops
[100]; /* Operations */
2976 char line
[HTTP_MAX_BUFFER
],
2978 *value
, /* Value for directive */
2979 *valptr
; /* Pointer into value */
2983 * Create the policy...
2986 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2990 * Read from the file...
2996 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2999 * Decode the directive...
3002 if (!strcasecmp(line
, "</Policy>"))
3005 cupsdLogMessage(CUPSD_LOG_WARN
,
3006 "Missing </Limit> before </Policy> on line %d!",
3011 else if (!strcasecmp(line
, "<Limit") && !op
)
3015 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3020 * Scan for IPP operation names...
3027 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3032 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3034 if (!strcasecmp(value
, "All"))
3035 ops
[num_ops
] = IPP_ANY_OPERATION
;
3036 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3037 cupsdLogMessage(CUPSD_LOG_ERROR
,
3038 "Bad IPP operation name \"%s\" on line %d!",
3044 cupsdLogMessage(CUPSD_LOG_ERROR
,
3045 "Too many operations listed on line %d!",
3048 for (value
= valptr
; isspace(*value
& 255); value
++);
3052 * If none are specified, apply the policy to all operations...
3057 ops
[0] = IPP_ANY_OPERATION
;
3062 * Add a new policy for the first operation...
3065 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3067 else if (!strcasecmp(line
, "</Limit>") && op
)
3070 * Finish the current operation limit...
3076 * Copy the policy to the other operations...
3079 for (i
= 1; i
< num_ops
; i
++)
3080 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3087 cupsdLogMessage(CUPSD_LOG_ERROR
,
3088 "Missing <Limit ops> directive before %s on line %d.",
3092 else if (!parse_aaa(op
, line
, value
, linenum
))
3095 cupsdLogMessage(CUPSD_LOG_ERROR
,
3096 "Unknown Policy Limit directive %s on line %d.",
3099 cupsdLogMessage(CUPSD_LOG_ERROR
,
3100 "Unknown Policy directive %s on line %d.",
3107 cupsdLogMessage(CUPSD_LOG_ERROR
,
3108 "Unexpected end-of-file at line %d while reading policy \"%s\"!",