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 * get_address() - Get an address + port number from a line.
28 * get_addr_and_mask() - Get an IP address and netmask.
29 * parse_aaa() - Parse authentication, authorization, and
30 * access control lines.
31 * read_configuration() - Read a configuration file.
32 * read_location() - Read a <Location path> definition.
33 * read_policy() - Read a <Policy name> definition.
37 * Include necessary headers...
43 #include <sys/utsname.h>
48 #endif /* HAVE_VSYSLOG */
52 * Possibly missing network definitions...
56 # define INADDR_NONE 0xffffffff
57 #endif /* !INADDR_NONE */
61 * Configuration variable structure...
66 CUPSD_VARTYPE_INTEGER
, /* Integer option */
67 CUPSD_VARTYPE_STRING
, /* String option */
68 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
73 char *name
; /* Name of variable */
74 void *ptr
; /* Pointer to variable */
75 cupsd_vartype_t type
; /* Type (int, string, address) */
83 static cupsd_var_t variables
[] =
85 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
86 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
87 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
88 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
89 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
90 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
91 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
92 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
93 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
94 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
95 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
96 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
97 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
98 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
99 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
100 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
101 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
102 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
103 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
104 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
105 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
106 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
107 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
108 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
109 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
110 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
111 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
112 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
113 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
114 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
115 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
116 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
117 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
118 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
119 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
120 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
121 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
123 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
124 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
127 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
135 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
136 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
137 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
138 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
139 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
140 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
141 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
142 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
143 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
144 { "RunAsUser", &RunAsUser
, CUPSD_VARTYPE_BOOLEAN
},
145 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
146 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
147 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
149 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
150 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
151 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
152 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
153 #endif /* HAVE_SSL */
154 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
155 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
156 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
157 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
158 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
}
160 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
163 static unsigned ones
[4] =
165 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
167 static unsigned zeros
[4] =
169 0x00000000, 0x00000000, 0x00000000, 0x00000000
177 static http_addrlist_t
*get_address(const char *value
, int defport
);
178 static int get_addr_and_mask(const char *value
, unsigned *ip
,
180 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
181 char *value
, int linenum
);
182 static int read_configuration(cups_file_t
*fp
);
183 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
184 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
188 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
191 int /* O - 1 on success, 0 otherwise */
192 cupsdReadConfiguration(void)
194 int i
; /* Looping var */
195 cups_file_t
*fp
; /* Configuration file */
196 int status
; /* Return status */
197 char temp
[1024], /* Temporary buffer */
198 *slash
; /* Directory separator */
199 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
201 cups_lang_t
*language
; /* Language */
202 struct passwd
*user
; /* Default user */
203 struct group
*group
; /* Default group */
204 char *old_serverroot
, /* Old ServerRoot */
205 *old_requestroot
; /* Old RequestRoot */
208 * Shutdown the server...
214 * Save the old root paths...
217 old_serverroot
= NULL
;
218 cupsdSetString(&old_serverroot
, ServerRoot
);
219 old_requestroot
= NULL
;
220 cupsdSetString(&old_requestroot
, RequestRoot
);
223 * Reset the server configuration data...
226 cupsdDeleteAllLocations();
244 for (i
= 0; i
< NumRelays
; i
++)
245 if (Relays
[i
].from
.type
== AUTH_NAME
)
246 free(Relays
[i
].from
.mask
.name
.name
);
253 if (NumListeners
> 0)
263 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
264 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
265 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
266 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
267 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
268 cupsdSetString(&DataDir
, CUPS_DATADIR
);
269 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
270 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
271 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
272 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
273 cupsdSetString(&Printcap
, "/etc/printcap");
274 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
275 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
276 cupsdSetString(&RemoteRoot
, "remroot");
277 cupsdSetString(&ServerHeader
, "CUPS/1.1");
278 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
280 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
281 if ((slash
= strrchr(temp
, '/')) != NULL
)
284 cupsdSetString(&ServerRoot
, temp
);
286 cupsdClearString(&Classification
);
287 ClassifyOverride
= 0;
291 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
293 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
294 cupsdSetString(&ServerKey
, "ssl/server.key");
295 # endif /* HAVE_CDSASSL */
296 #endif /* HAVE_SSL */
298 language
= cupsLangDefault();
300 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
301 cupsdSetString(&DefaultLanguage
, "en");
303 cupsdSetString(&DefaultLanguage
, language
->language
);
305 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
307 cupsdSetString(&RIPCache
, "8m");
309 if (getenv("TMPDIR") == NULL
)
310 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
312 cupsdSetString(&TempDir
, getenv("TMPDIR"));
315 * Find the default system group: "sys", "system", or "root"...
318 group
= getgrnam(CUPS_DEFAULT_GROUP
);
326 * Found the group, use it!
329 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
331 SystemGroupIDs
[0] = group
->gr_gid
;
336 * Find the group associated with GID 0...
343 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
345 cupsdSetString(&SystemGroups
[0], "unknown");
347 SystemGroupIDs
[0] = 0;
351 * Find the default user...
354 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
359 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
360 * complement number...)
369 * Find the default group (nobody)...
372 group
= getgrnam("nobody");
376 Group
= group
->gr_gid
;
380 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
381 * complement number...)
391 ConfigFilePerm
= 0640;
392 DefaultAuthType
= AUTH_BASIC
;
394 JobRetryInterval
= 300;
399 HostNameLookups
= FALSE
;
400 ImplicitClasses
= TRUE
;
401 ImplicitAnyClasses
= FALSE
;
402 HideImplicitMembers
= TRUE
;
404 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
405 ListenBackLog
= SOMAXCONN
;
407 LogLevel
= CUPSD_LOG_ERROR
;
409 MaxClientsPerHost
= 0;
410 MaxLogSize
= 1024 * 1024;
411 MaxPrinterHistory
= 10;
414 RootCertDuration
= 300;
416 Timeout
= DEFAULT_TIMEOUT
;
418 BrowseInterval
= DEFAULT_INTERVAL
;
419 BrowsePort
= ippPort();
420 BrowseLocalProtocols
= BROWSE_CUPS
;
421 BrowseRemoteProtocols
= BROWSE_CUPS
;
422 BrowseShortNames
= TRUE
;
423 BrowseTimeout
= DEFAULT_TIMEOUT
;
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 * Read the configuration file...
452 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
455 status
= read_configuration(fp
);
468 * Use the default system group if none was supplied in cupsd.conf...
471 if (NumSystemGroups
== 0)
475 * Get the access control list for browsing...
478 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
481 * Open the system log for cupsd if necessary...
485 if (!strcmp(AccessLog
, "syslog") ||
486 !strcmp(ErrorLog
, "syslog") ||
487 !strcmp(PageLog
, "syslog"))
488 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
489 #endif /* HAVE_VSYSLOG */
492 * Log the configuration file that was used...
495 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
499 * Validate the Group and SystemGroup settings - they cannot be the same,
500 * otherwise the CGI programs will be able to authenticate as root without
506 for (i
= 0; i
< NumSystemGroups
; i
++)
507 if (Group
== SystemGroupIDs
[i
])
510 if (i
< NumSystemGroups
)
513 * Log the error and reset the group to a safe value...
516 cupsdLogMessage(CUPSD_LOG_NOTICE
,
517 "Group and SystemGroup cannot use the same groups!");
518 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
520 group
= getgrnam("nobody");
524 Group
= group
->gr_gid
;
528 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
529 * complement number...)
538 * Check that we have at least one listen/port line; if not, report this
539 * as an error and exit!
542 if (NumListeners
== 0)
548 cupsdLogMessage(CUPSD_LOG_EMERG
,
549 "No valid Listen or Port lines were found in the configuration file!");
555 cupsdEndProcess(getpid(), 0);
559 * Set the default locale using the language and charset...
562 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
565 * Update all relative filenames to include the full path from ServerRoot...
568 if (DocumentRoot
[0] != '/')
569 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
571 if (RequestRoot
[0] != '/')
572 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
574 if (ServerBin
[0] != '/')
575 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
577 if (StateDir
[0] != '/')
578 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
580 if (CacheDir
[0] != '/')
581 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
584 if (ServerCertificate
[0] != '/')
585 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
587 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
589 chown(ServerCertificate
, RunUser
, Group
);
590 chmod(ServerCertificate
, ConfigFilePerm
);
593 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
594 if (ServerKey
[0] != '/')
595 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
597 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
599 chown(ServerKey
, RunUser
, Group
);
600 chmod(ServerKey
, ConfigFilePerm
);
602 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
603 #endif /* HAVE_SSL */
606 * Make sure that directories and config files are owned and
607 * writable by the user and group in the cupsd.conf file...
610 chown(CacheDir
, RunUser
, Group
);
611 chmod(CacheDir
, 0775);
613 snprintf(temp
, sizeof(temp
), "%s/ppd", CacheDir
);
616 chown(temp
, RunUser
, Group
);
619 chown(StateDir
, RunUser
, Group
);
620 chmod(StateDir
, 0775);
622 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
625 chown(temp
, User
, SystemGroupIDs
[0]);
631 chown(ServerRoot
, RunUser
, Group
);
632 chmod(ServerRoot
, 0755);
634 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
637 chown(temp
, RunUser
, Group
);
640 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
643 chown(temp
, RunUser
, Group
);
646 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
647 chown(temp
, RunUser
, Group
);
648 chmod(temp
, ConfigFilePerm
);
650 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
651 chown(temp
, RunUser
, Group
);
654 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
655 chown(temp
, RunUser
, Group
);
658 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
659 chown(temp
, User
, Group
);
663 * Make sure the request and temporary directories have the right
667 chown(RequestRoot
, RunUser
, Group
);
668 chmod(RequestRoot
, 0710);
670 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
674 * Update ownership and permissions if the CUPS temp directory
675 * is under the spool directory or does not exist...
678 if (access(TempDir
, 0))
679 mkdir(TempDir
, 01770);
681 chown(TempDir
, RunUser
, Group
);
682 chmod(TempDir
, 01770);
685 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
688 * Clean out the temporary directory...
691 cups_dir_t
*dir
; /* Temporary directory */
692 cups_dentry_t
*dent
; /* Directory entry */
693 char tempfile
[1024]; /* Temporary filename */
696 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
698 cupsdLogMessage(CUPSD_LOG_INFO
,
699 "Cleaning out old temporary files in \"%s\"...", TempDir
);
701 while ((dent
= cupsDirRead(dir
)) != NULL
)
703 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
705 if (unlink(tempfile
))
706 cupsdLogMessage(CUPSD_LOG_ERROR
,
707 "Unable to remove temporary file \"%s\" - %s",
708 tempfile
, strerror(errno
));
710 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
717 cupsdLogMessage(CUPSD_LOG_ERROR
,
718 "Unable to open temporary directory \"%s\" - %s",
719 TempDir
, strerror(errno
));
723 * Setup environment variables...
729 * Check the MaxClients setting, and then allocate memory for it...
732 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
735 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
738 MaxClients
= MaxFDs
/ 3;
741 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
743 cupsdLogMessage(CUPSD_LOG_ERROR
,
744 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
745 MaxClients
, strerror(errno
));
749 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
753 * Check the MaxActiveJobs setting; limit to 1/3 the available
754 * file descriptors, since we need a pipe for each job...
757 if (MaxActiveJobs
> (MaxFDs
/ 3))
758 MaxActiveJobs
= MaxFDs
/ 3;
760 if (Classification
&& strcasecmp(Classification
, "none") == 0)
761 cupsdClearString(&Classification
);
764 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
767 * Update the MaxClientsPerHost value, as needed...
770 if (MaxClientsPerHost
<= 0)
771 MaxClientsPerHost
= MaxClients
;
773 if (MaxClientsPerHost
> MaxClients
)
774 MaxClientsPerHost
= MaxClients
;
776 cupsdLogMessage(CUPSD_LOG_INFO
,
777 "Allowing up to %d client connections per host.",
781 * Update the default policy, as needed...
785 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
787 DefaultPolicyPtr
= NULL
;
789 if (!DefaultPolicyPtr
)
791 cupsd_policy_t
*p
; /* New policy */
792 cupsd_location_t
*po
; /* New policy operation */
796 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
799 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
800 cupsdLogMessage(CUPSD_LOG_INFO
,
801 "Using policy \"default\" as the default!");
804 cupsdLogMessage(CUPSD_LOG_INFO
,
805 "Creating CUPS default administrative policy:");
807 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
809 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
810 cupsdLogMessage(CUPSD_LOG_INFO
,
811 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
812 "Release-Job Restart-Job Purge-Jobs "
813 "Set-Job-Attributes Create-Job-Subscription "
814 "Renew-Subscription Cancel-Subscription "
815 "Get-Notifications Reprocess-Job Cancel-Current-Job "
816 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
817 "CUPS-Authenticate-Job>");
818 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
820 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
821 po
->order_type
= AUTH_ALLOW
;
822 po
->level
= AUTH_USER
;
824 cupsdAddName(po
, "@OWNER");
825 cupsdAddName(po
, "@SYSTEM");
826 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
828 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
829 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
830 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
831 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
832 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
833 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
834 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
835 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
836 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
837 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
838 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
839 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
840 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
841 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
842 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
843 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
844 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
846 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
848 cupsdLogMessage(CUPSD_LOG_INFO
,
849 "<Limit Pause-Printer Resume-Printer "
850 "Set-Printer-Attributes Enable-Printer "
851 "Disable-Printer Pause-Printer-After-Current-Job "
852 "Hold-New-Jobs Release-Held-New-Jobs "
853 "Deactivate-Printer Activate-Printer Restart-Printer "
854 "Shutdown-Printer Startup-Printer Promote-Job "
855 "Schedule-Job-After CUPS-Add-Printer "
856 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
857 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
858 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
859 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
861 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
862 po
->order_type
= AUTH_ALLOW
;
863 po
->type
= AUTH_BASIC
;
864 po
->level
= AUTH_USER
;
866 cupsdAddName(po
, "@SYSTEM");
867 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
869 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
870 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
871 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
872 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
873 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
874 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
875 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
876 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
877 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
878 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
879 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
880 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
881 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
882 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
883 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
884 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
885 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
886 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
887 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
888 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
889 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
891 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
893 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
894 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
896 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
897 po
->order_type
= AUTH_ALLOW
;
899 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
900 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
904 cupsdLogMessage(CUPSD_LOG_DEBUG
,"NumPolicies=%d", NumPolicies
);
905 for (i
= 0; i
< NumPolicies
; i
++)
906 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Policies[%d]=\"%s\"", i
,
910 * If we are doing a full reload or the server root has changed, flush
911 * the jobs, printers, etc. and start from scratch...
914 if (NeedReload
== RELOAD_ALL
||
915 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
916 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
918 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
924 cupsdDeleteAllSubscriptions();
926 cupsdDeleteAllClasses();
927 cupsdDeleteAllPrinters();
929 DefaultPrinter
= NULL
;
931 if (MimeDatabase
!= NULL
)
932 mimeDelete(MimeDatabase
);
936 for (i
= 0; i
< NumMimeTypes
; i
++)
937 free((void *)MimeTypes
[i
]);
943 * Read the MIME type and conversion database...
946 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
948 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
952 cupsdLogMessage(CUPSD_LOG_EMERG
,
953 "Unable to load MIME database from \'%s\'!", ServerRoot
);
957 cupsdLogMessage(CUPSD_LOG_INFO
,
958 "Loaded MIME database from \'%s\': %d types, %d filters...",
959 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
962 * Create a list of MIME types for the document-format-supported
966 NumMimeTypes
= MimeDatabase
->num_types
;
967 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
970 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
972 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
974 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
975 MimeDatabase
->types
[i
]->type
);
977 MimeTypes
[i
] = strdup(type
);
980 if (i
< NumMimeTypes
)
981 MimeTypes
[i
] = strdup("application/octet-stream");
987 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
988 cupsdLoadBanners(temp
);
991 * Load printers and classes...
994 cupsdLoadAllPrinters();
995 cupsdLoadAllClasses();
996 cupsdLoadRemoteCache();
997 cupsdWritePrintcap();
999 cupsdCreateCommonData();
1002 * Load queued jobs...
1008 * Load subscriptions...
1011 cupsdLoadAllSubscriptions();
1013 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1018 * Not a full reload, so recreate the common printer attributes...
1021 cupsdCreateCommonData();
1024 * Update all printers as needed...
1027 cupsdUpdatePrinters();
1028 cupsdWritePrintcap();
1030 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1034 * Reset the reload state...
1037 NeedReload
= RELOAD_NONE
;
1039 cupsdClearString(&old_serverroot
);
1040 cupsdClearString(&old_requestroot
);
1043 * Startup the server and return...
1053 * 'get_address()' - Get an address + port number from a line.
1056 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1057 get_address(const char *value
, /* I - Value string */
1058 int defport
) /* I - Default port */
1060 char buffer
[1024], /* Hostname + port number buffer */
1061 defpname
[255], /* Default port name */
1062 *hostname
, /* Hostname or IP */
1063 *portname
; /* Port number or name */
1064 http_addrlist_t
*addrlist
; /* Address list */
1068 * Check for an empty value...
1073 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1078 * Grab a hostname and port number; if there is no colon and the port name
1079 * is only digits, then we have a port number by itself...
1082 strlcpy(buffer
, value
, sizeof(buffer
));
1084 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1091 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1096 * Use the default port...
1099 sprintf(defpname
, "%d", defport
);
1100 portname
= defpname
;
1106 * The buffer contains just a port number...
1114 if (hostname
&& !strcmp(hostname
, "*"))
1118 * Now lookup the address using httpAddrGetList()...
1121 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1122 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1123 hostname
? hostname
: "(nil)");
1130 * 'get_addr_and_mask()' - Get an IP address and netmask.
1133 static int /* O - 1 on success, 0 on failure */
1134 get_addr_and_mask(const char *value
, /* I - String from config file */
1135 unsigned *ip
, /* O - Address value */
1136 unsigned *mask
) /* O - Mask value */
1138 int i
, j
, /* Looping vars */
1139 family
, /* Address family */
1140 ipcount
; /* Count of fields in address */
1141 unsigned ipval
; /* Value */
1142 const char *maskval
, /* Pointer to start of mask value */
1143 *ptr
, /* Pointer into value */
1145 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1147 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1148 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1149 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1150 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1153 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1155 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1156 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1157 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1158 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1159 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1160 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1161 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1162 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1164 #endif /* AF_INET6 */
1168 * Get the address...
1171 memset(ip
, 0, sizeof(unsigned) * 4);
1173 if ((maskval
= strchr(value
, '/')) != NULL
)
1176 maskval
= value
+ strlen(value
);
1180 * Check for an IPv6 address...
1186 * Parse hexadecimal IPv6 address...
1191 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1195 else if (!strncmp(ptr
, "::", 2))
1197 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1199 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1203 else if (isxdigit(*ptr
& 255))
1205 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1213 ip
[i
] |= ipval
<< 16;
1224 if (*ptr
&& *ptr
!= '/')
1228 #endif /* AF_INET6 */
1231 * Parse dotted-decimal IPv4 address...
1235 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1237 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1238 ip
[0] = ip
[1] = ip
[2] = 0;
1244 * Get the netmask value(s)...
1247 memset(mask
, 0, sizeof(unsigned) * 4);
1250 if (*maskval
== '[')
1253 * Get hexadecimal mask value...
1256 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1260 else if (!strncmp(ptr
, "::", 2))
1262 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1264 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1268 else if (isxdigit(*ptr
& 255))
1270 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1278 mask
[i
] |= ipval
<< 16;
1291 #endif /* AF_INET6 */
1292 if (strchr(maskval
, '.'))
1295 * Get dotted-decimal mask...
1298 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1301 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1302 mask
[0] = mask
[1] = mask
[2] = 0;
1307 * Get address/bits format...
1313 if (family
== AF_INET6
)
1318 mask
[0] = 0xffffffff;
1320 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1323 mask
[1] = 0xffffffff;
1327 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1330 mask
[2] = 0xffffffff;
1334 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1337 mask
[3] = 0xffffffff;
1341 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1344 #endif /* AF_INET6 */
1348 mask
[0] = 0xffffffff;
1349 mask
[1] = 0xffffffff;
1350 mask
[2] = 0xffffffff;
1353 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1355 mask
[3] = 0xffffffff;
1360 else if (family
== AF_INET6
)
1361 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1362 #endif /* AF_INET6 */
1364 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1366 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1367 "get_addr_and_mask(value=\"%s\", "
1368 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1369 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1373 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1376 if ((ip
[0] & ~mask
[0]) != 0 ||
1377 (ip
[1] & ~mask
[1]) != 0 ||
1378 (ip
[2] & ~mask
[2]) != 0 ||
1379 (ip
[3] & ~mask
[3]) != 0)
1387 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1390 static int /* O - 1 on success, 0 on failure */
1391 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1392 char *line
, /* I - Line from file */
1393 char *value
, /* I - Start of value data */
1394 int linenum
) /* I - Current line number */
1396 char *valptr
; /* Pointer into value */
1397 unsigned ip
[4], /* IP address components */
1398 mask
[4]; /* IP netmask components */
1401 if (!strcasecmp(line
, "Encryption"))
1404 * "Encryption xxx" - set required encryption level...
1407 if (!strcasecmp(value
, "never"))
1408 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1409 else if (!strcasecmp(value
, "always"))
1411 cupsdLogMessage(CUPSD_LOG_ERROR
,
1412 "Encryption value \"%s\" on line %d is invalid in this "
1413 "context. Using \"required\" instead.", value
, linenum
);
1415 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1417 else if (!strcasecmp(value
, "required"))
1418 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1419 else if (!strcasecmp(value
, "ifrequested"))
1420 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1423 cupsdLogMessage(CUPSD_LOG_ERROR
,
1424 "Unknown Encryption value %s on line %d.", value
, linenum
);
1428 else if (!strcasecmp(line
, "Order"))
1431 * "Order Deny,Allow" or "Order Allow,Deny"...
1434 if (!strncasecmp(value
, "deny", 4))
1435 loc
->order_type
= AUTH_ALLOW
;
1436 else if (!strncasecmp(value
, "allow", 5))
1437 loc
->order_type
= AUTH_DENY
;
1440 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1445 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1448 * Allow [From] host/ip...
1449 * Deny [From] host/ip...
1452 if (!strncasecmp(value
, "from", 4))
1455 * Strip leading "from"...
1460 while (isspace(*value
& 255))
1465 * Figure out what form the allow/deny address takes:
1476 * nnn.nnn.nnn.nnn/mm
1477 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1480 if (!strcasecmp(value
, "all"))
1486 if (!strcasecmp(line
, "Allow"))
1487 cupsdAllowIP(loc
, zeros
, zeros
);
1489 cupsdDenyIP(loc
, zeros
, zeros
);
1491 else if (!strcasecmp(value
, "none"))
1497 if (!strcasecmp(line
, "Allow"))
1498 cupsdAllowIP(loc
, ones
, zeros
);
1500 cupsdDenyIP(loc
, ones
, zeros
);
1502 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1505 * Host or domain name...
1508 if (value
[0] == '*')
1511 if (!strcasecmp(line
, "Allow"))
1512 cupsdAllowHost(loc
, value
);
1514 cupsdDenyHost(loc
, value
);
1519 * One of many IP address forms...
1522 if (!get_addr_and_mask(value
, ip
, mask
))
1524 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1529 if (!strcasecmp(line
, "Allow"))
1530 cupsdAllowIP(loc
, ip
, mask
);
1532 cupsdDenyIP(loc
, ip
, mask
);
1535 else if (!strcasecmp(line
, "AuthType"))
1538 * AuthType {none,basic,digest,basicdigest}
1541 if (!strcasecmp(value
, "none"))
1543 loc
->type
= AUTH_NONE
;
1544 loc
->level
= AUTH_ANON
;
1546 else if (!strcasecmp(value
, "basic"))
1548 loc
->type
= AUTH_BASIC
;
1550 if (loc
->level
== AUTH_ANON
)
1551 loc
->level
= AUTH_USER
;
1553 else if (!strcasecmp(value
, "digest"))
1555 loc
->type
= AUTH_DIGEST
;
1557 if (loc
->level
== AUTH_ANON
)
1558 loc
->level
= AUTH_USER
;
1560 else if (!strcasecmp(value
, "basicdigest"))
1562 loc
->type
= AUTH_BASICDIGEST
;
1564 if (loc
->level
== AUTH_ANON
)
1565 loc
->level
= AUTH_USER
;
1569 cupsdLogMessage(CUPSD_LOG_WARN
,
1570 "Unknown authorization type %s on line %d.",
1575 else if (!strcasecmp(line
, "AuthClass"))
1578 * AuthClass anonymous, user, system, group
1581 if (!strcasecmp(value
, "anonymous"))
1583 loc
->type
= AUTH_NONE
;
1584 loc
->level
= AUTH_ANON
;
1586 cupsdLogMessage(CUPSD_LOG_WARN
,
1587 "\"AuthClass %s\" is deprecated; consider removing "
1591 else if (!strcasecmp(value
, "user"))
1593 loc
->level
= AUTH_USER
;
1595 cupsdLogMessage(CUPSD_LOG_WARN
,
1596 "\"AuthClass %s\" is deprecated; consider using "
1597 "\"Require valid-user\" on line %d.",
1600 else if (!strcasecmp(value
, "group"))
1602 loc
->level
= AUTH_GROUP
;
1604 cupsdLogMessage(CUPSD_LOG_WARN
,
1605 "\"AuthClass %s\" is deprecated; consider using "
1606 "\"Require @groupname\" on line %d.",
1609 else if (!strcasecmp(value
, "system"))
1611 loc
->level
= AUTH_GROUP
;
1613 cupsdAddName(loc
, "@SYSTEM");
1615 cupsdLogMessage(CUPSD_LOG_WARN
,
1616 "\"AuthClass %s\" is deprecated; consider using "
1617 "\"Require @SYSTEM\" on line %d.",
1622 cupsdLogMessage(CUPSD_LOG_WARN
,
1623 "Unknown authorization class %s on line %d.",
1628 else if (!strcasecmp(line
, "AuthGroupName"))
1630 cupsdAddName(loc
, value
);
1632 cupsdLogMessage(CUPSD_LOG_WARN
,
1633 "\"AuthGroupName %s\" directive is deprecated; consider "
1634 "using \"Require @%s\" on line %d.",
1635 value
, value
, linenum
);
1637 else if (!strcasecmp(line
, "Require"))
1640 * Apache synonym for AuthClass and AuthGroupName...
1644 * Require valid-user
1645 * Require group names
1646 * Require user names
1649 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1654 if (!strcasecmp(value
, "valid-user") ||
1655 !strcasecmp(value
, "user"))
1656 loc
->level
= AUTH_USER
;
1657 else if (!strcasecmp(value
, "group"))
1658 loc
->level
= AUTH_GROUP
;
1661 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1667 * Get the list of names from the line...
1670 for (value
= valptr
; *value
;)
1672 while (isspace(*value
& 255))
1675 if (*value
== '\"' || *value
== '\'')
1678 * Grab quoted name...
1681 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1688 * Grab literal name.
1691 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1697 cupsdAddName(loc
, value
);
1699 for (value
= valptr
; isspace(*value
& 255); value
++);
1702 else if (!strcasecmp(line
, "Satisfy"))
1704 if (!strcasecmp(value
, "all"))
1705 loc
->satisfy
= AUTH_SATISFY_ALL
;
1706 else if (!strcasecmp(value
, "any"))
1707 loc
->satisfy
= AUTH_SATISFY_ANY
;
1710 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1723 * 'read_configuration()' - Read a configuration file.
1726 static int /* O - 1 on success, 0 on failure */
1727 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1729 int i
; /* Looping var */
1730 int linenum
; /* Current line number */
1731 char line
[HTTP_MAX_BUFFER
],
1732 /* Line from file */
1733 temp
[HTTP_MAX_BUFFER
],
1734 /* Temporary buffer for value */
1735 temp2
[HTTP_MAX_BUFFER
],
1736 /* Temporary buffer 2 for value */
1737 *ptr
, /* Pointer into line/temp */
1738 *value
, /* Pointer to value */
1739 *valueptr
, /* Pointer into value */
1740 quote
; /* Quote character */
1741 int valuelen
; /* Length of value */
1742 cupsd_var_t
*var
; /* Current variable */
1743 http_addrlist_t
*addrlist
, /* Address list */
1744 *addr
; /* Current address */
1745 unsigned ip
[4], /* Address value */
1746 mask
[4]; /* Netmask value */
1747 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1748 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1749 cupsd_location_t
*location
; /* Browse location */
1750 cups_file_t
*incfile
; /* Include file */
1751 char incname
[1024]; /* Include filename */
1752 struct group
*group
; /* Group */
1756 * Loop through each line in the file...
1761 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1764 * Decode the directive...
1767 if (!strcasecmp(line
, "Include"))
1773 if (value
[0] == '/')
1774 strlcpy(incname
, value
, sizeof(incname
));
1776 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1778 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1779 cupsdLogMessage(CUPSD_LOG_ERROR
,
1780 "Unable to include config file \"%s\" - %s",
1781 incname
, strerror(errno
));
1784 read_configuration(incfile
);
1785 cupsFileClose(incfile
);
1788 else if (!strcasecmp(line
, "<Location"))
1796 linenum
= read_location(fp
, value
, linenum
);
1802 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1807 else if (!strcasecmp(line
, "<Policy"))
1815 linenum
= read_policy(fp
, value
, linenum
);
1821 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1825 else if (!strcasecmp(line
, "FaxRetryInterval"))
1829 JobRetryInterval
= atoi(value
);
1830 cupsdLogMessage(CUPSD_LOG_WARN
,
1831 "FaxRetryInterval is deprecated; use "
1832 "JobRetryInterval on line %d.", linenum
);
1836 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1840 else if (!strcasecmp(line
, "FaxRetryLimit"))
1844 JobRetryLimit
= atoi(value
);
1845 cupsdLogMessage(CUPSD_LOG_WARN
,
1846 "FaxRetryLimit is deprecated; use "
1847 "JobRetryLimit on line %d.", linenum
);
1851 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1855 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
1857 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
1858 #endif /* HAVE_SSL */
1862 * Add listening address(es) to the list...
1865 cupsd_listener_t
*lis
; /* New listeners array */
1869 * Get the address list...
1872 addrlist
= get_address(value
, IPP_PORT
);
1876 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1882 * Add each address...
1885 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1888 * Allocate another listener...
1891 if (NumListeners
== 0)
1892 lis
= malloc(sizeof(cupsd_listener_t
));
1894 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1898 cupsdLogMessage(CUPSD_LOG_ERROR
,
1899 "Unable to allocate %s at line %d - %s.",
1900 line
, linenum
, strerror(errno
));
1905 lis
+= NumListeners
;
1908 * Copy the current address and log it...
1911 memset(lis
, 0, sizeof(cupsd_listener_t
));
1912 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
1915 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1916 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1917 #endif /* HAVE_SSL */
1920 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1921 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1922 ntohs(lis
->address
.ipv6
.sin6_port
));
1924 #endif /* AF_INET6 */
1926 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1927 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
1929 #endif /* AF_LOCAL */
1930 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
1931 ntohs(lis
->address
.ipv4
.sin_port
));
1940 httpAddrFreeList(addrlist
);
1942 else if (!strcasecmp(line
, "BrowseAddress"))
1945 * Add a browse address to the list...
1948 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
1951 if (NumBrowsers
== 0)
1952 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
1954 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
1958 cupsdLogMessage(CUPSD_LOG_ERROR
,
1959 "Unable to allocate BrowseAddress at line %d - %s.",
1960 linenum
, strerror(errno
));
1965 dira
+= NumBrowsers
;
1967 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
1969 if (!strcasecmp(value
, "@LOCAL"))
1972 * Send browse data to all local interfaces...
1975 strcpy(dira
->iface
, "*");
1978 else if (!strncasecmp(value
, "@IF(", 4))
1981 * Send browse data to the named interface...
1984 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1986 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1992 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
1995 * Only IPv4 addresses are supported...
1998 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1999 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2004 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2005 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2007 cupsdLogMessage(CUPSD_LOG_INFO
,
2008 "Sending browsing info to %s:%d (IPv4)",
2009 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2014 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2017 httpAddrFreeList(addrlist
);
2020 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2023 else if (!strcasecmp(line
, "BrowseOrder"))
2026 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2029 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2030 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2032 if (location
== NULL
)
2033 cupsdLogMessage(CUPSD_LOG_ERROR
,
2034 "Unable to initialize browse access control list!");
2035 else if (!strncasecmp(value
, "deny", 4))
2036 location
->order_type
= AUTH_ALLOW
;
2037 else if (!strncasecmp(value
, "allow", 5))
2038 location
->order_type
= AUTH_DENY
;
2040 cupsdLogMessage(CUPSD_LOG_ERROR
,
2041 "Unknown BrowseOrder value %s on line %d.",
2044 else if (!strcasecmp(line
, "BrowseProtocols") ||
2045 !strcasecmp(line
, "BrowseLocalProtocols") ||
2046 !strcasecmp(line
, "BrowseRemoteProtocols"))
2049 * "BrowseProtocol name [... name]"
2052 if (strcasecmp(line
, "BrowseLocalProtocols"))
2053 BrowseRemoteProtocols
= 0;
2054 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2055 BrowseLocalProtocols
= 0;
2059 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2060 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2063 if (value
[valuelen
])
2065 value
[valuelen
] = '\0';
2069 if (!strcasecmp(value
, "cups"))
2071 if (strcasecmp(line
, "BrowseLocalProtocols"))
2072 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2073 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2074 BrowseLocalProtocols
|= BROWSE_CUPS
;
2076 else if (!strcasecmp(value
, "slp"))
2078 if (strcasecmp(line
, "BrowseLocalProtocols"))
2079 BrowseRemoteProtocols
|= BROWSE_SLP
;
2080 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2081 BrowseLocalProtocols
|= BROWSE_SLP
;
2083 else if (!strcasecmp(value
, "ldap"))
2085 if (strcasecmp(line
, "BrowseLocalProtocols"))
2086 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2087 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2088 BrowseLocalProtocols
|= BROWSE_LDAP
;
2090 else if (!strcasecmp(value
, "all"))
2092 if (strcasecmp(line
, "BrowseLocalProtocols"))
2093 BrowseRemoteProtocols
|= BROWSE_ALL
;
2094 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2095 BrowseLocalProtocols
|= BROWSE_ALL
;
2099 cupsdLogMessage(CUPSD_LOG_ERROR
,
2100 "Unknown browse protocol \"%s\" on line %d.",
2105 for (value
+= valuelen
; *value
; value
++)
2106 if (!isspace(*value
) || *value
!= ',')
2110 else if (!strcasecmp(line
, "BrowseAllow") ||
2111 !strcasecmp(line
, "BrowseDeny"))
2114 * BrowseAllow [From] host/ip...
2115 * BrowseDeny [From] host/ip...
2118 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2119 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2121 if (location
== NULL
)
2122 cupsdLogMessage(CUPSD_LOG_ERROR
,
2123 "Unable to initialize browse access control list!");
2126 if (!strncasecmp(value
, "from ", 5))
2129 * Strip leading "from"...
2134 while (isspace(*value
))
2139 * Figure out what form the allow/deny address takes:
2150 * nnn.nnn.nnn.nnn/mm
2151 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2154 if (!strcasecmp(value
, "all"))
2160 if (!strcasecmp(line
, "BrowseAllow"))
2161 cupsdAllowIP(location
, zeros
, zeros
);
2163 cupsdDenyIP(location
, zeros
, zeros
);
2165 else if (!strcasecmp(value
, "none"))
2171 if (!strcasecmp(line
, "BrowseAllow"))
2172 cupsdAllowIP(location
, ones
, zeros
);
2174 cupsdDenyIP(location
, ones
, zeros
);
2176 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2179 * Host or domain name...
2182 if (value
[0] == '*')
2185 if (!strcasecmp(line
, "BrowseAllow"))
2186 cupsdAllowHost(location
, value
);
2188 cupsdDenyHost(location
, value
);
2193 * One of many IP address forms...
2196 if (!get_addr_and_mask(value
, ip
, mask
))
2198 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2203 if (!strcasecmp(line
, "BrowseAllow"))
2204 cupsdAllowIP(location
, ip
, mask
);
2206 cupsdDenyIP(location
, ip
, mask
);
2210 else if (!strcasecmp(line
, "BrowseRelay"))
2213 * BrowseRelay [from] source [to] destination
2217 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2219 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2223 cupsdLogMessage(CUPSD_LOG_ERROR
,
2224 "Unable to allocate BrowseRelay at line %d - %s.",
2225 linenum
, strerror(errno
));
2232 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2234 if (!strncasecmp(value
, "from ", 5))
2237 * Strip leading "from"...
2242 while (isspace(*value
))
2247 * Figure out what form the from address takes:
2256 * nnn.nnn.nnn.nnn/mm
2257 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2260 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2263 * Host or domain name...
2266 if (value
[0] == '*')
2269 strlcpy(temp
, value
, sizeof(temp
));
2270 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2273 relay
->from
.type
= AUTH_NAME
;
2274 relay
->from
.mask
.name
.name
= strdup(temp
);
2275 relay
->from
.mask
.name
.length
= strlen(temp
);
2280 * One of many IP address forms...
2283 if (!get_addr_and_mask(value
, ip
, mask
))
2285 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2290 relay
->from
.type
= AUTH_IP
;
2291 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2292 sizeof(relay
->from
.mask
.ip
.address
));
2293 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2294 sizeof(relay
->from
.mask
.ip
.netmask
));
2298 * Skip value and trailing whitespace...
2301 for (; *value
; value
++)
2302 if (isspace(*value
))
2305 while (isspace(*value
))
2308 if (!strncasecmp(value
, "to ", 3))
2311 * Strip leading "to"...
2316 while (isspace(*value
))
2321 * Get "to" address and port...
2324 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2327 * Only IPv4 addresses are supported...
2330 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2331 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2336 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2338 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2340 if (relay
->from
.type
== AUTH_IP
)
2341 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2342 relay
->from
.mask
.ip
.address
[0],
2343 relay
->from
.mask
.ip
.address
[1],
2344 relay
->from
.mask
.ip
.address
[2],
2345 relay
->from
.mask
.ip
.address
[3],
2346 relay
->from
.mask
.ip
.netmask
[0],
2347 relay
->from
.mask
.ip
.netmask
[1],
2348 relay
->from
.mask
.ip
.netmask
[2],
2349 relay
->from
.mask
.ip
.netmask
[3]);
2351 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2353 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2354 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2359 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2362 httpAddrFreeList(addrlist
);
2366 if (relay
->from
.type
== AUTH_NAME
)
2367 free(relay
->from
.mask
.name
.name
);
2369 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2373 else if (!strcasecmp(line
, "BrowsePoll"))
2376 * BrowsePoll address[:port]
2379 char *portname
; /* Port name */
2380 int portnum
; /* Port number */
2381 struct servent
*service
; /* Service */
2385 * Extract the port name from the address...
2388 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2392 if (isdigit(*portname
& 255))
2393 portnum
= atoi(portname
);
2394 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2395 portnum
= ntohs(service
->s_port
);
2398 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2404 portnum
= ippPort();
2407 * Add the poll entry...
2411 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2413 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2417 cupsdLogMessage(CUPSD_LOG_ERROR
,
2418 "Unable to allocate BrowsePoll at line %d - %s.",
2419 linenum
, strerror(errno
));
2427 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2429 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2430 pollp
->port
= portnum
;
2432 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2435 else if (!strcasecmp(line
, "DefaultAuthType"))
2438 * DefaultAuthType {basic,digest,basicdigest}
2441 if (!strcasecmp(value
, "basic"))
2442 DefaultAuthType
= AUTH_BASIC
;
2443 else if (!strcasecmp(value
, "digest"))
2444 DefaultAuthType
= AUTH_DIGEST
;
2445 else if (!strcasecmp(value
, "basicdigest"))
2446 DefaultAuthType
= AUTH_BASICDIGEST
;
2449 cupsdLogMessage(CUPSD_LOG_WARN
,
2450 "Unknown default authorization type %s on line %d.",
2455 else if (!strcasecmp(line
, "User"))
2458 * User ID to run as...
2461 if (value
&& isdigit(value
[0] & 255))
2463 int uid
= atoi(value
);
2466 cupsdLogMessage(CUPSD_LOG_ERROR
,
2467 "Will not use User 0 as specified on line %d "
2468 "for security reasons. You must use a non-"
2469 "privileged account instead.",
2476 struct passwd
*p
; /* Password information */
2479 p
= getpwnam(value
);
2484 cupsdLogMessage(CUPSD_LOG_ERROR
,
2485 "Will not use User %s (UID=0) as specified on line "
2486 "%d for security reasons. You must use a non-"
2487 "privileged account instead.",
2493 cupsdLogMessage(CUPSD_LOG_ERROR
,
2494 "Unknown User \"%s\" on line %d, ignoring!",
2498 cupsdLogMessage(CUPSD_LOG_ERROR
,
2499 "User directive on line %d missing the username!",
2502 else if (!strcasecmp(line
, "Group"))
2505 * Group ID to run as...
2508 if (isdigit(value
[0]))
2509 Group
= atoi(value
);
2513 group
= getgrnam(value
);
2516 Group
= group
->gr_gid
;
2518 cupsdLogMessage(CUPSD_LOG_ERROR
,
2519 "Unknown Group \"%s\" on line %d, ignoring!",
2523 else if (!strcasecmp(line
, "SystemGroup"))
2526 * System (admin) group(s)...
2529 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2531 if (*value
== '\'' || *value
== '\"')
2534 * Scan quoted name...
2539 for (valueptr
= value
; *valueptr
; valueptr
++)
2540 if (*valueptr
== quote
)
2546 * Scan space or comma-delimited name...
2549 for (valueptr
= value
; *valueptr
; valueptr
++)
2550 if (isspace(*valueptr
) || *valueptr
== ',')
2557 group
= getgrnam(value
);
2560 cupsdSetString(SystemGroups
+ i
, value
);
2561 SystemGroupIDs
[i
] = group
->gr_gid
;
2566 cupsdLogMessage(CUPSD_LOG_ERROR
,
2567 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2574 while (*value
== ',' || isspace(*value
))
2579 NumSystemGroups
= i
;
2581 else if (!strcasecmp(line
, "HostNameLookups"))
2584 * Do hostname lookups?
2587 if (!strcasecmp(value
, "off"))
2588 HostNameLookups
= 0;
2589 else if (!strcasecmp(value
, "on"))
2590 HostNameLookups
= 1;
2591 else if (!strcasecmp(value
, "double"))
2592 HostNameLookups
= 2;
2594 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2597 else if (!strcasecmp(line
, "LogLevel"))
2600 * Amount of logging to do...
2603 if (!strcasecmp(value
, "debug2"))
2604 LogLevel
= CUPSD_LOG_DEBUG2
;
2605 else if (!strcasecmp(value
, "debug"))
2606 LogLevel
= CUPSD_LOG_DEBUG
;
2607 else if (!strcasecmp(value
, "info"))
2608 LogLevel
= CUPSD_LOG_INFO
;
2609 else if (!strcasecmp(value
, "notice"))
2610 LogLevel
= CUPSD_LOG_NOTICE
;
2611 else if (!strcasecmp(value
, "warn"))
2612 LogLevel
= CUPSD_LOG_WARN
;
2613 else if (!strcasecmp(value
, "error"))
2614 LogLevel
= CUPSD_LOG_ERROR
;
2615 else if (!strcasecmp(value
, "crit"))
2616 LogLevel
= CUPSD_LOG_CRIT
;
2617 else if (!strcasecmp(value
, "alert"))
2618 LogLevel
= CUPSD_LOG_ALERT
;
2619 else if (!strcasecmp(value
, "emerg"))
2620 LogLevel
= CUPSD_LOG_EMERG
;
2621 else if (!strcasecmp(value
, "none"))
2622 LogLevel
= CUPSD_LOG_NONE
;
2624 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2627 else if (!strcasecmp(line
, "PrintcapFormat"))
2630 * Format of printcap file?
2633 if (!strcasecmp(value
, "bsd"))
2634 PrintcapFormat
= PRINTCAP_BSD
;
2635 else if (!strcasecmp(value
, "solaris"))
2636 PrintcapFormat
= PRINTCAP_SOLARIS
;
2638 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2641 else if (!strcasecmp(line
, "ServerTokens"))
2644 * Set the string used for the Server header...
2647 struct utsname plat
; /* Platform info */
2652 if (!strcasecmp(value
, "ProductOnly"))
2653 cupsdSetString(&ServerHeader
, "CUPS");
2654 else if (!strcasecmp(value
, "Major"))
2655 cupsdSetString(&ServerHeader
, "CUPS/1");
2656 else if (!strcasecmp(value
, "Minor"))
2657 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2658 else if (!strcasecmp(value
, "Minimal"))
2659 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2660 else if (!strcasecmp(value
, "OS"))
2661 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2662 else if (!strcasecmp(value
, "Full"))
2663 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2665 else if (!strcasecmp(value
, "None"))
2666 cupsdClearString(&ServerHeader
);
2668 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2671 else if (!strcasecmp(line
, "PassEnv"))
2674 * PassEnv variable [... variable]
2679 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2680 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2683 if (value
[valuelen
])
2685 value
[valuelen
] = '\0';
2689 cupsdSetEnv(value
, NULL
);
2691 for (value
+= valuelen
; *value
; value
++)
2692 if (!isspace(*value
) || *value
!= ',')
2696 else if (!strcasecmp(line
, "SetEnv"))
2699 * SetEnv variable value
2702 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2710 while (isspace(*valueptr
& 255))
2713 cupsdSetEnv(value
, valueptr
);
2716 cupsdLogMessage(CUPSD_LOG_ERROR
,
2717 "Missing value for SetEnv directive on line %d.",
2723 * Find a simple variable in the list...
2726 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2727 if (!strcasecmp(line
, var
->name
))
2733 * Unknown directive! Output an error message and continue...
2736 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2743 case CUPSD_VARTYPE_INTEGER
:
2746 char *units
; /* Units */
2749 n
= strtol(value
, &units
, 0);
2751 if (units
&& *units
)
2753 if (tolower(units
[0] & 255) == 'g')
2754 n
*= 1024 * 1024 * 1024;
2755 else if (tolower(units
[0] & 255) == 'm')
2757 else if (tolower(units
[0] & 255) == 'k')
2759 else if (tolower(units
[0] & 255) == 't')
2763 *((int *)var
->ptr
) = n
;
2767 case CUPSD_VARTYPE_BOOLEAN
:
2768 if (!strcasecmp(value
, "true") ||
2769 !strcasecmp(value
, "on") ||
2770 !strcasecmp(value
, "enabled") ||
2771 !strcasecmp(value
, "yes") ||
2773 *((int *)var
->ptr
) = TRUE
;
2774 else if (!strcasecmp(value
, "false") ||
2775 !strcasecmp(value
, "off") ||
2776 !strcasecmp(value
, "disabled") ||
2777 !strcasecmp(value
, "no") ||
2778 !strcasecmp(value
, "0"))
2779 *((int *)var
->ptr
) = FALSE
;
2781 cupsdLogMessage(CUPSD_LOG_ERROR
,
2782 "Unknown boolean value %s on line %d.",
2786 case CUPSD_VARTYPE_STRING
:
2787 cupsdSetString((char **)var
->ptr
, value
);
2798 * 'read_location()' - Read a <Location path> definition.
2801 static int /* O - New line number or 0 on error */
2802 read_location(cups_file_t
*fp
, /* I - Configuration file */
2803 char *location
, /* I - Location name/path */
2804 int linenum
) /* I - Current line number */
2806 cupsd_location_t
*loc
, /* New location */
2807 *parent
; /* Parent location */
2808 char line
[HTTP_MAX_BUFFER
],
2810 *value
, /* Value for directive */
2811 *valptr
; /* Pointer into value */
2814 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2817 parent
->limit
= AUTH_LIMIT_ALL
;
2820 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2823 * Decode the directive...
2826 if (!strcasecmp(line
, "</Location>"))
2828 else if (!strcasecmp(line
, "<Limit") ||
2829 !strcasecmp(line
, "<LimitExcept"))
2833 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2837 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2843 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2848 if (!strcmp(value
, "ALL"))
2849 loc
->limit
= AUTH_LIMIT_ALL
;
2850 else if (!strcmp(value
, "GET"))
2851 loc
->limit
|= AUTH_LIMIT_GET
;
2852 else if (!strcmp(value
, "HEAD"))
2853 loc
->limit
|= AUTH_LIMIT_HEAD
;
2854 else if (!strcmp(value
, "OPTIONS"))
2855 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2856 else if (!strcmp(value
, "POST"))
2857 loc
->limit
|= AUTH_LIMIT_POST
;
2858 else if (!strcmp(value
, "PUT"))
2859 loc
->limit
|= AUTH_LIMIT_PUT
;
2860 else if (!strcmp(value
, "TRACE"))
2861 loc
->limit
|= AUTH_LIMIT_TRACE
;
2863 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2866 for (value
= valptr
; isspace(*value
& 255); value
++);
2869 if (!strcasecmp(line
, "<LimitExcept"))
2870 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2872 parent
->limit
&= ~loc
->limit
;
2874 else if (!strcasecmp(line
, "</Limit>"))
2876 else if (!parse_aaa(loc
, line
, value
, linenum
))
2878 cupsdLogMessage(CUPSD_LOG_ERROR
,
2879 "Unknown Location directive %s on line %d.",
2885 cupsdLogMessage(CUPSD_LOG_ERROR
,
2886 "Unexpected end-of-file at line %d while reading location!",
2894 * 'read_policy()' - Read a <Policy name> definition.
2897 static int /* O - New line number or 0 on error */
2898 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2899 char *policy
, /* I - Location name/path */
2900 int linenum
) /* I - Current line number */
2902 int i
; /* Looping var */
2903 cupsd_policy_t
*pol
; /* Policy */
2904 cupsd_location_t
*op
; /* Policy operation */
2905 int num_ops
; /* Number of IPP operations */
2906 ipp_op_t ops
[100]; /* Operations */
2907 char line
[HTTP_MAX_BUFFER
],
2909 *value
, /* Value for directive */
2910 *valptr
; /* Pointer into value */
2914 * Create the policy...
2917 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2921 * Read from the file...
2927 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2930 * Decode the directive...
2933 if (!strcasecmp(line
, "</Policy>"))
2936 cupsdLogMessage(CUPSD_LOG_WARN
,
2937 "Missing </Limit> before </Policy> on line %d!",
2942 else if (!strcasecmp(line
, "<Limit") && !op
)
2946 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2951 * Scan for IPP operation names...
2958 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2963 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2965 if (!strcasecmp(value
, "All"))
2966 ops
[num_ops
] = IPP_ANY_OPERATION
;
2967 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2968 cupsdLogMessage(CUPSD_LOG_ERROR
,
2969 "Bad IPP operation name \"%s\" on line %d!",
2975 cupsdLogMessage(CUPSD_LOG_ERROR
,
2976 "Too many operations listed on line %d!",
2979 for (value
= valptr
; isspace(*value
& 255); value
++);
2983 * If none are specified, apply the policy to all operations...
2988 ops
[0] = IPP_ANY_OPERATION
;
2993 * Add a new policy for the first operation...
2996 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2998 else if (!strcasecmp(line
, "</Limit>") && op
)
3001 * Finish the current operation limit...
3007 * Copy the policy to the other operations...
3010 for (i
= 1; i
< num_ops
; i
++)
3011 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3018 cupsdLogMessage(CUPSD_LOG_ERROR
,
3019 "Missing <Limit ops> directive before %s on line %d.",
3023 else if (!parse_aaa(op
, line
, value
, linenum
))
3026 cupsdLogMessage(CUPSD_LOG_ERROR
,
3027 "Unknown Policy Limit directive %s on line %d.",
3030 cupsdLogMessage(CUPSD_LOG_ERROR
,
3031 "Unknown Policy directive %s on line %d.",
3038 cupsdLogMessage(CUPSD_LOG_ERROR
,
3039 "Unexpected end-of-file at line %d while reading policy \"%s\"!",