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 */
157 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
158 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
159 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
160 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
161 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
}
163 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
166 static unsigned ones
[4] =
168 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
170 static unsigned zeros
[4] =
172 0x00000000, 0x00000000, 0x00000000, 0x00000000
179 static int check_permissions(const char *filename
,
180 const char *suffix
, int mode
,
181 int user
, int group
, int is_dir
,
183 static http_addrlist_t
*get_address(const char *value
, int defport
);
184 static int get_addr_and_mask(const char *value
, unsigned *ip
,
186 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
187 char *value
, int linenum
);
188 static int read_configuration(cups_file_t
*fp
);
189 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
190 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
194 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
197 int /* O - 1 on success, 0 otherwise */
198 cupsdReadConfiguration(void)
200 int i
; /* Looping var */
201 cups_file_t
*fp
; /* Configuration file */
202 int status
; /* Return status */
203 char temp
[1024], /* Temporary buffer */
204 *slash
; /* Directory separator */
205 cups_lang_t
*language
; /* Language */
206 struct passwd
*user
; /* Default user */
207 struct group
*group
; /* Default group */
208 char *old_serverroot
, /* Old ServerRoot */
209 *old_requestroot
; /* Old RequestRoot */
212 * Shutdown the server...
218 * Save the old root paths...
221 old_serverroot
= NULL
;
222 cupsdSetString(&old_serverroot
, ServerRoot
);
223 old_requestroot
= NULL
;
224 cupsdSetString(&old_requestroot
, RequestRoot
);
227 * Reset the server configuration data...
230 cupsdDeleteAllLocations();
248 for (i
= 0; i
< NumRelays
; i
++)
249 if (Relays
[i
].from
.type
== AUTH_NAME
)
250 free(Relays
[i
].from
.mask
.name
.name
);
257 if (NumListeners
> 0)
267 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
268 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
269 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
270 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
271 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
272 cupsdSetString(&DataDir
, CUPS_DATADIR
);
273 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
274 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
275 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
276 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
277 cupsdSetString(&Printcap
, "/etc/printcap");
278 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
279 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
280 cupsdSetString(&RemoteRoot
, "remroot");
281 cupsdSetString(&ServerHeader
, "CUPS/1.1");
282 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
284 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
285 if ((slash
= strrchr(temp
, '/')) != NULL
)
288 cupsdSetString(&ServerRoot
, temp
);
290 cupsdClearString(&Classification
);
291 ClassifyOverride
= 0;
295 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
297 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
298 cupsdSetString(&ServerKey
, "ssl/server.key");
299 # endif /* HAVE_CDSASSL */
300 #endif /* HAVE_SSL */
302 language
= cupsLangDefault();
304 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
305 cupsdSetString(&DefaultLanguage
, "en");
307 cupsdSetString(&DefaultLanguage
, language
->language
);
309 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
311 cupsdSetString(&RIPCache
, "8m");
313 if (getenv("TMPDIR") == NULL
)
314 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
316 cupsdSetString(&TempDir
, getenv("TMPDIR"));
319 * Find the default system group: "sys", "system", or "root"...
322 group
= getgrnam(CUPS_DEFAULT_GROUP
);
330 * Found the group, use it!
333 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
335 SystemGroupIDs
[0] = group
->gr_gid
;
340 * Find the group associated with GID 0...
347 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
349 cupsdSetString(&SystemGroups
[0], "unknown");
351 SystemGroupIDs
[0] = 0;
355 * Find the default user...
358 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
363 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
364 * complement number...)
373 * Find the default group (nobody)...
376 group
= getgrnam("nobody");
380 Group
= group
->gr_gid
;
384 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
385 * complement number...)
395 ConfigFilePerm
= 0640; /* TODO: Add configure option */
396 DefaultAuthType
= AUTH_BASIC
;
398 JobRetryInterval
= 300;
403 HostNameLookups
= FALSE
;
404 ImplicitClasses
= TRUE
;
405 ImplicitAnyClasses
= FALSE
;
406 HideImplicitMembers
= TRUE
;
408 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
409 ListenBackLog
= SOMAXCONN
;
411 LogLevel
= CUPSD_LOG_ERROR
;
413 MaxClientsPerHost
= 0;
414 MaxLogSize
= 1024 * 1024;
415 MaxPrinterHistory
= 10;
418 RootCertDuration
= 300;
420 Timeout
= DEFAULT_TIMEOUT
;
422 BrowseInterval
= DEFAULT_INTERVAL
;
423 BrowsePort
= ippPort();
424 BrowseLocalProtocols
= BROWSE_CUPS
;
425 BrowseRemoteProtocols
= BROWSE_CUPS
;
426 BrowseShortNames
= TRUE
;
427 BrowseTimeout
= DEFAULT_TIMEOUT
;
429 DefaultShared
= TRUE
; /* TODO: Add configure option */
431 cupsdClearString(&BrowseLocalOptions
);
432 cupsdClearString(&BrowseRemoteOptions
);
434 JobHistory
= DEFAULT_HISTORY
;
435 JobFiles
= DEFAULT_FILES
;
440 MaxJobsPerPrinter
= 0;
443 cupsdDeleteAllPolicies();
444 cupsdClearString(&DefaultPolicy
);
446 MaxSubscriptions
= 100;
447 MaxSubscriptionsPerJob
= 0;
448 MaxSubscriptionsPerPrinter
= 0;
449 MaxSubscriptionsPerUser
= 0;
450 DefaultLeaseDuration
= 86400;
451 MaxLeaseDuration
= 0;
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 (NumListeners
== 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
, 0775, 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 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
707 cupsdLogMessage(CUPSD_LOG_ERROR
,
708 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
709 MaxClients
, strerror(errno
));
713 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
717 * Check the MaxActiveJobs setting; limit to 1/3 the available
718 * file descriptors, since we need a pipe for each job...
721 if (MaxActiveJobs
> (MaxFDs
/ 3))
722 MaxActiveJobs
= MaxFDs
/ 3;
724 if (Classification
&& strcasecmp(Classification
, "none") == 0)
725 cupsdClearString(&Classification
);
728 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
731 * Update the MaxClientsPerHost value, as needed...
734 if (MaxClientsPerHost
<= 0)
735 MaxClientsPerHost
= MaxClients
;
737 if (MaxClientsPerHost
> MaxClients
)
738 MaxClientsPerHost
= MaxClients
;
740 cupsdLogMessage(CUPSD_LOG_INFO
,
741 "Allowing up to %d client connections per host.",
745 * Update the default policy, as needed...
749 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
751 DefaultPolicyPtr
= NULL
;
753 if (!DefaultPolicyPtr
)
755 cupsd_policy_t
*p
; /* New policy */
756 cupsd_location_t
*po
; /* New policy operation */
760 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
763 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
764 cupsdLogMessage(CUPSD_LOG_INFO
,
765 "Using policy \"default\" as the default!");
768 cupsdLogMessage(CUPSD_LOG_INFO
,
769 "Creating CUPS default administrative policy:");
771 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
773 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
774 cupsdLogMessage(CUPSD_LOG_INFO
,
775 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
776 "Release-Job Restart-Job Purge-Jobs "
777 "Set-Job-Attributes Create-Job-Subscription "
778 "Renew-Subscription Cancel-Subscription "
779 "Get-Notifications Reprocess-Job Cancel-Current-Job "
780 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
781 "CUPS-Authenticate-Job>");
782 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
784 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
785 po
->order_type
= AUTH_ALLOW
;
786 po
->level
= AUTH_USER
;
788 cupsdAddName(po
, "@OWNER");
789 cupsdAddName(po
, "@SYSTEM");
790 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
792 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
793 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
794 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
795 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
796 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
797 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
798 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
799 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
800 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
801 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
802 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
803 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
804 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
805 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
806 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
807 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
808 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
810 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
812 cupsdLogMessage(CUPSD_LOG_INFO
,
813 "<Limit Pause-Printer Resume-Printer "
814 "Set-Printer-Attributes Enable-Printer "
815 "Disable-Printer Pause-Printer-After-Current-Job "
816 "Hold-New-Jobs Release-Held-New-Jobs "
817 "Deactivate-Printer Activate-Printer Restart-Printer "
818 "Shutdown-Printer Startup-Printer Promote-Job "
819 "Schedule-Job-After CUPS-Add-Printer "
820 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
821 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
822 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
823 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
825 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
826 po
->order_type
= AUTH_ALLOW
;
827 po
->type
= AUTH_BASIC
;
828 po
->level
= AUTH_USER
;
830 cupsdAddName(po
, "@SYSTEM");
831 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
833 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
834 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
835 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
836 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
837 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
838 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
839 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
840 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
841 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
842 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
843 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
844 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
845 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
846 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
847 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
848 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
849 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
850 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
851 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
852 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
853 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
855 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
857 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
858 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
860 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
861 po
->order_type
= AUTH_ALLOW
;
863 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
864 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
868 cupsdLogMessage(CUPSD_LOG_DEBUG
,"NumPolicies=%d", NumPolicies
);
869 for (i
= 0; i
< NumPolicies
; i
++)
870 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Policies[%d]=\"%s\"", i
,
874 * If we are doing a full reload or the server root has changed, flush
875 * the jobs, printers, etc. and start from scratch...
878 if (NeedReload
== RELOAD_ALL
||
879 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
880 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
882 mime_type_t
*type
; /* Current type */
883 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
887 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
893 cupsdDeleteAllSubscriptions();
895 cupsdDeleteAllClasses();
896 cupsdDeleteAllPrinters();
898 DefaultPrinter
= NULL
;
900 if (MimeDatabase
!= NULL
)
901 mimeDelete(MimeDatabase
);
905 for (i
= 0; i
< NumMimeTypes
; i
++)
906 free((void *)MimeTypes
[i
]);
912 * Read the MIME type and conversion database...
915 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
917 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
921 cupsdLogMessage(CUPSD_LOG_EMERG
,
922 "Unable to load MIME database from \'%s\'!", ServerRoot
);
926 cupsdLogMessage(CUPSD_LOG_INFO
,
927 "Loaded MIME database from \'%s\': %d types, %d filters...",
928 ServerRoot
, mimeNumTypes(MimeDatabase
),
929 mimeNumFilters(MimeDatabase
));
932 * Create a list of MIME types for the document-format-supported
936 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
937 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
940 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
942 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
944 i
++, type
= mimeNextType(MimeDatabase
))
946 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
948 MimeTypes
[i
] = strdup(mimetype
);
951 if (i
< NumMimeTypes
)
952 MimeTypes
[i
] = strdup("application/octet-stream");
958 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
959 cupsdLoadBanners(temp
);
962 * Load printers and classes...
965 cupsdLoadAllPrinters();
966 cupsdLoadAllClasses();
967 cupsdLoadRemoteCache();
968 cupsdWritePrintcap();
970 cupsdCreateCommonData();
973 * Load queued jobs...
979 * Load subscriptions...
982 cupsdLoadAllSubscriptions();
984 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
989 * Not a full reload, so recreate the common printer attributes...
992 cupsdCreateCommonData();
995 * Update all printers as needed...
998 cupsdUpdatePrinters();
999 cupsdWritePrintcap();
1001 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1005 * Reset the reload state...
1008 NeedReload
= RELOAD_NONE
;
1010 cupsdClearString(&old_serverroot
);
1011 cupsdClearString(&old_requestroot
);
1014 * Startup the server and return...
1024 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1027 static int /* O - 0 on success, -1 on error */
1028 check_permissions(const char *filename
, /* I - File/directory name */
1029 const char *suffix
, /* I - Additional file/directory name */
1030 int mode
, /* I - Permissions */
1031 int user
, /* I - Owner */
1032 int group
, /* I - Group */
1033 int is_dir
, /* I - 1 = directory, 0 = file */
1034 int create_dir
)/* I - 1 = create directory, 0 = not */
1036 int dir_created
= 0; /* Did we create a directory? */
1037 char pathname
[1024]; /* File name with prefix */
1038 struct stat fileinfo
; /* Stat buffer */
1042 * Prepend the given root to the filename before testing it...
1047 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1048 filename
= pathname
;
1052 * See if we can stat the file/directory...
1055 if (stat(filename
, &fileinfo
))
1057 if (errno
== ENOENT
&& create_dir
)
1059 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1062 if (mkdir(filename
, mode
))
1064 cupsdLogMessage(CUPSD_LOG_ERROR
,
1065 "Unable to create directory \"%s\" - %s", filename
,
1077 * Make sure it's a regular file...
1080 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1082 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1086 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1088 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1093 * Fix owner, group, and mode as needed...
1096 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1098 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1100 if (chown(filename
, user
, group
))
1102 cupsdLogMessage(CUPSD_LOG_ERROR
,
1103 "Unable to change ownership of \"%s\" - %s", filename
,
1109 if (dir_created
|| (fileinfo
.st_mode
& 0777) != mode
)
1111 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1113 if (chmod(filename
, mode
))
1115 cupsdLogMessage(CUPSD_LOG_ERROR
,
1116 "Unable to change permissions of \"%s\" - %s", filename
,
1123 * Everything is OK...
1131 * 'get_address()' - Get an address + port number from a line.
1134 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1135 get_address(const char *value
, /* I - Value string */
1136 int defport
) /* I - Default port */
1138 char buffer
[1024], /* Hostname + port number buffer */
1139 defpname
[255], /* Default port name */
1140 *hostname
, /* Hostname or IP */
1141 *portname
; /* Port number or name */
1142 http_addrlist_t
*addrlist
; /* Address list */
1146 * Check for an empty value...
1151 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1156 * Grab a hostname and port number; if there is no colon and the port name
1157 * is only digits, then we have a port number by itself...
1160 strlcpy(buffer
, value
, sizeof(buffer
));
1162 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1169 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1174 * Use the default port...
1177 sprintf(defpname
, "%d", defport
);
1178 portname
= defpname
;
1184 * The buffer contains just a port number...
1192 if (hostname
&& !strcmp(hostname
, "*"))
1196 * Now lookup the address using httpAddrGetList()...
1199 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1200 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1201 hostname
? hostname
: "(nil)");
1208 * 'get_addr_and_mask()' - Get an IP address and netmask.
1211 static int /* O - 1 on success, 0 on failure */
1212 get_addr_and_mask(const char *value
, /* I - String from config file */
1213 unsigned *ip
, /* O - Address value */
1214 unsigned *mask
) /* O - Mask value */
1216 int i
, j
, /* Looping vars */
1217 family
, /* Address family */
1218 ipcount
; /* Count of fields in address */
1219 unsigned ipval
; /* Value */
1220 const char *maskval
, /* Pointer to start of mask value */
1221 *ptr
, /* Pointer into value */
1223 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1225 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1226 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1227 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1228 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1231 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1233 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1234 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1235 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1236 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1237 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1238 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1239 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1240 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1242 #endif /* AF_INET6 */
1246 * Get the address...
1249 memset(ip
, 0, sizeof(unsigned) * 4);
1251 if ((maskval
= strchr(value
, '/')) != NULL
)
1254 maskval
= value
+ strlen(value
);
1258 * Check for an IPv6 address...
1264 * Parse hexadecimal IPv6 address...
1269 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1273 else if (!strncmp(ptr
, "::", 2))
1275 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1277 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1281 else if (isxdigit(*ptr
& 255))
1283 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1291 ip
[i
] |= ipval
<< 16;
1302 if (*ptr
&& *ptr
!= '/')
1306 #endif /* AF_INET6 */
1309 * Parse dotted-decimal IPv4 address...
1313 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1315 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1316 ip
[0] = ip
[1] = ip
[2] = 0;
1322 * Get the netmask value(s)...
1325 memset(mask
, 0, sizeof(unsigned) * 4);
1328 if (*maskval
== '[')
1331 * Get hexadecimal mask value...
1334 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1338 else if (!strncmp(ptr
, "::", 2))
1340 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1342 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1346 else if (isxdigit(*ptr
& 255))
1348 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1356 mask
[i
] |= ipval
<< 16;
1369 #endif /* AF_INET6 */
1370 if (strchr(maskval
, '.'))
1373 * Get dotted-decimal mask...
1376 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1379 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1380 mask
[0] = mask
[1] = mask
[2] = 0;
1385 * Get address/bits format...
1391 if (family
== AF_INET6
)
1396 mask
[0] = 0xffffffff;
1398 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1401 mask
[1] = 0xffffffff;
1405 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1408 mask
[2] = 0xffffffff;
1412 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1415 mask
[3] = 0xffffffff;
1419 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1422 #endif /* AF_INET6 */
1426 mask
[0] = 0xffffffff;
1427 mask
[1] = 0xffffffff;
1428 mask
[2] = 0xffffffff;
1431 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1433 mask
[3] = 0xffffffff;
1438 else if (family
== AF_INET6
)
1439 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1440 #endif /* AF_INET6 */
1442 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1444 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1445 "get_addr_and_mask(value=\"%s\", "
1446 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1447 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1451 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1454 if ((ip
[0] & ~mask
[0]) != 0 ||
1455 (ip
[1] & ~mask
[1]) != 0 ||
1456 (ip
[2] & ~mask
[2]) != 0 ||
1457 (ip
[3] & ~mask
[3]) != 0)
1465 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1468 static int /* O - 1 on success, 0 on failure */
1469 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1470 char *line
, /* I - Line from file */
1471 char *value
, /* I - Start of value data */
1472 int linenum
) /* I - Current line number */
1474 char *valptr
; /* Pointer into value */
1475 unsigned ip
[4], /* IP address components */
1476 mask
[4]; /* IP netmask components */
1479 if (!strcasecmp(line
, "Encryption"))
1482 * "Encryption xxx" - set required encryption level...
1485 if (!strcasecmp(value
, "never"))
1486 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1487 else if (!strcasecmp(value
, "always"))
1489 cupsdLogMessage(CUPSD_LOG_ERROR
,
1490 "Encryption value \"%s\" on line %d is invalid in this "
1491 "context. Using \"required\" instead.", value
, linenum
);
1493 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1495 else if (!strcasecmp(value
, "required"))
1496 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1497 else if (!strcasecmp(value
, "ifrequested"))
1498 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1501 cupsdLogMessage(CUPSD_LOG_ERROR
,
1502 "Unknown Encryption value %s on line %d.", value
, linenum
);
1506 else if (!strcasecmp(line
, "Order"))
1509 * "Order Deny,Allow" or "Order Allow,Deny"...
1512 if (!strncasecmp(value
, "deny", 4))
1513 loc
->order_type
= AUTH_ALLOW
;
1514 else if (!strncasecmp(value
, "allow", 5))
1515 loc
->order_type
= AUTH_DENY
;
1518 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1523 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1526 * Allow [From] host/ip...
1527 * Deny [From] host/ip...
1530 if (!strncasecmp(value
, "from", 4))
1533 * Strip leading "from"...
1538 while (isspace(*value
& 255))
1543 * Figure out what form the allow/deny address takes:
1554 * nnn.nnn.nnn.nnn/mm
1555 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1558 if (!strcasecmp(value
, "all"))
1564 if (!strcasecmp(line
, "Allow"))
1565 cupsdAllowIP(loc
, zeros
, zeros
);
1567 cupsdDenyIP(loc
, zeros
, zeros
);
1569 else if (!strcasecmp(value
, "none"))
1575 if (!strcasecmp(line
, "Allow"))
1576 cupsdAllowIP(loc
, ones
, zeros
);
1578 cupsdDenyIP(loc
, ones
, zeros
);
1580 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1583 * Host or domain name...
1586 if (value
[0] == '*')
1589 if (!strcasecmp(line
, "Allow"))
1590 cupsdAllowHost(loc
, value
);
1592 cupsdDenyHost(loc
, value
);
1597 * One of many IP address forms...
1600 if (!get_addr_and_mask(value
, ip
, mask
))
1602 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1607 if (!strcasecmp(line
, "Allow"))
1608 cupsdAllowIP(loc
, ip
, mask
);
1610 cupsdDenyIP(loc
, ip
, mask
);
1613 else if (!strcasecmp(line
, "AuthType"))
1616 * AuthType {none,basic,digest,basicdigest}
1619 if (!strcasecmp(value
, "none"))
1621 loc
->type
= AUTH_NONE
;
1622 loc
->level
= AUTH_ANON
;
1624 else if (!strcasecmp(value
, "basic"))
1626 loc
->type
= AUTH_BASIC
;
1628 if (loc
->level
== AUTH_ANON
)
1629 loc
->level
= AUTH_USER
;
1631 else if (!strcasecmp(value
, "digest"))
1633 loc
->type
= AUTH_DIGEST
;
1635 if (loc
->level
== AUTH_ANON
)
1636 loc
->level
= AUTH_USER
;
1638 else if (!strcasecmp(value
, "basicdigest"))
1640 loc
->type
= AUTH_BASICDIGEST
;
1642 if (loc
->level
== AUTH_ANON
)
1643 loc
->level
= AUTH_USER
;
1647 cupsdLogMessage(CUPSD_LOG_WARN
,
1648 "Unknown authorization type %s on line %d.",
1653 else if (!strcasecmp(line
, "AuthClass"))
1656 * AuthClass anonymous, user, system, group
1659 if (!strcasecmp(value
, "anonymous"))
1661 loc
->type
= AUTH_NONE
;
1662 loc
->level
= AUTH_ANON
;
1664 cupsdLogMessage(CUPSD_LOG_WARN
,
1665 "\"AuthClass %s\" is deprecated; consider removing "
1669 else if (!strcasecmp(value
, "user"))
1671 loc
->level
= AUTH_USER
;
1673 cupsdLogMessage(CUPSD_LOG_WARN
,
1674 "\"AuthClass %s\" is deprecated; consider using "
1675 "\"Require valid-user\" on line %d.",
1678 else if (!strcasecmp(value
, "group"))
1680 loc
->level
= AUTH_GROUP
;
1682 cupsdLogMessage(CUPSD_LOG_WARN
,
1683 "\"AuthClass %s\" is deprecated; consider using "
1684 "\"Require @groupname\" on line %d.",
1687 else if (!strcasecmp(value
, "system"))
1689 loc
->level
= AUTH_GROUP
;
1691 cupsdAddName(loc
, "@SYSTEM");
1693 cupsdLogMessage(CUPSD_LOG_WARN
,
1694 "\"AuthClass %s\" is deprecated; consider using "
1695 "\"Require @SYSTEM\" on line %d.",
1700 cupsdLogMessage(CUPSD_LOG_WARN
,
1701 "Unknown authorization class %s on line %d.",
1706 else if (!strcasecmp(line
, "AuthGroupName"))
1708 cupsdAddName(loc
, value
);
1710 cupsdLogMessage(CUPSD_LOG_WARN
,
1711 "\"AuthGroupName %s\" directive is deprecated; consider "
1712 "using \"Require @%s\" on line %d.",
1713 value
, value
, linenum
);
1715 else if (!strcasecmp(line
, "Require"))
1718 * Apache synonym for AuthClass and AuthGroupName...
1722 * Require valid-user
1723 * Require group names
1724 * Require user names
1727 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1732 if (!strcasecmp(value
, "valid-user") ||
1733 !strcasecmp(value
, "user"))
1734 loc
->level
= AUTH_USER
;
1735 else if (!strcasecmp(value
, "group"))
1736 loc
->level
= AUTH_GROUP
;
1739 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1745 * Get the list of names from the line...
1748 for (value
= valptr
; *value
;)
1750 while (isspace(*value
& 255))
1753 if (*value
== '\"' || *value
== '\'')
1756 * Grab quoted name...
1759 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1766 * Grab literal name.
1769 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1775 cupsdAddName(loc
, value
);
1777 for (value
= valptr
; isspace(*value
& 255); value
++);
1780 else if (!strcasecmp(line
, "Satisfy"))
1782 if (!strcasecmp(value
, "all"))
1783 loc
->satisfy
= AUTH_SATISFY_ALL
;
1784 else if (!strcasecmp(value
, "any"))
1785 loc
->satisfy
= AUTH_SATISFY_ANY
;
1788 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1801 * 'read_configuration()' - Read a configuration file.
1804 static int /* O - 1 on success, 0 on failure */
1805 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1807 int i
; /* Looping var */
1808 int linenum
; /* Current line number */
1809 char line
[HTTP_MAX_BUFFER
],
1810 /* Line from file */
1811 temp
[HTTP_MAX_BUFFER
],
1812 /* Temporary buffer for value */
1813 temp2
[HTTP_MAX_BUFFER
],
1814 /* Temporary buffer 2 for value */
1815 *ptr
, /* Pointer into line/temp */
1816 *value
, /* Pointer to value */
1817 *valueptr
, /* Pointer into value */
1818 quote
; /* Quote character */
1819 int valuelen
; /* Length of value */
1820 cupsd_var_t
*var
; /* Current variable */
1821 http_addrlist_t
*addrlist
, /* Address list */
1822 *addr
; /* Current address */
1823 unsigned ip
[4], /* Address value */
1824 mask
[4]; /* Netmask value */
1825 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1826 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1827 cupsd_location_t
*location
; /* Browse location */
1828 cups_file_t
*incfile
; /* Include file */
1829 char incname
[1024]; /* Include filename */
1830 struct group
*group
; /* Group */
1834 * Loop through each line in the file...
1839 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1842 * Decode the directive...
1845 if (!strcasecmp(line
, "Include"))
1851 if (value
[0] == '/')
1852 strlcpy(incname
, value
, sizeof(incname
));
1854 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1856 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1857 cupsdLogMessage(CUPSD_LOG_ERROR
,
1858 "Unable to include config file \"%s\" - %s",
1859 incname
, strerror(errno
));
1862 read_configuration(incfile
);
1863 cupsFileClose(incfile
);
1866 else if (!strcasecmp(line
, "<Location"))
1874 linenum
= read_location(fp
, value
, linenum
);
1880 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1885 else if (!strcasecmp(line
, "<Policy"))
1893 linenum
= read_policy(fp
, value
, linenum
);
1899 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1903 else if (!strcasecmp(line
, "FaxRetryInterval"))
1907 JobRetryInterval
= atoi(value
);
1908 cupsdLogMessage(CUPSD_LOG_WARN
,
1909 "FaxRetryInterval is deprecated; use "
1910 "JobRetryInterval on line %d.", linenum
);
1914 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1918 else if (!strcasecmp(line
, "FaxRetryLimit"))
1922 JobRetryLimit
= atoi(value
);
1923 cupsdLogMessage(CUPSD_LOG_WARN
,
1924 "FaxRetryLimit is deprecated; use "
1925 "JobRetryLimit on line %d.", linenum
);
1929 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1933 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
1935 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
1936 #endif /* HAVE_SSL */
1940 * Add listening address(es) to the list...
1943 cupsd_listener_t
*lis
; /* New listeners array */
1947 * Get the address list...
1950 addrlist
= get_address(value
, IPP_PORT
);
1954 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1960 * Add each address...
1963 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1966 * Allocate another listener...
1969 if (NumListeners
== 0)
1970 lis
= malloc(sizeof(cupsd_listener_t
));
1972 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1976 cupsdLogMessage(CUPSD_LOG_ERROR
,
1977 "Unable to allocate %s at line %d - %s.",
1978 line
, linenum
, strerror(errno
));
1983 lis
+= NumListeners
;
1986 * Copy the current address and log it...
1989 memset(lis
, 0, sizeof(cupsd_listener_t
));
1990 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
1993 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1994 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1995 #endif /* HAVE_SSL */
1998 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1999 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2000 ntohs(lis
->address
.ipv6
.sin6_port
));
2002 #endif /* AF_INET6 */
2004 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2005 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2007 #endif /* AF_LOCAL */
2008 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2009 ntohs(lis
->address
.ipv4
.sin_port
));
2018 httpAddrFreeList(addrlist
);
2020 else if (!strcasecmp(line
, "BrowseAddress"))
2023 * Add a browse address to the list...
2026 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2029 if (NumBrowsers
== 0)
2030 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2032 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2036 cupsdLogMessage(CUPSD_LOG_ERROR
,
2037 "Unable to allocate BrowseAddress at line %d - %s.",
2038 linenum
, strerror(errno
));
2043 dira
+= NumBrowsers
;
2045 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2047 if (!strcasecmp(value
, "@LOCAL"))
2050 * Send browse data to all local interfaces...
2053 strcpy(dira
->iface
, "*");
2056 else if (!strncasecmp(value
, "@IF(", 4))
2059 * Send browse data to the named interface...
2062 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2064 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2070 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2073 * Only IPv4 addresses are supported...
2076 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2077 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2082 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2083 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2085 cupsdLogMessage(CUPSD_LOG_INFO
,
2086 "Sending browsing info to %s:%d (IPv4)",
2087 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2092 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2095 httpAddrFreeList(addrlist
);
2098 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2101 else if (!strcasecmp(line
, "BrowseOrder"))
2104 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2107 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2108 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2110 if (location
== NULL
)
2111 cupsdLogMessage(CUPSD_LOG_ERROR
,
2112 "Unable to initialize browse access control list!");
2113 else if (!strncasecmp(value
, "deny", 4))
2114 location
->order_type
= AUTH_ALLOW
;
2115 else if (!strncasecmp(value
, "allow", 5))
2116 location
->order_type
= AUTH_DENY
;
2118 cupsdLogMessage(CUPSD_LOG_ERROR
,
2119 "Unknown BrowseOrder value %s on line %d.",
2122 else if (!strcasecmp(line
, "BrowseProtocols") ||
2123 !strcasecmp(line
, "BrowseLocalProtocols") ||
2124 !strcasecmp(line
, "BrowseRemoteProtocols"))
2127 * "BrowseProtocol name [... name]"
2130 if (strcasecmp(line
, "BrowseLocalProtocols"))
2131 BrowseRemoteProtocols
= 0;
2132 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2133 BrowseLocalProtocols
= 0;
2137 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2138 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2141 if (value
[valuelen
])
2143 value
[valuelen
] = '\0';
2147 if (!strcasecmp(value
, "cups"))
2149 if (strcasecmp(line
, "BrowseLocalProtocols"))
2150 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2151 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2152 BrowseLocalProtocols
|= BROWSE_CUPS
;
2154 else if (!strcasecmp(value
, "slp"))
2156 if (strcasecmp(line
, "BrowseLocalProtocols"))
2157 BrowseRemoteProtocols
|= BROWSE_SLP
;
2158 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2159 BrowseLocalProtocols
|= BROWSE_SLP
;
2161 else if (!strcasecmp(value
, "ldap"))
2163 if (strcasecmp(line
, "BrowseLocalProtocols"))
2164 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2165 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2166 BrowseLocalProtocols
|= BROWSE_LDAP
;
2168 else if (!strcasecmp(value
, "all"))
2170 if (strcasecmp(line
, "BrowseLocalProtocols"))
2171 BrowseRemoteProtocols
|= BROWSE_ALL
;
2172 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2173 BrowseLocalProtocols
|= BROWSE_ALL
;
2177 cupsdLogMessage(CUPSD_LOG_ERROR
,
2178 "Unknown browse protocol \"%s\" on line %d.",
2183 for (value
+= valuelen
; *value
; value
++)
2184 if (!isspace(*value
) || *value
!= ',')
2188 else if (!strcasecmp(line
, "BrowseAllow") ||
2189 !strcasecmp(line
, "BrowseDeny"))
2192 * BrowseAllow [From] host/ip...
2193 * BrowseDeny [From] host/ip...
2196 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2197 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2199 if (location
== NULL
)
2200 cupsdLogMessage(CUPSD_LOG_ERROR
,
2201 "Unable to initialize browse access control list!");
2204 if (!strncasecmp(value
, "from ", 5))
2207 * Strip leading "from"...
2212 while (isspace(*value
))
2217 * Figure out what form the allow/deny address takes:
2228 * nnn.nnn.nnn.nnn/mm
2229 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2232 if (!strcasecmp(value
, "all"))
2238 if (!strcasecmp(line
, "BrowseAllow"))
2239 cupsdAllowIP(location
, zeros
, zeros
);
2241 cupsdDenyIP(location
, zeros
, zeros
);
2243 else if (!strcasecmp(value
, "none"))
2249 if (!strcasecmp(line
, "BrowseAllow"))
2250 cupsdAllowIP(location
, ones
, zeros
);
2252 cupsdDenyIP(location
, ones
, zeros
);
2254 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2257 * Host or domain name...
2260 if (value
[0] == '*')
2263 if (!strcasecmp(line
, "BrowseAllow"))
2264 cupsdAllowHost(location
, value
);
2266 cupsdDenyHost(location
, value
);
2271 * One of many IP address forms...
2274 if (!get_addr_and_mask(value
, ip
, mask
))
2276 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2281 if (!strcasecmp(line
, "BrowseAllow"))
2282 cupsdAllowIP(location
, ip
, mask
);
2284 cupsdDenyIP(location
, ip
, mask
);
2288 else if (!strcasecmp(line
, "BrowseRelay"))
2291 * BrowseRelay [from] source [to] destination
2295 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2297 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2301 cupsdLogMessage(CUPSD_LOG_ERROR
,
2302 "Unable to allocate BrowseRelay at line %d - %s.",
2303 linenum
, strerror(errno
));
2310 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2312 if (!strncasecmp(value
, "from ", 5))
2315 * Strip leading "from"...
2320 while (isspace(*value
))
2325 * Figure out what form the from address takes:
2334 * nnn.nnn.nnn.nnn/mm
2335 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2338 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2341 * Host or domain name...
2344 if (value
[0] == '*')
2347 strlcpy(temp
, value
, sizeof(temp
));
2348 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2351 relay
->from
.type
= AUTH_NAME
;
2352 relay
->from
.mask
.name
.name
= strdup(temp
);
2353 relay
->from
.mask
.name
.length
= strlen(temp
);
2358 * One of many IP address forms...
2361 if (!get_addr_and_mask(value
, ip
, mask
))
2363 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2368 relay
->from
.type
= AUTH_IP
;
2369 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2370 sizeof(relay
->from
.mask
.ip
.address
));
2371 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2372 sizeof(relay
->from
.mask
.ip
.netmask
));
2376 * Skip value and trailing whitespace...
2379 for (; *value
; value
++)
2380 if (isspace(*value
))
2383 while (isspace(*value
))
2386 if (!strncasecmp(value
, "to ", 3))
2389 * Strip leading "to"...
2394 while (isspace(*value
))
2399 * Get "to" address and port...
2402 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2405 * Only IPv4 addresses are supported...
2408 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2409 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2414 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2416 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2418 if (relay
->from
.type
== AUTH_IP
)
2419 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2420 relay
->from
.mask
.ip
.address
[0],
2421 relay
->from
.mask
.ip
.address
[1],
2422 relay
->from
.mask
.ip
.address
[2],
2423 relay
->from
.mask
.ip
.address
[3],
2424 relay
->from
.mask
.ip
.netmask
[0],
2425 relay
->from
.mask
.ip
.netmask
[1],
2426 relay
->from
.mask
.ip
.netmask
[2],
2427 relay
->from
.mask
.ip
.netmask
[3]);
2429 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2431 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2432 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2437 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2440 httpAddrFreeList(addrlist
);
2444 if (relay
->from
.type
== AUTH_NAME
)
2445 free(relay
->from
.mask
.name
.name
);
2447 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2451 else if (!strcasecmp(line
, "BrowsePoll"))
2454 * BrowsePoll address[:port]
2457 char *portname
; /* Port name */
2458 int portnum
; /* Port number */
2459 struct servent
*service
; /* Service */
2463 * Extract the port name from the address...
2466 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2470 if (isdigit(*portname
& 255))
2471 portnum
= atoi(portname
);
2472 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2473 portnum
= ntohs(service
->s_port
);
2476 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2482 portnum
= ippPort();
2485 * Add the poll entry...
2489 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2491 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2495 cupsdLogMessage(CUPSD_LOG_ERROR
,
2496 "Unable to allocate BrowsePoll at line %d - %s.",
2497 linenum
, strerror(errno
));
2505 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2507 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2508 pollp
->port
= portnum
;
2510 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2513 else if (!strcasecmp(line
, "DefaultAuthType"))
2516 * DefaultAuthType {basic,digest,basicdigest}
2519 if (!strcasecmp(value
, "basic"))
2520 DefaultAuthType
= AUTH_BASIC
;
2521 else if (!strcasecmp(value
, "digest"))
2522 DefaultAuthType
= AUTH_DIGEST
;
2523 else if (!strcasecmp(value
, "basicdigest"))
2524 DefaultAuthType
= AUTH_BASICDIGEST
;
2527 cupsdLogMessage(CUPSD_LOG_WARN
,
2528 "Unknown default authorization type %s on line %d.",
2533 else if (!strcasecmp(line
, "User"))
2536 * User ID to run as...
2539 if (value
&& isdigit(value
[0] & 255))
2541 int uid
= atoi(value
);
2544 cupsdLogMessage(CUPSD_LOG_ERROR
,
2545 "Will not use User 0 as specified on line %d "
2546 "for security reasons. You must use a non-"
2547 "privileged account instead.",
2554 struct passwd
*p
; /* Password information */
2557 p
= getpwnam(value
);
2562 cupsdLogMessage(CUPSD_LOG_ERROR
,
2563 "Will not use User %s (UID=0) as specified on line "
2564 "%d for security reasons. You must use a non-"
2565 "privileged account instead.",
2571 cupsdLogMessage(CUPSD_LOG_ERROR
,
2572 "Unknown User \"%s\" on line %d, ignoring!",
2576 cupsdLogMessage(CUPSD_LOG_ERROR
,
2577 "User directive on line %d missing the username!",
2580 else if (!strcasecmp(line
, "Group"))
2583 * Group ID to run as...
2586 if (isdigit(value
[0]))
2587 Group
= atoi(value
);
2591 group
= getgrnam(value
);
2594 Group
= group
->gr_gid
;
2596 cupsdLogMessage(CUPSD_LOG_ERROR
,
2597 "Unknown Group \"%s\" on line %d, ignoring!",
2601 else if (!strcasecmp(line
, "SystemGroup"))
2604 * System (admin) group(s)...
2607 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2609 if (*value
== '\'' || *value
== '\"')
2612 * Scan quoted name...
2617 for (valueptr
= value
; *valueptr
; valueptr
++)
2618 if (*valueptr
== quote
)
2624 * Scan space or comma-delimited name...
2627 for (valueptr
= value
; *valueptr
; valueptr
++)
2628 if (isspace(*valueptr
) || *valueptr
== ',')
2635 group
= getgrnam(value
);
2638 cupsdSetString(SystemGroups
+ i
, value
);
2639 SystemGroupIDs
[i
] = group
->gr_gid
;
2644 cupsdLogMessage(CUPSD_LOG_ERROR
,
2645 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2652 while (*value
== ',' || isspace(*value
))
2657 NumSystemGroups
= i
;
2659 else if (!strcasecmp(line
, "HostNameLookups"))
2662 * Do hostname lookups?
2665 if (!strcasecmp(value
, "off"))
2666 HostNameLookups
= 0;
2667 else if (!strcasecmp(value
, "on"))
2668 HostNameLookups
= 1;
2669 else if (!strcasecmp(value
, "double"))
2670 HostNameLookups
= 2;
2672 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2675 else if (!strcasecmp(line
, "LogLevel"))
2678 * Amount of logging to do...
2681 if (!strcasecmp(value
, "debug2"))
2682 LogLevel
= CUPSD_LOG_DEBUG2
;
2683 else if (!strcasecmp(value
, "debug"))
2684 LogLevel
= CUPSD_LOG_DEBUG
;
2685 else if (!strcasecmp(value
, "info"))
2686 LogLevel
= CUPSD_LOG_INFO
;
2687 else if (!strcasecmp(value
, "notice"))
2688 LogLevel
= CUPSD_LOG_NOTICE
;
2689 else if (!strcasecmp(value
, "warn"))
2690 LogLevel
= CUPSD_LOG_WARN
;
2691 else if (!strcasecmp(value
, "error"))
2692 LogLevel
= CUPSD_LOG_ERROR
;
2693 else if (!strcasecmp(value
, "crit"))
2694 LogLevel
= CUPSD_LOG_CRIT
;
2695 else if (!strcasecmp(value
, "alert"))
2696 LogLevel
= CUPSD_LOG_ALERT
;
2697 else if (!strcasecmp(value
, "emerg"))
2698 LogLevel
= CUPSD_LOG_EMERG
;
2699 else if (!strcasecmp(value
, "none"))
2700 LogLevel
= CUPSD_LOG_NONE
;
2702 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2705 else if (!strcasecmp(line
, "PrintcapFormat"))
2708 * Format of printcap file?
2711 if (!strcasecmp(value
, "bsd"))
2712 PrintcapFormat
= PRINTCAP_BSD
;
2713 else if (!strcasecmp(value
, "solaris"))
2714 PrintcapFormat
= PRINTCAP_SOLARIS
;
2716 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2719 else if (!strcasecmp(line
, "ServerTokens"))
2722 * Set the string used for the Server header...
2725 struct utsname plat
; /* Platform info */
2730 if (!strcasecmp(value
, "ProductOnly"))
2731 cupsdSetString(&ServerHeader
, "CUPS");
2732 else if (!strcasecmp(value
, "Major"))
2733 cupsdSetString(&ServerHeader
, "CUPS/1");
2734 else if (!strcasecmp(value
, "Minor"))
2735 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2736 else if (!strcasecmp(value
, "Minimal"))
2737 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2738 else if (!strcasecmp(value
, "OS"))
2739 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2740 else if (!strcasecmp(value
, "Full"))
2741 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2743 else if (!strcasecmp(value
, "None"))
2744 cupsdClearString(&ServerHeader
);
2746 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2749 else if (!strcasecmp(line
, "PassEnv"))
2752 * PassEnv variable [... variable]
2757 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2758 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2761 if (value
[valuelen
])
2763 value
[valuelen
] = '\0';
2767 cupsdSetEnv(value
, NULL
);
2769 for (value
+= valuelen
; *value
; value
++)
2770 if (!isspace(*value
) || *value
!= ',')
2774 else if (!strcasecmp(line
, "SetEnv"))
2777 * SetEnv variable value
2780 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2788 while (isspace(*valueptr
& 255))
2791 cupsdSetEnv(value
, valueptr
);
2794 cupsdLogMessage(CUPSD_LOG_ERROR
,
2795 "Missing value for SetEnv directive on line %d.",
2801 * Find a simple variable in the list...
2804 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2805 if (!strcasecmp(line
, var
->name
))
2811 * Unknown directive! Output an error message and continue...
2814 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2821 case CUPSD_VARTYPE_INTEGER
:
2824 char *units
; /* Units */
2827 n
= strtol(value
, &units
, 0);
2829 if (units
&& *units
)
2831 if (tolower(units
[0] & 255) == 'g')
2832 n
*= 1024 * 1024 * 1024;
2833 else if (tolower(units
[0] & 255) == 'm')
2835 else if (tolower(units
[0] & 255) == 'k')
2837 else if (tolower(units
[0] & 255) == 't')
2841 *((int *)var
->ptr
) = n
;
2845 case CUPSD_VARTYPE_BOOLEAN
:
2846 if (!strcasecmp(value
, "true") ||
2847 !strcasecmp(value
, "on") ||
2848 !strcasecmp(value
, "enabled") ||
2849 !strcasecmp(value
, "yes") ||
2851 *((int *)var
->ptr
) = TRUE
;
2852 else if (!strcasecmp(value
, "false") ||
2853 !strcasecmp(value
, "off") ||
2854 !strcasecmp(value
, "disabled") ||
2855 !strcasecmp(value
, "no") ||
2856 !strcasecmp(value
, "0"))
2857 *((int *)var
->ptr
) = FALSE
;
2859 cupsdLogMessage(CUPSD_LOG_ERROR
,
2860 "Unknown boolean value %s on line %d.",
2864 case CUPSD_VARTYPE_STRING
:
2865 cupsdSetString((char **)var
->ptr
, value
);
2876 * 'read_location()' - Read a <Location path> definition.
2879 static int /* O - New line number or 0 on error */
2880 read_location(cups_file_t
*fp
, /* I - Configuration file */
2881 char *location
, /* I - Location name/path */
2882 int linenum
) /* I - Current line number */
2884 cupsd_location_t
*loc
, /* New location */
2885 *parent
; /* Parent location */
2886 char line
[HTTP_MAX_BUFFER
],
2888 *value
, /* Value for directive */
2889 *valptr
; /* Pointer into value */
2892 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2895 parent
->limit
= AUTH_LIMIT_ALL
;
2898 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2901 * Decode the directive...
2904 if (!strcasecmp(line
, "</Location>"))
2906 else if (!strcasecmp(line
, "<Limit") ||
2907 !strcasecmp(line
, "<LimitExcept"))
2911 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2915 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2921 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2926 if (!strcmp(value
, "ALL"))
2927 loc
->limit
= AUTH_LIMIT_ALL
;
2928 else if (!strcmp(value
, "GET"))
2929 loc
->limit
|= AUTH_LIMIT_GET
;
2930 else if (!strcmp(value
, "HEAD"))
2931 loc
->limit
|= AUTH_LIMIT_HEAD
;
2932 else if (!strcmp(value
, "OPTIONS"))
2933 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2934 else if (!strcmp(value
, "POST"))
2935 loc
->limit
|= AUTH_LIMIT_POST
;
2936 else if (!strcmp(value
, "PUT"))
2937 loc
->limit
|= AUTH_LIMIT_PUT
;
2938 else if (!strcmp(value
, "TRACE"))
2939 loc
->limit
|= AUTH_LIMIT_TRACE
;
2941 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2944 for (value
= valptr
; isspace(*value
& 255); value
++);
2947 if (!strcasecmp(line
, "<LimitExcept"))
2948 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2950 parent
->limit
&= ~loc
->limit
;
2952 else if (!strcasecmp(line
, "</Limit>"))
2954 else if (!parse_aaa(loc
, line
, value
, linenum
))
2956 cupsdLogMessage(CUPSD_LOG_ERROR
,
2957 "Unknown Location directive %s on line %d.",
2963 cupsdLogMessage(CUPSD_LOG_ERROR
,
2964 "Unexpected end-of-file at line %d while reading location!",
2972 * 'read_policy()' - Read a <Policy name> definition.
2975 static int /* O - New line number or 0 on error */
2976 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2977 char *policy
, /* I - Location name/path */
2978 int linenum
) /* I - Current line number */
2980 int i
; /* Looping var */
2981 cupsd_policy_t
*pol
; /* Policy */
2982 cupsd_location_t
*op
; /* Policy operation */
2983 int num_ops
; /* Number of IPP operations */
2984 ipp_op_t ops
[100]; /* Operations */
2985 char line
[HTTP_MAX_BUFFER
],
2987 *value
, /* Value for directive */
2988 *valptr
; /* Pointer into value */
2992 * Create the policy...
2995 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2999 * Read from the file...
3005 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3008 * Decode the directive...
3011 if (!strcasecmp(line
, "</Policy>"))
3014 cupsdLogMessage(CUPSD_LOG_WARN
,
3015 "Missing </Limit> before </Policy> on line %d!",
3020 else if (!strcasecmp(line
, "<Limit") && !op
)
3024 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3029 * Scan for IPP operation names...
3036 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3041 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3043 if (!strcasecmp(value
, "All"))
3044 ops
[num_ops
] = IPP_ANY_OPERATION
;
3045 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3046 cupsdLogMessage(CUPSD_LOG_ERROR
,
3047 "Bad IPP operation name \"%s\" on line %d!",
3053 cupsdLogMessage(CUPSD_LOG_ERROR
,
3054 "Too many operations listed on line %d!",
3057 for (value
= valptr
; isspace(*value
& 255); value
++);
3061 * If none are specified, apply the policy to all operations...
3066 ops
[0] = IPP_ANY_OPERATION
;
3071 * Add a new policy for the first operation...
3074 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3076 else if (!strcasecmp(line
, "</Limit>") && op
)
3079 * Finish the current operation limit...
3085 * Copy the policy to the other operations...
3088 for (i
= 1; i
< num_ops
; i
++)
3089 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3096 cupsdLogMessage(CUPSD_LOG_ERROR
,
3097 "Missing <Limit ops> directive before %s on line %d.",
3101 else if (!parse_aaa(op
, line
, value
, linenum
))
3104 cupsdLogMessage(CUPSD_LOG_ERROR
,
3105 "Unknown Policy Limit directive %s on line %d.",
3108 cupsdLogMessage(CUPSD_LOG_ERROR
,
3109 "Unknown Policy directive %s on line %d.",
3116 cupsdLogMessage(CUPSD_LOG_ERROR
,
3117 "Unexpected end-of-file at line %d while reading policy \"%s\"!",