4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdReadConfiguration() - Read the cupsd.conf file.
27 * get_address() - Get an address + port number from a line.
28 * get_addr_and_mask() - Get an IP address and netmask.
29 * parse_aaa() - Parse authentication, authorization, and
30 * access control lines.
31 * read_configuration() - Read a configuration file.
32 * read_location() - Read a <Location path> definition.
33 * read_policy() - Read a <Policy name> definition.
34 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
35 * required by SSLSetCertificate.
39 * Include necessary headers...
45 #include <sys/utsname.h>
49 # include <Security/SecureTransport.h>
50 # include <Security/SecIdentitySearch.h>
51 #endif /* HAVE_CDSASSL */
55 #endif /* HAVE_VSYSLOG */
59 * Possibly missing network definitions...
63 # define INADDR_NONE 0xffffffff
64 #endif /* !INADDR_NONE */
68 * Configuration variable structure...
73 CUPSD_VARTYPE_INTEGER
, /* Integer option */
74 CUPSD_VARTYPE_STRING
, /* String option */
75 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
80 char *name
; /* Name of variable */
81 void *ptr
; /* Pointer to variable */
82 cupsd_vartype_t type
; /* Type (int, string, address) */
90 static cupsd_var_t variables
[] =
92 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
93 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
94 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
95 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
96 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
97 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
98 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
99 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
100 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
101 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
102 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
103 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
104 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
105 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
106 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
107 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
108 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
109 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
110 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
111 { "FaxRetryLimit", &FaxRetryLimit
, CUPSD_VARTYPE_INTEGER
},
112 { "FaxRetryInterval", &FaxRetryInterval
, CUPSD_VARTYPE_INTEGER
},
113 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
114 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
115 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
116 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
117 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
118 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
119 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
120 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
121 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
122 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
123 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
124 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
127 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
135 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
136 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
137 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
138 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
139 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
140 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
141 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
142 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
143 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
144 { "RunAsUser", &RunAsUser
, CUPSD_VARTYPE_BOOLEAN
},
145 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
146 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
147 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
149 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
150 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
151 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
152 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
153 #endif /* HAVE_SSL */
154 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
155 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
156 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
157 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
158 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
}
160 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
163 static unsigned ones
[4] =
165 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
167 static unsigned zeros
[4] =
169 0x00000000, 0x00000000, 0x00000000, 0x00000000
173 CFArrayRef
CDSAGetServerCerts();
174 #endif /* HAVE_CDSASSL */
181 static int get_address(const char *value
, unsigned defaddress
, int defport
,
182 int deffamily
, http_addr_t
*address
);
183 static int get_addr_and_mask(const char *value
, unsigned *ip
,
185 static int parse_aaa(cupsd_location_t
*loc
, char *line
, char *value
, int linenum
);
186 static int read_configuration(cups_file_t
*fp
);
187 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
188 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
192 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
195 int /* O - 1 on success, 0 otherwise */
196 cupsdReadConfiguration(void)
198 int i
; /* Looping var */
199 cups_file_t
*fp
; /* Configuration file */
200 int status
; /* Return status */
201 char temp
[1024], /* Temporary buffer */
202 *slash
; /* Directory separator */
203 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
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)
259 #ifdef HAVE_DOMAINSOCKETS
260 int i
; /* Looping var */
261 cupsd_listener_t
*lis
; /* Current listening socket */
263 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
264 if (lis
->address
.sin_family
== AF_LOCAL
)
265 cupsdClearString((char **)&lis
->address
.sin_addr
);
266 #endif /* HAVE_DOMAINSOCKETS */
277 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
278 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
279 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
280 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
281 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
282 cupsdSetString(&DataDir
, CUPS_DATADIR
);
283 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
284 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
285 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
286 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
287 cupsdSetString(&Printcap
, "/etc/printcap");
288 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
289 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
290 cupsdSetString(&RemoteRoot
, "remroot");
291 cupsdSetString(&ServerHeader
, "CUPS/1.1");
292 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
294 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
295 if ((slash
= strrchr(temp
, '/')) != NULL
)
298 cupsdSetString(&ServerRoot
, temp
);
300 cupsdClearString(&Classification
);
301 ClassifyOverride
= 0;
305 cupsdSetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
307 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
308 cupsdSetString(&ServerKey
, "ssl/server.key");
309 # endif /* HAVE_CDSASSL */
310 #endif /* HAVE_SSL */
312 language
= cupsLangDefault();
314 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
315 cupsdSetString(&DefaultLanguage
, "en");
317 cupsdSetString(&DefaultLanguage
, language
->language
);
319 cupsdSetString(&DefaultCharset
, cupsEncodingName(language
->encoding
));
321 cupsdSetString(&RIPCache
, "8m");
323 if (getenv("TMPDIR") == NULL
)
324 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
326 cupsdSetString(&TempDir
, getenv("TMPDIR"));
329 * Find the default system group: "sys", "system", or "root"...
332 group
= getgrnam(CUPS_DEFAULT_GROUP
);
340 * Found the group, use it!
343 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
345 SystemGroupIDs
[0] = group
->gr_gid
;
350 * Find the group associated with GID 0...
357 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
359 cupsdSetString(&SystemGroups
[0], "unknown");
361 SystemGroupIDs
[0] = 0;
365 * Find the default user...
368 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
373 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
374 * complement number...)
383 * Find the default group (nobody)...
386 group
= getgrnam("nobody");
390 Group
= group
->gr_gid
;
394 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
395 * complement number...)
405 ConfigFilePerm
= 0640;
406 DefaultAuthType
= AUTH_BASIC
;
408 FaxRetryInterval
= 300;
413 HostNameLookups
= FALSE
;
414 ImplicitClasses
= TRUE
;
415 ImplicitAnyClasses
= FALSE
;
416 HideImplicitMembers
= TRUE
;
418 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
419 ListenBackLog
= SOMAXCONN
;
421 LogLevel
= CUPSD_LOG_ERROR
;
423 MaxClientsPerHost
= 0;
424 MaxLogSize
= 1024 * 1024;
425 MaxPrinterHistory
= 10;
428 RootCertDuration
= 300;
430 Timeout
= DEFAULT_TIMEOUT
;
432 BrowseInterval
= DEFAULT_INTERVAL
;
433 BrowsePort
= ippPort();
434 BrowseLocalProtocols
= BROWSE_CUPS
;
435 BrowseRemoteProtocols
= BROWSE_CUPS
;
436 BrowseShortNames
= TRUE
;
437 BrowseTimeout
= DEFAULT_TIMEOUT
;
440 cupsdClearString(&BrowseLocalOptions
);
441 cupsdClearString(&BrowseRemoteOptions
);
443 JobHistory
= DEFAULT_HISTORY
;
444 JobFiles
= DEFAULT_FILES
;
449 MaxJobsPerPrinter
= 0;
452 cupsdClearString(&DefaultPolicy
);
455 * Read the configuration file...
458 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
461 status
= read_configuration(fp
);
474 * Use the default system group if none was supplied in cupsd.conf...
477 if (NumSystemGroups
== 0)
481 * Get the access control list for browsing...
484 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
487 * Open the system log for cupsd if necessary...
491 if (!strcmp(AccessLog
, "syslog") ||
492 !strcmp(ErrorLog
, "syslog") ||
493 !strcmp(PageLog
, "syslog"))
494 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
495 #endif /* HAVE_VSYSLOG */
498 * Log the configuration file that was used...
501 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
505 * Validate the Group and SystemGroup settings - they cannot be the same,
506 * otherwise the CGI programs will be able to authenticate as root without
512 for (i
= 0; i
< NumSystemGroups
; i
++)
513 if (Group
== SystemGroupIDs
[i
])
516 if (i
< NumSystemGroups
)
519 * Log the error and reset the group to a safe value...
522 cupsdLogMessage(CUPSD_LOG_NOTICE
,
523 "Group and SystemGroup cannot use the same groups!");
524 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
526 group
= getgrnam("nobody");
530 Group
= group
->gr_gid
;
534 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
535 * complement number...)
544 * Check that we have at least one listen/port line; if not, report this
545 * as an error and exit!
548 if (NumListeners
== 0)
554 cupsdLogMessage(CUPSD_LOG_EMERG
,
555 "No valid Listen or Port lines were found in the configuration file!");
561 cupsdEndProcess(getpid(), 0);
565 * Set the default locale using the language and charset...
568 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
571 * Update all relative filenames to include the full path from ServerRoot...
574 if (DocumentRoot
[0] != '/')
575 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
577 if (RequestRoot
[0] != '/')
578 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
580 if (ServerBin
[0] != '/')
581 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
583 if (StateDir
[0] != '/')
584 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
586 if (CacheDir
[0] != '/')
587 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
590 if (ServerCertificate
[0] != '/')
591 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
593 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
594 chown(ServerCertificate
, RunUser
, Group
);
595 chmod(ServerCertificate
, ConfigFilePerm
);
597 if (ServerKey
[0] != '/')
598 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
600 chown(ServerKey
, RunUser
, Group
);
601 chmod(ServerKey
, ConfigFilePerm
);
602 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
603 #endif /* HAVE_SSL */
606 * Make sure that directories and config files are owned and
607 * writable by the user and group in the cupsd.conf file...
610 chown(CacheDir
, RunUser
, Group
);
611 chmod(CacheDir
, 0775);
613 snprintf(temp
, sizeof(temp
), "%s/ppd", CacheDir
);
616 chown(temp
, RunUser
, Group
);
619 chown(StateDir
, RunUser
, Group
);
620 chmod(StateDir
, 0775);
622 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
625 chown(temp
, User
, SystemGroupIDs
[0]);
631 chown(ServerRoot
, RunUser
, Group
);
632 chmod(ServerRoot
, 0755);
634 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
637 chown(temp
, RunUser
, Group
);
640 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
643 chown(temp
, RunUser
, Group
);
646 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
647 chown(temp
, RunUser
, Group
);
648 chmod(temp
, ConfigFilePerm
);
650 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
651 chown(temp
, RunUser
, Group
);
654 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
655 chown(temp
, RunUser
, Group
);
658 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
659 chown(temp
, User
, Group
);
663 * Make sure the request and temporary directories have the right
667 chown(RequestRoot
, RunUser
, Group
);
668 chmod(RequestRoot
, 0710);
670 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
674 * Update ownership and permissions if the CUPS temp directory
675 * is under the spool directory or does not exist...
678 if (access(TempDir
, 0))
679 mkdir(TempDir
, 01770);
681 chown(TempDir
, RunUser
, Group
);
682 chmod(TempDir
, 01770);
685 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
688 * Clean out the temporary directory...
691 cups_dir_t
*dir
; /* Temporary directory */
692 cups_dentry_t
*dent
; /* Directory entry */
693 char tempfile
[1024]; /* Temporary filename */
696 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
698 cupsdLogMessage(CUPSD_LOG_INFO
,
699 "Cleaning out old temporary files in \"%s\"...", TempDir
);
701 while ((dent
= cupsDirRead(dir
)) != NULL
)
703 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
705 if (unlink(tempfile
))
706 cupsdLogMessage(CUPSD_LOG_ERROR
,
707 "Unable to remove temporary file \"%s\" - %s",
708 tempfile
, strerror(errno
));
710 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
717 cupsdLogMessage(CUPSD_LOG_ERROR
,
718 "Unable to open temporary directory \"%s\" - %s",
719 TempDir
, strerror(errno
));
723 * Setup environment variables...
729 * Check the MaxClients setting, and then allocate memory for it...
732 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
735 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
738 MaxClients
= MaxFDs
/ 3;
741 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
743 cupsdLogMessage(CUPSD_LOG_ERROR
,
744 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
745 MaxClients
, strerror(errno
));
749 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
753 * Check the MaxActiveJobs setting; limit to 1/3 the available
754 * file descriptors, since we need a pipe for each job...
757 if (MaxActiveJobs
> (MaxFDs
/ 3))
758 MaxActiveJobs
= MaxFDs
/ 3;
760 if (Classification
&& strcasecmp(Classification
, "none") == 0)
761 cupsdClearString(&Classification
);
764 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
767 * Update the MaxClientsPerHost value, as needed...
770 if (MaxClientsPerHost
<= 0)
771 MaxClientsPerHost
= MaxClients
;
773 if (MaxClientsPerHost
> MaxClients
)
774 MaxClientsPerHost
= MaxClients
;
776 cupsdLogMessage(CUPSD_LOG_INFO
,
777 "Allowing up to %d client connections per host.",
781 * Update the default policy, as needed...
785 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
787 DefaultPolicyPtr
= NULL
;
789 if (!DefaultPolicyPtr
)
791 cupsd_policy_t
*p
; /* New policy */
792 cupsd_location_t
*po
; /* New policy operation */
796 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
799 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
800 cupsdLogMessage(CUPSD_LOG_INFO
,
801 "Using policy \"default\" as the default!");
804 cupsdLogMessage(CUPSD_LOG_INFO
,
805 "Creating CUPS default administrative policy:");
807 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
809 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
810 cupsdLogMessage(CUPSD_LOG_INFO
,
811 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
812 "Release-Job Restart-Job Purge-Jobs "
813 "Set-Job-Attributes Create-Job-Subscription "
814 "Renew-Subscription Cancel-Subscription "
815 "Get-Notifications Reprocess-Job Cancel-Current-Job "
816 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
817 "CUPS-Authenticate-Job>");
818 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
820 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
821 po
->order_type
= AUTH_ALLOW
;
822 po
->level
= AUTH_USER
;
824 cupsdAddName(po
, "@OWNER");
825 cupsdAddName(po
, "@SYSTEM");
826 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
828 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
829 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
830 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
831 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
832 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
833 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
834 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
835 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
836 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
837 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
838 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
839 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
840 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
841 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
842 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
843 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
844 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
846 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
848 cupsdLogMessage(CUPSD_LOG_INFO
,
849 "<Limit Pause-Printer Resume-Printer "
850 "Set-Printer-Attributes Enable-Printer "
851 "Disable-Printer Pause-Printer-After-Current-Job "
852 "Hold-New-Jobs Release-Held-New-Jobs "
853 "Deactivate-Printer Activate-Printer Restart-Printer "
854 "Shutdown-Printer Startup-Printer Promote-Job "
855 "Schedule-Job-After CUPS-Add-Printer "
856 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
857 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
858 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
859 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
861 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
862 po
->order_type
= AUTH_ALLOW
;
863 po
->type
= AUTH_BASIC
;
864 po
->level
= AUTH_USER
;
866 cupsdAddName(po
, "@SYSTEM");
867 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
869 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
870 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
871 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
872 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
873 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
874 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
875 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
876 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
877 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
878 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
879 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
880 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
881 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
882 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
883 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
884 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
885 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
886 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
887 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
888 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
889 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
891 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
893 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
894 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
896 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
897 po
->order_type
= AUTH_ALLOW
;
899 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
900 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
905 * If we are doing a full reload or the server root has changed, flush
906 * the jobs, printers, etc. and start from scratch...
909 if (NeedReload
== RELOAD_ALL
||
910 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
911 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
913 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
920 cupsdDeleteAllClasses();
921 cupsdDeleteAllPrinters();
923 DefaultPrinter
= NULL
;
925 if (MimeDatabase
!= NULL
)
926 mimeDelete(MimeDatabase
);
930 for (i
= 0; i
< NumMimeTypes
; i
++)
931 free((void *)MimeTypes
[i
]);
937 * Read the MIME type and conversion database...
940 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
942 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
946 cupsdLogMessage(CUPSD_LOG_EMERG
,
947 "Unable to load MIME database from \'%s\'!", ServerRoot
);
951 cupsdLogMessage(CUPSD_LOG_INFO
,
952 "Loaded MIME database from \'%s\': %d types, %d filters...",
953 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
956 * Create a list of MIME types for the document-format-supported
960 NumMimeTypes
= MimeDatabase
->num_types
;
961 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
964 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
966 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
968 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
969 MimeDatabase
->types
[i
]->type
);
971 MimeTypes
[i
] = strdup(type
);
974 if (i
< NumMimeTypes
)
975 MimeTypes
[i
] = strdup("application/octet-stream");
981 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
982 cupsdLoadBanners(temp
);
985 * Load printers and classes...
988 cupsdLoadAllPrinters();
989 cupsdLoadAllClasses();
991 cupsdCreateCommonData();
994 * Load queued jobs...
999 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1003 cupsdCreateCommonData();
1005 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1009 * Reset the reload state...
1012 NeedReload
= RELOAD_NONE
;
1014 cupsdClearString(&old_serverroot
);
1015 cupsdClearString(&old_requestroot
);
1018 * Startup the server and return...
1028 * 'get_address()' - Get an address + port number from a line.
1031 static int /* O - 1 if address good, 0 if bad */
1032 get_address(const char *value
, /* I - Value string */
1033 unsigned defaddress
, /* I - Default address */
1034 int defport
, /* I - Default port */
1035 int deffamily
, /* I - Default family */
1036 http_addr_t
*address
) /* O - Socket address */
1038 char hostname
[256], /* Hostname or IP */
1039 portname
[256], /* Port number or name */
1040 *ptr
; /* Pointer into hostname string */
1041 struct hostent
*host
; /* Host address */
1042 struct servent
*port
; /* Port number */
1046 * Check for an empty value...
1051 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1056 * Initialize the socket address to the defaults...
1059 memset(address
, 0, sizeof(http_addr_t
));
1062 if (deffamily
== AF_INET6
)
1064 address
->ipv6
.sin6_family
= AF_INET6
;
1065 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
1066 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
1067 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
1068 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
1069 address
->ipv6
.sin6_port
= htons(defport
);
1072 #endif /* AF_INET6 */
1074 address
->ipv4
.sin_family
= AF_INET
;
1075 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
1076 address
->ipv4
.sin_port
= htons(defport
);
1081 * If the address starts with a "/", it is a domain socket...
1086 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
1088 cupsdLogMessage(CUPSD_LOG_ERROR
, "Domain socket name \"%s\" too long!",
1093 address
->un
.sun_family
= AF_LOCAL
;
1094 strcpy(address
->un
.sun_path
, value
);
1098 #endif /* AF_LOCAL */
1101 * Try to grab a hostname and port number...
1104 strlcpy(hostname
, value
, sizeof(hostname
));
1106 if ((ptr
= strrchr(hostname
, ':')) != NULL
)
1109 * Copy hostname and port separately...
1114 strlcpy(portname
, ptr
, sizeof(portname
));
1116 else if (isdigit(value
[0] & 255))
1123 strlcpy(portname
, value
, sizeof(portname
));
1128 * Hostname by itself...
1135 * Decode the hostname and port number as needed...
1138 if (hostname
[0] && strcmp(hostname
, "*"))
1140 if ((host
= httpGetHostByName(hostname
)) == NULL
)
1142 cupsdLogMessage(CUPSD_LOG_ERROR
, "httpGetHostByName(\"%s\") failed - %s!",
1143 hostname
, hstrerror(h_errno
));
1147 httpAddrLoad(host
, defport
, 0, address
);
1150 if (portname
[0] != '\0')
1152 if (isdigit(portname
[0] & 255))
1155 if (address
->addr
.sa_family
== AF_INET6
)
1156 address
->ipv6
.sin6_port
= htons(atoi(portname
));
1158 #endif /* AF_INET6 */
1159 address
->ipv4
.sin_port
= htons(atoi(portname
));
1163 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
1165 cupsdLogMessage(CUPSD_LOG_ERROR
, "getservbyname(\"%s\") failed - %s!",
1166 portname
, strerror(errno
));
1172 if (address
->addr
.sa_family
== AF_INET6
)
1173 address
->ipv6
.sin6_port
= htons(port
->s_port
);
1175 #endif /* AF_INET6 */
1176 address
->ipv4
.sin_port
= htons(port
->s_port
);
1186 * 'get_addr_and_mask()' - Get an IP address and netmask.
1189 static int /* O - 1 on success, 0 on failure */
1190 get_addr_and_mask(const char *value
, /* I - String from config file */
1191 unsigned *ip
, /* O - Address value */
1192 unsigned *mask
) /* O - Mask value */
1194 int i
, /* Looping var */
1195 family
, /* Address family */
1196 ipcount
; /* Count of fields in address */
1197 const char *maskval
, /* Pointer to start of mask value */
1198 *ptr
; /* Pointer into value */
1199 static unsigned netmasks
[4][4] = /* Standard netmasks... */
1201 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1202 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1203 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1204 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1209 * Get the address...
1212 memset(ip
, 0, sizeof(unsigned) * 4);
1214 if ((maskval
= strchr(value
, '/')) != NULL
)
1217 maskval
= value
+ strlen(value
);
1221 * Check for an IPv6 address...
1227 * Parse hexadecimal IPv6 address...
1232 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 4; i
++)
1236 else if (*ptr
== ':')
1239 ip
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1241 if (*ptr
== ':' || *ptr
== ']')
1247 if (*ptr
&& *ptr
!= '/')
1251 #endif /* AF_INET6 */
1254 * Parse dotted-decimal IPv4 address...
1258 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1260 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1261 ip
[0] = ip
[1] = ip
[2] = 0;
1267 * Get the netmask value(s)...
1270 memset(mask
, 0, sizeof(unsigned) * 4);
1273 if (maskval
[1] == '[')
1276 * Get hexadecimal mask value...
1279 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 4; i
++)
1283 else if (*ptr
== ':')
1286 mask
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1288 if (*ptr
== ':' || *ptr
== ']')
1296 #endif /* AF_INET6 */
1297 if (strchr(maskval
, '.'))
1300 * Get dotted-decimal mask...
1303 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1306 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1307 mask
[0] = mask
[1] = mask
[2] = 0;
1312 * Get address/bits format...
1318 if (family
== AF_INET6
)
1323 mask
[0] = 0xffffffff;
1325 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1328 mask
[1] = 0xffffffff;
1332 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1335 mask
[2] = 0xffffffff;
1339 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1342 mask
[3] = 0xffffffff;
1346 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1349 #endif /* AF_INET6 */
1353 mask
[0] = 0xffffffff;
1354 mask
[1] = 0xffffffff;
1355 mask
[2] = 0xffffffff;
1358 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1360 mask
[3] = 0xffffffff;
1365 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1367 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1368 "get_addr_and_mask(value=\"%s\", "
1369 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1370 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1374 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1377 if ((ip
[0] & ~mask
[0]) != 0 ||
1378 (ip
[1] & ~mask
[1]) != 0 ||
1379 (ip
[2] & ~mask
[2]) != 0 ||
1380 (ip
[3] & ~mask
[3]) != 0)
1388 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1391 static int /* O - 1 on success, 0 on failure */
1392 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1393 char *line
, /* I - Line from file */
1394 char *value
, /* I - Start of value data */
1395 int linenum
) /* I - Current line number */
1397 char *valptr
; /* Pointer into value */
1398 unsigned ip
[4], /* IP address components */
1399 mask
[4]; /* IP netmask components */
1402 if (!strcasecmp(line
, "Encryption"))
1405 * "Encryption xxx" - set required encryption level...
1408 if (!strcasecmp(value
, "never"))
1409 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1410 else if (!strcasecmp(value
, "always"))
1412 cupsdLogMessage(CUPSD_LOG_ERROR
,
1413 "Encryption value \"%s\" on line %d is invalid in this "
1414 "context. Using \"required\" instead.", value
, linenum
);
1416 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1418 else if (!strcasecmp(value
, "required"))
1419 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1420 else if (!strcasecmp(value
, "ifrequested"))
1421 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1424 cupsdLogMessage(CUPSD_LOG_ERROR
,
1425 "Unknown Encryption value %s on line %d.", value
, linenum
);
1429 else if (!strcasecmp(line
, "Order"))
1432 * "Order Deny,Allow" or "Order Allow,Deny"...
1435 if (!strncasecmp(value
, "deny", 4))
1436 loc
->order_type
= AUTH_ALLOW
;
1437 else if (!strncasecmp(value
, "allow", 5))
1438 loc
->order_type
= AUTH_DENY
;
1441 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1446 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1449 * Allow [From] host/ip...
1450 * Deny [From] host/ip...
1453 if (!strncasecmp(value
, "from", 4))
1456 * Strip leading "from"...
1461 while (isspace(*value
& 255))
1466 * Figure out what form the allow/deny address takes:
1477 * nnn.nnn.nnn.nnn/mm
1478 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1481 if (!strcasecmp(value
, "all"))
1487 if (!strcasecmp(line
, "Allow"))
1488 cupsdAllowIP(loc
, zeros
, zeros
);
1490 cupsdDenyIP(loc
, zeros
, zeros
);
1492 else if (!strcasecmp(value
, "none"))
1498 if (!strcasecmp(line
, "Allow"))
1499 cupsdAllowIP(loc
, ones
, zeros
);
1501 cupsdDenyIP(loc
, ones
, zeros
);
1503 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1506 * Host or domain name...
1509 if (value
[0] == '*')
1512 if (!strcasecmp(line
, "Allow"))
1513 cupsdAllowHost(loc
, value
);
1515 cupsdDenyHost(loc
, value
);
1520 * One of many IP address forms...
1523 if (!get_addr_and_mask(value
, ip
, mask
))
1525 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1530 if (!strcasecmp(line
, "Allow"))
1531 cupsdAllowIP(loc
, ip
, mask
);
1533 cupsdDenyIP(loc
, ip
, mask
);
1536 else if (!strcasecmp(line
, "AuthType"))
1539 * AuthType {none,basic,digest,basicdigest}
1542 if (!strcasecmp(value
, "none"))
1544 loc
->type
= AUTH_NONE
;
1545 loc
->level
= AUTH_ANON
;
1547 else if (!strcasecmp(value
, "basic"))
1549 loc
->type
= AUTH_BASIC
;
1551 if (loc
->level
== AUTH_ANON
)
1552 loc
->level
= AUTH_USER
;
1554 else if (!strcasecmp(value
, "digest"))
1556 loc
->type
= AUTH_DIGEST
;
1558 if (loc
->level
== AUTH_ANON
)
1559 loc
->level
= AUTH_USER
;
1561 else if (!strcasecmp(value
, "basicdigest"))
1563 loc
->type
= AUTH_BASICDIGEST
;
1565 if (loc
->level
== AUTH_ANON
)
1566 loc
->level
= AUTH_USER
;
1570 cupsdLogMessage(CUPSD_LOG_WARN
,
1571 "Unknown authorization type %s on line %d.",
1576 else if (!strcasecmp(line
, "AuthClass"))
1579 * AuthClass anonymous, user, system, group
1582 if (!strcasecmp(value
, "anonymous"))
1584 loc
->type
= AUTH_NONE
;
1585 loc
->level
= AUTH_ANON
;
1587 else if (!strcasecmp(value
, "user"))
1588 loc
->level
= AUTH_USER
;
1589 else if (!strcasecmp(value
, "group"))
1590 loc
->level
= AUTH_GROUP
;
1591 else if (!strcasecmp(value
, "system"))
1593 loc
->level
= AUTH_GROUP
;
1595 cupsdAddName(loc
, "@SYSTEM");
1599 cupsdLogMessage(CUPSD_LOG_WARN
,
1600 "Unknown authorization class %s on line %d.",
1605 else if (!strcasecmp(line
, "AuthGroupName"))
1606 cupsdAddName(loc
, value
);
1607 else if (!strcasecmp(line
, "Require"))
1610 * Apache synonym for AuthClass and AuthGroupName...
1614 * Require valid-user
1615 * Require group names
1616 * Require user names
1619 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1624 if (!strcasecmp(value
, "valid-user") ||
1625 !strcasecmp(value
, "user"))
1626 loc
->level
= AUTH_USER
;
1627 else if (!strcasecmp(value
, "group"))
1628 loc
->level
= AUTH_GROUP
;
1631 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1637 * Get the list of names from the line...
1640 for (value
= valptr
; *value
;)
1642 while (isspace(*value
& 255))
1645 if (*value
== '\"' || *value
== '\'')
1648 * Grab quoted name...
1651 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1658 * Grab literal name.
1661 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1667 cupsdAddName(loc
, value
);
1669 for (value
= valptr
; isspace(*value
& 255); value
++);
1672 else if (!strcasecmp(line
, "Satisfy"))
1674 if (!strcasecmp(value
, "all"))
1675 loc
->satisfy
= AUTH_SATISFY_ALL
;
1676 else if (!strcasecmp(value
, "any"))
1677 loc
->satisfy
= AUTH_SATISFY_ANY
;
1680 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1693 * 'read_configuration()' - Read a configuration file.
1696 static int /* O - 1 on success, 0 on failure */
1697 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1699 int i
; /* Looping var */
1700 int linenum
; /* Current line number */
1701 char line
[HTTP_MAX_BUFFER
],
1702 /* Line from file */
1703 temp
[HTTP_MAX_BUFFER
],
1704 /* Temporary buffer for value */
1705 temp2
[HTTP_MAX_BUFFER
],
1706 /* Temporary buffer 2 for value */
1707 *ptr
, /* Pointer into line/temp */
1708 *value
; /* Pointer to value */
1709 int valuelen
; /* Length of value */
1710 cupsd_var_t
*var
; /* Current variable */
1711 unsigned ip
[4], /* Address value */
1712 mask
[4]; /* Netmask value */
1713 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1714 cupsd_dirsvc_poll_t
*poll
; /* Polling data */
1715 http_addr_t polladdr
; /* Polling address */
1716 cupsd_location_t
*location
; /* Browse location */
1717 cups_file_t
*incfile
; /* Include file */
1718 char incname
[1024]; /* Include filename */
1719 struct group
*group
; /* Group */
1723 * Loop through each line in the file...
1728 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1731 * Decode the directive...
1734 if (!strcasecmp(line
, "Include"))
1740 if (value
[0] == '/')
1741 strlcpy(incname
, value
, sizeof(incname
));
1743 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1745 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1746 cupsdLogMessage(CUPSD_LOG_ERROR
,
1747 "Unable to include config file \"%s\" - %s",
1748 incname
, strerror(errno
));
1751 read_configuration(incfile
);
1752 cupsFileClose(incfile
);
1755 else if (!strcasecmp(line
, "<Location"))
1763 linenum
= read_location(fp
, value
, linenum
);
1769 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1774 else if (!strcasecmp(line
, "<Policy"))
1782 linenum
= read_policy(fp
, value
, linenum
);
1788 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1792 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1795 * Add a listening address to the list...
1798 cupsd_listener_t
*lis
; /* New listeners array */
1801 if (NumListeners
== 0)
1802 lis
= malloc(sizeof(cupsd_listener_t
));
1804 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1808 cupsdLogMessage(CUPSD_LOG_ERROR
,
1809 "Unable to allocate %s at line %d - %s.",
1810 line
, linenum
, strerror(errno
));
1815 lis
+= NumListeners
;
1817 memset(lis
, 0, sizeof(cupsd_listener_t
));
1819 #if defined(AF_INET6) && !defined(__OpenBSD__)
1820 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET6
, &(lis
->address
)))
1822 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1823 #endif /* AF_INET6 && !__OpenBSD__ */
1825 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1828 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1829 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1830 ntohs(lis
->address
.ipv6
.sin6_port
));
1832 #endif /* AF_INET6 */
1834 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1835 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
1837 #endif /* AF_LOCAL */
1838 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
1839 ntohs(lis
->address
.ipv4
.sin_port
));
1844 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1848 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1851 * Add a listening address to the list...
1854 cupsd_listener_t
*lis
; /* New listeners array */
1857 if (NumListeners
== 0)
1858 lis
= malloc(sizeof(cupsd_listener_t
));
1860 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1864 cupsdLogMessage(CUPSD_LOG_ERROR
,
1865 "Unable to allocate %s at line %d - %s.",
1866 line
, linenum
, strerror(errno
));
1871 lis
+= NumListeners
;
1873 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1875 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1878 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1879 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1880 ntohs(lis
->address
.ipv6
.sin6_port
));
1882 #endif /* AF_INET6 */
1884 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1885 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
1887 #endif /* AF_LOCAL */
1888 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
1889 ntohs(lis
->address
.ipv4
.sin_port
));
1890 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1894 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1897 #endif /* HAVE_SSL */
1898 else if (!strcasecmp(line
, "BrowseAddress"))
1901 * Add a browse address to the list...
1904 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
1907 if (NumBrowsers
== 0)
1908 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
1910 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
1914 cupsdLogMessage(CUPSD_LOG_ERROR
,
1915 "Unable to allocate BrowseAddress at line %d - %s.",
1916 linenum
, strerror(errno
));
1921 dira
+= NumBrowsers
;
1923 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
1925 if (!strcasecmp(value
, "@LOCAL"))
1928 * Send browse data to all local interfaces...
1931 strcpy(dira
->iface
, "*");
1934 else if (!strncasecmp(value
, "@IF(", 4))
1937 * Send browse data to the named interface...
1940 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1942 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1948 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1950 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1953 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1954 cupsdLogMessage(CUPSD_LOG_INFO
,
1955 "Sending browsing info to %s:%d (IPv6)", temp
,
1956 ntohs(dira
->to
.ipv6
.sin6_port
));
1958 #endif /* AF_INET6 */
1959 cupsdLogMessage(CUPSD_LOG_INFO
, "Sending browsing info to %s:%d (IPv4)",
1960 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
1965 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
1968 else if (!strcasecmp(line
, "BrowseOrder"))
1971 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1974 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1975 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
1977 if (location
== NULL
)
1978 cupsdLogMessage(CUPSD_LOG_ERROR
,
1979 "Unable to initialize browse access control list!");
1980 else if (!strncasecmp(value
, "deny", 4))
1981 location
->order_type
= AUTH_ALLOW
;
1982 else if (!strncasecmp(value
, "allow", 5))
1983 location
->order_type
= AUTH_DENY
;
1985 cupsdLogMessage(CUPSD_LOG_ERROR
,
1986 "Unknown BrowseOrder value %s on line %d.",
1989 else if (!strcasecmp(line
, "BrowseProtocols") ||
1990 !strcasecmp(line
, "BrowseLocalProtocols") ||
1991 !strcasecmp(line
, "BrowseRemoteProtocols"))
1994 * "BrowseProtocol name [... name]"
1997 if (strcasecmp(line
, "BrowseLocalProtocols"))
1998 BrowseRemoteProtocols
= 0;
1999 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2000 BrowseLocalProtocols
= 0;
2004 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2005 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2008 if (value
[valuelen
])
2010 value
[valuelen
] = '\0';
2014 if (!strcasecmp(value
, "cups"))
2016 if (strcasecmp(line
, "BrowseLocalProtocols"))
2017 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2018 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2019 BrowseLocalProtocols
|= BROWSE_CUPS
;
2021 else if (!strcasecmp(value
, "slp"))
2023 if (strcasecmp(line
, "BrowseLocalProtocols"))
2024 BrowseRemoteProtocols
|= BROWSE_SLP
;
2025 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2026 BrowseLocalProtocols
|= BROWSE_SLP
;
2028 else if (!strcasecmp(value
, "ldap"))
2030 if (strcasecmp(line
, "BrowseLocalProtocols"))
2031 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2032 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2033 BrowseLocalProtocols
|= BROWSE_LDAP
;
2035 else if (!strcasecmp(value
, "all"))
2037 if (strcasecmp(line
, "BrowseLocalProtocols"))
2038 BrowseRemoteProtocols
|= BROWSE_ALL
;
2039 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2040 BrowseLocalProtocols
|= BROWSE_ALL
;
2044 cupsdLogMessage(CUPSD_LOG_ERROR
,
2045 "Unknown browse protocol \"%s\" on line %d.",
2050 for (value
+= valuelen
; *value
; value
++)
2051 if (!isspace(*value
) || *value
!= ',')
2055 else if (!strcasecmp(line
, "BrowseAllow") ||
2056 !strcasecmp(line
, "BrowseDeny"))
2059 * BrowseAllow [From] host/ip...
2060 * BrowseDeny [From] host/ip...
2063 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2064 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2066 if (location
== NULL
)
2067 cupsdLogMessage(CUPSD_LOG_ERROR
,
2068 "Unable to initialize browse access control list!");
2071 if (!strncasecmp(value
, "from ", 5))
2074 * Strip leading "from"...
2079 while (isspace(*value
))
2084 * Figure out what form the allow/deny address takes:
2095 * nnn.nnn.nnn.nnn/mm
2096 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2099 if (!strcasecmp(value
, "all"))
2105 if (!strcasecmp(line
, "BrowseAllow"))
2106 cupsdAllowIP(location
, zeros
, zeros
);
2108 cupsdDenyIP(location
, zeros
, zeros
);
2110 else if (!strcasecmp(value
, "none"))
2116 if (!strcasecmp(line
, "BrowseAllow"))
2117 cupsdAllowIP(location
, ones
, zeros
);
2119 cupsdDenyIP(location
, ones
, zeros
);
2121 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2124 * Host or domain name...
2127 if (value
[0] == '*')
2130 if (!strcasecmp(line
, "BrowseAllow"))
2131 cupsdAllowHost(location
, value
);
2133 cupsdDenyHost(location
, value
);
2138 * One of many IP address forms...
2141 if (!get_addr_and_mask(value
, ip
, mask
))
2143 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2148 if (!strcasecmp(line
, "BrowseAllow"))
2149 cupsdAllowIP(location
, ip
, mask
);
2151 cupsdDenyIP(location
, ip
, mask
);
2155 else if (!strcasecmp(line
, "BrowseRelay"))
2158 * BrowseRelay [from] source [to] destination
2162 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2164 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2168 cupsdLogMessage(CUPSD_LOG_ERROR
,
2169 "Unable to allocate BrowseRelay at line %d - %s.",
2170 linenum
, strerror(errno
));
2177 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2179 if (!strncasecmp(value
, "from ", 5))
2182 * Strip leading "from"...
2187 while (isspace(*value
))
2192 * Figure out what form the from address takes:
2201 * nnn.nnn.nnn.nnn/mm
2202 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2205 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2208 * Host or domain name...
2211 if (value
[0] == '*')
2214 strlcpy(temp
, value
, sizeof(temp
));
2215 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2218 relay
->from
.type
= AUTH_NAME
;
2219 relay
->from
.mask
.name
.name
= strdup(temp
);
2220 relay
->from
.mask
.name
.length
= strlen(temp
);
2225 * One of many IP address forms...
2228 if (!get_addr_and_mask(value
, ip
, mask
))
2230 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2235 relay
->from
.type
= AUTH_IP
;
2236 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2237 sizeof(relay
->from
.mask
.ip
.address
));
2238 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2239 sizeof(relay
->from
.mask
.ip
.netmask
));
2243 * Skip value and trailing whitespace...
2246 for (; *value
; value
++)
2247 if (isspace(*value
))
2250 while (isspace(*value
))
2253 if (!strncasecmp(value
, "to ", 3))
2256 * Strip leading "to"...
2261 while (isspace(*value
))
2266 * Get "to" address and port...
2269 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
2271 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2273 if (relay
->from
.type
== AUTH_IP
)
2274 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2275 relay
->from
.mask
.ip
.address
[0],
2276 relay
->from
.mask
.ip
.address
[1],
2277 relay
->from
.mask
.ip
.address
[2],
2278 relay
->from
.mask
.ip
.address
[3],
2279 relay
->from
.mask
.ip
.netmask
[0],
2280 relay
->from
.mask
.ip
.netmask
[1],
2281 relay
->from
.mask
.ip
.netmask
[2],
2282 relay
->from
.mask
.ip
.netmask
[3]);
2284 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2287 if (relay
->to
.addr
.sa_family
== AF_INET6
)
2288 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv6)",
2289 temp
, temp2
, ntohs(relay
->to
.ipv6
.sin6_port
));
2291 #endif /* AF_INET6 */
2292 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2293 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2299 if (relay
->from
.type
== AUTH_NAME
)
2300 free(relay
->from
.mask
.name
.name
);
2302 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2306 else if (!strcasecmp(line
, "BrowsePoll"))
2309 * BrowsePoll address[:port]
2313 poll
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2315 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2319 cupsdLogMessage(CUPSD_LOG_ERROR
,
2320 "Unable to allocate BrowsePoll at line %d - %s.",
2321 linenum
, strerror(errno
));
2329 * Get poll address and port...
2332 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
2335 memset(poll
, 0, sizeof(cupsd_dirsvc_poll_t
));
2337 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
2340 if (polladdr
.addr
.sa_family
== AF_INET6
)
2341 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
2343 #endif /* AF_INET6 */
2344 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
2346 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", poll
->hostname
,
2350 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad poll address %s at line %d.",
2353 else if (!strcasecmp(line
, "DefaultAuthType"))
2356 * DefaultAuthType {basic,digest,basicdigest}
2359 if (!strcasecmp(value
, "basic"))
2360 DefaultAuthType
= AUTH_BASIC
;
2361 else if (!strcasecmp(value
, "digest"))
2362 DefaultAuthType
= AUTH_DIGEST
;
2363 else if (!strcasecmp(value
, "basicdigest"))
2364 DefaultAuthType
= AUTH_BASICDIGEST
;
2367 cupsdLogMessage(CUPSD_LOG_WARN
,
2368 "Unknown default authorization type %s on line %d.",
2373 else if (!strcasecmp(line
, "User"))
2376 * User ID to run as...
2379 if (isdigit(value
[0]))
2383 struct passwd
*p
; /* Password information */
2386 p
= getpwnam(value
);
2391 cupsdLogMessage(CUPSD_LOG_ERROR
,
2392 "Unknown User \"%s\" on line %d, ignoring!",
2396 else if (!strcasecmp(line
, "Group"))
2399 * Group ID to run as...
2402 if (isdigit(value
[0]))
2403 Group
= atoi(value
);
2407 group
= getgrnam(value
);
2410 Group
= group
->gr_gid
;
2412 cupsdLogMessage(CUPSD_LOG_ERROR
,
2413 "Unknown Group \"%s\" on line %d, ignoring!",
2417 else if (!strcasecmp(line
, "SystemGroup"))
2420 * System (admin) group(s)...
2423 char *valueptr
, /* Pointer into value */
2424 quote
; /* Quote character */
2427 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2429 if (*value
== '\'' || *value
== '\"')
2432 * Scan quoted name...
2437 for (valueptr
= value
; *valueptr
; valueptr
++)
2438 if (*valueptr
== quote
)
2444 * Scan space or comma-delimited name...
2447 for (valueptr
= value
; *valueptr
; valueptr
++)
2448 if (isspace(*valueptr
) || *valueptr
== ',')
2455 group
= getgrnam(value
);
2458 cupsdSetString(SystemGroups
+ i
, value
);
2459 SystemGroupIDs
[i
] = group
->gr_gid
;
2464 cupsdLogMessage(CUPSD_LOG_ERROR
,
2465 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2472 while (*value
== ',' || isspace(*value
))
2477 NumSystemGroups
= i
;
2479 else if (!strcasecmp(line
, "HostNameLookups"))
2482 * Do hostname lookups?
2485 if (!strcasecmp(value
, "off"))
2486 HostNameLookups
= 0;
2487 else if (!strcasecmp(value
, "on"))
2488 HostNameLookups
= 1;
2489 else if (!strcasecmp(value
, "double"))
2490 HostNameLookups
= 2;
2492 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2495 else if (!strcasecmp(line
, "LogLevel"))
2498 * Amount of logging to do...
2501 if (!strcasecmp(value
, "debug2"))
2502 LogLevel
= CUPSD_LOG_DEBUG2
;
2503 else if (!strcasecmp(value
, "debug"))
2504 LogLevel
= CUPSD_LOG_DEBUG
;
2505 else if (!strcasecmp(value
, "info"))
2506 LogLevel
= CUPSD_LOG_INFO
;
2507 else if (!strcasecmp(value
, "notice"))
2508 LogLevel
= CUPSD_LOG_NOTICE
;
2509 else if (!strcasecmp(value
, "warn"))
2510 LogLevel
= CUPSD_LOG_WARN
;
2511 else if (!strcasecmp(value
, "error"))
2512 LogLevel
= CUPSD_LOG_ERROR
;
2513 else if (!strcasecmp(value
, "crit"))
2514 LogLevel
= CUPSD_LOG_CRIT
;
2515 else if (!strcasecmp(value
, "alert"))
2516 LogLevel
= CUPSD_LOG_ALERT
;
2517 else if (!strcasecmp(value
, "emerg"))
2518 LogLevel
= CUPSD_LOG_EMERG
;
2519 else if (!strcasecmp(value
, "none"))
2520 LogLevel
= CUPSD_LOG_NONE
;
2522 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2525 else if (!strcasecmp(line
, "PrintcapFormat"))
2528 * Format of printcap file?
2531 if (!strcasecmp(value
, "bsd"))
2532 PrintcapFormat
= PRINTCAP_BSD
;
2533 else if (!strcasecmp(value
, "solaris"))
2534 PrintcapFormat
= PRINTCAP_SOLARIS
;
2536 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2539 else if (!strcasecmp(line
, "ServerTokens"))
2542 * Set the string used for the Server header...
2545 struct utsname plat
; /* Platform info */
2550 if (!strcasecmp(value
, "ProductOnly"))
2551 cupsdSetString(&ServerHeader
, "CUPS");
2552 else if (!strcasecmp(value
, "Major"))
2553 cupsdSetString(&ServerHeader
, "CUPS/1");
2554 else if (!strcasecmp(value
, "Minor"))
2555 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2556 else if (!strcasecmp(value
, "Minimal"))
2557 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2558 else if (!strcasecmp(value
, "OS"))
2559 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2560 else if (!strcasecmp(value
, "Full"))
2561 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2563 else if (!strcasecmp(value
, "None"))
2564 cupsdClearString(&ServerHeader
);
2566 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2572 * Find a simple variable in the list...
2575 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2576 if (!strcasecmp(line
, var
->name
))
2582 * Unknown directive! Output an error message and continue...
2585 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2592 case CUPSD_VARTYPE_INTEGER
:
2595 char *units
; /* Units */
2598 n
= strtol(value
, &units
, 0);
2600 if (units
&& *units
)
2602 if (tolower(units
[0] & 255) == 'g')
2603 n
*= 1024 * 1024 * 1024;
2604 else if (tolower(units
[0] & 255) == 'm')
2606 else if (tolower(units
[0] & 255) == 'k')
2608 else if (tolower(units
[0] & 255) == 't')
2612 *((int *)var
->ptr
) = n
;
2616 case CUPSD_VARTYPE_BOOLEAN
:
2617 if (!strcasecmp(value
, "true") ||
2618 !strcasecmp(value
, "on") ||
2619 !strcasecmp(value
, "enabled") ||
2620 !strcasecmp(value
, "yes") ||
2622 *((int *)var
->ptr
) = TRUE
;
2623 else if (!strcasecmp(value
, "false") ||
2624 !strcasecmp(value
, "off") ||
2625 !strcasecmp(value
, "disabled") ||
2626 !strcasecmp(value
, "no") ||
2627 !strcasecmp(value
, "0"))
2628 *((int *)var
->ptr
) = FALSE
;
2630 cupsdLogMessage(CUPSD_LOG_ERROR
,
2631 "Unknown boolean value %s on line %d.",
2635 case CUPSD_VARTYPE_STRING
:
2636 cupsdSetString((char **)var
->ptr
, value
);
2647 * 'read_location()' - Read a <Location path> definition.
2650 static int /* O - New line number or 0 on error */
2651 read_location(cups_file_t
*fp
, /* I - Configuration file */
2652 char *location
, /* I - Location name/path */
2653 int linenum
) /* I - Current line number */
2655 cupsd_location_t
*loc
, /* New location */
2656 *parent
; /* Parent location */
2657 char line
[HTTP_MAX_BUFFER
],
2659 *value
, /* Value for directive */
2660 *valptr
; /* Pointer into value */
2663 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2666 parent
->limit
= AUTH_LIMIT_ALL
;
2669 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2672 * Decode the directive...
2675 if (!strcasecmp(line
, "</Location>"))
2677 else if (!strcasecmp(line
, "<Limit") ||
2678 !strcasecmp(line
, "<LimitExcept"))
2682 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2686 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2692 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2697 if (!strcmp(value
, "ALL"))
2698 loc
->limit
= AUTH_LIMIT_ALL
;
2699 else if (!strcmp(value
, "GET"))
2700 loc
->limit
|= AUTH_LIMIT_GET
;
2701 else if (!strcmp(value
, "HEAD"))
2702 loc
->limit
|= AUTH_LIMIT_HEAD
;
2703 else if (!strcmp(value
, "OPTIONS"))
2704 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2705 else if (!strcmp(value
, "POST"))
2706 loc
->limit
|= AUTH_LIMIT_POST
;
2707 else if (!strcmp(value
, "PUT"))
2708 loc
->limit
|= AUTH_LIMIT_PUT
;
2709 else if (!strcmp(value
, "TRACE"))
2710 loc
->limit
|= AUTH_LIMIT_TRACE
;
2712 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2715 for (value
= valptr
; isspace(*value
& 255); value
++);
2718 if (!strcasecmp(line
, "<LimitExcept"))
2719 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2721 parent
->limit
&= ~loc
->limit
;
2723 else if (!strcasecmp(line
, "</Limit>"))
2725 else if (!parse_aaa(loc
, line
, value
, linenum
))
2727 cupsdLogMessage(CUPSD_LOG_ERROR
,
2728 "Unknown Location directive %s on line %d.",
2734 cupsdLogMessage(CUPSD_LOG_ERROR
,
2735 "Unexpected end-of-file at line %d while reading location!",
2743 * 'read_policy()' - Read a <Policy name> definition.
2746 static int /* O - New line number or 0 on error */
2747 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2748 char *policy
, /* I - Location name/path */
2749 int linenum
) /* I - Current line number */
2751 int i
; /* Looping var */
2752 cupsd_policy_t
*pol
; /* Policy */
2753 cupsd_location_t
*op
; /* Policy operation */
2754 int num_ops
; /* Number of IPP operations */
2755 ipp_op_t ops
[100]; /* Operations */
2756 char line
[HTTP_MAX_BUFFER
],
2758 *value
, /* Value for directive */
2759 *valptr
; /* Pointer into value */
2763 * Create the policy...
2766 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2770 * Read from the file...
2776 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2779 * Decode the directive...
2782 if (!strcasecmp(line
, "</Policy>"))
2785 cupsdLogMessage(CUPSD_LOG_WARN
,
2786 "Missing </Limit> before </Policy> on line %d!",
2791 else if (!strcasecmp(line
, "<Limit") && !op
)
2795 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2800 * Scan for IPP operation names...
2807 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2812 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2814 if (!strcasecmp(value
, "All"))
2815 ops
[num_ops
] = IPP_ANY_OPERATION
;
2816 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2817 cupsdLogMessage(CUPSD_LOG_ERROR
,
2818 "Bad IPP operation name \"%s\" on line %d!",
2824 cupsdLogMessage(CUPSD_LOG_ERROR
,
2825 "Too many operations listed on line %d!",
2828 for (value
= valptr
; isspace(*value
& 255); value
++);
2832 * If none are specified, apply the policy to all operations...
2837 ops
[0] = IPP_ANY_OPERATION
;
2842 * Add a new policy for the first operation...
2845 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2847 else if (!strcasecmp(line
, "</Limit>") && op
)
2850 * Finish the current operation limit...
2856 * Copy the policy to the other operations...
2859 for (i
= 1; i
< num_ops
; i
++)
2860 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
2867 cupsdLogMessage(CUPSD_LOG_ERROR
,
2868 "Missing <Limit ops> directive before %s on line %d.",
2872 else if (!parse_aaa(op
, line
, value
, linenum
))
2875 cupsdLogMessage(CUPSD_LOG_ERROR
,
2876 "Unknown Policy Limit directive %s on line %d.",
2879 cupsdLogMessage(CUPSD_LOG_ERROR
,
2880 "Unknown Policy directive %s on line %d.",
2887 cupsdLogMessage(CUPSD_LOG_ERROR
,
2888 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2897 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2898 * required by SSLSetCertificate.
2900 * For now we assumes that there is exactly one SecIdentity in the
2901 * keychain - i.e. there is exactly one matching cert/private key pair.
2902 * In the future we will search a keychain for a SecIdentity matching a
2903 * specific criteria. We also skip the operation of adding additional
2904 * non-signing certs from the keychain to the CFArrayRef.
2906 * To create a self-signed certificate for testing use the certtool.
2907 * Executing the following as root will do it:
2909 * certtool c c v k=CUPS
2913 CDSAGetServerCerts(void)
2915 OSStatus err
; /* Error info */
2916 SecKeychainRef kcRef
; /* Keychain reference */
2917 SecIdentitySearchRef srchRef
; /* Search reference */
2918 SecIdentityRef identity
; /* Identity */
2919 CFArrayRef ca
; /* Certificate array */
2926 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2929 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot open keychain \"%s\", error %d.",
2930 ServerCertificate
, err
);
2934 * Search for "any" identity matching specified key use;
2935 * in this app, we expect there to be exactly one.
2938 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2941 cupsdLogMessage(CUPSD_LOG_ERROR
,
2942 "Cannot find signing key in keychain \"%s\", error %d",
2943 ServerCertificate
, err
);
2946 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2949 cupsdLogMessage(CUPSD_LOG_ERROR
,
2950 "Cannot find signing key in keychain \"%s\", error %d",
2951 ServerCertificate
, err
);
2954 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2955 cupsdLogMessage(CUPSD_LOG_ERROR
,
2956 "SecIdentitySearchCopyNext CFTypeID failure!");
2960 * Found one. Place it in a CFArray.
2961 * TBD: snag other (non-identity) certs from keychain and add them
2965 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2968 cupsdLogMessage(CUPSD_LOG_ERROR
, "CFArrayCreate error");
2971 /*CFRelease(identity);*/
2974 /*CFRelease(srchRef);*/
2977 /*CFRelease(kcRef);*/
2982 #endif /* HAVE_CDSASSL */