4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdReadConfiguration() - Read the cupsd.conf file.
27 * check_permissions() - Fix the mode and ownership of a file or
29 * get_address() - Get an address + port number from a line.
30 * get_addr_and_mask() - Get an IP address and netmask.
31 * parse_aaa() - Parse authentication, authorization, and
32 * access control lines.
33 * read_configuration() - Read a configuration file.
34 * read_location() - Read a <Location path> definition.
35 * read_policy() - Read a <Policy name> definition.
39 * Include necessary headers...
45 #include <sys/utsname.h>
50 #endif /* HAVE_VSYSLOG */
54 * Possibly missing network definitions...
58 # define INADDR_NONE 0xffffffff
59 #endif /* !INADDR_NONE */
63 * Configuration variable structure...
68 CUPSD_VARTYPE_INTEGER
, /* Integer option */
69 CUPSD_VARTYPE_STRING
, /* String option */
70 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
75 char *name
; /* Name of variable */
76 void *ptr
; /* Pointer to variable */
77 cupsd_vartype_t type
; /* Type (int, string, address) */
85 static cupsd_var_t variables
[] =
87 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
88 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
89 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
90 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
91 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
92 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
93 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
94 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
95 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
96 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
97 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
98 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
99 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
100 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
101 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
102 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
103 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
104 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
105 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
106 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
107 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
108 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
109 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
110 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
111 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
112 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
113 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
114 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
115 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
116 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
117 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
118 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
119 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
120 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
121 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
123 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
124 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
127 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
138 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
139 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
140 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
141 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
142 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
143 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
144 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
145 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
146 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
147 { "RunAsUser", &RunAsUser
, CUPSD_VARTYPE_BOOLEAN
},
148 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
149 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
150 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
152 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
153 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
154 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
155 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
156 #endif /* HAVE_SSL */
158 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
159 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
160 #endif /* HAVE_LAUNCHD */
161 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
162 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
163 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
164 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
165 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
}
167 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
170 static unsigned ones
[4] =
172 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
174 static unsigned zeros
[4] =
176 0x00000000, 0x00000000, 0x00000000, 0x00000000
183 static int check_permissions(const char *filename
,
184 const char *suffix
, int mode
,
185 int user
, int group
, int is_dir
,
187 static http_addrlist_t
*get_address(const char *value
, int defport
);
188 static int get_addr_and_mask(const char *value
, unsigned *ip
,
190 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
191 char *value
, int linenum
);
192 static int read_configuration(cups_file_t
*fp
);
193 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
194 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
198 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
201 int /* O - 1 on success, 0 otherwise */
202 cupsdReadConfiguration(void)
204 int i
; /* Looping var */
205 cups_file_t
*fp
; /* Configuration file */
206 int status
; /* Return status */
207 char temp
[1024], /* Temporary buffer */
208 *slash
; /* Directory separator */
209 cups_lang_t
*language
; /* Language */
210 struct passwd
*user
; /* Default user */
211 struct group
*group
; /* Default group */
212 char *old_serverroot
, /* Old ServerRoot */
213 *old_requestroot
; /* Old RequestRoot */
216 * Save the old root paths...
219 old_serverroot
= NULL
;
220 cupsdSetString(&old_serverroot
, ServerRoot
);
221 old_requestroot
= NULL
;
222 cupsdSetString(&old_requestroot
, RequestRoot
);
225 * Reset the server configuration data...
228 cupsdDeleteAllLocations();
246 for (i
= 0; i
< NumRelays
; i
++)
247 if (Relays
[i
].from
.type
== AUTH_NAME
)
248 free(Relays
[i
].from
.mask
.name
.name
);
255 if (NumListeners
> 0)
265 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
266 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
267 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
268 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
269 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
270 cupsdSetString(&DataDir
, CUPS_DATADIR
);
271 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
272 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
273 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
274 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
275 cupsdSetString(&Printcap
, "/etc/printcap");
276 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
277 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
278 cupsdSetString(&RemoteRoot
, "remroot");
279 cupsdSetString(&ServerHeader
, "CUPS/1.1");
280 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
282 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
283 if ((slash
= strrchr(temp
, '/')) != NULL
)
286 cupsdSetString(&ServerRoot
, temp
);
288 cupsdClearString(&Classification
);
289 ClassifyOverride
= 0;
293 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
295 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
296 cupsdSetString(&ServerKey
, "ssl/server.key");
297 # endif /* HAVE_CDSASSL */
298 #endif /* HAVE_SSL */
300 language
= cupsLangDefault();
302 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
303 cupsdSetString(&DefaultLanguage
, "en");
305 cupsdSetString(&DefaultLanguage
, language
->language
);
307 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
309 cupsdSetString(&RIPCache
, "8m");
311 if (getenv("TMPDIR") == NULL
)
312 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
314 cupsdSetString(&TempDir
, getenv("TMPDIR"));
317 * Find the default system group: "sys", "system", or "root"...
320 group
= getgrnam(CUPS_DEFAULT_GROUP
);
328 * Found the group, use it!
331 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
333 SystemGroupIDs
[0] = group
->gr_gid
;
338 * Find the group associated with GID 0...
345 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
347 cupsdSetString(&SystemGroups
[0], "unknown");
349 SystemGroupIDs
[0] = 0;
353 * Find the default user...
356 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
361 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
362 * complement number...)
371 * Find the default group (nobody)...
374 group
= getgrnam("nobody");
378 Group
= group
->gr_gid
;
382 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
383 * complement number...)
393 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
394 DefaultAuthType
= AUTH_BASIC
;
396 JobRetryInterval
= 300;
401 HostNameLookups
= FALSE
;
402 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
403 ImplicitAnyClasses
= FALSE
;
404 HideImplicitMembers
= TRUE
;
406 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
407 ListenBackLog
= SOMAXCONN
;
408 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
409 LogLevel
= CUPSD_LOG_ERROR
;
411 MaxClientsPerHost
= 0;
412 MaxLogSize
= 1024 * 1024;
413 MaxPrinterHistory
= 10;
416 RootCertDuration
= 300;
418 Timeout
= DEFAULT_TIMEOUT
;
420 BrowseInterval
= DEFAULT_INTERVAL
;
421 BrowsePort
= ippPort();
422 BrowseLocalProtocols
= BROWSE_CUPS
; /* TODO: Use configure option */
423 BrowseRemoteProtocols
= BROWSE_CUPS
; /* TODO: Use configure option */
424 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
425 BrowseTimeout
= DEFAULT_TIMEOUT
;
426 Browsing
= CUPS_DEFAULT_BROWSING
;
427 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
429 cupsdClearString(&BrowseLocalOptions
);
430 cupsdClearString(&BrowseRemoteOptions
);
432 JobHistory
= DEFAULT_HISTORY
;
433 JobFiles
= DEFAULT_FILES
;
438 MaxJobsPerPrinter
= 0;
441 cupsdDeleteAllPolicies();
442 cupsdClearString(&DefaultPolicy
);
444 MaxSubscriptions
= 100;
445 MaxSubscriptionsPerJob
= 0;
446 MaxSubscriptionsPerPrinter
= 0;
447 MaxSubscriptionsPerUser
= 0;
448 DefaultLeaseDuration
= 86400;
449 MaxLeaseDuration
= 0;
452 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
453 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
454 #endif /* HAVE_LAUNCHD */
457 * Read the configuration file...
460 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
463 status
= read_configuration(fp
);
476 * Use the default system group if none was supplied in cupsd.conf...
479 if (NumSystemGroups
== 0)
483 * Get the access control list for browsing...
486 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
489 * Open the system log for cupsd if necessary...
493 if (!strcmp(AccessLog
, "syslog") ||
494 !strcmp(ErrorLog
, "syslog") ||
495 !strcmp(PageLog
, "syslog"))
496 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
497 #endif /* HAVE_VSYSLOG */
500 * Log the configuration file that was used...
503 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
507 * Validate the Group and SystemGroup settings - they cannot be the same,
508 * otherwise the CGI programs will be able to authenticate as root without
514 for (i
= 0; i
< NumSystemGroups
; i
++)
515 if (Group
== SystemGroupIDs
[i
])
518 if (i
< NumSystemGroups
)
521 * Log the error and reset the group to a safe value...
524 cupsdLogMessage(CUPSD_LOG_NOTICE
,
525 "Group and SystemGroup cannot use the same groups!");
526 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
528 group
= getgrnam("nobody");
532 Group
= group
->gr_gid
;
536 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
537 * complement number...)
546 * Check that we have at least one listen/port line; if not, report this
547 * as an error and exit!
550 if (NumListeners
== 0)
556 cupsdLogMessage(CUPSD_LOG_EMERG
,
557 "No valid Listen or Port lines were found in the configuration file!");
563 cupsdEndProcess(getpid(), 0);
567 * Set the default locale using the language and charset...
570 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
573 * Update all relative filenames to include the full path from ServerRoot...
576 if (DocumentRoot
[0] != '/')
577 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
579 if (RequestRoot
[0] != '/')
580 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
582 if (ServerBin
[0] != '/')
583 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
585 if (StateDir
[0] != '/')
586 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
588 if (CacheDir
[0] != '/')
589 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
592 if (ServerCertificate
[0] != '/')
593 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
595 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
597 chown(ServerCertificate
, RunUser
, Group
);
598 chmod(ServerCertificate
, 0600);
601 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
602 if (ServerKey
[0] != '/')
603 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
605 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
607 chown(ServerKey
, RunUser
, Group
);
608 chmod(ServerKey
, 0600);
610 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
611 #endif /* HAVE_SSL */
614 * Make sure that directories and config files are owned and
615 * writable by the user and group in the cupsd.conf file...
618 check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1);
619 check_permissions(CacheDir
, "ppd", 0755, RunUser
, Group
, 1, 1);
621 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1);
622 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
623 SystemGroupIDs
[0], 1, 1);
625 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0);
626 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1);
627 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0);
628 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
, Group
,
630 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
, 0, 0);
631 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
, 0, 0);
632 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0);
635 * Make sure the request and temporary directories have the right
639 check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1);
641 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
645 * Update ownership and permissions if the CUPS temp directory
646 * is under the spool directory or does not exist...
649 check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1);
652 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
655 * Clean out the temporary directory...
658 cups_dir_t
*dir
; /* Temporary directory */
659 cups_dentry_t
*dent
; /* Directory entry */
660 char tempfile
[1024]; /* Temporary filename */
663 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
665 cupsdLogMessage(CUPSD_LOG_INFO
,
666 "Cleaning out old temporary files in \"%s\"...", TempDir
);
668 while ((dent
= cupsDirRead(dir
)) != NULL
)
670 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
672 if (unlink(tempfile
))
673 cupsdLogMessage(CUPSD_LOG_ERROR
,
674 "Unable to remove temporary file \"%s\" - %s",
675 tempfile
, strerror(errno
));
677 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
684 cupsdLogMessage(CUPSD_LOG_ERROR
,
685 "Unable to open temporary directory \"%s\" - %s",
686 TempDir
, strerror(errno
));
690 * Setup environment variables...
696 * Check the MaxClients setting, and then allocate memory for it...
699 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
702 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
705 MaxClients
= MaxFDs
/ 3;
708 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
710 cupsdLogMessage(CUPSD_LOG_ERROR
,
711 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
712 MaxClients
, strerror(errno
));
716 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
720 * Check the MaxActiveJobs setting; limit to 1/3 the available
721 * file descriptors, since we need a pipe for each job...
724 if (MaxActiveJobs
> (MaxFDs
/ 3))
725 MaxActiveJobs
= MaxFDs
/ 3;
727 if (Classification
&& strcasecmp(Classification
, "none") == 0)
728 cupsdClearString(&Classification
);
731 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
734 * Update the MaxClientsPerHost value, as needed...
737 if (MaxClientsPerHost
<= 0)
738 MaxClientsPerHost
= MaxClients
;
740 if (MaxClientsPerHost
> MaxClients
)
741 MaxClientsPerHost
= MaxClients
;
743 cupsdLogMessage(CUPSD_LOG_INFO
,
744 "Allowing up to %d client connections per host.",
748 * Update the default policy, as needed...
752 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
754 DefaultPolicyPtr
= NULL
;
756 if (!DefaultPolicyPtr
)
758 cupsd_policy_t
*p
; /* New policy */
759 cupsd_location_t
*po
; /* New policy operation */
763 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
766 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
767 cupsdLogMessage(CUPSD_LOG_INFO
,
768 "Using policy \"default\" as the default!");
771 cupsdLogMessage(CUPSD_LOG_INFO
,
772 "Creating CUPS default administrative policy:");
774 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
776 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
777 cupsdLogMessage(CUPSD_LOG_INFO
,
778 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
779 "Release-Job Restart-Job Purge-Jobs "
780 "Set-Job-Attributes Create-Job-Subscription "
781 "Renew-Subscription Cancel-Subscription "
782 "Get-Notifications Reprocess-Job Cancel-Current-Job "
783 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
784 "CUPS-Authenticate-Job>");
785 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
787 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
788 po
->order_type
= AUTH_ALLOW
;
789 po
->level
= AUTH_USER
;
791 cupsdAddName(po
, "@OWNER");
792 cupsdAddName(po
, "@SYSTEM");
793 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
795 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
796 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
797 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
798 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
799 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
800 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
801 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
802 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
803 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
804 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
805 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
806 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
807 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
808 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
809 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
810 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
811 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
813 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
815 cupsdLogMessage(CUPSD_LOG_INFO
,
816 "<Limit Pause-Printer Resume-Printer "
817 "Set-Printer-Attributes Enable-Printer "
818 "Disable-Printer Pause-Printer-After-Current-Job "
819 "Hold-New-Jobs Release-Held-New-Jobs "
820 "Deactivate-Printer Activate-Printer Restart-Printer "
821 "Shutdown-Printer Startup-Printer Promote-Job "
822 "Schedule-Job-After CUPS-Add-Printer "
823 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
824 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
825 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
826 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
828 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
829 po
->order_type
= AUTH_ALLOW
;
830 po
->type
= AUTH_BASIC
;
831 po
->level
= AUTH_USER
;
833 cupsdAddName(po
, "@SYSTEM");
834 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
836 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
837 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
838 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
839 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
840 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
841 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
842 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
843 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
844 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
845 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
846 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
847 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
848 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
849 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
850 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
851 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
852 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
853 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
854 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
855 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
856 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
858 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
860 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
861 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
863 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
864 po
->order_type
= AUTH_ALLOW
;
866 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
867 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
871 cupsdLogMessage(CUPSD_LOG_DEBUG
,"NumPolicies=%d", NumPolicies
);
872 for (i
= 0; i
< NumPolicies
; i
++)
873 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Policies[%d]=\"%s\"", i
,
877 * If we are doing a full reload or the server root has changed, flush
878 * the jobs, printers, etc. and start from scratch...
881 if (NeedReload
== RELOAD_ALL
||
882 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
883 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
885 mime_type_t
*type
; /* Current type */
886 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
890 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
896 cupsdDeleteAllSubscriptions();
898 cupsdDeleteAllClasses();
899 cupsdDeleteAllPrinters();
901 DefaultPrinter
= NULL
;
903 if (MimeDatabase
!= NULL
)
904 mimeDelete(MimeDatabase
);
908 for (i
= 0; i
< NumMimeTypes
; i
++)
909 free((void *)MimeTypes
[i
]);
915 * Read the MIME type and conversion database...
918 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
920 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
924 cupsdLogMessage(CUPSD_LOG_EMERG
,
925 "Unable to load MIME database from \'%s\'!", ServerRoot
);
929 cupsdLogMessage(CUPSD_LOG_INFO
,
930 "Loaded MIME database from \'%s\': %d types, %d filters...",
931 ServerRoot
, mimeNumTypes(MimeDatabase
),
932 mimeNumFilters(MimeDatabase
));
935 * Create a list of MIME types for the document-format-supported
939 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
940 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
943 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
945 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
947 i
++, type
= mimeNextType(MimeDatabase
))
949 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
951 MimeTypes
[i
] = strdup(mimetype
);
954 if (i
< NumMimeTypes
)
955 MimeTypes
[i
] = strdup("application/octet-stream");
961 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
962 cupsdLoadBanners(temp
);
965 * Load printers and classes...
968 cupsdLoadAllPrinters();
969 cupsdLoadAllClasses();
970 cupsdLoadRemoteCache();
971 cupsdWritePrintcap();
973 cupsdCreateCommonData();
976 * Load queued jobs...
982 * Load subscriptions...
985 cupsdLoadAllSubscriptions();
987 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
992 * Not a full reload, so recreate the common printer attributes...
995 cupsdCreateCommonData();
998 * Update all printers as needed...
1001 cupsdUpdatePrinters();
1002 cupsdWritePrintcap();
1004 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1008 * Reset the reload state...
1011 NeedReload
= RELOAD_NONE
;
1013 cupsdClearString(&old_serverroot
);
1014 cupsdClearString(&old_requestroot
);
1021 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1024 static int /* O - 0 on success, -1 on error */
1025 check_permissions(const char *filename
, /* I - File/directory name */
1026 const char *suffix
, /* I - Additional file/directory name */
1027 int mode
, /* I - Permissions */
1028 int user
, /* I - Owner */
1029 int group
, /* I - Group */
1030 int is_dir
, /* I - 1 = directory, 0 = file */
1031 int create_dir
)/* I - 1 = create directory, 0 = not */
1033 int dir_created
= 0; /* Did we create a directory? */
1034 char pathname
[1024]; /* File name with prefix */
1035 struct stat fileinfo
; /* Stat buffer */
1039 * Prepend the given root to the filename before testing it...
1044 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1045 filename
= pathname
;
1049 * See if we can stat the file/directory...
1052 if (stat(filename
, &fileinfo
))
1054 if (errno
== ENOENT
&& create_dir
)
1056 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1059 if (mkdir(filename
, mode
))
1061 cupsdLogMessage(CUPSD_LOG_ERROR
,
1062 "Unable to create directory \"%s\" - %s", filename
,
1074 * Make sure it's a regular file...
1077 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1079 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1083 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1085 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1090 * Fix owner, group, and mode as needed...
1093 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1095 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1097 if (chown(filename
, user
, group
))
1099 cupsdLogMessage(CUPSD_LOG_ERROR
,
1100 "Unable to change ownership of \"%s\" - %s", filename
,
1106 if (dir_created
|| (fileinfo
.st_mode
& 0777) != mode
)
1108 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1110 if (chmod(filename
, mode
))
1112 cupsdLogMessage(CUPSD_LOG_ERROR
,
1113 "Unable to change permissions of \"%s\" - %s", filename
,
1120 * Everything is OK...
1128 * 'get_address()' - Get an address + port number from a line.
1131 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1132 get_address(const char *value
, /* I - Value string */
1133 int defport
) /* I - Default port */
1135 char buffer
[1024], /* Hostname + port number buffer */
1136 defpname
[255], /* Default port name */
1137 *hostname
, /* Hostname or IP */
1138 *portname
; /* Port number or name */
1139 http_addrlist_t
*addrlist
; /* Address list */
1143 * Check for an empty value...
1148 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1153 * Grab a hostname and port number; if there is no colon and the port name
1154 * is only digits, then we have a port number by itself...
1157 strlcpy(buffer
, value
, sizeof(buffer
));
1159 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1166 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1171 * Use the default port...
1174 sprintf(defpname
, "%d", defport
);
1175 portname
= defpname
;
1181 * The buffer contains just a port number...
1189 if (hostname
&& !strcmp(hostname
, "*"))
1193 * Now lookup the address using httpAddrGetList()...
1196 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1197 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1198 hostname
? hostname
: "(nil)");
1205 * 'get_addr_and_mask()' - Get an IP address and netmask.
1208 static int /* O - 1 on success, 0 on failure */
1209 get_addr_and_mask(const char *value
, /* I - String from config file */
1210 unsigned *ip
, /* O - Address value */
1211 unsigned *mask
) /* O - Mask value */
1213 int i
, j
, /* Looping vars */
1214 family
, /* Address family */
1215 ipcount
; /* Count of fields in address */
1216 unsigned ipval
; /* Value */
1217 const char *maskval
, /* Pointer to start of mask value */
1218 *ptr
, /* Pointer into value */
1220 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1222 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1223 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1224 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1225 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1228 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1230 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1231 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1232 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1233 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1234 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1235 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1236 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1237 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1239 #endif /* AF_INET6 */
1243 * Get the address...
1246 memset(ip
, 0, sizeof(unsigned) * 4);
1248 if ((maskval
= strchr(value
, '/')) != NULL
)
1251 maskval
= value
+ strlen(value
);
1255 * Check for an IPv6 address...
1261 * Parse hexadecimal IPv6 address...
1266 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1270 else if (!strncmp(ptr
, "::", 2))
1272 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1274 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1278 else if (isxdigit(*ptr
& 255))
1280 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1288 ip
[i
] |= ipval
<< 16;
1299 if (*ptr
&& *ptr
!= '/')
1303 #endif /* AF_INET6 */
1306 * Parse dotted-decimal IPv4 address...
1310 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1312 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1313 ip
[0] = ip
[1] = ip
[2] = 0;
1319 * Get the netmask value(s)...
1322 memset(mask
, 0, sizeof(unsigned) * 4);
1325 if (*maskval
== '[')
1328 * Get hexadecimal mask value...
1331 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1335 else if (!strncmp(ptr
, "::", 2))
1337 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1339 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1343 else if (isxdigit(*ptr
& 255))
1345 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1353 mask
[i
] |= ipval
<< 16;
1366 #endif /* AF_INET6 */
1367 if (strchr(maskval
, '.'))
1370 * Get dotted-decimal mask...
1373 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1376 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1377 mask
[0] = mask
[1] = mask
[2] = 0;
1382 * Get address/bits format...
1388 if (family
== AF_INET6
)
1393 mask
[0] = 0xffffffff;
1395 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1398 mask
[1] = 0xffffffff;
1402 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1405 mask
[2] = 0xffffffff;
1409 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1412 mask
[3] = 0xffffffff;
1416 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1419 #endif /* AF_INET6 */
1423 mask
[0] = 0xffffffff;
1424 mask
[1] = 0xffffffff;
1425 mask
[2] = 0xffffffff;
1428 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1430 mask
[3] = 0xffffffff;
1435 else if (family
== AF_INET6
)
1436 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1437 #endif /* AF_INET6 */
1439 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1441 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1442 "get_addr_and_mask(value=\"%s\", "
1443 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1444 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1448 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1451 if ((ip
[0] & ~mask
[0]) != 0 ||
1452 (ip
[1] & ~mask
[1]) != 0 ||
1453 (ip
[2] & ~mask
[2]) != 0 ||
1454 (ip
[3] & ~mask
[3]) != 0)
1462 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1465 static int /* O - 1 on success, 0 on failure */
1466 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1467 char *line
, /* I - Line from file */
1468 char *value
, /* I - Start of value data */
1469 int linenum
) /* I - Current line number */
1471 char *valptr
; /* Pointer into value */
1472 unsigned ip
[4], /* IP address components */
1473 mask
[4]; /* IP netmask components */
1476 if (!strcasecmp(line
, "Encryption"))
1479 * "Encryption xxx" - set required encryption level...
1482 if (!strcasecmp(value
, "never"))
1483 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1484 else if (!strcasecmp(value
, "always"))
1486 cupsdLogMessage(CUPSD_LOG_ERROR
,
1487 "Encryption value \"%s\" on line %d is invalid in this "
1488 "context. Using \"required\" instead.", value
, linenum
);
1490 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1492 else if (!strcasecmp(value
, "required"))
1493 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1494 else if (!strcasecmp(value
, "ifrequested"))
1495 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1498 cupsdLogMessage(CUPSD_LOG_ERROR
,
1499 "Unknown Encryption value %s on line %d.", value
, linenum
);
1503 else if (!strcasecmp(line
, "Order"))
1506 * "Order Deny,Allow" or "Order Allow,Deny"...
1509 if (!strncasecmp(value
, "deny", 4))
1510 loc
->order_type
= AUTH_ALLOW
;
1511 else if (!strncasecmp(value
, "allow", 5))
1512 loc
->order_type
= AUTH_DENY
;
1515 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1520 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1523 * Allow [From] host/ip...
1524 * Deny [From] host/ip...
1527 if (!strncasecmp(value
, "from", 4))
1530 * Strip leading "from"...
1535 while (isspace(*value
& 255))
1540 * Figure out what form the allow/deny address takes:
1551 * nnn.nnn.nnn.nnn/mm
1552 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1555 if (!strcasecmp(value
, "all"))
1561 if (!strcasecmp(line
, "Allow"))
1562 cupsdAllowIP(loc
, zeros
, zeros
);
1564 cupsdDenyIP(loc
, zeros
, zeros
);
1566 else if (!strcasecmp(value
, "none"))
1572 if (!strcasecmp(line
, "Allow"))
1573 cupsdAllowIP(loc
, ones
, zeros
);
1575 cupsdDenyIP(loc
, ones
, zeros
);
1577 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1580 * Host or domain name...
1583 if (value
[0] == '*')
1586 if (!strcasecmp(line
, "Allow"))
1587 cupsdAllowHost(loc
, value
);
1589 cupsdDenyHost(loc
, value
);
1594 * One of many IP address forms...
1597 if (!get_addr_and_mask(value
, ip
, mask
))
1599 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1604 if (!strcasecmp(line
, "Allow"))
1605 cupsdAllowIP(loc
, ip
, mask
);
1607 cupsdDenyIP(loc
, ip
, mask
);
1610 else if (!strcasecmp(line
, "AuthType"))
1613 * AuthType {none,basic,digest,basicdigest}
1616 if (!strcasecmp(value
, "none"))
1618 loc
->type
= AUTH_NONE
;
1619 loc
->level
= AUTH_ANON
;
1621 else if (!strcasecmp(value
, "basic"))
1623 loc
->type
= AUTH_BASIC
;
1625 if (loc
->level
== AUTH_ANON
)
1626 loc
->level
= AUTH_USER
;
1628 else if (!strcasecmp(value
, "digest"))
1630 loc
->type
= AUTH_DIGEST
;
1632 if (loc
->level
== AUTH_ANON
)
1633 loc
->level
= AUTH_USER
;
1635 else if (!strcasecmp(value
, "basicdigest"))
1637 loc
->type
= AUTH_BASICDIGEST
;
1639 if (loc
->level
== AUTH_ANON
)
1640 loc
->level
= AUTH_USER
;
1644 cupsdLogMessage(CUPSD_LOG_WARN
,
1645 "Unknown authorization type %s on line %d.",
1650 else if (!strcasecmp(line
, "AuthClass"))
1653 * AuthClass anonymous, user, system, group
1656 if (!strcasecmp(value
, "anonymous"))
1658 loc
->type
= AUTH_NONE
;
1659 loc
->level
= AUTH_ANON
;
1661 cupsdLogMessage(CUPSD_LOG_WARN
,
1662 "\"AuthClass %s\" is deprecated; consider removing "
1666 else if (!strcasecmp(value
, "user"))
1668 loc
->level
= AUTH_USER
;
1670 cupsdLogMessage(CUPSD_LOG_WARN
,
1671 "\"AuthClass %s\" is deprecated; consider using "
1672 "\"Require valid-user\" on line %d.",
1675 else if (!strcasecmp(value
, "group"))
1677 loc
->level
= AUTH_GROUP
;
1679 cupsdLogMessage(CUPSD_LOG_WARN
,
1680 "\"AuthClass %s\" is deprecated; consider using "
1681 "\"Require @groupname\" on line %d.",
1684 else if (!strcasecmp(value
, "system"))
1686 loc
->level
= AUTH_GROUP
;
1688 cupsdAddName(loc
, "@SYSTEM");
1690 cupsdLogMessage(CUPSD_LOG_WARN
,
1691 "\"AuthClass %s\" is deprecated; consider using "
1692 "\"Require @SYSTEM\" on line %d.",
1697 cupsdLogMessage(CUPSD_LOG_WARN
,
1698 "Unknown authorization class %s on line %d.",
1703 else if (!strcasecmp(line
, "AuthGroupName"))
1705 cupsdAddName(loc
, value
);
1707 cupsdLogMessage(CUPSD_LOG_WARN
,
1708 "\"AuthGroupName %s\" directive is deprecated; consider "
1709 "using \"Require @%s\" on line %d.",
1710 value
, value
, linenum
);
1712 else if (!strcasecmp(line
, "Require"))
1715 * Apache synonym for AuthClass and AuthGroupName...
1719 * Require valid-user
1720 * Require group names
1721 * Require user names
1724 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1729 if (!strcasecmp(value
, "valid-user") ||
1730 !strcasecmp(value
, "user"))
1731 loc
->level
= AUTH_USER
;
1732 else if (!strcasecmp(value
, "group"))
1733 loc
->level
= AUTH_GROUP
;
1736 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1742 * Get the list of names from the line...
1745 for (value
= valptr
; *value
;)
1747 while (isspace(*value
& 255))
1750 if (*value
== '\"' || *value
== '\'')
1753 * Grab quoted name...
1756 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1763 * Grab literal name.
1766 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1772 cupsdAddName(loc
, value
);
1774 for (value
= valptr
; isspace(*value
& 255); value
++);
1777 else if (!strcasecmp(line
, "Satisfy"))
1779 if (!strcasecmp(value
, "all"))
1780 loc
->satisfy
= AUTH_SATISFY_ALL
;
1781 else if (!strcasecmp(value
, "any"))
1782 loc
->satisfy
= AUTH_SATISFY_ANY
;
1785 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1798 * 'read_configuration()' - Read a configuration file.
1801 static int /* O - 1 on success, 0 on failure */
1802 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1804 int i
; /* Looping var */
1805 int linenum
; /* Current line number */
1806 char line
[HTTP_MAX_BUFFER
],
1807 /* Line from file */
1808 temp
[HTTP_MAX_BUFFER
],
1809 /* Temporary buffer for value */
1810 temp2
[HTTP_MAX_BUFFER
],
1811 /* Temporary buffer 2 for value */
1812 *ptr
, /* Pointer into line/temp */
1813 *value
, /* Pointer to value */
1814 *valueptr
, /* Pointer into value */
1815 quote
; /* Quote character */
1816 int valuelen
; /* Length of value */
1817 cupsd_var_t
*var
; /* Current variable */
1818 http_addrlist_t
*addrlist
, /* Address list */
1819 *addr
; /* Current address */
1820 unsigned ip
[4], /* Address value */
1821 mask
[4]; /* Netmask value */
1822 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1823 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1824 cupsd_location_t
*location
; /* Browse location */
1825 cups_file_t
*incfile
; /* Include file */
1826 char incname
[1024]; /* Include filename */
1827 struct group
*group
; /* Group */
1831 * Loop through each line in the file...
1836 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1839 * Decode the directive...
1842 if (!strcasecmp(line
, "Include"))
1848 if (value
[0] == '/')
1849 strlcpy(incname
, value
, sizeof(incname
));
1851 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1853 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1854 cupsdLogMessage(CUPSD_LOG_ERROR
,
1855 "Unable to include config file \"%s\" - %s",
1856 incname
, strerror(errno
));
1859 read_configuration(incfile
);
1860 cupsFileClose(incfile
);
1863 else if (!strcasecmp(line
, "<Location"))
1871 linenum
= read_location(fp
, value
, linenum
);
1877 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1882 else if (!strcasecmp(line
, "<Policy"))
1890 linenum
= read_policy(fp
, value
, linenum
);
1896 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1900 else if (!strcasecmp(line
, "FaxRetryInterval"))
1904 JobRetryInterval
= atoi(value
);
1905 cupsdLogMessage(CUPSD_LOG_WARN
,
1906 "FaxRetryInterval is deprecated; use "
1907 "JobRetryInterval on line %d.", linenum
);
1911 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1915 else if (!strcasecmp(line
, "FaxRetryLimit"))
1919 JobRetryLimit
= atoi(value
);
1920 cupsdLogMessage(CUPSD_LOG_WARN
,
1921 "FaxRetryLimit is deprecated; use "
1922 "JobRetryLimit on line %d.", linenum
);
1926 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1930 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
1932 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
1933 #endif /* HAVE_SSL */
1937 * Add listening address(es) to the list...
1940 cupsd_listener_t
*lis
; /* New listeners array */
1944 * Get the address list...
1947 addrlist
= get_address(value
, IPP_PORT
);
1951 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1957 * Add each address...
1960 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1963 * Allocate another listener...
1966 if (NumListeners
== 0)
1967 lis
= malloc(sizeof(cupsd_listener_t
));
1969 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1973 cupsdLogMessage(CUPSD_LOG_ERROR
,
1974 "Unable to allocate %s at line %d - %s.",
1975 line
, linenum
, strerror(errno
));
1980 lis
+= NumListeners
;
1983 * Copy the current address and log it...
1986 memset(lis
, 0, sizeof(cupsd_listener_t
));
1987 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
1991 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1992 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1993 #endif /* HAVE_SSL */
1996 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
1999 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2000 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2001 ntohs(lis
->address
.ipv6
.sin6_port
));
2003 #endif /* AF_INET6 */
2005 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2006 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2008 #endif /* AF_LOCAL */
2009 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2010 ntohs(lis
->address
.ipv4
.sin_port
));
2019 httpAddrFreeList(addrlist
);
2021 else if (!strcasecmp(line
, "BrowseAddress"))
2024 * Add a browse address to the list...
2027 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2030 if (NumBrowsers
== 0)
2031 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2033 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2037 cupsdLogMessage(CUPSD_LOG_ERROR
,
2038 "Unable to allocate BrowseAddress at line %d - %s.",
2039 linenum
, strerror(errno
));
2044 dira
+= NumBrowsers
;
2046 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2048 if (!strcasecmp(value
, "@LOCAL"))
2051 * Send browse data to all local interfaces...
2054 strcpy(dira
->iface
, "*");
2057 else if (!strncasecmp(value
, "@IF(", 4))
2060 * Send browse data to the named interface...
2063 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2065 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2071 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2074 * Only IPv4 addresses are supported...
2077 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2078 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2083 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2084 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2086 cupsdLogMessage(CUPSD_LOG_INFO
,
2087 "Sending browsing info to %s:%d (IPv4)",
2088 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2093 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2096 httpAddrFreeList(addrlist
);
2099 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2102 else if (!strcasecmp(line
, "BrowseOrder"))
2105 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2108 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2109 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2111 if (location
== NULL
)
2112 cupsdLogMessage(CUPSD_LOG_ERROR
,
2113 "Unable to initialize browse access control list!");
2114 else if (!strncasecmp(value
, "deny", 4))
2115 location
->order_type
= AUTH_ALLOW
;
2116 else if (!strncasecmp(value
, "allow", 5))
2117 location
->order_type
= AUTH_DENY
;
2119 cupsdLogMessage(CUPSD_LOG_ERROR
,
2120 "Unknown BrowseOrder value %s on line %d.",
2123 else if (!strcasecmp(line
, "BrowseProtocols") ||
2124 !strcasecmp(line
, "BrowseLocalProtocols") ||
2125 !strcasecmp(line
, "BrowseRemoteProtocols"))
2128 * "BrowseProtocol name [... name]"
2131 if (strcasecmp(line
, "BrowseLocalProtocols"))
2132 BrowseRemoteProtocols
= 0;
2133 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2134 BrowseLocalProtocols
= 0;
2138 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2139 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2142 if (value
[valuelen
])
2144 value
[valuelen
] = '\0';
2148 if (!strcasecmp(value
, "cups"))
2150 if (strcasecmp(line
, "BrowseLocalProtocols"))
2151 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2152 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2153 BrowseLocalProtocols
|= BROWSE_CUPS
;
2155 else if (!strcasecmp(value
, "slp"))
2157 if (strcasecmp(line
, "BrowseLocalProtocols"))
2158 BrowseRemoteProtocols
|= BROWSE_SLP
;
2159 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2160 BrowseLocalProtocols
|= BROWSE_SLP
;
2162 else if (!strcasecmp(value
, "ldap"))
2164 if (strcasecmp(line
, "BrowseLocalProtocols"))
2165 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2166 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2167 BrowseLocalProtocols
|= BROWSE_LDAP
;
2169 else if (!strcasecmp(value
, "all"))
2171 if (strcasecmp(line
, "BrowseLocalProtocols"))
2172 BrowseRemoteProtocols
|= BROWSE_ALL
;
2173 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2174 BrowseLocalProtocols
|= BROWSE_ALL
;
2178 cupsdLogMessage(CUPSD_LOG_ERROR
,
2179 "Unknown browse protocol \"%s\" on line %d.",
2184 for (value
+= valuelen
; *value
; value
++)
2185 if (!isspace(*value
) || *value
!= ',')
2189 else if (!strcasecmp(line
, "BrowseAllow") ||
2190 !strcasecmp(line
, "BrowseDeny"))
2193 * BrowseAllow [From] host/ip...
2194 * BrowseDeny [From] host/ip...
2197 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2198 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2200 if (location
== NULL
)
2201 cupsdLogMessage(CUPSD_LOG_ERROR
,
2202 "Unable to initialize browse access control list!");
2205 if (!strncasecmp(value
, "from ", 5))
2208 * Strip leading "from"...
2213 while (isspace(*value
))
2218 * Figure out what form the allow/deny address takes:
2229 * nnn.nnn.nnn.nnn/mm
2230 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2233 if (!strcasecmp(value
, "all"))
2239 if (!strcasecmp(line
, "BrowseAllow"))
2240 cupsdAllowIP(location
, zeros
, zeros
);
2242 cupsdDenyIP(location
, zeros
, zeros
);
2244 else if (!strcasecmp(value
, "none"))
2250 if (!strcasecmp(line
, "BrowseAllow"))
2251 cupsdAllowIP(location
, ones
, zeros
);
2253 cupsdDenyIP(location
, ones
, zeros
);
2255 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2258 * Host or domain name...
2261 if (value
[0] == '*')
2264 if (!strcasecmp(line
, "BrowseAllow"))
2265 cupsdAllowHost(location
, value
);
2267 cupsdDenyHost(location
, value
);
2272 * One of many IP address forms...
2275 if (!get_addr_and_mask(value
, ip
, mask
))
2277 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2282 if (!strcasecmp(line
, "BrowseAllow"))
2283 cupsdAllowIP(location
, ip
, mask
);
2285 cupsdDenyIP(location
, ip
, mask
);
2289 else if (!strcasecmp(line
, "BrowseRelay"))
2292 * BrowseRelay [from] source [to] destination
2296 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2298 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2302 cupsdLogMessage(CUPSD_LOG_ERROR
,
2303 "Unable to allocate BrowseRelay at line %d - %s.",
2304 linenum
, strerror(errno
));
2311 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2313 if (!strncasecmp(value
, "from ", 5))
2316 * Strip leading "from"...
2321 while (isspace(*value
))
2326 * Figure out what form the from address takes:
2335 * nnn.nnn.nnn.nnn/mm
2336 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2339 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2342 * Host or domain name...
2345 if (value
[0] == '*')
2348 strlcpy(temp
, value
, sizeof(temp
));
2349 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2352 relay
->from
.type
= AUTH_NAME
;
2353 relay
->from
.mask
.name
.name
= strdup(temp
);
2354 relay
->from
.mask
.name
.length
= strlen(temp
);
2359 * One of many IP address forms...
2362 if (!get_addr_and_mask(value
, ip
, mask
))
2364 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2369 relay
->from
.type
= AUTH_IP
;
2370 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2371 sizeof(relay
->from
.mask
.ip
.address
));
2372 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2373 sizeof(relay
->from
.mask
.ip
.netmask
));
2377 * Skip value and trailing whitespace...
2380 for (; *value
; value
++)
2381 if (isspace(*value
))
2384 while (isspace(*value
))
2387 if (!strncasecmp(value
, "to ", 3))
2390 * Strip leading "to"...
2395 while (isspace(*value
))
2400 * Get "to" address and port...
2403 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2406 * Only IPv4 addresses are supported...
2409 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2410 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2415 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2417 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2419 if (relay
->from
.type
== AUTH_IP
)
2420 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2421 relay
->from
.mask
.ip
.address
[0],
2422 relay
->from
.mask
.ip
.address
[1],
2423 relay
->from
.mask
.ip
.address
[2],
2424 relay
->from
.mask
.ip
.address
[3],
2425 relay
->from
.mask
.ip
.netmask
[0],
2426 relay
->from
.mask
.ip
.netmask
[1],
2427 relay
->from
.mask
.ip
.netmask
[2],
2428 relay
->from
.mask
.ip
.netmask
[3]);
2430 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2432 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2433 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2438 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2441 httpAddrFreeList(addrlist
);
2445 if (relay
->from
.type
== AUTH_NAME
)
2446 free(relay
->from
.mask
.name
.name
);
2448 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2452 else if (!strcasecmp(line
, "BrowsePoll"))
2455 * BrowsePoll address[:port]
2458 char *portname
; /* Port name */
2459 int portnum
; /* Port number */
2460 struct servent
*service
; /* Service */
2464 * Extract the port name from the address...
2467 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2471 if (isdigit(*portname
& 255))
2472 portnum
= atoi(portname
);
2473 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2474 portnum
= ntohs(service
->s_port
);
2477 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2483 portnum
= ippPort();
2486 * Add the poll entry...
2490 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2492 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2496 cupsdLogMessage(CUPSD_LOG_ERROR
,
2497 "Unable to allocate BrowsePoll at line %d - %s.",
2498 linenum
, strerror(errno
));
2506 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2508 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2509 pollp
->port
= portnum
;
2511 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2514 else if (!strcasecmp(line
, "DefaultAuthType"))
2517 * DefaultAuthType {basic,digest,basicdigest}
2520 if (!strcasecmp(value
, "basic"))
2521 DefaultAuthType
= AUTH_BASIC
;
2522 else if (!strcasecmp(value
, "digest"))
2523 DefaultAuthType
= AUTH_DIGEST
;
2524 else if (!strcasecmp(value
, "basicdigest"))
2525 DefaultAuthType
= AUTH_BASICDIGEST
;
2528 cupsdLogMessage(CUPSD_LOG_WARN
,
2529 "Unknown default authorization type %s on line %d.",
2534 else if (!strcasecmp(line
, "User"))
2537 * User ID to run as...
2540 if (value
&& isdigit(value
[0] & 255))
2542 int uid
= atoi(value
);
2545 cupsdLogMessage(CUPSD_LOG_ERROR
,
2546 "Will not use User 0 as specified on line %d "
2547 "for security reasons. You must use a non-"
2548 "privileged account instead.",
2555 struct passwd
*p
; /* Password information */
2558 p
= getpwnam(value
);
2563 cupsdLogMessage(CUPSD_LOG_ERROR
,
2564 "Will not use User %s (UID=0) as specified on line "
2565 "%d for security reasons. You must use a non-"
2566 "privileged account instead.",
2572 cupsdLogMessage(CUPSD_LOG_ERROR
,
2573 "Unknown User \"%s\" on line %d, ignoring!",
2577 cupsdLogMessage(CUPSD_LOG_ERROR
,
2578 "User directive on line %d missing the username!",
2581 else if (!strcasecmp(line
, "Group"))
2584 * Group ID to run as...
2587 if (isdigit(value
[0]))
2588 Group
= atoi(value
);
2592 group
= getgrnam(value
);
2595 Group
= group
->gr_gid
;
2597 cupsdLogMessage(CUPSD_LOG_ERROR
,
2598 "Unknown Group \"%s\" on line %d, ignoring!",
2602 else if (!strcasecmp(line
, "SystemGroup"))
2605 * System (admin) group(s)...
2608 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2610 if (*value
== '\'' || *value
== '\"')
2613 * Scan quoted name...
2618 for (valueptr
= value
; *valueptr
; valueptr
++)
2619 if (*valueptr
== quote
)
2625 * Scan space or comma-delimited name...
2628 for (valueptr
= value
; *valueptr
; valueptr
++)
2629 if (isspace(*valueptr
) || *valueptr
== ',')
2636 group
= getgrnam(value
);
2639 cupsdSetString(SystemGroups
+ i
, value
);
2640 SystemGroupIDs
[i
] = group
->gr_gid
;
2645 cupsdLogMessage(CUPSD_LOG_ERROR
,
2646 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2653 while (*value
== ',' || isspace(*value
))
2658 NumSystemGroups
= i
;
2660 else if (!strcasecmp(line
, "HostNameLookups"))
2663 * Do hostname lookups?
2666 if (!strcasecmp(value
, "off"))
2667 HostNameLookups
= 0;
2668 else if (!strcasecmp(value
, "on"))
2669 HostNameLookups
= 1;
2670 else if (!strcasecmp(value
, "double"))
2671 HostNameLookups
= 2;
2673 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2676 else if (!strcasecmp(line
, "LogLevel"))
2679 * Amount of logging to do...
2682 if (!strcasecmp(value
, "debug2"))
2683 LogLevel
= CUPSD_LOG_DEBUG2
;
2684 else if (!strcasecmp(value
, "debug"))
2685 LogLevel
= CUPSD_LOG_DEBUG
;
2686 else if (!strcasecmp(value
, "info"))
2687 LogLevel
= CUPSD_LOG_INFO
;
2688 else if (!strcasecmp(value
, "notice"))
2689 LogLevel
= CUPSD_LOG_NOTICE
;
2690 else if (!strcasecmp(value
, "warn"))
2691 LogLevel
= CUPSD_LOG_WARN
;
2692 else if (!strcasecmp(value
, "error"))
2693 LogLevel
= CUPSD_LOG_ERROR
;
2694 else if (!strcasecmp(value
, "crit"))
2695 LogLevel
= CUPSD_LOG_CRIT
;
2696 else if (!strcasecmp(value
, "alert"))
2697 LogLevel
= CUPSD_LOG_ALERT
;
2698 else if (!strcasecmp(value
, "emerg"))
2699 LogLevel
= CUPSD_LOG_EMERG
;
2700 else if (!strcasecmp(value
, "none"))
2701 LogLevel
= CUPSD_LOG_NONE
;
2703 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2706 else if (!strcasecmp(line
, "PrintcapFormat"))
2709 * Format of printcap file?
2712 if (!strcasecmp(value
, "bsd"))
2713 PrintcapFormat
= PRINTCAP_BSD
;
2714 else if (!strcasecmp(value
, "solaris"))
2715 PrintcapFormat
= PRINTCAP_SOLARIS
;
2717 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2720 else if (!strcasecmp(line
, "ServerTokens"))
2723 * Set the string used for the Server header...
2726 struct utsname plat
; /* Platform info */
2731 if (!strcasecmp(value
, "ProductOnly"))
2732 cupsdSetString(&ServerHeader
, "CUPS");
2733 else if (!strcasecmp(value
, "Major"))
2734 cupsdSetString(&ServerHeader
, "CUPS/1");
2735 else if (!strcasecmp(value
, "Minor"))
2736 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2737 else if (!strcasecmp(value
, "Minimal"))
2738 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2739 else if (!strcasecmp(value
, "OS"))
2740 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2741 else if (!strcasecmp(value
, "Full"))
2742 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2744 else if (!strcasecmp(value
, "None"))
2745 cupsdClearString(&ServerHeader
);
2747 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2750 else if (!strcasecmp(line
, "PassEnv"))
2753 * PassEnv variable [... variable]
2758 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2759 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2762 if (value
[valuelen
])
2764 value
[valuelen
] = '\0';
2768 cupsdSetEnv(value
, NULL
);
2770 for (value
+= valuelen
; *value
; value
++)
2771 if (!isspace(*value
) || *value
!= ',')
2775 else if (!strcasecmp(line
, "SetEnv"))
2778 * SetEnv variable value
2781 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2789 while (isspace(*valueptr
& 255))
2792 cupsdSetEnv(value
, valueptr
);
2795 cupsdLogMessage(CUPSD_LOG_ERROR
,
2796 "Missing value for SetEnv directive on line %d.",
2802 * Find a simple variable in the list...
2805 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2806 if (!strcasecmp(line
, var
->name
))
2812 * Unknown directive! Output an error message and continue...
2815 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2822 case CUPSD_VARTYPE_INTEGER
:
2825 char *units
; /* Units */
2828 n
= strtol(value
, &units
, 0);
2830 if (units
&& *units
)
2832 if (tolower(units
[0] & 255) == 'g')
2833 n
*= 1024 * 1024 * 1024;
2834 else if (tolower(units
[0] & 255) == 'm')
2836 else if (tolower(units
[0] & 255) == 'k')
2838 else if (tolower(units
[0] & 255) == 't')
2842 *((int *)var
->ptr
) = n
;
2846 case CUPSD_VARTYPE_BOOLEAN
:
2847 if (!strcasecmp(value
, "true") ||
2848 !strcasecmp(value
, "on") ||
2849 !strcasecmp(value
, "enabled") ||
2850 !strcasecmp(value
, "yes") ||
2852 *((int *)var
->ptr
) = TRUE
;
2853 else if (!strcasecmp(value
, "false") ||
2854 !strcasecmp(value
, "off") ||
2855 !strcasecmp(value
, "disabled") ||
2856 !strcasecmp(value
, "no") ||
2857 !strcasecmp(value
, "0"))
2858 *((int *)var
->ptr
) = FALSE
;
2860 cupsdLogMessage(CUPSD_LOG_ERROR
,
2861 "Unknown boolean value %s on line %d.",
2865 case CUPSD_VARTYPE_STRING
:
2866 cupsdSetString((char **)var
->ptr
, value
);
2877 * 'read_location()' - Read a <Location path> definition.
2880 static int /* O - New line number or 0 on error */
2881 read_location(cups_file_t
*fp
, /* I - Configuration file */
2882 char *location
, /* I - Location name/path */
2883 int linenum
) /* I - Current line number */
2885 cupsd_location_t
*loc
, /* New location */
2886 *parent
; /* Parent location */
2887 char line
[HTTP_MAX_BUFFER
],
2889 *value
, /* Value for directive */
2890 *valptr
; /* Pointer into value */
2893 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2896 parent
->limit
= AUTH_LIMIT_ALL
;
2899 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2902 * Decode the directive...
2905 if (!strcasecmp(line
, "</Location>"))
2907 else if (!strcasecmp(line
, "<Limit") ||
2908 !strcasecmp(line
, "<LimitExcept"))
2912 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2916 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2922 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2927 if (!strcmp(value
, "ALL"))
2928 loc
->limit
= AUTH_LIMIT_ALL
;
2929 else if (!strcmp(value
, "GET"))
2930 loc
->limit
|= AUTH_LIMIT_GET
;
2931 else if (!strcmp(value
, "HEAD"))
2932 loc
->limit
|= AUTH_LIMIT_HEAD
;
2933 else if (!strcmp(value
, "OPTIONS"))
2934 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2935 else if (!strcmp(value
, "POST"))
2936 loc
->limit
|= AUTH_LIMIT_POST
;
2937 else if (!strcmp(value
, "PUT"))
2938 loc
->limit
|= AUTH_LIMIT_PUT
;
2939 else if (!strcmp(value
, "TRACE"))
2940 loc
->limit
|= AUTH_LIMIT_TRACE
;
2942 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2945 for (value
= valptr
; isspace(*value
& 255); value
++);
2948 if (!strcasecmp(line
, "<LimitExcept"))
2949 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2951 parent
->limit
&= ~loc
->limit
;
2953 else if (!strcasecmp(line
, "</Limit>"))
2955 else if (!parse_aaa(loc
, line
, value
, linenum
))
2957 cupsdLogMessage(CUPSD_LOG_ERROR
,
2958 "Unknown Location directive %s on line %d.",
2964 cupsdLogMessage(CUPSD_LOG_ERROR
,
2965 "Unexpected end-of-file at line %d while reading location!",
2973 * 'read_policy()' - Read a <Policy name> definition.
2976 static int /* O - New line number or 0 on error */
2977 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2978 char *policy
, /* I - Location name/path */
2979 int linenum
) /* I - Current line number */
2981 int i
; /* Looping var */
2982 cupsd_policy_t
*pol
; /* Policy */
2983 cupsd_location_t
*op
; /* Policy operation */
2984 int num_ops
; /* Number of IPP operations */
2985 ipp_op_t ops
[100]; /* Operations */
2986 char line
[HTTP_MAX_BUFFER
],
2988 *value
, /* Value for directive */
2989 *valptr
; /* Pointer into value */
2993 * Create the policy...
2996 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3000 * Read from the file...
3006 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3009 * Decode the directive...
3012 if (!strcasecmp(line
, "</Policy>"))
3015 cupsdLogMessage(CUPSD_LOG_WARN
,
3016 "Missing </Limit> before </Policy> on line %d!",
3021 else if (!strcasecmp(line
, "<Limit") && !op
)
3025 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3030 * Scan for IPP operation names...
3037 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3042 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3044 if (!strcasecmp(value
, "All"))
3045 ops
[num_ops
] = IPP_ANY_OPERATION
;
3046 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3047 cupsdLogMessage(CUPSD_LOG_ERROR
,
3048 "Bad IPP operation name \"%s\" on line %d!",
3054 cupsdLogMessage(CUPSD_LOG_ERROR
,
3055 "Too many operations listed on line %d!",
3058 for (value
= valptr
; isspace(*value
& 255); value
++);
3062 * If none are specified, apply the policy to all operations...
3067 ops
[0] = IPP_ANY_OPERATION
;
3072 * Add a new policy for the first operation...
3075 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3077 else if (!strcasecmp(line
, "</Limit>") && op
)
3080 * Finish the current operation limit...
3086 * Copy the policy to the other operations...
3089 for (i
= 1; i
< num_ops
; i
++)
3090 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3097 cupsdLogMessage(CUPSD_LOG_ERROR
,
3098 "Missing <Limit ops> directive before %s on line %d.",
3102 else if (!parse_aaa(op
, line
, value
, linenum
))
3105 cupsdLogMessage(CUPSD_LOG_ERROR
,
3106 "Unknown Policy Limit directive %s on line %d.",
3109 cupsdLogMessage(CUPSD_LOG_ERROR
,
3110 "Unknown Policy directive %s on line %d.",
3117 cupsdLogMessage(CUPSD_LOG_ERROR
,
3118 "Unexpected end-of-file at line %d while reading policy \"%s\"!",