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.
37 * Include necessary headers...
43 #include <sys/utsname.h>
48 #endif /* HAVE_VSYSLOG */
52 * Possibly missing network definitions...
56 # define INADDR_NONE 0xffffffff
57 #endif /* !INADDR_NONE */
61 * Configuration variable structure...
66 CUPSD_VARTYPE_INTEGER
, /* Integer option */
67 CUPSD_VARTYPE_STRING
, /* String option */
68 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
73 char *name
; /* Name of variable */
74 void *ptr
; /* Pointer to variable */
75 cupsd_vartype_t type
; /* Type (int, string, address) */
83 static cupsd_var_t variables
[] =
85 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
86 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
87 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
88 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
89 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
90 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
91 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
92 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
93 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
94 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
95 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
96 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
97 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
98 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
99 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
100 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
101 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
102 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
103 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
104 { "FaxRetryLimit", &FaxRetryLimit
, CUPSD_VARTYPE_INTEGER
},
105 { "FaxRetryInterval", &FaxRetryInterval
, CUPSD_VARTYPE_INTEGER
},
106 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
107 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
108 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
109 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
110 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
111 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
112 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
113 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
114 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
115 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
116 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
117 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
118 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
119 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
120 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
121 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
123 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
124 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
127 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
128 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
129 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
130 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
131 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
132 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
133 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
134 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
135 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
136 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
137 { "RunAsUser", &RunAsUser
, CUPSD_VARTYPE_BOOLEAN
},
138 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
139 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
140 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
142 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
143 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
144 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
145 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
146 #endif /* HAVE_SSL */
147 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
148 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
149 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
150 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
151 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
}
153 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
156 static unsigned ones
[4] =
158 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
160 static unsigned zeros
[4] =
162 0x00000000, 0x00000000, 0x00000000, 0x00000000
170 static http_addrlist_t
*get_address(const char *value
, int defport
);
171 static int get_addr_and_mask(const char *value
, unsigned *ip
,
173 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
174 char *value
, int linenum
);
175 static int read_configuration(cups_file_t
*fp
);
176 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
177 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
181 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
184 int /* O - 1 on success, 0 otherwise */
185 cupsdReadConfiguration(void)
187 int i
; /* Looping var */
188 cups_file_t
*fp
; /* Configuration file */
189 int status
; /* Return status */
190 char temp
[1024], /* Temporary buffer */
191 *slash
; /* Directory separator */
192 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
194 cups_lang_t
*language
; /* Language */
195 struct passwd
*user
; /* Default user */
196 struct group
*group
; /* Default group */
197 char *old_serverroot
, /* Old ServerRoot */
198 *old_requestroot
; /* Old RequestRoot */
201 * Shutdown the server...
207 * Save the old root paths...
210 old_serverroot
= NULL
;
211 cupsdSetString(&old_serverroot
, ServerRoot
);
212 old_requestroot
= NULL
;
213 cupsdSetString(&old_requestroot
, RequestRoot
);
216 * Reset the server configuration data...
219 cupsdDeleteAllLocations();
237 for (i
= 0; i
< NumRelays
; i
++)
238 if (Relays
[i
].from
.type
== AUTH_NAME
)
239 free(Relays
[i
].from
.mask
.name
.name
);
246 if (NumListeners
> 0)
256 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
257 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
258 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
259 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
260 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
261 cupsdSetString(&DataDir
, CUPS_DATADIR
);
262 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
263 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
264 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
265 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
266 cupsdSetString(&Printcap
, "/etc/printcap");
267 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
268 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
269 cupsdSetString(&RemoteRoot
, "remroot");
270 cupsdSetString(&ServerHeader
, "CUPS/1.1");
271 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
273 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
274 if ((slash
= strrchr(temp
, '/')) != NULL
)
277 cupsdSetString(&ServerRoot
, temp
);
279 cupsdClearString(&Classification
);
280 ClassifyOverride
= 0;
284 cupsdSetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
286 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
287 cupsdSetString(&ServerKey
, "ssl/server.key");
288 # endif /* HAVE_CDSASSL */
289 #endif /* HAVE_SSL */
291 language
= cupsLangDefault();
293 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
294 cupsdSetString(&DefaultLanguage
, "en");
296 cupsdSetString(&DefaultLanguage
, language
->language
);
298 cupsdSetString(&DefaultCharset
, cupsEncodingName(language
->encoding
));
300 cupsdSetString(&RIPCache
, "8m");
302 if (getenv("TMPDIR") == NULL
)
303 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
305 cupsdSetString(&TempDir
, getenv("TMPDIR"));
308 * Find the default system group: "sys", "system", or "root"...
311 group
= getgrnam(CUPS_DEFAULT_GROUP
);
319 * Found the group, use it!
322 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
324 SystemGroupIDs
[0] = group
->gr_gid
;
329 * Find the group associated with GID 0...
336 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
338 cupsdSetString(&SystemGroups
[0], "unknown");
340 SystemGroupIDs
[0] = 0;
344 * Find the default user...
347 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
352 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
353 * complement number...)
362 * Find the default group (nobody)...
365 group
= getgrnam("nobody");
369 Group
= group
->gr_gid
;
373 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
374 * complement number...)
384 ConfigFilePerm
= 0640;
385 DefaultAuthType
= AUTH_BASIC
;
387 FaxRetryInterval
= 300;
392 HostNameLookups
= FALSE
;
393 ImplicitClasses
= TRUE
;
394 ImplicitAnyClasses
= FALSE
;
395 HideImplicitMembers
= TRUE
;
397 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
398 ListenBackLog
= SOMAXCONN
;
400 LogLevel
= CUPSD_LOG_ERROR
;
402 MaxClientsPerHost
= 0;
403 MaxLogSize
= 1024 * 1024;
404 MaxPrinterHistory
= 10;
407 RootCertDuration
= 300;
409 Timeout
= DEFAULT_TIMEOUT
;
411 BrowseInterval
= DEFAULT_INTERVAL
;
412 BrowsePort
= ippPort();
413 BrowseLocalProtocols
= BROWSE_CUPS
;
414 BrowseRemoteProtocols
= BROWSE_CUPS
;
415 BrowseShortNames
= TRUE
;
416 BrowseTimeout
= DEFAULT_TIMEOUT
;
419 cupsdClearString(&BrowseLocalOptions
);
420 cupsdClearString(&BrowseRemoteOptions
);
422 JobHistory
= DEFAULT_HISTORY
;
423 JobFiles
= DEFAULT_FILES
;
428 MaxJobsPerPrinter
= 0;
431 cupsdDeleteAllPolicies();
432 cupsdClearString(&DefaultPolicy
);
435 * Read the configuration file...
438 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
441 status
= read_configuration(fp
);
454 * Use the default system group if none was supplied in cupsd.conf...
457 if (NumSystemGroups
== 0)
461 * Get the access control list for browsing...
464 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
467 * Open the system log for cupsd if necessary...
471 if (!strcmp(AccessLog
, "syslog") ||
472 !strcmp(ErrorLog
, "syslog") ||
473 !strcmp(PageLog
, "syslog"))
474 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
475 #endif /* HAVE_VSYSLOG */
478 * Log the configuration file that was used...
481 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
485 * Validate the Group and SystemGroup settings - they cannot be the same,
486 * otherwise the CGI programs will be able to authenticate as root without
492 for (i
= 0; i
< NumSystemGroups
; i
++)
493 if (Group
== SystemGroupIDs
[i
])
496 if (i
< NumSystemGroups
)
499 * Log the error and reset the group to a safe value...
502 cupsdLogMessage(CUPSD_LOG_NOTICE
,
503 "Group and SystemGroup cannot use the same groups!");
504 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
506 group
= getgrnam("nobody");
510 Group
= group
->gr_gid
;
514 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
515 * complement number...)
524 * Check that we have at least one listen/port line; if not, report this
525 * as an error and exit!
528 if (NumListeners
== 0)
534 cupsdLogMessage(CUPSD_LOG_EMERG
,
535 "No valid Listen or Port lines were found in the configuration file!");
541 cupsdEndProcess(getpid(), 0);
545 * Set the default locale using the language and charset...
548 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
551 * Update all relative filenames to include the full path from ServerRoot...
554 if (DocumentRoot
[0] != '/')
555 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
557 if (RequestRoot
[0] != '/')
558 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
560 if (ServerBin
[0] != '/')
561 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
563 if (StateDir
[0] != '/')
564 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
566 if (CacheDir
[0] != '/')
567 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
570 if (ServerCertificate
[0] != '/')
571 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
573 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
574 chown(ServerCertificate
, RunUser
, Group
);
575 chmod(ServerCertificate
, ConfigFilePerm
);
577 if (ServerKey
[0] != '/')
578 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
580 chown(ServerKey
, RunUser
, Group
);
581 chmod(ServerKey
, ConfigFilePerm
);
582 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
583 #endif /* HAVE_SSL */
586 * Make sure that directories and config files are owned and
587 * writable by the user and group in the cupsd.conf file...
590 chown(CacheDir
, RunUser
, Group
);
591 chmod(CacheDir
, 0775);
593 snprintf(temp
, sizeof(temp
), "%s/ppd", CacheDir
);
596 chown(temp
, RunUser
, Group
);
599 chown(StateDir
, RunUser
, Group
);
600 chmod(StateDir
, 0775);
602 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
605 chown(temp
, User
, SystemGroupIDs
[0]);
611 chown(ServerRoot
, RunUser
, Group
);
612 chmod(ServerRoot
, 0755);
614 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
617 chown(temp
, RunUser
, Group
);
620 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
623 chown(temp
, RunUser
, Group
);
626 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
627 chown(temp
, RunUser
, Group
);
628 chmod(temp
, ConfigFilePerm
);
630 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
631 chown(temp
, RunUser
, Group
);
634 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
635 chown(temp
, RunUser
, Group
);
638 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
639 chown(temp
, User
, Group
);
643 * Make sure the request and temporary directories have the right
647 chown(RequestRoot
, RunUser
, Group
);
648 chmod(RequestRoot
, 0710);
650 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
654 * Update ownership and permissions if the CUPS temp directory
655 * is under the spool directory or does not exist...
658 if (access(TempDir
, 0))
659 mkdir(TempDir
, 01770);
661 chown(TempDir
, RunUser
, Group
);
662 chmod(TempDir
, 01770);
665 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
668 * Clean out the temporary directory...
671 cups_dir_t
*dir
; /* Temporary directory */
672 cups_dentry_t
*dent
; /* Directory entry */
673 char tempfile
[1024]; /* Temporary filename */
676 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
678 cupsdLogMessage(CUPSD_LOG_INFO
,
679 "Cleaning out old temporary files in \"%s\"...", TempDir
);
681 while ((dent
= cupsDirRead(dir
)) != NULL
)
683 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
685 if (unlink(tempfile
))
686 cupsdLogMessage(CUPSD_LOG_ERROR
,
687 "Unable to remove temporary file \"%s\" - %s",
688 tempfile
, strerror(errno
));
690 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
697 cupsdLogMessage(CUPSD_LOG_ERROR
,
698 "Unable to open temporary directory \"%s\" - %s",
699 TempDir
, strerror(errno
));
703 * Setup environment variables...
709 * Check the MaxClients setting, and then allocate memory for it...
712 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
715 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
718 MaxClients
= MaxFDs
/ 3;
721 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
723 cupsdLogMessage(CUPSD_LOG_ERROR
,
724 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
725 MaxClients
, strerror(errno
));
729 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
733 * Check the MaxActiveJobs setting; limit to 1/3 the available
734 * file descriptors, since we need a pipe for each job...
737 if (MaxActiveJobs
> (MaxFDs
/ 3))
738 MaxActiveJobs
= MaxFDs
/ 3;
740 if (Classification
&& strcasecmp(Classification
, "none") == 0)
741 cupsdClearString(&Classification
);
744 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
747 * Update the MaxClientsPerHost value, as needed...
750 if (MaxClientsPerHost
<= 0)
751 MaxClientsPerHost
= MaxClients
;
753 if (MaxClientsPerHost
> MaxClients
)
754 MaxClientsPerHost
= MaxClients
;
756 cupsdLogMessage(CUPSD_LOG_INFO
,
757 "Allowing up to %d client connections per host.",
761 * Update the default policy, as needed...
765 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
767 DefaultPolicyPtr
= NULL
;
769 if (!DefaultPolicyPtr
)
771 cupsd_policy_t
*p
; /* New policy */
772 cupsd_location_t
*po
; /* New policy operation */
776 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
779 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
780 cupsdLogMessage(CUPSD_LOG_INFO
,
781 "Using policy \"default\" as the default!");
784 cupsdLogMessage(CUPSD_LOG_INFO
,
785 "Creating CUPS default administrative policy:");
787 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
789 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
790 cupsdLogMessage(CUPSD_LOG_INFO
,
791 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
792 "Release-Job Restart-Job Purge-Jobs "
793 "Set-Job-Attributes Create-Job-Subscription "
794 "Renew-Subscription Cancel-Subscription "
795 "Get-Notifications Reprocess-Job Cancel-Current-Job "
796 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
797 "CUPS-Authenticate-Job>");
798 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
800 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
801 po
->order_type
= AUTH_ALLOW
;
802 po
->level
= AUTH_USER
;
804 cupsdAddName(po
, "@OWNER");
805 cupsdAddName(po
, "@SYSTEM");
806 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
808 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
809 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
810 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
811 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
812 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
813 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
814 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
815 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
816 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
817 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
818 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
819 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
820 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
821 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
822 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
823 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
824 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
826 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
828 cupsdLogMessage(CUPSD_LOG_INFO
,
829 "<Limit Pause-Printer Resume-Printer "
830 "Set-Printer-Attributes Enable-Printer "
831 "Disable-Printer Pause-Printer-After-Current-Job "
832 "Hold-New-Jobs Release-Held-New-Jobs "
833 "Deactivate-Printer Activate-Printer Restart-Printer "
834 "Shutdown-Printer Startup-Printer Promote-Job "
835 "Schedule-Job-After CUPS-Add-Printer "
836 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
837 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
838 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
839 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
841 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
842 po
->order_type
= AUTH_ALLOW
;
843 po
->type
= AUTH_BASIC
;
844 po
->level
= AUTH_USER
;
846 cupsdAddName(po
, "@SYSTEM");
847 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
849 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
850 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
851 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
852 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
853 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
854 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
855 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
856 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
857 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
858 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
859 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
860 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
861 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
862 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
863 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
864 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
865 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
866 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
867 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
868 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
869 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
871 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
873 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
874 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
876 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
877 po
->order_type
= AUTH_ALLOW
;
879 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
880 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
884 cupsdLogMessage(CUPSD_LOG_DEBUG
,"NumPolicies=%d", NumPolicies
);
885 for (i
= 0; i
< NumPolicies
; i
++)
886 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Policies[%d]=\"%s\"", i
,
890 * If we are doing a full reload or the server root has changed, flush
891 * the jobs, printers, etc. and start from scratch...
894 if (NeedReload
== RELOAD_ALL
||
895 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
896 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
898 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
905 cupsdDeleteAllClasses();
906 cupsdDeleteAllPrinters();
908 DefaultPrinter
= NULL
;
910 if (MimeDatabase
!= NULL
)
911 mimeDelete(MimeDatabase
);
915 for (i
= 0; i
< NumMimeTypes
; i
++)
916 free((void *)MimeTypes
[i
]);
922 * Read the MIME type and conversion database...
925 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
927 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
931 cupsdLogMessage(CUPSD_LOG_EMERG
,
932 "Unable to load MIME database from \'%s\'!", ServerRoot
);
936 cupsdLogMessage(CUPSD_LOG_INFO
,
937 "Loaded MIME database from \'%s\': %d types, %d filters...",
938 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
941 * Create a list of MIME types for the document-format-supported
945 NumMimeTypes
= MimeDatabase
->num_types
;
946 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
949 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
951 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
953 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
954 MimeDatabase
->types
[i
]->type
);
956 MimeTypes
[i
] = strdup(type
);
959 if (i
< NumMimeTypes
)
960 MimeTypes
[i
] = strdup("application/octet-stream");
966 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
967 cupsdLoadBanners(temp
);
970 * Load printers and classes...
973 cupsdLoadAllPrinters();
974 cupsdLoadAllClasses();
976 cupsdCreateCommonData();
979 * Load queued jobs...
984 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
989 * Not a full reload, so recreate the common printer attributes...
992 cupsdCreateCommonData();
995 * Update all printers as needed...
998 cupsdUpdatePrinters();
1000 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1004 * Reset the reload state...
1007 NeedReload
= RELOAD_NONE
;
1009 cupsdClearString(&old_serverroot
);
1010 cupsdClearString(&old_requestroot
);
1013 * Startup the server and return...
1023 * 'get_address()' - Get an address + port number from a line.
1026 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1027 get_address(const char *value
, /* I - Value string */
1028 int defport
) /* I - Default port */
1030 char buffer
[1024], /* Hostname + port number buffer */
1031 defpname
[255], /* Default port name */
1032 *hostname
, /* Hostname or IP */
1033 *portname
; /* Port number or name */
1034 http_addrlist_t
*addrlist
; /* Address list */
1038 * Check for an empty value...
1043 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1048 * Grab a hostname and port number; if there is no colon and the port name
1049 * is only digits, then we have a port number by itself...
1052 strlcpy(buffer
, value
, sizeof(buffer
));
1054 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1061 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1066 * Use the default port...
1069 sprintf(defpname
, "%d", defport
);
1070 portname
= defpname
;
1076 * The buffer contains just a port number...
1084 if (hostname
&& !strcmp(hostname
, "*"))
1088 * Now lookup the address using httpAddrGetList()...
1091 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1092 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1093 hostname
? hostname
: "(nil)");
1100 * 'get_addr_and_mask()' - Get an IP address and netmask.
1103 static int /* O - 1 on success, 0 on failure */
1104 get_addr_and_mask(const char *value
, /* I - String from config file */
1105 unsigned *ip
, /* O - Address value */
1106 unsigned *mask
) /* O - Mask value */
1108 int i
, j
, /* Looping vars */
1109 family
, /* Address family */
1110 ipcount
; /* Count of fields in address */
1111 unsigned ipval
; /* Value */
1112 const char *maskval
, /* Pointer to start of mask value */
1113 *ptr
, /* Pointer into value */
1115 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1117 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1118 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1119 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1120 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1123 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1125 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1126 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1127 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1128 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1129 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1130 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1131 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1132 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1134 #endif /* AF_INET6 */
1138 * Get the address...
1141 memset(ip
, 0, sizeof(unsigned) * 4);
1143 if ((maskval
= strchr(value
, '/')) != NULL
)
1146 maskval
= value
+ strlen(value
);
1150 * Check for an IPv6 address...
1156 * Parse hexadecimal IPv6 address...
1161 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1165 else if (!strncmp(ptr
, "::", 2))
1167 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1169 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1173 else if (isxdigit(*ptr
& 255))
1175 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1183 ip
[i
] |= ipval
<< 16;
1194 if (*ptr
&& *ptr
!= '/')
1198 #endif /* AF_INET6 */
1201 * Parse dotted-decimal IPv4 address...
1205 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1207 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1208 ip
[0] = ip
[1] = ip
[2] = 0;
1214 * Get the netmask value(s)...
1217 memset(mask
, 0, sizeof(unsigned) * 4);
1220 if (*maskval
== '[')
1223 * Get hexadecimal mask value...
1226 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1230 else if (!strncmp(ptr
, "::", 2))
1232 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1234 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1238 else if (isxdigit(*ptr
& 255))
1240 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1248 mask
[i
] |= ipval
<< 16;
1261 #endif /* AF_INET6 */
1262 if (strchr(maskval
, '.'))
1265 * Get dotted-decimal mask...
1268 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1271 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1272 mask
[0] = mask
[1] = mask
[2] = 0;
1277 * Get address/bits format...
1283 if (family
== AF_INET6
)
1288 mask
[0] = 0xffffffff;
1290 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1293 mask
[1] = 0xffffffff;
1297 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1300 mask
[2] = 0xffffffff;
1304 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1307 mask
[3] = 0xffffffff;
1311 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1314 #endif /* AF_INET6 */
1318 mask
[0] = 0xffffffff;
1319 mask
[1] = 0xffffffff;
1320 mask
[2] = 0xffffffff;
1323 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1325 mask
[3] = 0xffffffff;
1330 else if (family
== AF_INET6
)
1331 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1332 #endif /* AF_INET6 */
1334 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1336 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1337 "get_addr_and_mask(value=\"%s\", "
1338 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1339 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1343 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1346 if ((ip
[0] & ~mask
[0]) != 0 ||
1347 (ip
[1] & ~mask
[1]) != 0 ||
1348 (ip
[2] & ~mask
[2]) != 0 ||
1349 (ip
[3] & ~mask
[3]) != 0)
1357 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1360 static int /* O - 1 on success, 0 on failure */
1361 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1362 char *line
, /* I - Line from file */
1363 char *value
, /* I - Start of value data */
1364 int linenum
) /* I - Current line number */
1366 char *valptr
; /* Pointer into value */
1367 unsigned ip
[4], /* IP address components */
1368 mask
[4]; /* IP netmask components */
1371 if (!strcasecmp(line
, "Encryption"))
1374 * "Encryption xxx" - set required encryption level...
1377 if (!strcasecmp(value
, "never"))
1378 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1379 else if (!strcasecmp(value
, "always"))
1381 cupsdLogMessage(CUPSD_LOG_ERROR
,
1382 "Encryption value \"%s\" on line %d is invalid in this "
1383 "context. Using \"required\" instead.", value
, linenum
);
1385 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1387 else if (!strcasecmp(value
, "required"))
1388 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1389 else if (!strcasecmp(value
, "ifrequested"))
1390 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1393 cupsdLogMessage(CUPSD_LOG_ERROR
,
1394 "Unknown Encryption value %s on line %d.", value
, linenum
);
1398 else if (!strcasecmp(line
, "Order"))
1401 * "Order Deny,Allow" or "Order Allow,Deny"...
1404 if (!strncasecmp(value
, "deny", 4))
1405 loc
->order_type
= AUTH_ALLOW
;
1406 else if (!strncasecmp(value
, "allow", 5))
1407 loc
->order_type
= AUTH_DENY
;
1410 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1415 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1418 * Allow [From] host/ip...
1419 * Deny [From] host/ip...
1422 if (!strncasecmp(value
, "from", 4))
1425 * Strip leading "from"...
1430 while (isspace(*value
& 255))
1435 * Figure out what form the allow/deny address takes:
1446 * nnn.nnn.nnn.nnn/mm
1447 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1450 if (!strcasecmp(value
, "all"))
1456 if (!strcasecmp(line
, "Allow"))
1457 cupsdAllowIP(loc
, zeros
, zeros
);
1459 cupsdDenyIP(loc
, zeros
, zeros
);
1461 else if (!strcasecmp(value
, "none"))
1467 if (!strcasecmp(line
, "Allow"))
1468 cupsdAllowIP(loc
, ones
, zeros
);
1470 cupsdDenyIP(loc
, ones
, zeros
);
1472 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1475 * Host or domain name...
1478 if (value
[0] == '*')
1481 if (!strcasecmp(line
, "Allow"))
1482 cupsdAllowHost(loc
, value
);
1484 cupsdDenyHost(loc
, value
);
1489 * One of many IP address forms...
1492 if (!get_addr_and_mask(value
, ip
, mask
))
1494 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1499 if (!strcasecmp(line
, "Allow"))
1500 cupsdAllowIP(loc
, ip
, mask
);
1502 cupsdDenyIP(loc
, ip
, mask
);
1505 else if (!strcasecmp(line
, "AuthType"))
1508 * AuthType {none,basic,digest,basicdigest}
1511 if (!strcasecmp(value
, "none"))
1513 loc
->type
= AUTH_NONE
;
1514 loc
->level
= AUTH_ANON
;
1516 else if (!strcasecmp(value
, "basic"))
1518 loc
->type
= AUTH_BASIC
;
1520 if (loc
->level
== AUTH_ANON
)
1521 loc
->level
= AUTH_USER
;
1523 else if (!strcasecmp(value
, "digest"))
1525 loc
->type
= AUTH_DIGEST
;
1527 if (loc
->level
== AUTH_ANON
)
1528 loc
->level
= AUTH_USER
;
1530 else if (!strcasecmp(value
, "basicdigest"))
1532 loc
->type
= AUTH_BASICDIGEST
;
1534 if (loc
->level
== AUTH_ANON
)
1535 loc
->level
= AUTH_USER
;
1539 cupsdLogMessage(CUPSD_LOG_WARN
,
1540 "Unknown authorization type %s on line %d.",
1545 else if (!strcasecmp(line
, "AuthClass"))
1548 * AuthClass anonymous, user, system, group
1551 if (!strcasecmp(value
, "anonymous"))
1553 loc
->type
= AUTH_NONE
;
1554 loc
->level
= AUTH_ANON
;
1556 else if (!strcasecmp(value
, "user"))
1557 loc
->level
= AUTH_USER
;
1558 else if (!strcasecmp(value
, "group"))
1559 loc
->level
= AUTH_GROUP
;
1560 else if (!strcasecmp(value
, "system"))
1562 loc
->level
= AUTH_GROUP
;
1564 cupsdAddName(loc
, "@SYSTEM");
1568 cupsdLogMessage(CUPSD_LOG_WARN
,
1569 "Unknown authorization class %s on line %d.",
1574 else if (!strcasecmp(line
, "AuthGroupName"))
1575 cupsdAddName(loc
, value
);
1576 else if (!strcasecmp(line
, "Require"))
1579 * Apache synonym for AuthClass and AuthGroupName...
1583 * Require valid-user
1584 * Require group names
1585 * Require user names
1588 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1593 if (!strcasecmp(value
, "valid-user") ||
1594 !strcasecmp(value
, "user"))
1595 loc
->level
= AUTH_USER
;
1596 else if (!strcasecmp(value
, "group"))
1597 loc
->level
= AUTH_GROUP
;
1600 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1606 * Get the list of names from the line...
1609 for (value
= valptr
; *value
;)
1611 while (isspace(*value
& 255))
1614 if (*value
== '\"' || *value
== '\'')
1617 * Grab quoted name...
1620 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1627 * Grab literal name.
1630 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1636 cupsdAddName(loc
, value
);
1638 for (value
= valptr
; isspace(*value
& 255); value
++);
1641 else if (!strcasecmp(line
, "Satisfy"))
1643 if (!strcasecmp(value
, "all"))
1644 loc
->satisfy
= AUTH_SATISFY_ALL
;
1645 else if (!strcasecmp(value
, "any"))
1646 loc
->satisfy
= AUTH_SATISFY_ANY
;
1649 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1662 * 'read_configuration()' - Read a configuration file.
1665 static int /* O - 1 on success, 0 on failure */
1666 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1668 int i
; /* Looping var */
1669 int linenum
; /* Current line number */
1670 char line
[HTTP_MAX_BUFFER
],
1671 /* Line from file */
1672 temp
[HTTP_MAX_BUFFER
],
1673 /* Temporary buffer for value */
1674 temp2
[HTTP_MAX_BUFFER
],
1675 /* Temporary buffer 2 for value */
1676 *ptr
, /* Pointer into line/temp */
1677 *value
, /* Pointer to value */
1678 *valueptr
, /* Pointer into value */
1679 quote
; /* Quote character */
1680 int valuelen
; /* Length of value */
1681 cupsd_var_t
*var
; /* Current variable */
1682 http_addrlist_t
*addrlist
, /* Address list */
1683 *addr
; /* Current address */
1684 unsigned ip
[4], /* Address value */
1685 mask
[4]; /* Netmask value */
1686 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1687 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1688 cupsd_location_t
*location
; /* Browse location */
1689 cups_file_t
*incfile
; /* Include file */
1690 char incname
[1024]; /* Include filename */
1691 struct group
*group
; /* Group */
1695 * Loop through each line in the file...
1700 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1703 * Decode the directive...
1706 if (!strcasecmp(line
, "Include"))
1712 if (value
[0] == '/')
1713 strlcpy(incname
, value
, sizeof(incname
));
1715 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1717 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1718 cupsdLogMessage(CUPSD_LOG_ERROR
,
1719 "Unable to include config file \"%s\" - %s",
1720 incname
, strerror(errno
));
1723 read_configuration(incfile
);
1724 cupsFileClose(incfile
);
1727 else if (!strcasecmp(line
, "<Location"))
1735 linenum
= read_location(fp
, value
, linenum
);
1741 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1746 else if (!strcasecmp(line
, "<Policy"))
1754 linenum
= read_policy(fp
, value
, linenum
);
1760 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1764 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
1766 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
1767 #endif /* HAVE_SSL */
1771 * Add listening address(es) to the list...
1774 cupsd_listener_t
*lis
; /* New listeners array */
1778 * Get the address list...
1781 addrlist
= get_address(value
, IPP_PORT
);
1785 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1791 * Add each address...
1794 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1797 * Allocate another listener...
1800 if (NumListeners
== 0)
1801 lis
= malloc(sizeof(cupsd_listener_t
));
1803 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1807 cupsdLogMessage(CUPSD_LOG_ERROR
,
1808 "Unable to allocate %s at line %d - %s.",
1809 line
, linenum
, strerror(errno
));
1814 lis
+= NumListeners
;
1817 * Copy the current address and log it...
1820 memset(lis
, 0, sizeof(cupsd_listener_t
));
1821 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
1824 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1825 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1826 #endif /* HAVE_SSL */
1829 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1830 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1831 ntohs(lis
->address
.ipv6
.sin6_port
));
1833 #endif /* AF_INET6 */
1835 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1836 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
1838 #endif /* AF_LOCAL */
1839 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
1840 ntohs(lis
->address
.ipv4
.sin_port
));
1849 httpAddrFreeList(addrlist
);
1851 else if (!strcasecmp(line
, "BrowseAddress"))
1854 * Add a browse address to the list...
1857 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
1860 if (NumBrowsers
== 0)
1861 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
1863 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
1867 cupsdLogMessage(CUPSD_LOG_ERROR
,
1868 "Unable to allocate BrowseAddress at line %d - %s.",
1869 linenum
, strerror(errno
));
1874 dira
+= NumBrowsers
;
1876 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
1878 if (!strcasecmp(value
, "@LOCAL"))
1881 * Send browse data to all local interfaces...
1884 strcpy(dira
->iface
, "*");
1887 else if (!strncasecmp(value
, "@IF(", 4))
1890 * Send browse data to the named interface...
1893 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1895 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1901 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
1904 * Only IPv4 addresses are supported...
1907 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1908 if (addr
->addr
.addr
.sa_family
== AF_INET
)
1913 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
1914 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1916 cupsdLogMessage(CUPSD_LOG_INFO
,
1917 "Sending browsing info to %s:%d (IPv4)",
1918 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
1923 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
1926 httpAddrFreeList(addrlist
);
1929 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
1932 else if (!strcasecmp(line
, "BrowseOrder"))
1935 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1938 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1939 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
1941 if (location
== NULL
)
1942 cupsdLogMessage(CUPSD_LOG_ERROR
,
1943 "Unable to initialize browse access control list!");
1944 else if (!strncasecmp(value
, "deny", 4))
1945 location
->order_type
= AUTH_ALLOW
;
1946 else if (!strncasecmp(value
, "allow", 5))
1947 location
->order_type
= AUTH_DENY
;
1949 cupsdLogMessage(CUPSD_LOG_ERROR
,
1950 "Unknown BrowseOrder value %s on line %d.",
1953 else if (!strcasecmp(line
, "BrowseProtocols") ||
1954 !strcasecmp(line
, "BrowseLocalProtocols") ||
1955 !strcasecmp(line
, "BrowseRemoteProtocols"))
1958 * "BrowseProtocol name [... name]"
1961 if (strcasecmp(line
, "BrowseLocalProtocols"))
1962 BrowseRemoteProtocols
= 0;
1963 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1964 BrowseLocalProtocols
= 0;
1968 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1969 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1972 if (value
[valuelen
])
1974 value
[valuelen
] = '\0';
1978 if (!strcasecmp(value
, "cups"))
1980 if (strcasecmp(line
, "BrowseLocalProtocols"))
1981 BrowseRemoteProtocols
|= BROWSE_CUPS
;
1982 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1983 BrowseLocalProtocols
|= BROWSE_CUPS
;
1985 else if (!strcasecmp(value
, "slp"))
1987 if (strcasecmp(line
, "BrowseLocalProtocols"))
1988 BrowseRemoteProtocols
|= BROWSE_SLP
;
1989 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1990 BrowseLocalProtocols
|= BROWSE_SLP
;
1992 else if (!strcasecmp(value
, "ldap"))
1994 if (strcasecmp(line
, "BrowseLocalProtocols"))
1995 BrowseRemoteProtocols
|= BROWSE_LDAP
;
1996 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1997 BrowseLocalProtocols
|= BROWSE_LDAP
;
1999 else if (!strcasecmp(value
, "all"))
2001 if (strcasecmp(line
, "BrowseLocalProtocols"))
2002 BrowseRemoteProtocols
|= BROWSE_ALL
;
2003 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2004 BrowseLocalProtocols
|= BROWSE_ALL
;
2008 cupsdLogMessage(CUPSD_LOG_ERROR
,
2009 "Unknown browse protocol \"%s\" on line %d.",
2014 for (value
+= valuelen
; *value
; value
++)
2015 if (!isspace(*value
) || *value
!= ',')
2019 else if (!strcasecmp(line
, "BrowseAllow") ||
2020 !strcasecmp(line
, "BrowseDeny"))
2023 * BrowseAllow [From] host/ip...
2024 * BrowseDeny [From] host/ip...
2027 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2028 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2030 if (location
== NULL
)
2031 cupsdLogMessage(CUPSD_LOG_ERROR
,
2032 "Unable to initialize browse access control list!");
2035 if (!strncasecmp(value
, "from ", 5))
2038 * Strip leading "from"...
2043 while (isspace(*value
))
2048 * Figure out what form the allow/deny address takes:
2059 * nnn.nnn.nnn.nnn/mm
2060 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2063 if (!strcasecmp(value
, "all"))
2069 if (!strcasecmp(line
, "BrowseAllow"))
2070 cupsdAllowIP(location
, zeros
, zeros
);
2072 cupsdDenyIP(location
, zeros
, zeros
);
2074 else if (!strcasecmp(value
, "none"))
2080 if (!strcasecmp(line
, "BrowseAllow"))
2081 cupsdAllowIP(location
, ones
, zeros
);
2083 cupsdDenyIP(location
, ones
, zeros
);
2085 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2088 * Host or domain name...
2091 if (value
[0] == '*')
2094 if (!strcasecmp(line
, "BrowseAllow"))
2095 cupsdAllowHost(location
, value
);
2097 cupsdDenyHost(location
, value
);
2102 * One of many IP address forms...
2105 if (!get_addr_and_mask(value
, ip
, mask
))
2107 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2112 if (!strcasecmp(line
, "BrowseAllow"))
2113 cupsdAllowIP(location
, ip
, mask
);
2115 cupsdDenyIP(location
, ip
, mask
);
2119 else if (!strcasecmp(line
, "BrowseRelay"))
2122 * BrowseRelay [from] source [to] destination
2126 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2128 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2132 cupsdLogMessage(CUPSD_LOG_ERROR
,
2133 "Unable to allocate BrowseRelay at line %d - %s.",
2134 linenum
, strerror(errno
));
2141 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2143 if (!strncasecmp(value
, "from ", 5))
2146 * Strip leading "from"...
2151 while (isspace(*value
))
2156 * Figure out what form the from address takes:
2165 * nnn.nnn.nnn.nnn/mm
2166 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2169 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2172 * Host or domain name...
2175 if (value
[0] == '*')
2178 strlcpy(temp
, value
, sizeof(temp
));
2179 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2182 relay
->from
.type
= AUTH_NAME
;
2183 relay
->from
.mask
.name
.name
= strdup(temp
);
2184 relay
->from
.mask
.name
.length
= strlen(temp
);
2189 * One of many IP address forms...
2192 if (!get_addr_and_mask(value
, ip
, mask
))
2194 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2199 relay
->from
.type
= AUTH_IP
;
2200 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2201 sizeof(relay
->from
.mask
.ip
.address
));
2202 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2203 sizeof(relay
->from
.mask
.ip
.netmask
));
2207 * Skip value and trailing whitespace...
2210 for (; *value
; value
++)
2211 if (isspace(*value
))
2214 while (isspace(*value
))
2217 if (!strncasecmp(value
, "to ", 3))
2220 * Strip leading "to"...
2225 while (isspace(*value
))
2230 * Get "to" address and port...
2233 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2236 * Only IPv4 addresses are supported...
2239 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2240 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2245 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2247 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2249 if (relay
->from
.type
== AUTH_IP
)
2250 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2251 relay
->from
.mask
.ip
.address
[0],
2252 relay
->from
.mask
.ip
.address
[1],
2253 relay
->from
.mask
.ip
.address
[2],
2254 relay
->from
.mask
.ip
.address
[3],
2255 relay
->from
.mask
.ip
.netmask
[0],
2256 relay
->from
.mask
.ip
.netmask
[1],
2257 relay
->from
.mask
.ip
.netmask
[2],
2258 relay
->from
.mask
.ip
.netmask
[3]);
2260 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2262 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2263 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2268 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2271 httpAddrFreeList(addrlist
);
2275 if (relay
->from
.type
== AUTH_NAME
)
2276 free(relay
->from
.mask
.name
.name
);
2278 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2282 else if (!strcasecmp(line
, "BrowsePoll"))
2285 * BrowsePoll address[:port]
2288 char *portname
; /* Port name */
2289 int portnum
; /* Port number */
2290 struct servent
*service
; /* Service */
2294 * Extract the port name from the address...
2297 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2301 if (isdigit(*portname
& 255))
2302 portnum
= atoi(portname
);
2303 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2304 portnum
= ntohs(service
->s_port
);
2307 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2313 portnum
= ippPort();
2316 * Add the poll entry...
2320 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2322 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2326 cupsdLogMessage(CUPSD_LOG_ERROR
,
2327 "Unable to allocate BrowsePoll at line %d - %s.",
2328 linenum
, strerror(errno
));
2336 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2338 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2339 pollp
->port
= portnum
;
2341 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2344 else if (!strcasecmp(line
, "DefaultAuthType"))
2347 * DefaultAuthType {basic,digest,basicdigest}
2350 if (!strcasecmp(value
, "basic"))
2351 DefaultAuthType
= AUTH_BASIC
;
2352 else if (!strcasecmp(value
, "digest"))
2353 DefaultAuthType
= AUTH_DIGEST
;
2354 else if (!strcasecmp(value
, "basicdigest"))
2355 DefaultAuthType
= AUTH_BASICDIGEST
;
2358 cupsdLogMessage(CUPSD_LOG_WARN
,
2359 "Unknown default authorization type %s on line %d.",
2364 else if (!strcasecmp(line
, "User"))
2367 * User ID to run as...
2370 if (isdigit(value
[0]))
2374 struct passwd
*p
; /* Password information */
2377 p
= getpwnam(value
);
2382 cupsdLogMessage(CUPSD_LOG_ERROR
,
2383 "Unknown User \"%s\" on line %d, ignoring!",
2387 else if (!strcasecmp(line
, "Group"))
2390 * Group ID to run as...
2393 if (isdigit(value
[0]))
2394 Group
= atoi(value
);
2398 group
= getgrnam(value
);
2401 Group
= group
->gr_gid
;
2403 cupsdLogMessage(CUPSD_LOG_ERROR
,
2404 "Unknown Group \"%s\" on line %d, ignoring!",
2408 else if (!strcasecmp(line
, "SystemGroup"))
2411 * System (admin) group(s)...
2414 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2416 if (*value
== '\'' || *value
== '\"')
2419 * Scan quoted name...
2424 for (valueptr
= value
; *valueptr
; valueptr
++)
2425 if (*valueptr
== quote
)
2431 * Scan space or comma-delimited name...
2434 for (valueptr
= value
; *valueptr
; valueptr
++)
2435 if (isspace(*valueptr
) || *valueptr
== ',')
2442 group
= getgrnam(value
);
2445 cupsdSetString(SystemGroups
+ i
, value
);
2446 SystemGroupIDs
[i
] = group
->gr_gid
;
2451 cupsdLogMessage(CUPSD_LOG_ERROR
,
2452 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2459 while (*value
== ',' || isspace(*value
))
2464 NumSystemGroups
= i
;
2466 else if (!strcasecmp(line
, "HostNameLookups"))
2469 * Do hostname lookups?
2472 if (!strcasecmp(value
, "off"))
2473 HostNameLookups
= 0;
2474 else if (!strcasecmp(value
, "on"))
2475 HostNameLookups
= 1;
2476 else if (!strcasecmp(value
, "double"))
2477 HostNameLookups
= 2;
2479 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2482 else if (!strcasecmp(line
, "LogLevel"))
2485 * Amount of logging to do...
2488 if (!strcasecmp(value
, "debug2"))
2489 LogLevel
= CUPSD_LOG_DEBUG2
;
2490 else if (!strcasecmp(value
, "debug"))
2491 LogLevel
= CUPSD_LOG_DEBUG
;
2492 else if (!strcasecmp(value
, "info"))
2493 LogLevel
= CUPSD_LOG_INFO
;
2494 else if (!strcasecmp(value
, "notice"))
2495 LogLevel
= CUPSD_LOG_NOTICE
;
2496 else if (!strcasecmp(value
, "warn"))
2497 LogLevel
= CUPSD_LOG_WARN
;
2498 else if (!strcasecmp(value
, "error"))
2499 LogLevel
= CUPSD_LOG_ERROR
;
2500 else if (!strcasecmp(value
, "crit"))
2501 LogLevel
= CUPSD_LOG_CRIT
;
2502 else if (!strcasecmp(value
, "alert"))
2503 LogLevel
= CUPSD_LOG_ALERT
;
2504 else if (!strcasecmp(value
, "emerg"))
2505 LogLevel
= CUPSD_LOG_EMERG
;
2506 else if (!strcasecmp(value
, "none"))
2507 LogLevel
= CUPSD_LOG_NONE
;
2509 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2512 else if (!strcasecmp(line
, "PrintcapFormat"))
2515 * Format of printcap file?
2518 if (!strcasecmp(value
, "bsd"))
2519 PrintcapFormat
= PRINTCAP_BSD
;
2520 else if (!strcasecmp(value
, "solaris"))
2521 PrintcapFormat
= PRINTCAP_SOLARIS
;
2523 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2526 else if (!strcasecmp(line
, "ServerTokens"))
2529 * Set the string used for the Server header...
2532 struct utsname plat
; /* Platform info */
2537 if (!strcasecmp(value
, "ProductOnly"))
2538 cupsdSetString(&ServerHeader
, "CUPS");
2539 else if (!strcasecmp(value
, "Major"))
2540 cupsdSetString(&ServerHeader
, "CUPS/1");
2541 else if (!strcasecmp(value
, "Minor"))
2542 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2543 else if (!strcasecmp(value
, "Minimal"))
2544 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2545 else if (!strcasecmp(value
, "OS"))
2546 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2547 else if (!strcasecmp(value
, "Full"))
2548 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2550 else if (!strcasecmp(value
, "None"))
2551 cupsdClearString(&ServerHeader
);
2553 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2556 else if (!strcasecmp(line
, "PassEnv"))
2559 * PassEnv variable [... variable]
2564 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2565 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2568 if (value
[valuelen
])
2570 value
[valuelen
] = '\0';
2574 cupsdSetEnv(value
, NULL
);
2576 for (value
+= valuelen
; *value
; value
++)
2577 if (!isspace(*value
) || *value
!= ',')
2581 else if (!strcasecmp(line
, "SetEnv"))
2584 * SetEnv variable value
2587 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2595 while (isspace(*valueptr
& 255))
2598 cupsdSetEnv(value
, valueptr
);
2601 cupsdLogMessage(CUPSD_LOG_ERROR
,
2602 "Missing value for SetEnv directive on line %d.",
2608 * Find a simple variable in the list...
2611 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2612 if (!strcasecmp(line
, var
->name
))
2618 * Unknown directive! Output an error message and continue...
2621 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2628 case CUPSD_VARTYPE_INTEGER
:
2631 char *units
; /* Units */
2634 n
= strtol(value
, &units
, 0);
2636 if (units
&& *units
)
2638 if (tolower(units
[0] & 255) == 'g')
2639 n
*= 1024 * 1024 * 1024;
2640 else if (tolower(units
[0] & 255) == 'm')
2642 else if (tolower(units
[0] & 255) == 'k')
2644 else if (tolower(units
[0] & 255) == 't')
2648 *((int *)var
->ptr
) = n
;
2652 case CUPSD_VARTYPE_BOOLEAN
:
2653 if (!strcasecmp(value
, "true") ||
2654 !strcasecmp(value
, "on") ||
2655 !strcasecmp(value
, "enabled") ||
2656 !strcasecmp(value
, "yes") ||
2658 *((int *)var
->ptr
) = TRUE
;
2659 else if (!strcasecmp(value
, "false") ||
2660 !strcasecmp(value
, "off") ||
2661 !strcasecmp(value
, "disabled") ||
2662 !strcasecmp(value
, "no") ||
2663 !strcasecmp(value
, "0"))
2664 *((int *)var
->ptr
) = FALSE
;
2666 cupsdLogMessage(CUPSD_LOG_ERROR
,
2667 "Unknown boolean value %s on line %d.",
2671 case CUPSD_VARTYPE_STRING
:
2672 cupsdSetString((char **)var
->ptr
, value
);
2683 * 'read_location()' - Read a <Location path> definition.
2686 static int /* O - New line number or 0 on error */
2687 read_location(cups_file_t
*fp
, /* I - Configuration file */
2688 char *location
, /* I - Location name/path */
2689 int linenum
) /* I - Current line number */
2691 cupsd_location_t
*loc
, /* New location */
2692 *parent
; /* Parent location */
2693 char line
[HTTP_MAX_BUFFER
],
2695 *value
, /* Value for directive */
2696 *valptr
; /* Pointer into value */
2699 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2702 parent
->limit
= AUTH_LIMIT_ALL
;
2705 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2708 * Decode the directive...
2711 if (!strcasecmp(line
, "</Location>"))
2713 else if (!strcasecmp(line
, "<Limit") ||
2714 !strcasecmp(line
, "<LimitExcept"))
2718 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2722 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2728 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2733 if (!strcmp(value
, "ALL"))
2734 loc
->limit
= AUTH_LIMIT_ALL
;
2735 else if (!strcmp(value
, "GET"))
2736 loc
->limit
|= AUTH_LIMIT_GET
;
2737 else if (!strcmp(value
, "HEAD"))
2738 loc
->limit
|= AUTH_LIMIT_HEAD
;
2739 else if (!strcmp(value
, "OPTIONS"))
2740 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2741 else if (!strcmp(value
, "POST"))
2742 loc
->limit
|= AUTH_LIMIT_POST
;
2743 else if (!strcmp(value
, "PUT"))
2744 loc
->limit
|= AUTH_LIMIT_PUT
;
2745 else if (!strcmp(value
, "TRACE"))
2746 loc
->limit
|= AUTH_LIMIT_TRACE
;
2748 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2751 for (value
= valptr
; isspace(*value
& 255); value
++);
2754 if (!strcasecmp(line
, "<LimitExcept"))
2755 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2757 parent
->limit
&= ~loc
->limit
;
2759 else if (!strcasecmp(line
, "</Limit>"))
2761 else if (!parse_aaa(loc
, line
, value
, linenum
))
2763 cupsdLogMessage(CUPSD_LOG_ERROR
,
2764 "Unknown Location directive %s on line %d.",
2770 cupsdLogMessage(CUPSD_LOG_ERROR
,
2771 "Unexpected end-of-file at line %d while reading location!",
2779 * 'read_policy()' - Read a <Policy name> definition.
2782 static int /* O - New line number or 0 on error */
2783 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2784 char *policy
, /* I - Location name/path */
2785 int linenum
) /* I - Current line number */
2787 int i
; /* Looping var */
2788 cupsd_policy_t
*pol
; /* Policy */
2789 cupsd_location_t
*op
; /* Policy operation */
2790 int num_ops
; /* Number of IPP operations */
2791 ipp_op_t ops
[100]; /* Operations */
2792 char line
[HTTP_MAX_BUFFER
],
2794 *value
, /* Value for directive */
2795 *valptr
; /* Pointer into value */
2799 * Create the policy...
2802 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2806 * Read from the file...
2812 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2815 * Decode the directive...
2818 if (!strcasecmp(line
, "</Policy>"))
2821 cupsdLogMessage(CUPSD_LOG_WARN
,
2822 "Missing </Limit> before </Policy> on line %d!",
2827 else if (!strcasecmp(line
, "<Limit") && !op
)
2831 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2836 * Scan for IPP operation names...
2843 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2848 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2850 if (!strcasecmp(value
, "All"))
2851 ops
[num_ops
] = IPP_ANY_OPERATION
;
2852 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2853 cupsdLogMessage(CUPSD_LOG_ERROR
,
2854 "Bad IPP operation name \"%s\" on line %d!",
2860 cupsdLogMessage(CUPSD_LOG_ERROR
,
2861 "Too many operations listed on line %d!",
2864 for (value
= valptr
; isspace(*value
& 255); value
++);
2868 * If none are specified, apply the policy to all operations...
2873 ops
[0] = IPP_ANY_OPERATION
;
2878 * Add a new policy for the first operation...
2881 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2883 else if (!strcasecmp(line
, "</Limit>") && op
)
2886 * Finish the current operation limit...
2892 * Copy the policy to the other operations...
2895 for (i
= 1; i
< num_ops
; i
++)
2896 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
2903 cupsdLogMessage(CUPSD_LOG_ERROR
,
2904 "Missing <Limit ops> directive before %s on line %d.",
2908 else if (!parse_aaa(op
, line
, value
, linenum
))
2911 cupsdLogMessage(CUPSD_LOG_ERROR
,
2912 "Unknown Policy Limit directive %s on line %d.",
2915 cupsdLogMessage(CUPSD_LOG_ERROR
,
2916 "Unknown Policy directive %s on line %d.",
2923 cupsdLogMessage(CUPSD_LOG_ERROR
,
2924 "Unexpected end-of-file at line %d while reading policy \"%s\"!",