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 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
105 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
106 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
107 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
108 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
109 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
110 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
111 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
112 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
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 JobRetryInterval
= 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 (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
575 chown(ServerCertificate
, RunUser
, Group
);
576 chmod(ServerCertificate
, ConfigFilePerm
);
579 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
580 if (ServerKey
[0] != '/')
581 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
583 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
585 chown(ServerKey
, RunUser
, Group
);
586 chmod(ServerKey
, ConfigFilePerm
);
588 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
589 #endif /* HAVE_SSL */
592 * Make sure that directories and config files are owned and
593 * writable by the user and group in the cupsd.conf file...
596 chown(CacheDir
, RunUser
, Group
);
597 chmod(CacheDir
, 0775);
599 snprintf(temp
, sizeof(temp
), "%s/ppd", CacheDir
);
602 chown(temp
, RunUser
, Group
);
605 chown(StateDir
, RunUser
, Group
);
606 chmod(StateDir
, 0775);
608 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
611 chown(temp
, User
, SystemGroupIDs
[0]);
617 chown(ServerRoot
, RunUser
, Group
);
618 chmod(ServerRoot
, 0755);
620 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
623 chown(temp
, RunUser
, Group
);
626 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
629 chown(temp
, RunUser
, Group
);
632 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
633 chown(temp
, RunUser
, Group
);
634 chmod(temp
, ConfigFilePerm
);
636 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
637 chown(temp
, RunUser
, Group
);
640 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
641 chown(temp
, RunUser
, Group
);
644 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
645 chown(temp
, User
, Group
);
649 * Make sure the request and temporary directories have the right
653 chown(RequestRoot
, RunUser
, Group
);
654 chmod(RequestRoot
, 0710);
656 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
660 * Update ownership and permissions if the CUPS temp directory
661 * is under the spool directory or does not exist...
664 if (access(TempDir
, 0))
665 mkdir(TempDir
, 01770);
667 chown(TempDir
, RunUser
, Group
);
668 chmod(TempDir
, 01770);
671 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
674 * Clean out the temporary directory...
677 cups_dir_t
*dir
; /* Temporary directory */
678 cups_dentry_t
*dent
; /* Directory entry */
679 char tempfile
[1024]; /* Temporary filename */
682 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
684 cupsdLogMessage(CUPSD_LOG_INFO
,
685 "Cleaning out old temporary files in \"%s\"...", TempDir
);
687 while ((dent
= cupsDirRead(dir
)) != NULL
)
689 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
691 if (unlink(tempfile
))
692 cupsdLogMessage(CUPSD_LOG_ERROR
,
693 "Unable to remove temporary file \"%s\" - %s",
694 tempfile
, strerror(errno
));
696 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
703 cupsdLogMessage(CUPSD_LOG_ERROR
,
704 "Unable to open temporary directory \"%s\" - %s",
705 TempDir
, strerror(errno
));
709 * Setup environment variables...
715 * Check the MaxClients setting, and then allocate memory for it...
718 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
721 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
724 MaxClients
= MaxFDs
/ 3;
727 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
729 cupsdLogMessage(CUPSD_LOG_ERROR
,
730 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
731 MaxClients
, strerror(errno
));
735 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
739 * Check the MaxActiveJobs setting; limit to 1/3 the available
740 * file descriptors, since we need a pipe for each job...
743 if (MaxActiveJobs
> (MaxFDs
/ 3))
744 MaxActiveJobs
= MaxFDs
/ 3;
746 if (Classification
&& strcasecmp(Classification
, "none") == 0)
747 cupsdClearString(&Classification
);
750 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
753 * Update the MaxClientsPerHost value, as needed...
756 if (MaxClientsPerHost
<= 0)
757 MaxClientsPerHost
= MaxClients
;
759 if (MaxClientsPerHost
> MaxClients
)
760 MaxClientsPerHost
= MaxClients
;
762 cupsdLogMessage(CUPSD_LOG_INFO
,
763 "Allowing up to %d client connections per host.",
767 * Update the default policy, as needed...
771 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
773 DefaultPolicyPtr
= NULL
;
775 if (!DefaultPolicyPtr
)
777 cupsd_policy_t
*p
; /* New policy */
778 cupsd_location_t
*po
; /* New policy operation */
782 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
785 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
786 cupsdLogMessage(CUPSD_LOG_INFO
,
787 "Using policy \"default\" as the default!");
790 cupsdLogMessage(CUPSD_LOG_INFO
,
791 "Creating CUPS default administrative policy:");
793 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
795 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
796 cupsdLogMessage(CUPSD_LOG_INFO
,
797 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
798 "Release-Job Restart-Job Purge-Jobs "
799 "Set-Job-Attributes Create-Job-Subscription "
800 "Renew-Subscription Cancel-Subscription "
801 "Get-Notifications Reprocess-Job Cancel-Current-Job "
802 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
803 "CUPS-Authenticate-Job>");
804 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
806 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
807 po
->order_type
= AUTH_ALLOW
;
808 po
->level
= AUTH_USER
;
810 cupsdAddName(po
, "@OWNER");
811 cupsdAddName(po
, "@SYSTEM");
812 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
814 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
815 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
816 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
817 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
818 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
819 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
820 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
821 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
822 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
823 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
824 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
825 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
826 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
827 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
828 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
829 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
830 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
832 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
834 cupsdLogMessage(CUPSD_LOG_INFO
,
835 "<Limit Pause-Printer Resume-Printer "
836 "Set-Printer-Attributes Enable-Printer "
837 "Disable-Printer Pause-Printer-After-Current-Job "
838 "Hold-New-Jobs Release-Held-New-Jobs "
839 "Deactivate-Printer Activate-Printer Restart-Printer "
840 "Shutdown-Printer Startup-Printer Promote-Job "
841 "Schedule-Job-After CUPS-Add-Printer "
842 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
843 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
844 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
845 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
847 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
848 po
->order_type
= AUTH_ALLOW
;
849 po
->type
= AUTH_BASIC
;
850 po
->level
= AUTH_USER
;
852 cupsdAddName(po
, "@SYSTEM");
853 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
855 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
856 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
857 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
858 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
859 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
860 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
861 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
862 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
863 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
864 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
865 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
866 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
867 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
868 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
869 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
870 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
871 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
872 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
873 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
874 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
875 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
877 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
879 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
880 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
882 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
883 po
->order_type
= AUTH_ALLOW
;
885 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
886 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
890 cupsdLogMessage(CUPSD_LOG_DEBUG
,"NumPolicies=%d", NumPolicies
);
891 for (i
= 0; i
< NumPolicies
; i
++)
892 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Policies[%d]=\"%s\"", i
,
896 * If we are doing a full reload or the server root has changed, flush
897 * the jobs, printers, etc. and start from scratch...
900 if (NeedReload
== RELOAD_ALL
||
901 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
902 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
904 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
911 cupsdDeleteAllClasses();
912 cupsdDeleteAllPrinters();
914 DefaultPrinter
= NULL
;
916 if (MimeDatabase
!= NULL
)
917 mimeDelete(MimeDatabase
);
921 for (i
= 0; i
< NumMimeTypes
; i
++)
922 free((void *)MimeTypes
[i
]);
928 * Read the MIME type and conversion database...
931 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
933 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
937 cupsdLogMessage(CUPSD_LOG_EMERG
,
938 "Unable to load MIME database from \'%s\'!", ServerRoot
);
942 cupsdLogMessage(CUPSD_LOG_INFO
,
943 "Loaded MIME database from \'%s\': %d types, %d filters...",
944 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
947 * Create a list of MIME types for the document-format-supported
951 NumMimeTypes
= MimeDatabase
->num_types
;
952 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
955 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
957 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
959 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
960 MimeDatabase
->types
[i
]->type
);
962 MimeTypes
[i
] = strdup(type
);
965 if (i
< NumMimeTypes
)
966 MimeTypes
[i
] = strdup("application/octet-stream");
972 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
973 cupsdLoadBanners(temp
);
976 * Load printers and classes...
979 cupsdLoadAllPrinters();
980 cupsdLoadAllClasses();
982 cupsdCreateCommonData();
985 * Load queued jobs...
990 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
995 * Not a full reload, so recreate the common printer attributes...
998 cupsdCreateCommonData();
1001 * Update all printers as needed...
1004 cupsdUpdatePrinters();
1006 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1010 * Reset the reload state...
1013 NeedReload
= RELOAD_NONE
;
1015 cupsdClearString(&old_serverroot
);
1016 cupsdClearString(&old_requestroot
);
1019 * Startup the server and return...
1029 * 'get_address()' - Get an address + port number from a line.
1032 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1033 get_address(const char *value
, /* I - Value string */
1034 int defport
) /* I - Default port */
1036 char buffer
[1024], /* Hostname + port number buffer */
1037 defpname
[255], /* Default port name */
1038 *hostname
, /* Hostname or IP */
1039 *portname
; /* Port number or name */
1040 http_addrlist_t
*addrlist
; /* Address list */
1044 * Check for an empty value...
1049 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1054 * Grab a hostname and port number; if there is no colon and the port name
1055 * is only digits, then we have a port number by itself...
1058 strlcpy(buffer
, value
, sizeof(buffer
));
1060 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1067 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1072 * Use the default port...
1075 sprintf(defpname
, "%d", defport
);
1076 portname
= defpname
;
1082 * The buffer contains just a port number...
1090 if (hostname
&& !strcmp(hostname
, "*"))
1094 * Now lookup the address using httpAddrGetList()...
1097 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1098 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1099 hostname
? hostname
: "(nil)");
1106 * 'get_addr_and_mask()' - Get an IP address and netmask.
1109 static int /* O - 1 on success, 0 on failure */
1110 get_addr_and_mask(const char *value
, /* I - String from config file */
1111 unsigned *ip
, /* O - Address value */
1112 unsigned *mask
) /* O - Mask value */
1114 int i
, j
, /* Looping vars */
1115 family
, /* Address family */
1116 ipcount
; /* Count of fields in address */
1117 unsigned ipval
; /* Value */
1118 const char *maskval
, /* Pointer to start of mask value */
1119 *ptr
, /* Pointer into value */
1121 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1123 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1124 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1125 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1126 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1129 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1131 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1132 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1133 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1134 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1135 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1136 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1137 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1138 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1140 #endif /* AF_INET6 */
1144 * Get the address...
1147 memset(ip
, 0, sizeof(unsigned) * 4);
1149 if ((maskval
= strchr(value
, '/')) != NULL
)
1152 maskval
= value
+ strlen(value
);
1156 * Check for an IPv6 address...
1162 * Parse hexadecimal IPv6 address...
1167 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1171 else if (!strncmp(ptr
, "::", 2))
1173 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1175 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1179 else if (isxdigit(*ptr
& 255))
1181 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1189 ip
[i
] |= ipval
<< 16;
1200 if (*ptr
&& *ptr
!= '/')
1204 #endif /* AF_INET6 */
1207 * Parse dotted-decimal IPv4 address...
1211 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1213 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1214 ip
[0] = ip
[1] = ip
[2] = 0;
1220 * Get the netmask value(s)...
1223 memset(mask
, 0, sizeof(unsigned) * 4);
1226 if (*maskval
== '[')
1229 * Get hexadecimal mask value...
1232 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1236 else if (!strncmp(ptr
, "::", 2))
1238 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1240 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1244 else if (isxdigit(*ptr
& 255))
1246 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1254 mask
[i
] |= ipval
<< 16;
1267 #endif /* AF_INET6 */
1268 if (strchr(maskval
, '.'))
1271 * Get dotted-decimal mask...
1274 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1277 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1278 mask
[0] = mask
[1] = mask
[2] = 0;
1283 * Get address/bits format...
1289 if (family
== AF_INET6
)
1294 mask
[0] = 0xffffffff;
1296 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1299 mask
[1] = 0xffffffff;
1303 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1306 mask
[2] = 0xffffffff;
1310 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1313 mask
[3] = 0xffffffff;
1317 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1320 #endif /* AF_INET6 */
1324 mask
[0] = 0xffffffff;
1325 mask
[1] = 0xffffffff;
1326 mask
[2] = 0xffffffff;
1329 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1331 mask
[3] = 0xffffffff;
1336 else if (family
== AF_INET6
)
1337 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1338 #endif /* AF_INET6 */
1340 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1342 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1343 "get_addr_and_mask(value=\"%s\", "
1344 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1345 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1349 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1352 if ((ip
[0] & ~mask
[0]) != 0 ||
1353 (ip
[1] & ~mask
[1]) != 0 ||
1354 (ip
[2] & ~mask
[2]) != 0 ||
1355 (ip
[3] & ~mask
[3]) != 0)
1363 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1366 static int /* O - 1 on success, 0 on failure */
1367 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1368 char *line
, /* I - Line from file */
1369 char *value
, /* I - Start of value data */
1370 int linenum
) /* I - Current line number */
1372 char *valptr
; /* Pointer into value */
1373 unsigned ip
[4], /* IP address components */
1374 mask
[4]; /* IP netmask components */
1377 if (!strcasecmp(line
, "Encryption"))
1380 * "Encryption xxx" - set required encryption level...
1383 if (!strcasecmp(value
, "never"))
1384 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1385 else if (!strcasecmp(value
, "always"))
1387 cupsdLogMessage(CUPSD_LOG_ERROR
,
1388 "Encryption value \"%s\" on line %d is invalid in this "
1389 "context. Using \"required\" instead.", value
, linenum
);
1391 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1393 else if (!strcasecmp(value
, "required"))
1394 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1395 else if (!strcasecmp(value
, "ifrequested"))
1396 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1399 cupsdLogMessage(CUPSD_LOG_ERROR
,
1400 "Unknown Encryption value %s on line %d.", value
, linenum
);
1404 else if (!strcasecmp(line
, "Order"))
1407 * "Order Deny,Allow" or "Order Allow,Deny"...
1410 if (!strncasecmp(value
, "deny", 4))
1411 loc
->order_type
= AUTH_ALLOW
;
1412 else if (!strncasecmp(value
, "allow", 5))
1413 loc
->order_type
= AUTH_DENY
;
1416 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1421 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1424 * Allow [From] host/ip...
1425 * Deny [From] host/ip...
1428 if (!strncasecmp(value
, "from", 4))
1431 * Strip leading "from"...
1436 while (isspace(*value
& 255))
1441 * Figure out what form the allow/deny address takes:
1452 * nnn.nnn.nnn.nnn/mm
1453 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1456 if (!strcasecmp(value
, "all"))
1462 if (!strcasecmp(line
, "Allow"))
1463 cupsdAllowIP(loc
, zeros
, zeros
);
1465 cupsdDenyIP(loc
, zeros
, zeros
);
1467 else if (!strcasecmp(value
, "none"))
1473 if (!strcasecmp(line
, "Allow"))
1474 cupsdAllowIP(loc
, ones
, zeros
);
1476 cupsdDenyIP(loc
, ones
, zeros
);
1478 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1481 * Host or domain name...
1484 if (value
[0] == '*')
1487 if (!strcasecmp(line
, "Allow"))
1488 cupsdAllowHost(loc
, value
);
1490 cupsdDenyHost(loc
, value
);
1495 * One of many IP address forms...
1498 if (!get_addr_and_mask(value
, ip
, mask
))
1500 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1505 if (!strcasecmp(line
, "Allow"))
1506 cupsdAllowIP(loc
, ip
, mask
);
1508 cupsdDenyIP(loc
, ip
, mask
);
1511 else if (!strcasecmp(line
, "AuthType"))
1514 * AuthType {none,basic,digest,basicdigest}
1517 if (!strcasecmp(value
, "none"))
1519 loc
->type
= AUTH_NONE
;
1520 loc
->level
= AUTH_ANON
;
1522 else if (!strcasecmp(value
, "basic"))
1524 loc
->type
= AUTH_BASIC
;
1526 if (loc
->level
== AUTH_ANON
)
1527 loc
->level
= AUTH_USER
;
1529 else if (!strcasecmp(value
, "digest"))
1531 loc
->type
= AUTH_DIGEST
;
1533 if (loc
->level
== AUTH_ANON
)
1534 loc
->level
= AUTH_USER
;
1536 else if (!strcasecmp(value
, "basicdigest"))
1538 loc
->type
= AUTH_BASICDIGEST
;
1540 if (loc
->level
== AUTH_ANON
)
1541 loc
->level
= AUTH_USER
;
1545 cupsdLogMessage(CUPSD_LOG_WARN
,
1546 "Unknown authorization type %s on line %d.",
1551 else if (!strcasecmp(line
, "AuthClass"))
1554 * AuthClass anonymous, user, system, group
1557 if (!strcasecmp(value
, "anonymous"))
1559 loc
->type
= AUTH_NONE
;
1560 loc
->level
= AUTH_ANON
;
1562 cupsdLogMessage(CUPSD_LOG_WARN
,
1563 "\"AuthClass %s\" is deprecated; consider removing "
1567 else if (!strcasecmp(value
, "user"))
1569 loc
->level
= AUTH_USER
;
1571 cupsdLogMessage(CUPSD_LOG_WARN
,
1572 "\"AuthClass %s\" is deprecated; consider using "
1573 "\"Require valid-user\" on line %d.",
1576 else if (!strcasecmp(value
, "group"))
1578 loc
->level
= AUTH_GROUP
;
1580 cupsdLogMessage(CUPSD_LOG_WARN
,
1581 "\"AuthClass %s\" is deprecated; consider using "
1582 "\"Require @groupname\" on line %d.",
1585 else if (!strcasecmp(value
, "system"))
1587 loc
->level
= AUTH_GROUP
;
1589 cupsdAddName(loc
, "@SYSTEM");
1591 cupsdLogMessage(CUPSD_LOG_WARN
,
1592 "\"AuthClass %s\" is deprecated; consider using "
1593 "\"Require @SYSTEM\" on line %d.",
1598 cupsdLogMessage(CUPSD_LOG_WARN
,
1599 "Unknown authorization class %s on line %d.",
1604 else if (!strcasecmp(line
, "AuthGroupName"))
1606 cupsdAddName(loc
, value
);
1608 cupsdLogMessage(CUPSD_LOG_WARN
,
1609 "\"AuthGroupName %s\" directive is deprecated; consider "
1610 "using \"Require @%s\" on line %d.",
1611 value
, value
, linenum
);
1613 else if (!strcasecmp(line
, "Require"))
1616 * Apache synonym for AuthClass and AuthGroupName...
1620 * Require valid-user
1621 * Require group names
1622 * Require user names
1625 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1630 if (!strcasecmp(value
, "valid-user") ||
1631 !strcasecmp(value
, "user"))
1632 loc
->level
= AUTH_USER
;
1633 else if (!strcasecmp(value
, "group"))
1634 loc
->level
= AUTH_GROUP
;
1637 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1643 * Get the list of names from the line...
1646 for (value
= valptr
; *value
;)
1648 while (isspace(*value
& 255))
1651 if (*value
== '\"' || *value
== '\'')
1654 * Grab quoted name...
1657 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1664 * Grab literal name.
1667 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1673 cupsdAddName(loc
, value
);
1675 for (value
= valptr
; isspace(*value
& 255); value
++);
1678 else if (!strcasecmp(line
, "Satisfy"))
1680 if (!strcasecmp(value
, "all"))
1681 loc
->satisfy
= AUTH_SATISFY_ALL
;
1682 else if (!strcasecmp(value
, "any"))
1683 loc
->satisfy
= AUTH_SATISFY_ANY
;
1686 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1699 * 'read_configuration()' - Read a configuration file.
1702 static int /* O - 1 on success, 0 on failure */
1703 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1705 int i
; /* Looping var */
1706 int linenum
; /* Current line number */
1707 char line
[HTTP_MAX_BUFFER
],
1708 /* Line from file */
1709 temp
[HTTP_MAX_BUFFER
],
1710 /* Temporary buffer for value */
1711 temp2
[HTTP_MAX_BUFFER
],
1712 /* Temporary buffer 2 for value */
1713 *ptr
, /* Pointer into line/temp */
1714 *value
, /* Pointer to value */
1715 *valueptr
, /* Pointer into value */
1716 quote
; /* Quote character */
1717 int valuelen
; /* Length of value */
1718 cupsd_var_t
*var
; /* Current variable */
1719 http_addrlist_t
*addrlist
, /* Address list */
1720 *addr
; /* Current address */
1721 unsigned ip
[4], /* Address value */
1722 mask
[4]; /* Netmask value */
1723 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1724 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1725 cupsd_location_t
*location
; /* Browse location */
1726 cups_file_t
*incfile
; /* Include file */
1727 char incname
[1024]; /* Include filename */
1728 struct group
*group
; /* Group */
1732 * Loop through each line in the file...
1737 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1740 * Decode the directive...
1743 if (!strcasecmp(line
, "Include"))
1749 if (value
[0] == '/')
1750 strlcpy(incname
, value
, sizeof(incname
));
1752 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1754 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1755 cupsdLogMessage(CUPSD_LOG_ERROR
,
1756 "Unable to include config file \"%s\" - %s",
1757 incname
, strerror(errno
));
1760 read_configuration(incfile
);
1761 cupsFileClose(incfile
);
1764 else if (!strcasecmp(line
, "<Location"))
1772 linenum
= read_location(fp
, value
, linenum
);
1778 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1783 else if (!strcasecmp(line
, "<Policy"))
1791 linenum
= read_policy(fp
, value
, linenum
);
1797 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1801 else if (!strcasecmp(line
, "FaxRetryInterval"))
1805 JobRetryInterval
= atoi(value
);
1806 cupsdLogMessage(CUPSD_LOG_WARN
,
1807 "FaxRetryInterval is deprecated; use "
1808 "JobRetryInterval on line %d.", linenum
);
1812 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1816 else if (!strcasecmp(line
, "FaxRetryLimit"))
1820 JobRetryLimit
= atoi(value
);
1821 cupsdLogMessage(CUPSD_LOG_WARN
,
1822 "FaxRetryLimit is deprecated; use "
1823 "JobRetryLimit on line %d.", linenum
);
1827 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1831 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
1833 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
1834 #endif /* HAVE_SSL */
1838 * Add listening address(es) to the list...
1841 cupsd_listener_t
*lis
; /* New listeners array */
1845 * Get the address list...
1848 addrlist
= get_address(value
, IPP_PORT
);
1852 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1858 * Add each address...
1861 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1864 * Allocate another listener...
1867 if (NumListeners
== 0)
1868 lis
= malloc(sizeof(cupsd_listener_t
));
1870 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1874 cupsdLogMessage(CUPSD_LOG_ERROR
,
1875 "Unable to allocate %s at line %d - %s.",
1876 line
, linenum
, strerror(errno
));
1881 lis
+= NumListeners
;
1884 * Copy the current address and log it...
1887 memset(lis
, 0, sizeof(cupsd_listener_t
));
1888 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
1891 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1892 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1893 #endif /* HAVE_SSL */
1896 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1897 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1898 ntohs(lis
->address
.ipv6
.sin6_port
));
1900 #endif /* AF_INET6 */
1902 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1903 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
1905 #endif /* AF_LOCAL */
1906 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
1907 ntohs(lis
->address
.ipv4
.sin_port
));
1916 httpAddrFreeList(addrlist
);
1918 else if (!strcasecmp(line
, "BrowseAddress"))
1921 * Add a browse address to the list...
1924 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
1927 if (NumBrowsers
== 0)
1928 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
1930 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
1934 cupsdLogMessage(CUPSD_LOG_ERROR
,
1935 "Unable to allocate BrowseAddress at line %d - %s.",
1936 linenum
, strerror(errno
));
1941 dira
+= NumBrowsers
;
1943 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
1945 if (!strcasecmp(value
, "@LOCAL"))
1948 * Send browse data to all local interfaces...
1951 strcpy(dira
->iface
, "*");
1954 else if (!strncasecmp(value
, "@IF(", 4))
1957 * Send browse data to the named interface...
1960 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1962 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1968 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
1971 * Only IPv4 addresses are supported...
1974 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1975 if (addr
->addr
.addr
.sa_family
== AF_INET
)
1980 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
1981 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1983 cupsdLogMessage(CUPSD_LOG_INFO
,
1984 "Sending browsing info to %s:%d (IPv4)",
1985 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
1990 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
1993 httpAddrFreeList(addrlist
);
1996 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
1999 else if (!strcasecmp(line
, "BrowseOrder"))
2002 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2005 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2006 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2008 if (location
== NULL
)
2009 cupsdLogMessage(CUPSD_LOG_ERROR
,
2010 "Unable to initialize browse access control list!");
2011 else if (!strncasecmp(value
, "deny", 4))
2012 location
->order_type
= AUTH_ALLOW
;
2013 else if (!strncasecmp(value
, "allow", 5))
2014 location
->order_type
= AUTH_DENY
;
2016 cupsdLogMessage(CUPSD_LOG_ERROR
,
2017 "Unknown BrowseOrder value %s on line %d.",
2020 else if (!strcasecmp(line
, "BrowseProtocols") ||
2021 !strcasecmp(line
, "BrowseLocalProtocols") ||
2022 !strcasecmp(line
, "BrowseRemoteProtocols"))
2025 * "BrowseProtocol name [... name]"
2028 if (strcasecmp(line
, "BrowseLocalProtocols"))
2029 BrowseRemoteProtocols
= 0;
2030 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2031 BrowseLocalProtocols
= 0;
2035 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2036 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2039 if (value
[valuelen
])
2041 value
[valuelen
] = '\0';
2045 if (!strcasecmp(value
, "cups"))
2047 if (strcasecmp(line
, "BrowseLocalProtocols"))
2048 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2049 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2050 BrowseLocalProtocols
|= BROWSE_CUPS
;
2052 else if (!strcasecmp(value
, "slp"))
2054 if (strcasecmp(line
, "BrowseLocalProtocols"))
2055 BrowseRemoteProtocols
|= BROWSE_SLP
;
2056 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2057 BrowseLocalProtocols
|= BROWSE_SLP
;
2059 else if (!strcasecmp(value
, "ldap"))
2061 if (strcasecmp(line
, "BrowseLocalProtocols"))
2062 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2063 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2064 BrowseLocalProtocols
|= BROWSE_LDAP
;
2066 else if (!strcasecmp(value
, "all"))
2068 if (strcasecmp(line
, "BrowseLocalProtocols"))
2069 BrowseRemoteProtocols
|= BROWSE_ALL
;
2070 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2071 BrowseLocalProtocols
|= BROWSE_ALL
;
2075 cupsdLogMessage(CUPSD_LOG_ERROR
,
2076 "Unknown browse protocol \"%s\" on line %d.",
2081 for (value
+= valuelen
; *value
; value
++)
2082 if (!isspace(*value
) || *value
!= ',')
2086 else if (!strcasecmp(line
, "BrowseAllow") ||
2087 !strcasecmp(line
, "BrowseDeny"))
2090 * BrowseAllow [From] host/ip...
2091 * BrowseDeny [From] host/ip...
2094 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2095 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2097 if (location
== NULL
)
2098 cupsdLogMessage(CUPSD_LOG_ERROR
,
2099 "Unable to initialize browse access control list!");
2102 if (!strncasecmp(value
, "from ", 5))
2105 * Strip leading "from"...
2110 while (isspace(*value
))
2115 * Figure out what form the allow/deny address takes:
2126 * nnn.nnn.nnn.nnn/mm
2127 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2130 if (!strcasecmp(value
, "all"))
2136 if (!strcasecmp(line
, "BrowseAllow"))
2137 cupsdAllowIP(location
, zeros
, zeros
);
2139 cupsdDenyIP(location
, zeros
, zeros
);
2141 else if (!strcasecmp(value
, "none"))
2147 if (!strcasecmp(line
, "BrowseAllow"))
2148 cupsdAllowIP(location
, ones
, zeros
);
2150 cupsdDenyIP(location
, ones
, zeros
);
2152 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2155 * Host or domain name...
2158 if (value
[0] == '*')
2161 if (!strcasecmp(line
, "BrowseAllow"))
2162 cupsdAllowHost(location
, value
);
2164 cupsdDenyHost(location
, value
);
2169 * One of many IP address forms...
2172 if (!get_addr_and_mask(value
, ip
, mask
))
2174 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2179 if (!strcasecmp(line
, "BrowseAllow"))
2180 cupsdAllowIP(location
, ip
, mask
);
2182 cupsdDenyIP(location
, ip
, mask
);
2186 else if (!strcasecmp(line
, "BrowseRelay"))
2189 * BrowseRelay [from] source [to] destination
2193 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2195 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2199 cupsdLogMessage(CUPSD_LOG_ERROR
,
2200 "Unable to allocate BrowseRelay at line %d - %s.",
2201 linenum
, strerror(errno
));
2208 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2210 if (!strncasecmp(value
, "from ", 5))
2213 * Strip leading "from"...
2218 while (isspace(*value
))
2223 * Figure out what form the from address takes:
2232 * nnn.nnn.nnn.nnn/mm
2233 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2236 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2239 * Host or domain name...
2242 if (value
[0] == '*')
2245 strlcpy(temp
, value
, sizeof(temp
));
2246 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2249 relay
->from
.type
= AUTH_NAME
;
2250 relay
->from
.mask
.name
.name
= strdup(temp
);
2251 relay
->from
.mask
.name
.length
= strlen(temp
);
2256 * One of many IP address forms...
2259 if (!get_addr_and_mask(value
, ip
, mask
))
2261 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2266 relay
->from
.type
= AUTH_IP
;
2267 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2268 sizeof(relay
->from
.mask
.ip
.address
));
2269 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2270 sizeof(relay
->from
.mask
.ip
.netmask
));
2274 * Skip value and trailing whitespace...
2277 for (; *value
; value
++)
2278 if (isspace(*value
))
2281 while (isspace(*value
))
2284 if (!strncasecmp(value
, "to ", 3))
2287 * Strip leading "to"...
2292 while (isspace(*value
))
2297 * Get "to" address and port...
2300 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2303 * Only IPv4 addresses are supported...
2306 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2307 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2312 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2314 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2316 if (relay
->from
.type
== AUTH_IP
)
2317 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2318 relay
->from
.mask
.ip
.address
[0],
2319 relay
->from
.mask
.ip
.address
[1],
2320 relay
->from
.mask
.ip
.address
[2],
2321 relay
->from
.mask
.ip
.address
[3],
2322 relay
->from
.mask
.ip
.netmask
[0],
2323 relay
->from
.mask
.ip
.netmask
[1],
2324 relay
->from
.mask
.ip
.netmask
[2],
2325 relay
->from
.mask
.ip
.netmask
[3]);
2327 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2329 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2330 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2335 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2338 httpAddrFreeList(addrlist
);
2342 if (relay
->from
.type
== AUTH_NAME
)
2343 free(relay
->from
.mask
.name
.name
);
2345 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2349 else if (!strcasecmp(line
, "BrowsePoll"))
2352 * BrowsePoll address[:port]
2355 char *portname
; /* Port name */
2356 int portnum
; /* Port number */
2357 struct servent
*service
; /* Service */
2361 * Extract the port name from the address...
2364 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2368 if (isdigit(*portname
& 255))
2369 portnum
= atoi(portname
);
2370 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2371 portnum
= ntohs(service
->s_port
);
2374 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2380 portnum
= ippPort();
2383 * Add the poll entry...
2387 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2389 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2393 cupsdLogMessage(CUPSD_LOG_ERROR
,
2394 "Unable to allocate BrowsePoll at line %d - %s.",
2395 linenum
, strerror(errno
));
2403 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2405 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2406 pollp
->port
= portnum
;
2408 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2411 else if (!strcasecmp(line
, "DefaultAuthType"))
2414 * DefaultAuthType {basic,digest,basicdigest}
2417 if (!strcasecmp(value
, "basic"))
2418 DefaultAuthType
= AUTH_BASIC
;
2419 else if (!strcasecmp(value
, "digest"))
2420 DefaultAuthType
= AUTH_DIGEST
;
2421 else if (!strcasecmp(value
, "basicdigest"))
2422 DefaultAuthType
= AUTH_BASICDIGEST
;
2425 cupsdLogMessage(CUPSD_LOG_WARN
,
2426 "Unknown default authorization type %s on line %d.",
2431 else if (!strcasecmp(line
, "User"))
2434 * User ID to run as...
2437 if (isdigit(value
[0]))
2441 struct passwd
*p
; /* Password information */
2444 p
= getpwnam(value
);
2449 cupsdLogMessage(CUPSD_LOG_ERROR
,
2450 "Unknown User \"%s\" on line %d, ignoring!",
2454 else if (!strcasecmp(line
, "Group"))
2457 * Group ID to run as...
2460 if (isdigit(value
[0]))
2461 Group
= atoi(value
);
2465 group
= getgrnam(value
);
2468 Group
= group
->gr_gid
;
2470 cupsdLogMessage(CUPSD_LOG_ERROR
,
2471 "Unknown Group \"%s\" on line %d, ignoring!",
2475 else if (!strcasecmp(line
, "SystemGroup"))
2478 * System (admin) group(s)...
2481 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2483 if (*value
== '\'' || *value
== '\"')
2486 * Scan quoted name...
2491 for (valueptr
= value
; *valueptr
; valueptr
++)
2492 if (*valueptr
== quote
)
2498 * Scan space or comma-delimited name...
2501 for (valueptr
= value
; *valueptr
; valueptr
++)
2502 if (isspace(*valueptr
) || *valueptr
== ',')
2509 group
= getgrnam(value
);
2512 cupsdSetString(SystemGroups
+ i
, value
);
2513 SystemGroupIDs
[i
] = group
->gr_gid
;
2518 cupsdLogMessage(CUPSD_LOG_ERROR
,
2519 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2526 while (*value
== ',' || isspace(*value
))
2531 NumSystemGroups
= i
;
2533 else if (!strcasecmp(line
, "HostNameLookups"))
2536 * Do hostname lookups?
2539 if (!strcasecmp(value
, "off"))
2540 HostNameLookups
= 0;
2541 else if (!strcasecmp(value
, "on"))
2542 HostNameLookups
= 1;
2543 else if (!strcasecmp(value
, "double"))
2544 HostNameLookups
= 2;
2546 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2549 else if (!strcasecmp(line
, "LogLevel"))
2552 * Amount of logging to do...
2555 if (!strcasecmp(value
, "debug2"))
2556 LogLevel
= CUPSD_LOG_DEBUG2
;
2557 else if (!strcasecmp(value
, "debug"))
2558 LogLevel
= CUPSD_LOG_DEBUG
;
2559 else if (!strcasecmp(value
, "info"))
2560 LogLevel
= CUPSD_LOG_INFO
;
2561 else if (!strcasecmp(value
, "notice"))
2562 LogLevel
= CUPSD_LOG_NOTICE
;
2563 else if (!strcasecmp(value
, "warn"))
2564 LogLevel
= CUPSD_LOG_WARN
;
2565 else if (!strcasecmp(value
, "error"))
2566 LogLevel
= CUPSD_LOG_ERROR
;
2567 else if (!strcasecmp(value
, "crit"))
2568 LogLevel
= CUPSD_LOG_CRIT
;
2569 else if (!strcasecmp(value
, "alert"))
2570 LogLevel
= CUPSD_LOG_ALERT
;
2571 else if (!strcasecmp(value
, "emerg"))
2572 LogLevel
= CUPSD_LOG_EMERG
;
2573 else if (!strcasecmp(value
, "none"))
2574 LogLevel
= CUPSD_LOG_NONE
;
2576 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2579 else if (!strcasecmp(line
, "PrintcapFormat"))
2582 * Format of printcap file?
2585 if (!strcasecmp(value
, "bsd"))
2586 PrintcapFormat
= PRINTCAP_BSD
;
2587 else if (!strcasecmp(value
, "solaris"))
2588 PrintcapFormat
= PRINTCAP_SOLARIS
;
2590 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2593 else if (!strcasecmp(line
, "ServerTokens"))
2596 * Set the string used for the Server header...
2599 struct utsname plat
; /* Platform info */
2604 if (!strcasecmp(value
, "ProductOnly"))
2605 cupsdSetString(&ServerHeader
, "CUPS");
2606 else if (!strcasecmp(value
, "Major"))
2607 cupsdSetString(&ServerHeader
, "CUPS/1");
2608 else if (!strcasecmp(value
, "Minor"))
2609 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2610 else if (!strcasecmp(value
, "Minimal"))
2611 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2612 else if (!strcasecmp(value
, "OS"))
2613 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2614 else if (!strcasecmp(value
, "Full"))
2615 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2617 else if (!strcasecmp(value
, "None"))
2618 cupsdClearString(&ServerHeader
);
2620 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2623 else if (!strcasecmp(line
, "PassEnv"))
2626 * PassEnv variable [... variable]
2631 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2632 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2635 if (value
[valuelen
])
2637 value
[valuelen
] = '\0';
2641 cupsdSetEnv(value
, NULL
);
2643 for (value
+= valuelen
; *value
; value
++)
2644 if (!isspace(*value
) || *value
!= ',')
2648 else if (!strcasecmp(line
, "SetEnv"))
2651 * SetEnv variable value
2654 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2662 while (isspace(*valueptr
& 255))
2665 cupsdSetEnv(value
, valueptr
);
2668 cupsdLogMessage(CUPSD_LOG_ERROR
,
2669 "Missing value for SetEnv directive on line %d.",
2675 * Find a simple variable in the list...
2678 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2679 if (!strcasecmp(line
, var
->name
))
2685 * Unknown directive! Output an error message and continue...
2688 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2695 case CUPSD_VARTYPE_INTEGER
:
2698 char *units
; /* Units */
2701 n
= strtol(value
, &units
, 0);
2703 if (units
&& *units
)
2705 if (tolower(units
[0] & 255) == 'g')
2706 n
*= 1024 * 1024 * 1024;
2707 else if (tolower(units
[0] & 255) == 'm')
2709 else if (tolower(units
[0] & 255) == 'k')
2711 else if (tolower(units
[0] & 255) == 't')
2715 *((int *)var
->ptr
) = n
;
2719 case CUPSD_VARTYPE_BOOLEAN
:
2720 if (!strcasecmp(value
, "true") ||
2721 !strcasecmp(value
, "on") ||
2722 !strcasecmp(value
, "enabled") ||
2723 !strcasecmp(value
, "yes") ||
2725 *((int *)var
->ptr
) = TRUE
;
2726 else if (!strcasecmp(value
, "false") ||
2727 !strcasecmp(value
, "off") ||
2728 !strcasecmp(value
, "disabled") ||
2729 !strcasecmp(value
, "no") ||
2730 !strcasecmp(value
, "0"))
2731 *((int *)var
->ptr
) = FALSE
;
2733 cupsdLogMessage(CUPSD_LOG_ERROR
,
2734 "Unknown boolean value %s on line %d.",
2738 case CUPSD_VARTYPE_STRING
:
2739 cupsdSetString((char **)var
->ptr
, value
);
2750 * 'read_location()' - Read a <Location path> definition.
2753 static int /* O - New line number or 0 on error */
2754 read_location(cups_file_t
*fp
, /* I - Configuration file */
2755 char *location
, /* I - Location name/path */
2756 int linenum
) /* I - Current line number */
2758 cupsd_location_t
*loc
, /* New location */
2759 *parent
; /* Parent location */
2760 char line
[HTTP_MAX_BUFFER
],
2762 *value
, /* Value for directive */
2763 *valptr
; /* Pointer into value */
2766 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2769 parent
->limit
= AUTH_LIMIT_ALL
;
2772 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2775 * Decode the directive...
2778 if (!strcasecmp(line
, "</Location>"))
2780 else if (!strcasecmp(line
, "<Limit") ||
2781 !strcasecmp(line
, "<LimitExcept"))
2785 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2789 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2795 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2800 if (!strcmp(value
, "ALL"))
2801 loc
->limit
= AUTH_LIMIT_ALL
;
2802 else if (!strcmp(value
, "GET"))
2803 loc
->limit
|= AUTH_LIMIT_GET
;
2804 else if (!strcmp(value
, "HEAD"))
2805 loc
->limit
|= AUTH_LIMIT_HEAD
;
2806 else if (!strcmp(value
, "OPTIONS"))
2807 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2808 else if (!strcmp(value
, "POST"))
2809 loc
->limit
|= AUTH_LIMIT_POST
;
2810 else if (!strcmp(value
, "PUT"))
2811 loc
->limit
|= AUTH_LIMIT_PUT
;
2812 else if (!strcmp(value
, "TRACE"))
2813 loc
->limit
|= AUTH_LIMIT_TRACE
;
2815 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2818 for (value
= valptr
; isspace(*value
& 255); value
++);
2821 if (!strcasecmp(line
, "<LimitExcept"))
2822 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2824 parent
->limit
&= ~loc
->limit
;
2826 else if (!strcasecmp(line
, "</Limit>"))
2828 else if (!parse_aaa(loc
, line
, value
, linenum
))
2830 cupsdLogMessage(CUPSD_LOG_ERROR
,
2831 "Unknown Location directive %s on line %d.",
2837 cupsdLogMessage(CUPSD_LOG_ERROR
,
2838 "Unexpected end-of-file at line %d while reading location!",
2846 * 'read_policy()' - Read a <Policy name> definition.
2849 static int /* O - New line number or 0 on error */
2850 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2851 char *policy
, /* I - Location name/path */
2852 int linenum
) /* I - Current line number */
2854 int i
; /* Looping var */
2855 cupsd_policy_t
*pol
; /* Policy */
2856 cupsd_location_t
*op
; /* Policy operation */
2857 int num_ops
; /* Number of IPP operations */
2858 ipp_op_t ops
[100]; /* Operations */
2859 char line
[HTTP_MAX_BUFFER
],
2861 *value
, /* Value for directive */
2862 *valptr
; /* Pointer into value */
2866 * Create the policy...
2869 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2873 * Read from the file...
2879 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2882 * Decode the directive...
2885 if (!strcasecmp(line
, "</Policy>"))
2888 cupsdLogMessage(CUPSD_LOG_WARN
,
2889 "Missing </Limit> before </Policy> on line %d!",
2894 else if (!strcasecmp(line
, "<Limit") && !op
)
2898 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2903 * Scan for IPP operation names...
2910 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2915 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2917 if (!strcasecmp(value
, "All"))
2918 ops
[num_ops
] = IPP_ANY_OPERATION
;
2919 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2920 cupsdLogMessage(CUPSD_LOG_ERROR
,
2921 "Bad IPP operation name \"%s\" on line %d!",
2927 cupsdLogMessage(CUPSD_LOG_ERROR
,
2928 "Too many operations listed on line %d!",
2931 for (value
= valptr
; isspace(*value
& 255); value
++);
2935 * If none are specified, apply the policy to all operations...
2940 ops
[0] = IPP_ANY_OPERATION
;
2945 * Add a new policy for the first operation...
2948 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2950 else if (!strcasecmp(line
, "</Limit>") && op
)
2953 * Finish the current operation limit...
2959 * Copy the policy to the other operations...
2962 for (i
= 1; i
< num_ops
; i
++)
2963 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
2970 cupsdLogMessage(CUPSD_LOG_ERROR
,
2971 "Missing <Limit ops> directive before %s on line %d.",
2975 else if (!parse_aaa(op
, line
, value
, linenum
))
2978 cupsdLogMessage(CUPSD_LOG_ERROR
,
2979 "Unknown Policy Limit directive %s on line %d.",
2982 cupsdLogMessage(CUPSD_LOG_ERROR
,
2983 "Unknown Policy directive %s on line %d.",
2990 cupsdLogMessage(CUPSD_LOG_ERROR
,
2991 "Unexpected end-of-file at line %d while reading policy \"%s\"!",