2 * "$Id: conf.c 6783 2007-08-10 19:48:57Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdCheckPermissions() - Fix the mode and ownership of a file or
19 * cupsdReadConfiguration() - Read the cupsd.conf file.
20 * get_address() - Get an address + port number from a line.
21 * get_addr_and_mask() - Get an IP address and netmask.
22 * parse_aaa() - Parse authentication, authorization, and
23 * access control lines.
24 * parse_groups() - Parse system group names in a string.
25 * parse_protocols() - Parse browse protocols in a string.
26 * read_configuration() - Read a configuration file.
27 * read_location() - Read a <Location path> definition.
28 * read_policy() - Read a <Policy name> definition.
32 * Include necessary headers...
38 #include <sys/utsname.h>
43 * Possibly missing network definitions...
47 # define INADDR_NONE 0xffffffff
48 #endif /* !INADDR_NONE */
52 * Configuration variable structure...
57 CUPSD_VARTYPE_INTEGER
, /* Integer option */
58 CUPSD_VARTYPE_STRING
, /* String option */
59 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
60 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
65 char *name
; /* Name of variable */
66 void *ptr
; /* Pointer to variable */
67 cupsd_vartype_t type
; /* Type (int, string, address) */
75 static cupsd_var_t variables
[] =
77 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
79 { "AppleQuotas", &AppleQuotas
, CUPSD_VARTYPE_BOOLEAN
},
80 #endif /* __APPLE__ */
81 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
82 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
84 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
85 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
86 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
87 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
88 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
89 #endif /* HAVE_LDAP */
90 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
91 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
92 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
93 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
94 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
95 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
96 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
97 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
98 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
99 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
100 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
101 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
102 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
103 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
104 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
105 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
106 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
107 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
108 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
109 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
110 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
111 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
112 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
114 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
115 #endif /* HAVE_GSSAPI */
116 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
117 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
118 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
119 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
120 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
121 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
123 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
124 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
125 #endif /* HAVE_LAUNCHD */
126 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
127 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
128 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
145 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
146 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
147 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
148 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
149 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
150 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
151 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
152 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
153 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
154 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
155 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
156 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
158 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
159 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
160 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
161 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
162 #endif /* HAVE_SSL */
163 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
164 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
165 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
166 #ifdef HAVE_AUTHORIZATION_H
167 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
168 #endif /* HAVE_AUTHORIZATION_H */
169 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
170 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
171 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
173 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
176 static unsigned ones
[4] =
178 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
180 static unsigned zeros
[4] =
182 0x00000000, 0x00000000, 0x00000000, 0x00000000
189 static http_addrlist_t
*get_address(const char *value
, int defport
);
190 static int get_addr_and_mask(const char *value
, unsigned *ip
,
192 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
193 char *value
, int linenum
);
194 static int parse_groups(const char *s
);
195 static int parse_protocols(const char *s
);
196 static int read_configuration(cups_file_t
*fp
);
197 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
198 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
202 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
205 int /* O - 0 on success, -1 on error, 1 on warning */
206 cupsdCheckPermissions(
207 const char *filename
, /* I - File/directory name */
208 const char *suffix
, /* I - Additional file/directory name */
209 int mode
, /* I - Permissions */
210 int user
, /* I - Owner */
211 int group
, /* I - Group */
212 int is_dir
, /* I - 1 = directory, 0 = file */
213 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
215 int dir_created
= 0; /* Did we create a directory? */
216 char pathname
[1024]; /* File name with prefix */
217 struct stat fileinfo
; /* Stat buffer */
221 * Prepend the given root to the filename before testing it...
226 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
231 * See if we can stat the file/directory...
234 if (stat(filename
, &fileinfo
))
236 if (errno
== ENOENT
&& create_dir
)
239 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
242 if (mkdir(filename
, mode
))
245 cupsdLogMessage(CUPSD_LOG_ERROR
,
246 "Unable to create directory \"%s\" - %s", filename
,
249 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
258 return (create_dir
? -1 : 1);
262 * Make sure it's a regular file...
265 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
267 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
271 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
274 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
276 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
282 * Fix owner, group, and mode as needed...
285 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
288 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
291 if (chown(filename
, user
, group
) && !getuid())
294 cupsdLogMessage(CUPSD_LOG_ERROR
,
295 "Unable to change ownership of \"%s\" - %s", filename
,
298 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
305 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
308 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
311 if (chmod(filename
, mode
))
314 cupsdLogMessage(CUPSD_LOG_ERROR
,
315 "Unable to change permissions of \"%s\" - %s", filename
,
318 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
326 * Everything is OK...
334 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
337 int /* O - 1 on success, 0 otherwise */
338 cupsdReadConfiguration(void)
340 int i
; /* Looping var */
341 cups_file_t
*fp
; /* Configuration file */
342 int status
; /* Return status */
343 char temp
[1024], /* Temporary buffer */
344 *slash
; /* Directory separator */
345 cups_lang_t
*language
; /* Language */
346 struct passwd
*user
; /* Default user */
347 struct group
*group
; /* Default group */
348 char *old_serverroot
, /* Old ServerRoot */
349 *old_requestroot
; /* Old RequestRoot */
350 const char *tmpdir
; /* TMPDIR environment variable */
351 struct stat tmpinfo
; /* Temporary directory info */
355 * Save the old root paths...
358 old_serverroot
= NULL
;
359 cupsdSetString(&old_serverroot
, ServerRoot
);
360 old_requestroot
= NULL
;
361 cupsdSetString(&old_requestroot
, RequestRoot
);
364 * Reset the server configuration data...
367 cupsdDeleteAllLocations();
386 for (i
= 0; i
< NumRelays
; i
++)
387 if (Relays
[i
].from
.type
== AUTH_NAME
)
388 free(Relays
[i
].from
.mask
.name
.name
);
395 cupsdDeleteAllListeners();
401 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
402 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
403 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
404 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
405 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
406 cupsdSetString(&DataDir
, CUPS_DATADIR
);
407 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
408 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
409 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
410 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
411 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
412 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
413 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
414 cupsdSetString(&RemoteRoot
, "remroot");
415 cupsdSetString(&ServerHeader
, "CUPS/1.2");
416 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
418 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
419 #endif /* HAVE_GSSAPI */
421 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
422 PrintcapFormat
= PRINTCAP_SOLARIS
;
424 PrintcapFormat
= PRINTCAP_BSD
;
426 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
427 if ((slash
= strrchr(temp
, '/')) != NULL
)
430 cupsdSetString(&ServerRoot
, temp
);
432 cupsdClearString(&Classification
);
433 ClassifyOverride
= 0;
437 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
439 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
440 cupsdSetString(&ServerKey
, "ssl/server.key");
441 # endif /* HAVE_CDSASSL */
442 #endif /* HAVE_SSL */
444 language
= cupsLangDefault();
446 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
447 cupsdSetString(&DefaultLanguage
, "en");
449 cupsdSetString(&DefaultLanguage
, language
->language
);
451 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
453 cupsdSetString(&RIPCache
, "8m");
455 cupsdSetString(&TempDir
, NULL
);
458 * Find the default user...
461 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
466 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
467 * complement number...)
476 * Find the default group...
479 group
= getgrnam(CUPS_DEFAULT_GROUP
);
483 Group
= group
->gr_gid
;
487 * Fallback to group "nobody"...
490 group
= getgrnam("nobody");
494 Group
= group
->gr_gid
;
498 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
499 * complement number...)
510 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
511 DefaultAuthType
= AUTH_BASIC
;
513 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
514 #endif /* HAVE_SSL */
516 JobRetryInterval
= 300;
521 HostNameLookups
= FALSE
;
522 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
523 ImplicitAnyClasses
= FALSE
;
524 HideImplicitMembers
= TRUE
;
526 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
527 ListenBackLog
= SOMAXCONN
;
528 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
529 LogLevel
= CUPSD_LOG_ERROR
;
531 MaxClientsPerHost
= 0;
532 MaxLogSize
= 1024 * 1024;
533 MaxPrinterHistory
= 10;
536 RootCertDuration
= 300;
537 Timeout
= DEFAULT_TIMEOUT
;
540 BrowseInterval
= DEFAULT_INTERVAL
;
541 BrowsePort
= ippPort();
542 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
543 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
544 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
545 BrowseTimeout
= DEFAULT_TIMEOUT
;
546 Browsing
= CUPS_DEFAULT_BROWSING
;
547 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
549 cupsdClearString(&BrowseLocalOptions
);
550 cupsdClearString(&BrowseRemoteOptions
);
552 cupsdSetString(&ErrorPolicy
, "stop-printer");
555 cupsdClearString(&BrowseLDAPBindDN
);
556 cupsdClearString(&BrowseLDAPDN
);
557 cupsdClearString(&BrowseLDAPPassword
);
558 cupsdClearString(&BrowseLDAPServer
);
559 cupsdClearString(&BrowseLDAPCACertFile
);
560 #endif /* HAVE_LDAP */
562 JobHistory
= DEFAULT_HISTORY
;
563 JobFiles
= DEFAULT_FILES
;
568 MaxJobsPerPrinter
= 0;
569 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
571 cupsdDeleteAllPolicies();
572 cupsdClearString(&DefaultPolicy
);
574 #ifdef HAVE_AUTHORIZATION_H
575 cupsdClearString(&SystemGroupAuthKey
);
576 #endif /* HAVE_AUTHORIZATION_H */
578 MaxSubscriptions
= 100;
579 MaxSubscriptionsPerJob
= 0;
580 MaxSubscriptionsPerPrinter
= 0;
581 MaxSubscriptionsPerUser
= 0;
582 DefaultLeaseDuration
= 86400;
583 MaxLeaseDuration
= 0;
586 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
587 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
588 #endif /* HAVE_LAUNCHD */
592 #endif /* __APPLE__ */
595 * Read the configuration file...
598 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
601 status
= read_configuration(fp
);
611 * See if the ServerName is an IP address...
614 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
616 ServerNameIsIP
= !*slash
;
619 * Use the default system group if none was supplied in cupsd.conf...
622 if (NumSystemGroups
== 0)
624 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
627 * Find the group associated with GID 0...
634 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
636 cupsdSetString(&SystemGroups
[0], "unknown");
638 SystemGroupIDs
[0] = 0;
644 * Get the access control list for browsing...
647 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
650 * Open the system log for cupsd if necessary...
654 if (!strcmp(AccessLog
, "syslog") ||
655 !strcmp(ErrorLog
, "syslog") ||
656 !strcmp(PageLog
, "syslog"))
657 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
658 #endif /* HAVE_VSYSLOG */
661 * Log the configuration file that was used...
664 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
668 * Validate the Group and SystemGroup settings - they cannot be the same,
669 * otherwise the CGI programs will be able to authenticate as root without
675 for (i
= 0; i
< NumSystemGroups
; i
++)
676 if (Group
== SystemGroupIDs
[i
])
679 if (i
< NumSystemGroups
)
682 * Log the error and reset the group to a safe value...
685 cupsdLogMessage(CUPSD_LOG_NOTICE
,
686 "Group and SystemGroup cannot use the same groups!");
687 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
689 group
= getgrnam("nobody");
693 Group
= group
->gr_gid
;
697 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
698 * complement number...)
707 * Check that we have at least one listen/port line; if not, report this
708 * as an error and exit!
711 if (cupsArrayCount(Listeners
) == 0)
717 cupsdLogMessage(CUPSD_LOG_EMERG
,
718 "No valid Listen or Port lines were found in the configuration file!");
724 cupsdEndProcess(getpid(), 0);
728 * Set the default locale using the language and charset...
731 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
734 * Update all relative filenames to include the full path from ServerRoot...
737 if (DocumentRoot
[0] != '/')
738 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
740 if (RequestRoot
[0] != '/')
741 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
743 if (ServerBin
[0] != '/')
744 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
746 if (StateDir
[0] != '/')
747 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
749 if (CacheDir
[0] != '/')
750 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
753 if (ServerCertificate
[0] != '/')
754 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
756 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
758 chown(ServerCertificate
, RunUser
, Group
);
759 chmod(ServerCertificate
, 0600);
762 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
763 if (ServerKey
[0] != '/')
764 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
766 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
768 chown(ServerKey
, RunUser
, Group
);
769 chmod(ServerKey
, 0600);
771 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
772 #endif /* HAVE_SSL */
775 * Make sure that directories and config files are owned and
776 * writable by the user and group in the cupsd.conf file...
779 if (cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
781 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
783 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
785 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
786 SystemGroupIDs
[0], 1, 1) < 0 ||
787 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
789 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
791 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
793 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
795 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
797 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
799 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
804 * Update TempDir to the default if it hasn't been set already...
809 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
812 * TMPDIR is defined, see if it is OK for us to use...
815 if (stat(tmpdir
, &tmpinfo
))
816 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
817 tmpdir
, strerror(errno
));
818 else if (!S_ISDIR(tmpinfo
.st_mode
))
819 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
821 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
822 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
823 !(tmpinfo
.st_mode
& S_IWOTH
))
824 cupsdLogMessage(CUPSD_LOG_ERROR
,
825 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
827 cupsdSetString(&TempDir
, tmpdir
);
832 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
834 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
839 * Make sure the temporary directory has the right permissions...
842 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
846 * Update ownership and permissions if the CUPS temp directory
847 * is under the spool directory or does not exist...
850 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
855 * Setup environment variables...
861 * Check the MaxClients setting, and then allocate memory for it...
864 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
867 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
870 MaxClients
= MaxFDs
/ 3;
873 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
877 * Check the MaxActiveJobs setting; limit to 1/3 the available
878 * file descriptors, since we need a pipe for each job...
881 if (MaxActiveJobs
> (MaxFDs
/ 3))
882 MaxActiveJobs
= MaxFDs
/ 3;
884 if (Classification
&& !strcasecmp(Classification
, "none"))
885 cupsdClearString(&Classification
);
888 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
891 * Update the MaxClientsPerHost value, as needed...
894 if (MaxClientsPerHost
<= 0)
895 MaxClientsPerHost
= MaxClients
;
897 if (MaxClientsPerHost
> MaxClients
)
898 MaxClientsPerHost
= MaxClients
;
900 cupsdLogMessage(CUPSD_LOG_INFO
,
901 "Allowing up to %d client connections per host.",
905 * Make sure that BrowseTimeout is at least twice the interval...
908 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
910 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
914 BrowseTimeout
= BrowseInterval
* 2;
916 BrowseTimeout
= DEFAULT_TIMEOUT
;
918 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
923 * Update the default policy, as needed...
927 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
929 DefaultPolicyPtr
= NULL
;
931 if (!DefaultPolicyPtr
)
933 cupsd_policy_t
*p
; /* New policy */
934 cupsd_location_t
*po
; /* New policy operation */
938 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
941 cupsdSetString(&DefaultPolicy
, "default");
943 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
944 cupsdLogMessage(CUPSD_LOG_INFO
,
945 "Using policy \"default\" as the default!");
948 cupsdLogMessage(CUPSD_LOG_INFO
,
949 "Creating CUPS default administrative policy:");
951 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
953 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
954 cupsdLogMessage(CUPSD_LOG_INFO
,
955 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
956 "Release-Job Restart-Job Purge-Jobs "
957 "Set-Job-Attributes Create-Job-Subscription "
958 "Renew-Subscription Cancel-Subscription "
959 "Get-Notifications Reprocess-Job Cancel-Current-Job "
960 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
961 "CUPS-Authenticate-Job>");
962 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
964 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
965 po
->order_type
= AUTH_ALLOW
;
966 po
->level
= AUTH_USER
;
968 cupsdAddName(po
, "@OWNER");
969 cupsdAddName(po
, "@SYSTEM");
970 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
972 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
973 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
974 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
975 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
976 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
977 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
978 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
979 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
980 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
981 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
982 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
983 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
984 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
985 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
986 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
987 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
988 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
990 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
992 cupsdLogMessage(CUPSD_LOG_INFO
,
993 "<Limit Pause-Printer Resume-Printer "
994 "Set-Printer-Attributes Enable-Printer "
995 "Disable-Printer Pause-Printer-After-Current-Job "
996 "Hold-New-Jobs Release-Held-New-Jobs "
997 "Deactivate-Printer Activate-Printer Restart-Printer "
998 "Shutdown-Printer Startup-Printer Promote-Job "
999 "Schedule-Job-After CUPS-Add-Printer "
1000 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1001 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1002 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1003 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1005 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1006 po
->order_type
= AUTH_ALLOW
;
1007 po
->type
= AUTH_DEFAULT
;
1008 po
->level
= AUTH_USER
;
1010 cupsdAddName(po
, "@SYSTEM");
1011 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1013 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1014 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1015 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1016 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1017 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1018 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1019 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1020 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1021 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1022 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1023 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1024 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1025 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1026 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1027 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1028 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1029 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1030 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1031 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1032 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1033 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1035 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1037 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1038 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1040 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1041 po
->order_type
= AUTH_ALLOW
;
1043 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1044 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1048 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1050 for (i
= 0; i
< NumPolicies
; i
++)
1051 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1052 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
1056 * If we are doing a full reload or the server root has changed, flush
1057 * the jobs, printers, etc. and start from scratch...
1060 if (NeedReload
== RELOAD_ALL
||
1061 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1062 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1064 mime_type_t
*type
; /* Current type */
1065 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1066 /* MIME type name */
1069 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1072 * Free all memory...
1075 cupsdDeleteAllSubscriptions();
1077 cupsdDeleteAllClasses();
1078 cupsdDeleteAllPrinters();
1080 DefaultPrinter
= NULL
;
1082 if (MimeDatabase
!= NULL
)
1083 mimeDelete(MimeDatabase
);
1087 for (i
= 0; i
< NumMimeTypes
; i
++)
1088 _cupsStrFree(MimeTypes
[i
]);
1094 * Read the MIME type and conversion database...
1097 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1099 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
1103 cupsdLogMessage(CUPSD_LOG_EMERG
,
1104 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1108 cupsdLogMessage(CUPSD_LOG_INFO
,
1109 "Loaded MIME database from \'%s\': %d types, %d filters...",
1110 ServerRoot
, mimeNumTypes(MimeDatabase
),
1111 mimeNumFilters(MimeDatabase
));
1114 * Create a list of MIME types for the document-format-supported
1118 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1119 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1122 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
1124 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1126 i
++, type
= mimeNextType(MimeDatabase
))
1128 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1130 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1133 if (i
< NumMimeTypes
)
1134 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1136 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1138 mime_filter_t
*filter
; /* Current filter */
1141 for (type
= mimeFirstType(MimeDatabase
);
1143 type
= mimeNextType(MimeDatabase
))
1144 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1145 type
->super
, type
->type
);
1147 for (filter
= mimeFirstFilter(MimeDatabase
);
1149 filter
= mimeNextFilter(MimeDatabase
))
1150 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1151 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1152 filter
->src
->super
, filter
->src
->type
,
1153 filter
->dst
->super
, filter
->dst
->type
,
1154 filter
->cost
, filter
->filter
);
1161 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1162 cupsdLoadBanners(temp
);
1165 * Load printers and classes...
1168 cupsdLoadAllPrinters();
1169 cupsdLoadAllClasses();
1170 cupsdLoadRemoteCache();
1171 cupsdWritePrintcap();
1173 cupsdCreateCommonData();
1176 * Load queued jobs...
1182 * Load subscriptions...
1185 cupsdLoadAllSubscriptions();
1187 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1192 * Not a full reload, so recreate the common printer attributes...
1195 cupsdCreateCommonData();
1198 * Update all printers as needed...
1201 cupsdUpdatePrinters();
1202 cupsdWritePrintcap();
1204 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1208 * Reset the reload state...
1211 NeedReload
= RELOAD_NONE
;
1213 cupsdClearString(&old_serverroot
);
1214 cupsdClearString(&old_requestroot
);
1221 * 'get_address()' - Get an address + port number from a line.
1224 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1225 get_address(const char *value
, /* I - Value string */
1226 int defport
) /* I - Default port */
1228 char buffer
[1024], /* Hostname + port number buffer */
1229 defpname
[255], /* Default port name */
1230 *hostname
, /* Hostname or IP */
1231 *portname
; /* Port number or name */
1232 http_addrlist_t
*addrlist
; /* Address list */
1236 * Check for an empty value...
1241 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1246 * Grab a hostname and port number; if there is no colon and the port name
1247 * is only digits, then we have a port number by itself...
1250 strlcpy(buffer
, value
, sizeof(buffer
));
1252 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1259 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1264 * Use the default port...
1267 sprintf(defpname
, "%d", defport
);
1268 portname
= defpname
;
1274 * The buffer contains just a port number...
1282 if (hostname
&& !strcmp(hostname
, "*"))
1286 * Now lookup the address using httpAddrGetList()...
1289 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1290 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1291 hostname
? hostname
: "(nil)");
1298 * 'get_addr_and_mask()' - Get an IP address and netmask.
1301 static int /* O - 1 on success, 0 on failure */
1302 get_addr_and_mask(const char *value
, /* I - String from config file */
1303 unsigned *ip
, /* O - Address value */
1304 unsigned *mask
) /* O - Mask value */
1306 int i
, j
, /* Looping vars */
1307 family
, /* Address family */
1308 ipcount
; /* Count of fields in address */
1309 unsigned ipval
; /* Value */
1310 const char *maskval
, /* Pointer to start of mask value */
1311 *ptr
, /* Pointer into value */
1316 * Get the address...
1319 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1320 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1322 if ((maskval
= strchr(value
, '/')) != NULL
)
1325 maskval
= value
+ strlen(value
);
1329 * Check for an IPv6 address...
1335 * Parse hexadecimal IPv6 address...
1340 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1344 else if (!strncmp(ptr
, "::", 2))
1346 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1348 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1353 else if (isxdigit(*ptr
& 255))
1355 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1363 ip
[i
/ 2] |= ipval
<< 16;
1377 if (*ptr
&& *ptr
!= '/')
1381 #endif /* AF_INET6 */
1384 * Parse dotted-decimal IPv4 address...
1387 unsigned val
[4]; /* IPv4 address values */
1391 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1394 * Range check the IP numbers...
1397 for (i
= 0; i
< ipcount
; i
++)
1402 * Make sure the trailing values are zeroed, as some C libraries like
1403 * glibc apparently like to fill the unused arguments with garbage...
1406 for (i
= ipcount
; i
< 4; i
++)
1410 * Merge everything into a 32-bit IPv4 address in ip[3]...
1413 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1416 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1422 * Get the netmask value(s)...
1425 memset(mask
, 0, sizeof(unsigned) * 4);
1427 if (strchr(maskval
, '.'))
1430 * Get dotted-decimal mask...
1433 if (family
!= AF_INET
)
1436 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1439 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1440 mask
[0] = mask
[1] = mask
[2] = 0;
1445 * Get address/bits format...
1451 if (family
== AF_INET6
)
1459 mask
[0] = 0xffffffff;
1461 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1464 mask
[1] = 0xffffffff;
1468 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1471 mask
[2] = 0xffffffff;
1475 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1478 mask
[3] = 0xffffffff;
1482 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1485 #endif /* AF_INET6 */
1490 mask
[0] = 0xffffffff;
1491 mask
[1] = 0xffffffff;
1492 mask
[2] = 0xffffffff;
1495 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1497 mask
[3] = 0xffffffff;
1502 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1503 "get_addr_and_mask(value=\"%s\", "
1504 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1505 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1509 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1512 if ((ip
[0] & ~mask
[0]) != 0 ||
1513 (ip
[1] & ~mask
[1]) != 0 ||
1514 (ip
[2] & ~mask
[2]) != 0 ||
1515 (ip
[3] & ~mask
[3]) != 0)
1523 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1526 static int /* O - 1 on success, 0 on failure */
1527 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1528 char *line
, /* I - Line from file */
1529 char *value
, /* I - Start of value data */
1530 int linenum
) /* I - Current line number */
1532 char *valptr
; /* Pointer into value */
1533 unsigned ip
[4], /* IP address components */
1534 mask
[4]; /* IP netmask components */
1537 if (!strcasecmp(line
, "Encryption"))
1540 * "Encryption xxx" - set required encryption level...
1543 if (!strcasecmp(value
, "never"))
1544 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1545 else if (!strcasecmp(value
, "always"))
1547 cupsdLogMessage(CUPSD_LOG_ERROR
,
1548 "Encryption value \"%s\" on line %d is invalid in this "
1549 "context. Using \"required\" instead.", value
, linenum
);
1551 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1553 else if (!strcasecmp(value
, "required"))
1554 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1555 else if (!strcasecmp(value
, "ifrequested"))
1556 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1559 cupsdLogMessage(CUPSD_LOG_ERROR
,
1560 "Unknown Encryption value %s on line %d.", value
, linenum
);
1564 else if (!strcasecmp(line
, "Order"))
1567 * "Order Deny,Allow" or "Order Allow,Deny"...
1570 if (!strncasecmp(value
, "deny", 4))
1571 loc
->order_type
= AUTH_ALLOW
;
1572 else if (!strncasecmp(value
, "allow", 5))
1573 loc
->order_type
= AUTH_DENY
;
1576 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1581 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1584 * Allow [From] host/ip...
1585 * Deny [From] host/ip...
1588 if (!strncasecmp(value
, "from", 4))
1591 * Strip leading "from"...
1596 while (isspace(*value
& 255))
1601 * Figure out what form the allow/deny address takes:
1612 * nnn.nnn.nnn.nnn/mm
1613 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1616 if (!strcasecmp(value
, "all"))
1622 if (!strcasecmp(line
, "Allow"))
1623 cupsdAllowIP(loc
, zeros
, zeros
);
1625 cupsdDenyIP(loc
, zeros
, zeros
);
1627 else if (!strcasecmp(value
, "none"))
1633 if (!strcasecmp(line
, "Allow"))
1634 cupsdAllowIP(loc
, ones
, zeros
);
1636 cupsdDenyIP(loc
, ones
, zeros
);
1639 else if (value
[0] == '*' || value
[0] == '.' ||
1640 (!isdigit(value
[0] & 255) && value
[0] != '['))
1642 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1643 #endif /* AF_INET6 */
1646 * Host or domain name...
1649 if (value
[0] == '*')
1652 if (!strcasecmp(line
, "Allow"))
1653 cupsdAllowHost(loc
, value
);
1655 cupsdDenyHost(loc
, value
);
1660 * One of many IP address forms...
1663 if (!get_addr_and_mask(value
, ip
, mask
))
1665 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1670 if (!strcasecmp(line
, "Allow"))
1671 cupsdAllowIP(loc
, ip
, mask
);
1673 cupsdDenyIP(loc
, ip
, mask
);
1676 else if (!strcasecmp(line
, "AuthType"))
1679 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1682 if (!strcasecmp(value
, "none"))
1684 loc
->type
= AUTH_NONE
;
1685 loc
->level
= AUTH_ANON
;
1687 else if (!strcasecmp(value
, "basic"))
1689 loc
->type
= AUTH_BASIC
;
1691 if (loc
->level
== AUTH_ANON
)
1692 loc
->level
= AUTH_USER
;
1694 else if (!strcasecmp(value
, "digest"))
1696 loc
->type
= AUTH_DIGEST
;
1698 if (loc
->level
== AUTH_ANON
)
1699 loc
->level
= AUTH_USER
;
1701 else if (!strcasecmp(value
, "basicdigest"))
1703 loc
->type
= AUTH_BASICDIGEST
;
1705 if (loc
->level
== AUTH_ANON
)
1706 loc
->level
= AUTH_USER
;
1708 else if (!strcasecmp(value
, "default"))
1710 loc
->type
= AUTH_DEFAULT
;
1712 if (loc
->level
== AUTH_ANON
)
1713 loc
->level
= AUTH_USER
;
1716 else if (!strcasecmp(value
, "negotiate"))
1718 loc
->type
= AUTH_NEGOTIATE
;
1720 if (loc
->level
== AUTH_ANON
)
1721 loc
->level
= AUTH_USER
;
1723 #endif /* HAVE_GSSAPI */
1726 cupsdLogMessage(CUPSD_LOG_WARN
,
1727 "Unknown authorization type %s on line %d.",
1732 else if (!strcasecmp(line
, "AuthClass"))
1735 * AuthClass anonymous, user, system, group
1738 if (!strcasecmp(value
, "anonymous"))
1740 loc
->type
= AUTH_NONE
;
1741 loc
->level
= AUTH_ANON
;
1743 cupsdLogMessage(CUPSD_LOG_WARN
,
1744 "\"AuthClass %s\" is deprecated; consider removing "
1748 else if (!strcasecmp(value
, "user"))
1750 loc
->level
= AUTH_USER
;
1752 cupsdLogMessage(CUPSD_LOG_WARN
,
1753 "\"AuthClass %s\" is deprecated; consider using "
1754 "\"Require valid-user\" on line %d.",
1757 else if (!strcasecmp(value
, "group"))
1759 loc
->level
= AUTH_GROUP
;
1761 cupsdLogMessage(CUPSD_LOG_WARN
,
1762 "\"AuthClass %s\" is deprecated; consider using "
1763 "\"Require user @groupname\" on line %d.",
1766 else if (!strcasecmp(value
, "system"))
1768 loc
->level
= AUTH_GROUP
;
1770 cupsdAddName(loc
, "@SYSTEM");
1772 cupsdLogMessage(CUPSD_LOG_WARN
,
1773 "\"AuthClass %s\" is deprecated; consider using "
1774 "\"Require user @SYSTEM\" on line %d.",
1779 cupsdLogMessage(CUPSD_LOG_WARN
,
1780 "Unknown authorization class %s on line %d.",
1785 else if (!strcasecmp(line
, "AuthGroupName"))
1787 cupsdAddName(loc
, value
);
1789 cupsdLogMessage(CUPSD_LOG_WARN
,
1790 "\"AuthGroupName %s\" directive is deprecated; consider "
1791 "using \"Require user @%s\" on line %d.",
1792 value
, value
, linenum
);
1794 else if (!strcasecmp(line
, "Require"))
1797 * Apache synonym for AuthClass and AuthGroupName...
1801 * Require valid-user
1802 * Require group names
1803 * Require user names
1806 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1811 if (!strcasecmp(value
, "valid-user") ||
1812 !strcasecmp(value
, "user"))
1813 loc
->level
= AUTH_USER
;
1814 else if (!strcasecmp(value
, "group"))
1815 loc
->level
= AUTH_GROUP
;
1818 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1824 * Get the list of names from the line...
1827 for (value
= valptr
; *value
;)
1829 while (isspace(*value
& 255))
1832 #ifdef HAVE_AUTHORIZATION_H
1833 if (!strncmp(value
, "@AUTHKEY(", 9))
1836 * Grab "@AUTHKEY(name)" value...
1839 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1845 #endif /* HAVE_AUTHORIZATION_H */
1846 if (*value
== '\"' || *value
== '\'')
1849 * Grab quoted name...
1852 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1859 * Grab literal name.
1862 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1868 cupsdAddName(loc
, value
);
1870 for (value
= valptr
; isspace(*value
& 255); value
++);
1873 else if (!strcasecmp(line
, "Satisfy"))
1875 if (!strcasecmp(value
, "all"))
1876 loc
->satisfy
= AUTH_SATISFY_ALL
;
1877 else if (!strcasecmp(value
, "any"))
1878 loc
->satisfy
= AUTH_SATISFY_ANY
;
1881 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1894 * 'parse_groups()' - Parse system group names in a string.
1897 static int /* O - 1 on success, 0 on failure */
1898 parse_groups(const char *s
) /* I - Space-delimited groups */
1900 int status
; /* Return status */
1901 char value
[1024], /* Value string */
1902 *valstart
, /* Pointer into value */
1903 *valend
, /* End of value */
1904 quote
; /* Quote character */
1905 struct group
*group
; /* Group */
1909 * Make a copy of the string and parse out the groups...
1912 strlcpy(value
, s
, sizeof(value
));
1917 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1919 if (*valstart
== '\'' || *valstart
== '\"')
1922 * Scan quoted name...
1925 quote
= *valstart
++;
1927 for (valend
= valstart
; *valend
; valend
++)
1928 if (*valend
== quote
)
1934 * Scan space or comma-delimited name...
1937 for (valend
= valstart
; *valend
; valend
++)
1938 if (isspace(*valend
) || *valend
== ',')
1945 group
= getgrnam(valstart
);
1948 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1949 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1960 while (*valstart
== ',' || isspace(*valstart
))
1969 * 'parse_protocols()' - Parse browse protocols in a string.
1972 static int /* O - Browse protocol bits */
1973 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1975 int protocols
; /* Browse protocol bits */
1976 char value
[1024], /* Value string */
1977 *valstart
, /* Pointer into value */
1978 *valend
; /* End of value */
1982 * Empty protocol line yields NULL pointer...
1989 * Loop through the value string,...
1992 strlcpy(value
, s
, sizeof(value
));
1996 for (valstart
= value
; *valstart
;)
1999 * Get the current space/comma-delimited protocol name...
2002 for (valend
= valstart
; *valend
; valend
++)
2003 if (isspace(*valend
& 255) || *valend
== ',')
2010 * Add the protocol to the bitmask...
2013 if (!strcasecmp(valstart
, "cups"))
2014 protocols
|= BROWSE_CUPS
;
2015 else if (!strcasecmp(valstart
, "slp"))
2016 protocols
|= BROWSE_SLP
;
2017 else if (!strcasecmp(valstart
, "ldap"))
2018 protocols
|= BROWSE_LDAP
;
2019 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
2020 protocols
|= BROWSE_DNSSD
;
2021 else if (!strcasecmp(valstart
, "all"))
2022 protocols
|= BROWSE_ALL
;
2023 else if (strcasecmp(valstart
, "none"))
2026 for (valstart
= valend
; *valstart
; valstart
++)
2027 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2036 * 'read_configuration()' - Read a configuration file.
2039 static int /* O - 1 on success, 0 on failure */
2040 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2042 int i
; /* Looping var */
2043 int linenum
; /* Current line number */
2044 char line
[HTTP_MAX_BUFFER
],
2045 /* Line from file */
2046 temp
[HTTP_MAX_BUFFER
],
2047 /* Temporary buffer for value */
2048 temp2
[HTTP_MAX_BUFFER
],
2049 /* Temporary buffer 2 for value */
2050 *ptr
, /* Pointer into line/temp */
2051 *value
, /* Pointer to value */
2052 *valueptr
; /* Pointer into value */
2053 int valuelen
; /* Length of value */
2054 cupsd_var_t
*var
; /* Current variable */
2055 http_addrlist_t
*addrlist
, /* Address list */
2056 *addr
; /* Current address */
2057 unsigned ip
[4], /* Address value */
2058 mask
[4]; /* Netmask value */
2059 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2060 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2061 cupsd_location_t
*location
; /* Browse location */
2062 cups_file_t
*incfile
; /* Include file */
2063 char incname
[1024]; /* Include filename */
2064 struct group
*group
; /* Group */
2068 * Loop through each line in the file...
2073 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2076 * Decode the directive...
2079 if (!strcasecmp(line
, "Include"))
2085 if (value
[0] == '/')
2086 strlcpy(incname
, value
, sizeof(incname
));
2088 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2090 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2091 cupsdLogMessage(CUPSD_LOG_ERROR
,
2092 "Unable to include config file \"%s\" - %s",
2093 incname
, strerror(errno
));
2096 read_configuration(incfile
);
2097 cupsFileClose(incfile
);
2100 else if (!strcasecmp(line
, "<Location"))
2108 linenum
= read_location(fp
, value
, linenum
);
2114 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2119 else if (!strcasecmp(line
, "<Policy"))
2127 linenum
= read_policy(fp
, value
, linenum
);
2133 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2137 else if (!strcasecmp(line
, "FaxRetryInterval"))
2141 JobRetryInterval
= atoi(value
);
2142 cupsdLogMessage(CUPSD_LOG_WARN
,
2143 "FaxRetryInterval is deprecated; use "
2144 "JobRetryInterval on line %d.", linenum
);
2148 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2152 else if (!strcasecmp(line
, "FaxRetryLimit"))
2156 JobRetryLimit
= atoi(value
);
2157 cupsdLogMessage(CUPSD_LOG_WARN
,
2158 "FaxRetryLimit is deprecated; use "
2159 "JobRetryLimit on line %d.", linenum
);
2163 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2167 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2169 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2170 #endif /* HAVE_SSL */
2174 * Add listening address(es) to the list...
2177 cupsd_listener_t
*lis
; /* New listeners array */
2181 * Get the address list...
2184 addrlist
= get_address(value
, IPP_PORT
);
2188 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2194 * Add each address...
2197 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2200 * Allocate another listener...
2204 Listeners
= cupsArrayNew(NULL
, NULL
);
2208 cupsdLogMessage(CUPSD_LOG_ERROR
,
2209 "Unable to allocate %s at line %d - %s.",
2210 line
, linenum
, strerror(errno
));
2214 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2216 cupsdLogMessage(CUPSD_LOG_ERROR
,
2217 "Unable to allocate %s at line %d - %s.",
2218 line
, linenum
, strerror(errno
));
2222 cupsArrayAdd(Listeners
, lis
);
2225 * Copy the current address and log it...
2228 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2232 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2233 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2234 #endif /* HAVE_SSL */
2236 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2239 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2240 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2241 ntohs(lis
->address
.ipv6
.sin6_port
));
2243 #endif /* AF_INET6 */
2245 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2246 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2248 #endif /* AF_LOCAL */
2249 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2250 ntohs(lis
->address
.ipv4
.sin_port
));
2257 httpAddrFreeList(addrlist
);
2259 else if (!strcasecmp(line
, "BrowseAddress"))
2262 * Add a browse address to the list...
2265 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2268 if (NumBrowsers
== 0)
2269 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2271 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2275 cupsdLogMessage(CUPSD_LOG_ERROR
,
2276 "Unable to allocate BrowseAddress at line %d - %s.",
2277 linenum
, strerror(errno
));
2282 dira
+= NumBrowsers
;
2284 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2286 if (!strcasecmp(value
, "@LOCAL"))
2289 * Send browse data to all local interfaces...
2292 strcpy(dira
->iface
, "*");
2295 else if (!strncasecmp(value
, "@IF(", 4))
2298 * Send browse data to the named interface...
2301 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2303 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2309 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2312 * Only IPv4 addresses are supported...
2315 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2316 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2321 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2322 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2324 cupsdLogMessage(CUPSD_LOG_INFO
,
2325 "Sending browsing info to %s:%d (IPv4)",
2326 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2331 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2334 httpAddrFreeList(addrlist
);
2337 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2340 else if (!strcasecmp(line
, "BrowseOrder"))
2343 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2346 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2347 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2349 if (location
== NULL
)
2350 cupsdLogMessage(CUPSD_LOG_ERROR
,
2351 "Unable to initialize browse access control list!");
2352 else if (!strncasecmp(value
, "deny", 4))
2353 location
->order_type
= AUTH_ALLOW
;
2354 else if (!strncasecmp(value
, "allow", 5))
2355 location
->order_type
= AUTH_DENY
;
2357 cupsdLogMessage(CUPSD_LOG_ERROR
,
2358 "Unknown BrowseOrder value %s on line %d.",
2361 else if (!strcasecmp(line
, "BrowseProtocols") ||
2362 !strcasecmp(line
, "BrowseLocalProtocols") ||
2363 !strcasecmp(line
, "BrowseRemoteProtocols"))
2366 * "BrowseProtocols name [... name]"
2367 * "BrowseLocalProtocols name [... name]"
2368 * "BrowseRemoteProtocols name [... name]"
2371 int protocols
= parse_protocols(value
);
2375 cupsdLogMessage(CUPSD_LOG_ERROR
,
2376 "Unknown browse protocol \"%s\" on line %d.",
2381 if (strcasecmp(line
, "BrowseLocalProtocols"))
2382 BrowseRemoteProtocols
= protocols
;
2383 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2384 BrowseLocalProtocols
= protocols
;
2386 else if (!strcasecmp(line
, "BrowseAllow") ||
2387 !strcasecmp(line
, "BrowseDeny"))
2390 * BrowseAllow [From] host/ip...
2391 * BrowseDeny [From] host/ip...
2394 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2395 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2397 if (location
== NULL
)
2398 cupsdLogMessage(CUPSD_LOG_ERROR
,
2399 "Unable to initialize browse access control list!");
2402 if (!strncasecmp(value
, "from ", 5))
2405 * Strip leading "from"...
2410 while (isspace(*value
))
2415 * Figure out what form the allow/deny address takes:
2426 * nnn.nnn.nnn.nnn/mm
2427 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2430 if (!strcasecmp(value
, "all"))
2436 if (!strcasecmp(line
, "BrowseAllow"))
2437 cupsdAllowIP(location
, zeros
, zeros
);
2439 cupsdDenyIP(location
, zeros
, zeros
);
2441 else if (!strcasecmp(value
, "none"))
2447 if (!strcasecmp(line
, "BrowseAllow"))
2448 cupsdAllowIP(location
, ones
, zeros
);
2450 cupsdDenyIP(location
, ones
, zeros
);
2453 else if (value
[0] == '*' || value
[0] == '.' ||
2454 (!isdigit(value
[0] & 255) && value
[0] != '['))
2456 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2457 #endif /* AF_INET6 */
2460 * Host or domain name...
2463 if (value
[0] == '*')
2466 if (!strcasecmp(line
, "BrowseAllow"))
2467 cupsdAllowHost(location
, value
);
2469 cupsdDenyHost(location
, value
);
2474 * One of many IP address forms...
2477 if (!get_addr_and_mask(value
, ip
, mask
))
2479 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2484 if (!strcasecmp(line
, "BrowseAllow"))
2485 cupsdAllowIP(location
, ip
, mask
);
2487 cupsdDenyIP(location
, ip
, mask
);
2491 else if (!strcasecmp(line
, "BrowseRelay"))
2494 * BrowseRelay [from] source [to] destination
2498 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2500 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2504 cupsdLogMessage(CUPSD_LOG_ERROR
,
2505 "Unable to allocate BrowseRelay at line %d - %s.",
2506 linenum
, strerror(errno
));
2513 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2515 if (!strncasecmp(value
, "from ", 5))
2518 * Strip leading "from"...
2523 while (isspace(*value
))
2528 * Figure out what form the from address takes:
2537 * nnn.nnn.nnn.nnn/mm
2538 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2542 if (value
[0] == '*' || value
[0] == '.' ||
2543 (!isdigit(value
[0] & 255) && value
[0] != '['))
2545 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2546 #endif /* AF_INET6 */
2549 * Host or domain name...
2552 if (value
[0] == '*')
2555 strlcpy(temp
, value
, sizeof(temp
));
2556 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2559 relay
->from
.type
= AUTH_NAME
;
2560 relay
->from
.mask
.name
.name
= strdup(temp
);
2561 relay
->from
.mask
.name
.length
= strlen(temp
);
2566 * One of many IP address forms...
2569 if (!get_addr_and_mask(value
, ip
, mask
))
2571 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2576 relay
->from
.type
= AUTH_IP
;
2577 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2578 sizeof(relay
->from
.mask
.ip
.address
));
2579 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2580 sizeof(relay
->from
.mask
.ip
.netmask
));
2584 * Skip value and trailing whitespace...
2587 for (; *value
; value
++)
2588 if (isspace(*value
))
2591 while (isspace(*value
))
2594 if (!strncasecmp(value
, "to ", 3))
2597 * Strip leading "to"...
2602 while (isspace(*value
))
2607 * Get "to" address and port...
2610 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2613 * Only IPv4 addresses are supported...
2616 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2617 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2622 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2624 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2626 if (relay
->from
.type
== AUTH_IP
)
2627 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2628 relay
->from
.mask
.ip
.address
[0] >> 24,
2629 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2630 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2631 relay
->from
.mask
.ip
.address
[0] & 255,
2632 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2633 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2634 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2635 relay
->from
.mask
.ip
.netmask
[0] & 255);
2637 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2639 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2640 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2645 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2648 httpAddrFreeList(addrlist
);
2652 if (relay
->from
.type
== AUTH_NAME
)
2653 free(relay
->from
.mask
.name
.name
);
2655 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2659 else if (!strcasecmp(line
, "BrowsePoll"))
2662 * BrowsePoll address[:port]
2665 char *portname
; /* Port name */
2666 int portnum
; /* Port number */
2667 struct servent
*service
; /* Service */
2671 * Extract the port name from the address...
2674 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2678 if (isdigit(*portname
& 255))
2679 portnum
= atoi(portname
);
2680 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2681 portnum
= ntohs(service
->s_port
);
2684 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2690 portnum
= ippPort();
2693 * Add the poll entry...
2697 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2699 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2703 cupsdLogMessage(CUPSD_LOG_ERROR
,
2704 "Unable to allocate BrowsePoll at line %d - %s.",
2705 linenum
, strerror(errno
));
2713 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2715 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2716 pollp
->port
= portnum
;
2718 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2721 else if (!strcasecmp(line
, "DefaultAuthType"))
2724 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2727 if (!strcasecmp(value
, "none"))
2728 DefaultAuthType
= AUTH_NONE
;
2729 else if (!strcasecmp(value
, "basic"))
2730 DefaultAuthType
= AUTH_BASIC
;
2731 else if (!strcasecmp(value
, "digest"))
2732 DefaultAuthType
= AUTH_DIGEST
;
2733 else if (!strcasecmp(value
, "basicdigest"))
2734 DefaultAuthType
= AUTH_BASICDIGEST
;
2736 else if (!strcasecmp(value
, "negotiate"))
2737 DefaultAuthType
= AUTH_NEGOTIATE
;
2738 #endif /* HAVE_GSSAPI */
2741 cupsdLogMessage(CUPSD_LOG_WARN
,
2742 "Unknown default authorization type %s on line %d.",
2748 else if (!strcasecmp(line
, "DefaultEncryption"))
2751 * DefaultEncryption {Never,IfRequested,Required}
2754 if (!value
|| !strcasecmp(value
, "never"))
2755 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2756 else if (!strcasecmp(value
, "required"))
2757 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2758 else if (!strcasecmp(value
, "ifrequested"))
2759 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2762 cupsdLogMessage(CUPSD_LOG_WARN
,
2763 "Unknown default encryption %s on line %d.",
2768 #endif /* HAVE_SSL */
2770 else if (!strcasecmp(line
, "Krb5Keytab"))
2772 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2775 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2776 gsskrb5_register_acceptor_identity(value
);
2778 cupsdSetEnv("KRB5_KTNAME", value
);
2779 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2781 #endif /* HAVE_GSSAPI */
2782 else if (!strcasecmp(line
, "User"))
2785 * User ID to run as...
2788 if (value
&& isdigit(value
[0] & 255))
2790 int uid
= atoi(value
);
2793 cupsdLogMessage(CUPSD_LOG_ERROR
,
2794 "Will not use User 0 as specified on line %d "
2795 "for security reasons. You must use a non-"
2796 "privileged account instead.",
2803 struct passwd
*p
; /* Password information */
2806 p
= getpwnam(value
);
2811 cupsdLogMessage(CUPSD_LOG_ERROR
,
2812 "Will not use User %s (UID=0) as specified on line "
2813 "%d for security reasons. You must use a non-"
2814 "privileged account instead.",
2820 cupsdLogMessage(CUPSD_LOG_ERROR
,
2821 "Unknown User \"%s\" on line %d, ignoring!",
2825 cupsdLogMessage(CUPSD_LOG_ERROR
,
2826 "User directive on line %d missing the username!",
2829 else if (!strcasecmp(line
, "Group"))
2832 * Group ID to run as...
2835 if (isdigit(value
[0]))
2836 Group
= atoi(value
);
2840 group
= getgrnam(value
);
2843 Group
= group
->gr_gid
;
2845 cupsdLogMessage(CUPSD_LOG_ERROR
,
2846 "Unknown Group \"%s\" on line %d, ignoring!",
2850 else if (!strcasecmp(line
, "SystemGroup"))
2853 * SystemGroup (admin) group(s)...
2856 if (!parse_groups(value
))
2857 cupsdLogMessage(CUPSD_LOG_ERROR
,
2858 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2861 else if (!strcasecmp(line
, "HostNameLookups"))
2864 * Do hostname lookups?
2867 if (!strcasecmp(value
, "off"))
2868 HostNameLookups
= 0;
2869 else if (!strcasecmp(value
, "on"))
2870 HostNameLookups
= 1;
2871 else if (!strcasecmp(value
, "double"))
2872 HostNameLookups
= 2;
2874 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2877 else if (!strcasecmp(line
, "LogLevel"))
2880 * Amount of logging to do...
2883 if (!strcasecmp(value
, "debug2"))
2884 LogLevel
= CUPSD_LOG_DEBUG2
;
2885 else if (!strcasecmp(value
, "debug"))
2886 LogLevel
= CUPSD_LOG_DEBUG
;
2887 else if (!strcasecmp(value
, "info"))
2888 LogLevel
= CUPSD_LOG_INFO
;
2889 else if (!strcasecmp(value
, "notice"))
2890 LogLevel
= CUPSD_LOG_NOTICE
;
2891 else if (!strcasecmp(value
, "warn"))
2892 LogLevel
= CUPSD_LOG_WARN
;
2893 else if (!strcasecmp(value
, "error"))
2894 LogLevel
= CUPSD_LOG_ERROR
;
2895 else if (!strcasecmp(value
, "crit"))
2896 LogLevel
= CUPSD_LOG_CRIT
;
2897 else if (!strcasecmp(value
, "alert"))
2898 LogLevel
= CUPSD_LOG_ALERT
;
2899 else if (!strcasecmp(value
, "emerg"))
2900 LogLevel
= CUPSD_LOG_EMERG
;
2901 else if (!strcasecmp(value
, "none"))
2902 LogLevel
= CUPSD_LOG_NONE
;
2904 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2907 else if (!strcasecmp(line
, "PrintcapFormat"))
2910 * Format of printcap file?
2913 if (!strcasecmp(value
, "bsd"))
2914 PrintcapFormat
= PRINTCAP_BSD
;
2915 else if (!strcasecmp(value
, "solaris"))
2916 PrintcapFormat
= PRINTCAP_SOLARIS
;
2918 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2921 else if (!strcasecmp(line
, "ServerTokens"))
2924 * Set the string used for the Server header...
2927 struct utsname plat
; /* Platform info */
2932 if (!strcasecmp(value
, "ProductOnly"))
2933 cupsdSetString(&ServerHeader
, "CUPS");
2934 else if (!strcasecmp(value
, "Major"))
2935 cupsdSetString(&ServerHeader
, "CUPS/1");
2936 else if (!strcasecmp(value
, "Minor"))
2937 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2938 else if (!strcasecmp(value
, "Minimal"))
2939 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2940 else if (!strcasecmp(value
, "OS"))
2941 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2942 else if (!strcasecmp(value
, "Full"))
2943 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2945 else if (!strcasecmp(value
, "None"))
2946 cupsdClearString(&ServerHeader
);
2948 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2951 else if (!strcasecmp(line
, "PassEnv"))
2954 * PassEnv variable [... variable]
2959 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2960 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2963 if (value
[valuelen
])
2965 value
[valuelen
] = '\0';
2969 cupsdSetEnv(value
, NULL
);
2971 for (value
+= valuelen
; *value
; value
++)
2972 if (!isspace(*value
) || *value
!= ',')
2976 else if (!strcasecmp(line
, "SetEnv"))
2979 * SetEnv variable value
2982 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2990 while (isspace(*valueptr
& 255))
2993 cupsdSetEnv(value
, valueptr
);
2996 cupsdLogMessage(CUPSD_LOG_ERROR
,
2997 "Missing value for SetEnv directive on line %d.",
3003 * Find a simple variable in the list...
3006 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3007 if (!strcasecmp(line
, var
->name
))
3013 * Unknown directive! Output an error message and continue...
3016 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3023 case CUPSD_VARTYPE_INTEGER
:
3025 cupsdLogMessage(CUPSD_LOG_ERROR
,
3026 "Missing integer value for %s on line %d!",
3031 char *units
; /* Units */
3034 n
= strtol(value
, &units
, 0);
3036 if (units
&& *units
)
3038 if (tolower(units
[0] & 255) == 'g')
3039 n
*= 1024 * 1024 * 1024;
3040 else if (tolower(units
[0] & 255) == 'm')
3042 else if (tolower(units
[0] & 255) == 'k')
3044 else if (tolower(units
[0] & 255) == 't')
3049 cupsdLogMessage(CUPSD_LOG_ERROR
,
3050 "Bad negative integer value for %s on line %d!",
3053 *((int *)var
->ptr
) = n
;
3057 case CUPSD_VARTYPE_BOOLEAN
:
3059 cupsdLogMessage(CUPSD_LOG_ERROR
,
3060 "Missing boolean value for %s on line %d!",
3062 else if (!strcasecmp(value
, "true") ||
3063 !strcasecmp(value
, "on") ||
3064 !strcasecmp(value
, "enabled") ||
3065 !strcasecmp(value
, "yes") ||
3067 *((int *)var
->ptr
) = TRUE
;
3068 else if (!strcasecmp(value
, "false") ||
3069 !strcasecmp(value
, "off") ||
3070 !strcasecmp(value
, "disabled") ||
3071 !strcasecmp(value
, "no") ||
3072 !strcasecmp(value
, "0"))
3073 *((int *)var
->ptr
) = FALSE
;
3075 cupsdLogMessage(CUPSD_LOG_ERROR
,
3076 "Unknown boolean value %s on line %d.",
3080 case CUPSD_VARTYPE_PATHNAME
:
3081 if (value
[0] == '/')
3082 strlcpy(temp
, value
, sizeof(temp
));
3084 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3086 if (access(temp
, 0))
3088 cupsdLogMessage(CUPSD_LOG_ERROR
,
3089 "File or directory for \"%s %s\" on line %d "
3090 "does not exist!", line
, value
, linenum
);
3094 case CUPSD_VARTYPE_STRING
:
3095 cupsdSetString((char **)var
->ptr
, value
);
3106 * 'read_location()' - Read a <Location path> definition.
3109 static int /* O - New line number or 0 on error */
3110 read_location(cups_file_t
*fp
, /* I - Configuration file */
3111 char *location
, /* I - Location name/path */
3112 int linenum
) /* I - Current line number */
3114 cupsd_location_t
*loc
, /* New location */
3115 *parent
; /* Parent location */
3116 char line
[HTTP_MAX_BUFFER
],
3118 *value
, /* Value for directive */
3119 *valptr
; /* Pointer into value */
3122 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3125 parent
->limit
= AUTH_LIMIT_ALL
;
3128 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3131 * Decode the directive...
3134 if (!strcasecmp(line
, "</Location>"))
3136 else if (!strcasecmp(line
, "<Limit") ||
3137 !strcasecmp(line
, "<LimitExcept"))
3141 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3145 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3151 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3156 if (!strcmp(value
, "ALL"))
3157 loc
->limit
= AUTH_LIMIT_ALL
;
3158 else if (!strcmp(value
, "GET"))
3159 loc
->limit
|= AUTH_LIMIT_GET
;
3160 else if (!strcmp(value
, "HEAD"))
3161 loc
->limit
|= AUTH_LIMIT_HEAD
;
3162 else if (!strcmp(value
, "OPTIONS"))
3163 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3164 else if (!strcmp(value
, "POST"))
3165 loc
->limit
|= AUTH_LIMIT_POST
;
3166 else if (!strcmp(value
, "PUT"))
3167 loc
->limit
|= AUTH_LIMIT_PUT
;
3168 else if (!strcmp(value
, "TRACE"))
3169 loc
->limit
|= AUTH_LIMIT_TRACE
;
3171 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3174 for (value
= valptr
; isspace(*value
& 255); value
++);
3177 if (!strcasecmp(line
, "<LimitExcept"))
3178 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3180 parent
->limit
&= ~loc
->limit
;
3182 else if (!strcasecmp(line
, "</Limit>"))
3184 else if (!parse_aaa(loc
, line
, value
, linenum
))
3186 cupsdLogMessage(CUPSD_LOG_ERROR
,
3187 "Unknown Location directive %s on line %d.",
3193 cupsdLogMessage(CUPSD_LOG_ERROR
,
3194 "Unexpected end-of-file at line %d while reading location!",
3202 * 'read_policy()' - Read a <Policy name> definition.
3205 static int /* O - New line number or 0 on error */
3206 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3207 char *policy
, /* I - Location name/path */
3208 int linenum
) /* I - Current line number */
3210 int i
; /* Looping var */
3211 cupsd_policy_t
*pol
; /* Policy */
3212 cupsd_location_t
*op
; /* Policy operation */
3213 int num_ops
; /* Number of IPP operations */
3214 ipp_op_t ops
[100]; /* Operations */
3215 char line
[HTTP_MAX_BUFFER
],
3217 *value
, /* Value for directive */
3218 *valptr
; /* Pointer into value */
3222 * Create the policy...
3225 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3229 * Read from the file...
3235 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3238 * Decode the directive...
3241 if (!strcasecmp(line
, "</Policy>"))
3244 cupsdLogMessage(CUPSD_LOG_WARN
,
3245 "Missing </Limit> before </Policy> on line %d!",
3250 else if (!strcasecmp(line
, "<Limit") && !op
)
3254 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3259 * Scan for IPP operation names...
3266 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3271 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3273 if (!strcasecmp(value
, "All"))
3274 ops
[num_ops
] = IPP_ANY_OPERATION
;
3275 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3276 cupsdLogMessage(CUPSD_LOG_ERROR
,
3277 "Bad IPP operation name \"%s\" on line %d!",
3283 cupsdLogMessage(CUPSD_LOG_ERROR
,
3284 "Too many operations listed on line %d!",
3287 for (value
= valptr
; isspace(*value
& 255); value
++);
3291 * If none are specified, apply the policy to all operations...
3296 ops
[0] = IPP_ANY_OPERATION
;
3301 * Add a new policy for the first operation...
3304 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3306 else if (!strcasecmp(line
, "</Limit>") && op
)
3309 * Finish the current operation limit...
3315 * Copy the policy to the other operations...
3318 for (i
= 1; i
< num_ops
; i
++)
3319 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3326 cupsdLogMessage(CUPSD_LOG_ERROR
,
3327 "Missing <Limit ops> directive before %s on line %d.",
3331 else if (!parse_aaa(op
, line
, value
, linenum
))
3334 cupsdLogMessage(CUPSD_LOG_ERROR
,
3335 "Unknown Policy Limit directive %s on line %d.",
3338 cupsdLogMessage(CUPSD_LOG_ERROR
,
3339 "Unknown Policy directive %s on line %d.",
3346 cupsdLogMessage(CUPSD_LOG_ERROR
,
3347 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3355 * End of "$Id: conf.c 6783 2007-08-10 19:48:57Z mike $".