2 * "$Id: conf.c 6649 2007-07-11 21:46:42Z 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>
44 * Possibly missing network definitions...
48 # define INADDR_NONE 0xffffffff
49 #endif /* !INADDR_NONE */
53 * Configuration variable structure...
58 CUPSD_VARTYPE_INTEGER
, /* Integer option */
59 CUPSD_VARTYPE_STRING
, /* String option */
60 CUPSD_VARTYPE_BOOLEAN
/* Boolean 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_STRING
},
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_STRING
},
158 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
159 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
160 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
161 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
162 #endif /* HAVE_SSL */
163 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
164 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
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_STRING
},
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)
854 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
857 * Clean out the temporary directory...
860 cups_dir_t
*dir
; /* Temporary directory */
861 cups_dentry_t
*dent
; /* Directory entry */
862 char tempfile
[1024]; /* Temporary filename */
865 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
867 cupsdLogMessage(CUPSD_LOG_INFO
,
868 "Cleaning out old temporary files in \"%s\"...", TempDir
);
870 while ((dent
= cupsDirRead(dir
)) != NULL
)
872 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
874 if (unlink(tempfile
))
875 cupsdLogMessage(CUPSD_LOG_ERROR
,
876 "Unable to remove temporary file \"%s\" - %s",
877 tempfile
, strerror(errno
));
879 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
886 cupsdLogMessage(CUPSD_LOG_ERROR
,
887 "Unable to open temporary directory \"%s\" - %s",
888 TempDir
, strerror(errno
));
892 * Setup environment variables...
898 * Check the MaxClients setting, and then allocate memory for it...
901 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
904 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
907 MaxClients
= MaxFDs
/ 3;
910 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
914 * Check the MaxActiveJobs setting; limit to 1/3 the available
915 * file descriptors, since we need a pipe for each job...
918 if (MaxActiveJobs
> (MaxFDs
/ 3))
919 MaxActiveJobs
= MaxFDs
/ 3;
921 if (Classification
&& !strcasecmp(Classification
, "none"))
922 cupsdClearString(&Classification
);
925 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
928 * Update the MaxClientsPerHost value, as needed...
931 if (MaxClientsPerHost
<= 0)
932 MaxClientsPerHost
= MaxClients
;
934 if (MaxClientsPerHost
> MaxClients
)
935 MaxClientsPerHost
= MaxClients
;
937 cupsdLogMessage(CUPSD_LOG_INFO
,
938 "Allowing up to %d client connections per host.",
942 * Make sure that BrowseTimeout is at least twice the interval...
945 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
947 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
951 BrowseTimeout
= BrowseInterval
* 2;
953 BrowseTimeout
= DEFAULT_TIMEOUT
;
955 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
960 * Update the default policy, as needed...
964 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
966 DefaultPolicyPtr
= NULL
;
968 if (!DefaultPolicyPtr
)
970 cupsd_policy_t
*p
; /* New policy */
971 cupsd_location_t
*po
; /* New policy operation */
975 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
978 cupsdSetString(&DefaultPolicy
, "default");
980 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
981 cupsdLogMessage(CUPSD_LOG_INFO
,
982 "Using policy \"default\" as the default!");
985 cupsdLogMessage(CUPSD_LOG_INFO
,
986 "Creating CUPS default administrative policy:");
988 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
990 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
991 cupsdLogMessage(CUPSD_LOG_INFO
,
992 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
993 "Release-Job Restart-Job Purge-Jobs "
994 "Set-Job-Attributes Create-Job-Subscription "
995 "Renew-Subscription Cancel-Subscription "
996 "Get-Notifications Reprocess-Job Cancel-Current-Job "
997 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
998 "CUPS-Authenticate-Job>");
999 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1001 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1002 po
->order_type
= AUTH_ALLOW
;
1003 po
->level
= AUTH_USER
;
1005 cupsdAddName(po
, "@OWNER");
1006 cupsdAddName(po
, "@SYSTEM");
1007 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1009 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1010 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1011 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1012 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1013 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1014 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1015 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1016 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1017 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1018 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1019 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1020 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1021 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1022 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1023 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1024 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1025 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1027 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1029 cupsdLogMessage(CUPSD_LOG_INFO
,
1030 "<Limit Pause-Printer Resume-Printer "
1031 "Set-Printer-Attributes Enable-Printer "
1032 "Disable-Printer Pause-Printer-After-Current-Job "
1033 "Hold-New-Jobs Release-Held-New-Jobs "
1034 "Deactivate-Printer Activate-Printer Restart-Printer "
1035 "Shutdown-Printer Startup-Printer Promote-Job "
1036 "Schedule-Job-After CUPS-Add-Printer "
1037 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1038 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1039 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1040 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1042 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1043 po
->order_type
= AUTH_ALLOW
;
1044 po
->type
= DefaultAuthType
;
1045 po
->level
= AUTH_USER
;
1047 cupsdAddName(po
, "@SYSTEM");
1048 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1050 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1051 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1052 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1053 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1054 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1055 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1056 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1057 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1058 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1059 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1060 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1061 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1062 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1063 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1064 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1065 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1066 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1067 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1068 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1069 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1070 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1072 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1074 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1075 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1077 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1078 po
->order_type
= AUTH_ALLOW
;
1080 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1081 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1085 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1087 for (i
= 0; i
< NumPolicies
; i
++)
1088 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1089 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
1093 * If we are doing a full reload or the server root has changed, flush
1094 * the jobs, printers, etc. and start from scratch...
1097 if (NeedReload
== RELOAD_ALL
||
1098 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1099 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1101 mime_type_t
*type
; /* Current type */
1102 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1103 /* MIME type name */
1106 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1109 * Free all memory...
1112 cupsdDeleteAllSubscriptions();
1114 cupsdDeleteAllClasses();
1115 cupsdDeleteAllPrinters();
1117 DefaultPrinter
= NULL
;
1119 if (MimeDatabase
!= NULL
)
1120 mimeDelete(MimeDatabase
);
1124 for (i
= 0; i
< NumMimeTypes
; i
++)
1125 _cupsStrFree(MimeTypes
[i
]);
1131 * Read the MIME type and conversion database...
1134 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1136 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
1140 cupsdLogMessage(CUPSD_LOG_EMERG
,
1141 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1145 cupsdLogMessage(CUPSD_LOG_INFO
,
1146 "Loaded MIME database from \'%s\': %d types, %d filters...",
1147 ServerRoot
, mimeNumTypes(MimeDatabase
),
1148 mimeNumFilters(MimeDatabase
));
1151 * Create a list of MIME types for the document-format-supported
1155 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1156 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1159 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
1161 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1163 i
++, type
= mimeNextType(MimeDatabase
))
1165 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1167 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1170 if (i
< NumMimeTypes
)
1171 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1173 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1175 mime_filter_t
*filter
; /* Current filter */
1178 for (type
= mimeFirstType(MimeDatabase
);
1180 type
= mimeNextType(MimeDatabase
))
1181 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1182 type
->super
, type
->type
);
1184 for (filter
= mimeFirstFilter(MimeDatabase
);
1186 filter
= mimeNextFilter(MimeDatabase
))
1187 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1188 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1189 filter
->src
->super
, filter
->src
->type
,
1190 filter
->dst
->super
, filter
->dst
->type
,
1191 filter
->cost
, filter
->filter
);
1198 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1199 cupsdLoadBanners(temp
);
1202 * Load printers and classes...
1205 cupsdLoadAllPrinters();
1206 cupsdLoadAllClasses();
1207 cupsdLoadRemoteCache();
1208 cupsdWritePrintcap();
1210 cupsdCreateCommonData();
1213 * Load queued jobs...
1219 * Load subscriptions...
1222 cupsdLoadAllSubscriptions();
1224 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1229 * Not a full reload, so recreate the common printer attributes...
1232 cupsdCreateCommonData();
1235 * Update all printers as needed...
1238 cupsdUpdatePrinters();
1239 cupsdWritePrintcap();
1241 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1245 * Reset the reload state...
1248 NeedReload
= RELOAD_NONE
;
1250 cupsdClearString(&old_serverroot
);
1251 cupsdClearString(&old_requestroot
);
1258 * 'get_address()' - Get an address + port number from a line.
1261 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1262 get_address(const char *value
, /* I - Value string */
1263 int defport
) /* I - Default port */
1265 char buffer
[1024], /* Hostname + port number buffer */
1266 defpname
[255], /* Default port name */
1267 *hostname
, /* Hostname or IP */
1268 *portname
; /* Port number or name */
1269 http_addrlist_t
*addrlist
; /* Address list */
1273 * Check for an empty value...
1278 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1283 * Grab a hostname and port number; if there is no colon and the port name
1284 * is only digits, then we have a port number by itself...
1287 strlcpy(buffer
, value
, sizeof(buffer
));
1289 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1296 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1301 * Use the default port...
1304 sprintf(defpname
, "%d", defport
);
1305 portname
= defpname
;
1311 * The buffer contains just a port number...
1319 if (hostname
&& !strcmp(hostname
, "*"))
1323 * Now lookup the address using httpAddrGetList()...
1326 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1327 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1328 hostname
? hostname
: "(nil)");
1335 * 'get_addr_and_mask()' - Get an IP address and netmask.
1338 static int /* O - 1 on success, 0 on failure */
1339 get_addr_and_mask(const char *value
, /* I - String from config file */
1340 unsigned *ip
, /* O - Address value */
1341 unsigned *mask
) /* O - Mask value */
1343 int i
, j
, /* Looping vars */
1344 family
, /* Address family */
1345 ipcount
; /* Count of fields in address */
1346 unsigned ipval
; /* Value */
1347 const char *maskval
, /* Pointer to start of mask value */
1348 *ptr
, /* Pointer into value */
1353 * Get the address...
1356 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1357 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1359 if ((maskval
= strchr(value
, '/')) != NULL
)
1362 maskval
= value
+ strlen(value
);
1366 * Check for an IPv6 address...
1372 * Parse hexadecimal IPv6 address...
1377 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1381 else if (!strncmp(ptr
, "::", 2))
1383 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1385 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1390 else if (isxdigit(*ptr
& 255))
1392 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1400 ip
[i
/ 2] |= ipval
<< 16;
1414 if (*ptr
&& *ptr
!= '/')
1418 #endif /* AF_INET6 */
1421 * Parse dotted-decimal IPv4 address...
1424 unsigned val
[4]; /* IPv4 address values */
1428 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1431 * Range check the IP numbers...
1434 for (i
= 0; i
< ipcount
; i
++)
1439 * Make sure the trailing values are zeroed, as some C libraries like
1440 * glibc apparently like to fill the unused arguments with garbage...
1443 for (i
= ipcount
; i
< 4; i
++)
1447 * Merge everything into a 32-bit IPv4 address in ip[3]...
1450 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1453 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1459 * Get the netmask value(s)...
1462 memset(mask
, 0, sizeof(unsigned) * 4);
1464 if (strchr(maskval
, '.'))
1467 * Get dotted-decimal mask...
1470 if (family
!= AF_INET
)
1473 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1476 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1477 mask
[0] = mask
[1] = mask
[2] = 0;
1482 * Get address/bits format...
1488 if (family
== AF_INET6
)
1496 mask
[0] = 0xffffffff;
1498 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1501 mask
[1] = 0xffffffff;
1505 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1508 mask
[2] = 0xffffffff;
1512 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1515 mask
[3] = 0xffffffff;
1519 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1522 #endif /* AF_INET6 */
1527 mask
[0] = 0xffffffff;
1528 mask
[1] = 0xffffffff;
1529 mask
[2] = 0xffffffff;
1532 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1534 mask
[3] = 0xffffffff;
1539 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1540 "get_addr_and_mask(value=\"%s\", "
1541 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1542 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1546 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1549 if ((ip
[0] & ~mask
[0]) != 0 ||
1550 (ip
[1] & ~mask
[1]) != 0 ||
1551 (ip
[2] & ~mask
[2]) != 0 ||
1552 (ip
[3] & ~mask
[3]) != 0)
1560 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1563 static int /* O - 1 on success, 0 on failure */
1564 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1565 char *line
, /* I - Line from file */
1566 char *value
, /* I - Start of value data */
1567 int linenum
) /* I - Current line number */
1569 char *valptr
; /* Pointer into value */
1570 unsigned ip
[4], /* IP address components */
1571 mask
[4]; /* IP netmask components */
1574 if (!strcasecmp(line
, "Encryption"))
1577 * "Encryption xxx" - set required encryption level...
1580 if (!strcasecmp(value
, "never"))
1581 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1582 else if (!strcasecmp(value
, "always"))
1584 cupsdLogMessage(CUPSD_LOG_ERROR
,
1585 "Encryption value \"%s\" on line %d is invalid in this "
1586 "context. Using \"required\" instead.", value
, linenum
);
1588 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1590 else if (!strcasecmp(value
, "required"))
1591 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1592 else if (!strcasecmp(value
, "ifrequested"))
1593 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1596 cupsdLogMessage(CUPSD_LOG_ERROR
,
1597 "Unknown Encryption value %s on line %d.", value
, linenum
);
1601 else if (!strcasecmp(line
, "Order"))
1604 * "Order Deny,Allow" or "Order Allow,Deny"...
1607 if (!strncasecmp(value
, "deny", 4))
1608 loc
->order_type
= AUTH_ALLOW
;
1609 else if (!strncasecmp(value
, "allow", 5))
1610 loc
->order_type
= AUTH_DENY
;
1613 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1618 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1621 * Allow [From] host/ip...
1622 * Deny [From] host/ip...
1625 if (!strncasecmp(value
, "from", 4))
1628 * Strip leading "from"...
1633 while (isspace(*value
& 255))
1638 * Figure out what form the allow/deny address takes:
1649 * nnn.nnn.nnn.nnn/mm
1650 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1653 if (!strcasecmp(value
, "all"))
1659 if (!strcasecmp(line
, "Allow"))
1660 cupsdAllowIP(loc
, zeros
, zeros
);
1662 cupsdDenyIP(loc
, zeros
, zeros
);
1664 else if (!strcasecmp(value
, "none"))
1670 if (!strcasecmp(line
, "Allow"))
1671 cupsdAllowIP(loc
, ones
, zeros
);
1673 cupsdDenyIP(loc
, ones
, zeros
);
1676 else if (value
[0] == '*' || value
[0] == '.' ||
1677 (!isdigit(value
[0] & 255) && value
[0] != '['))
1679 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1680 #endif /* AF_INET6 */
1683 * Host or domain name...
1686 if (value
[0] == '*')
1689 if (!strcasecmp(line
, "Allow"))
1690 cupsdAllowHost(loc
, value
);
1692 cupsdDenyHost(loc
, value
);
1697 * One of many IP address forms...
1700 if (!get_addr_and_mask(value
, ip
, mask
))
1702 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1707 if (!strcasecmp(line
, "Allow"))
1708 cupsdAllowIP(loc
, ip
, mask
);
1710 cupsdDenyIP(loc
, ip
, mask
);
1713 else if (!strcasecmp(line
, "AuthType"))
1716 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1719 if (!strcasecmp(value
, "none"))
1721 loc
->type
= AUTH_NONE
;
1722 loc
->level
= AUTH_ANON
;
1724 else if (!strcasecmp(value
, "basic"))
1726 loc
->type
= AUTH_BASIC
;
1728 if (loc
->level
== AUTH_ANON
)
1729 loc
->level
= AUTH_USER
;
1731 else if (!strcasecmp(value
, "digest"))
1733 loc
->type
= AUTH_DIGEST
;
1735 if (loc
->level
== AUTH_ANON
)
1736 loc
->level
= AUTH_USER
;
1738 else if (!strcasecmp(value
, "basicdigest"))
1740 loc
->type
= AUTH_BASICDIGEST
;
1742 if (loc
->level
== AUTH_ANON
)
1743 loc
->level
= AUTH_USER
;
1745 else if (!strcasecmp(value
, "default"))
1747 loc
->type
= DefaultAuthType
;
1749 if (loc
->level
== AUTH_ANON
)
1750 loc
->level
= AUTH_USER
;
1753 else if (!strcasecmp(value
, "negotiate"))
1755 loc
->type
= AUTH_NEGOTIATE
;
1757 if (loc
->level
== AUTH_ANON
)
1758 loc
->level
= AUTH_USER
;
1760 #endif /* HAVE_GSSAPI */
1763 cupsdLogMessage(CUPSD_LOG_WARN
,
1764 "Unknown authorization type %s on line %d.",
1769 else if (!strcasecmp(line
, "AuthClass"))
1772 * AuthClass anonymous, user, system, group
1775 if (!strcasecmp(value
, "anonymous"))
1777 loc
->type
= AUTH_NONE
;
1778 loc
->level
= AUTH_ANON
;
1780 cupsdLogMessage(CUPSD_LOG_WARN
,
1781 "\"AuthClass %s\" is deprecated; consider removing "
1785 else if (!strcasecmp(value
, "user"))
1787 loc
->level
= AUTH_USER
;
1789 cupsdLogMessage(CUPSD_LOG_WARN
,
1790 "\"AuthClass %s\" is deprecated; consider using "
1791 "\"Require valid-user\" on line %d.",
1794 else if (!strcasecmp(value
, "group"))
1796 loc
->level
= AUTH_GROUP
;
1798 cupsdLogMessage(CUPSD_LOG_WARN
,
1799 "\"AuthClass %s\" is deprecated; consider using "
1800 "\"Require user @groupname\" on line %d.",
1803 else if (!strcasecmp(value
, "system"))
1805 loc
->level
= AUTH_GROUP
;
1807 cupsdAddName(loc
, "@SYSTEM");
1809 cupsdLogMessage(CUPSD_LOG_WARN
,
1810 "\"AuthClass %s\" is deprecated; consider using "
1811 "\"Require user @SYSTEM\" on line %d.",
1816 cupsdLogMessage(CUPSD_LOG_WARN
,
1817 "Unknown authorization class %s on line %d.",
1822 else if (!strcasecmp(line
, "AuthGroupName"))
1824 cupsdAddName(loc
, value
);
1826 cupsdLogMessage(CUPSD_LOG_WARN
,
1827 "\"AuthGroupName %s\" directive is deprecated; consider "
1828 "using \"Require user @%s\" on line %d.",
1829 value
, value
, linenum
);
1831 else if (!strcasecmp(line
, "Require"))
1834 * Apache synonym for AuthClass and AuthGroupName...
1838 * Require valid-user
1839 * Require group names
1840 * Require user names
1843 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1848 if (!strcasecmp(value
, "valid-user") ||
1849 !strcasecmp(value
, "user"))
1850 loc
->level
= AUTH_USER
;
1851 else if (!strcasecmp(value
, "group"))
1852 loc
->level
= AUTH_GROUP
;
1855 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1861 * Get the list of names from the line...
1864 for (value
= valptr
; *value
;)
1866 while (isspace(*value
& 255))
1869 #ifdef HAVE_AUTHORIZATION_H
1870 if (!strncmp(value
, "@AUTHKEY(", 9))
1873 * Grab "@AUTHKEY(name)" value...
1876 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1882 #endif /* HAVE_AUTHORIZATION_H */
1883 if (*value
== '\"' || *value
== '\'')
1886 * Grab quoted name...
1889 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1896 * Grab literal name.
1899 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1905 cupsdAddName(loc
, value
);
1907 for (value
= valptr
; isspace(*value
& 255); value
++);
1910 else if (!strcasecmp(line
, "Satisfy"))
1912 if (!strcasecmp(value
, "all"))
1913 loc
->satisfy
= AUTH_SATISFY_ALL
;
1914 else if (!strcasecmp(value
, "any"))
1915 loc
->satisfy
= AUTH_SATISFY_ANY
;
1918 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1931 * 'parse_groups()' - Parse system group names in a string.
1934 static int /* O - 1 on success, 0 on failure */
1935 parse_groups(const char *s
) /* I - Space-delimited groups */
1937 int status
; /* Return status */
1938 char value
[1024], /* Value string */
1939 *valstart
, /* Pointer into value */
1940 *valend
, /* End of value */
1941 quote
; /* Quote character */
1942 struct group
*group
; /* Group */
1946 * Make a copy of the string and parse out the groups...
1949 strlcpy(value
, s
, sizeof(value
));
1954 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1956 if (*valstart
== '\'' || *valstart
== '\"')
1959 * Scan quoted name...
1962 quote
= *valstart
++;
1964 for (valend
= valstart
; *valend
; valend
++)
1965 if (*valend
== quote
)
1971 * Scan space or comma-delimited name...
1974 for (valend
= valstart
; *valend
; valend
++)
1975 if (isspace(*valend
) || *valend
== ',')
1982 group
= getgrnam(valstart
);
1985 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1986 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1997 while (*valstart
== ',' || isspace(*valstart
))
2006 * 'parse_protocols()' - Parse browse protocols in a string.
2009 static int /* O - Browse protocol bits */
2010 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2012 int protocols
; /* Browse protocol bits */
2013 char value
[1024], /* Value string */
2014 *valstart
, /* Pointer into value */
2015 *valend
; /* End of value */
2019 * Empty protocol line yields NULL pointer...
2026 * Loop through the value string,...
2029 strlcpy(value
, s
, sizeof(value
));
2033 for (valstart
= value
; *valstart
;)
2036 * Get the current space/comma-delimited protocol name...
2039 for (valend
= valstart
; *valend
; valend
++)
2040 if (isspace(*valend
& 255) || *valend
== ',')
2047 * Add the protocol to the bitmask...
2050 if (!strcasecmp(valstart
, "cups"))
2051 protocols
|= BROWSE_CUPS
;
2052 else if (!strcasecmp(valstart
, "slp"))
2053 protocols
|= BROWSE_SLP
;
2054 else if (!strcasecmp(valstart
, "ldap"))
2055 protocols
|= BROWSE_LDAP
;
2056 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
2057 protocols
|= BROWSE_DNSSD
;
2058 else if (!strcasecmp(valstart
, "all"))
2059 protocols
|= BROWSE_ALL
;
2060 else if (strcasecmp(valstart
, "none"))
2063 for (valstart
= valend
; *valstart
; valstart
++)
2064 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2073 * 'read_configuration()' - Read a configuration file.
2076 static int /* O - 1 on success, 0 on failure */
2077 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2079 int i
; /* Looping var */
2080 int linenum
; /* Current line number */
2081 char line
[HTTP_MAX_BUFFER
],
2082 /* Line from file */
2083 temp
[HTTP_MAX_BUFFER
],
2084 /* Temporary buffer for value */
2085 temp2
[HTTP_MAX_BUFFER
],
2086 /* Temporary buffer 2 for value */
2087 *ptr
, /* Pointer into line/temp */
2088 *value
, /* Pointer to value */
2089 *valueptr
; /* Pointer into value */
2090 int valuelen
; /* Length of value */
2091 cupsd_var_t
*var
; /* Current variable */
2092 http_addrlist_t
*addrlist
, /* Address list */
2093 *addr
; /* Current address */
2094 unsigned ip
[4], /* Address value */
2095 mask
[4]; /* Netmask value */
2096 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2097 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2098 cupsd_location_t
*location
; /* Browse location */
2099 cups_file_t
*incfile
; /* Include file */
2100 char incname
[1024]; /* Include filename */
2101 struct group
*group
; /* Group */
2105 * Loop through each line in the file...
2110 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2113 * Decode the directive...
2116 if (!strcasecmp(line
, "Include"))
2122 if (value
[0] == '/')
2123 strlcpy(incname
, value
, sizeof(incname
));
2125 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2127 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2128 cupsdLogMessage(CUPSD_LOG_ERROR
,
2129 "Unable to include config file \"%s\" - %s",
2130 incname
, strerror(errno
));
2133 read_configuration(incfile
);
2134 cupsFileClose(incfile
);
2137 else if (!strcasecmp(line
, "<Location"))
2145 linenum
= read_location(fp
, value
, linenum
);
2151 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2156 else if (!strcasecmp(line
, "<Policy"))
2164 linenum
= read_policy(fp
, value
, linenum
);
2170 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2174 else if (!strcasecmp(line
, "FaxRetryInterval"))
2178 JobRetryInterval
= atoi(value
);
2179 cupsdLogMessage(CUPSD_LOG_WARN
,
2180 "FaxRetryInterval is deprecated; use "
2181 "JobRetryInterval on line %d.", linenum
);
2185 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2189 else if (!strcasecmp(line
, "FaxRetryLimit"))
2193 JobRetryLimit
= atoi(value
);
2194 cupsdLogMessage(CUPSD_LOG_WARN
,
2195 "FaxRetryLimit is deprecated; use "
2196 "JobRetryLimit on line %d.", linenum
);
2200 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2204 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2206 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2207 #endif /* HAVE_SSL */
2211 * Add listening address(es) to the list...
2214 cupsd_listener_t
*lis
; /* New listeners array */
2218 * Get the address list...
2221 addrlist
= get_address(value
, IPP_PORT
);
2225 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2231 * Add each address...
2234 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2237 * Allocate another listener...
2241 Listeners
= cupsArrayNew(NULL
, NULL
);
2245 cupsdLogMessage(CUPSD_LOG_ERROR
,
2246 "Unable to allocate %s at line %d - %s.",
2247 line
, linenum
, strerror(errno
));
2251 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2253 cupsdLogMessage(CUPSD_LOG_ERROR
,
2254 "Unable to allocate %s at line %d - %s.",
2255 line
, linenum
, strerror(errno
));
2259 cupsArrayAdd(Listeners
, lis
);
2262 * Copy the current address and log it...
2265 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2269 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2270 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2271 #endif /* HAVE_SSL */
2273 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2276 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2277 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2278 ntohs(lis
->address
.ipv6
.sin6_port
));
2280 #endif /* AF_INET6 */
2282 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2283 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2285 #endif /* AF_LOCAL */
2286 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2287 ntohs(lis
->address
.ipv4
.sin_port
));
2294 httpAddrFreeList(addrlist
);
2296 else if (!strcasecmp(line
, "BrowseAddress"))
2299 * Add a browse address to the list...
2302 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2305 if (NumBrowsers
== 0)
2306 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2308 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2312 cupsdLogMessage(CUPSD_LOG_ERROR
,
2313 "Unable to allocate BrowseAddress at line %d - %s.",
2314 linenum
, strerror(errno
));
2319 dira
+= NumBrowsers
;
2321 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2323 if (!strcasecmp(value
, "@LOCAL"))
2326 * Send browse data to all local interfaces...
2329 strcpy(dira
->iface
, "*");
2332 else if (!strncasecmp(value
, "@IF(", 4))
2335 * Send browse data to the named interface...
2338 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2340 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2346 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2349 * Only IPv4 addresses are supported...
2352 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2353 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2358 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2359 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2361 cupsdLogMessage(CUPSD_LOG_INFO
,
2362 "Sending browsing info to %s:%d (IPv4)",
2363 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2368 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2371 httpAddrFreeList(addrlist
);
2374 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2377 else if (!strcasecmp(line
, "BrowseOrder"))
2380 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2383 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2384 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2386 if (location
== NULL
)
2387 cupsdLogMessage(CUPSD_LOG_ERROR
,
2388 "Unable to initialize browse access control list!");
2389 else if (!strncasecmp(value
, "deny", 4))
2390 location
->order_type
= AUTH_ALLOW
;
2391 else if (!strncasecmp(value
, "allow", 5))
2392 location
->order_type
= AUTH_DENY
;
2394 cupsdLogMessage(CUPSD_LOG_ERROR
,
2395 "Unknown BrowseOrder value %s on line %d.",
2398 else if (!strcasecmp(line
, "BrowseProtocols") ||
2399 !strcasecmp(line
, "BrowseLocalProtocols") ||
2400 !strcasecmp(line
, "BrowseRemoteProtocols"))
2403 * "BrowseProtocols name [... name]"
2404 * "BrowseLocalProtocols name [... name]"
2405 * "BrowseRemoteProtocols name [... name]"
2408 int protocols
= parse_protocols(value
);
2412 cupsdLogMessage(CUPSD_LOG_ERROR
,
2413 "Unknown browse protocol \"%s\" on line %d.",
2418 if (strcasecmp(line
, "BrowseLocalProtocols"))
2419 BrowseRemoteProtocols
= protocols
;
2420 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2421 BrowseLocalProtocols
= protocols
;
2423 else if (!strcasecmp(line
, "BrowseAllow") ||
2424 !strcasecmp(line
, "BrowseDeny"))
2427 * BrowseAllow [From] host/ip...
2428 * BrowseDeny [From] host/ip...
2431 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2432 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2434 if (location
== NULL
)
2435 cupsdLogMessage(CUPSD_LOG_ERROR
,
2436 "Unable to initialize browse access control list!");
2439 if (!strncasecmp(value
, "from ", 5))
2442 * Strip leading "from"...
2447 while (isspace(*value
))
2452 * Figure out what form the allow/deny address takes:
2463 * nnn.nnn.nnn.nnn/mm
2464 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2467 if (!strcasecmp(value
, "all"))
2473 if (!strcasecmp(line
, "BrowseAllow"))
2474 cupsdAllowIP(location
, zeros
, zeros
);
2476 cupsdDenyIP(location
, zeros
, zeros
);
2478 else if (!strcasecmp(value
, "none"))
2484 if (!strcasecmp(line
, "BrowseAllow"))
2485 cupsdAllowIP(location
, ones
, zeros
);
2487 cupsdDenyIP(location
, ones
, zeros
);
2490 else if (value
[0] == '*' || value
[0] == '.' ||
2491 (!isdigit(value
[0] & 255) && value
[0] != '['))
2493 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2494 #endif /* AF_INET6 */
2497 * Host or domain name...
2500 if (value
[0] == '*')
2503 if (!strcasecmp(line
, "BrowseAllow"))
2504 cupsdAllowHost(location
, value
);
2506 cupsdDenyHost(location
, value
);
2511 * One of many IP address forms...
2514 if (!get_addr_and_mask(value
, ip
, mask
))
2516 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2521 if (!strcasecmp(line
, "BrowseAllow"))
2522 cupsdAllowIP(location
, ip
, mask
);
2524 cupsdDenyIP(location
, ip
, mask
);
2528 else if (!strcasecmp(line
, "BrowseRelay"))
2531 * BrowseRelay [from] source [to] destination
2535 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2537 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2541 cupsdLogMessage(CUPSD_LOG_ERROR
,
2542 "Unable to allocate BrowseRelay at line %d - %s.",
2543 linenum
, strerror(errno
));
2550 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2552 if (!strncasecmp(value
, "from ", 5))
2555 * Strip leading "from"...
2560 while (isspace(*value
))
2565 * Figure out what form the from address takes:
2574 * nnn.nnn.nnn.nnn/mm
2575 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2579 if (value
[0] == '*' || value
[0] == '.' ||
2580 (!isdigit(value
[0] & 255) && value
[0] != '['))
2582 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2583 #endif /* AF_INET6 */
2586 * Host or domain name...
2589 if (value
[0] == '*')
2592 strlcpy(temp
, value
, sizeof(temp
));
2593 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2596 relay
->from
.type
= AUTH_NAME
;
2597 relay
->from
.mask
.name
.name
= strdup(temp
);
2598 relay
->from
.mask
.name
.length
= strlen(temp
);
2603 * One of many IP address forms...
2606 if (!get_addr_and_mask(value
, ip
, mask
))
2608 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2613 relay
->from
.type
= AUTH_IP
;
2614 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2615 sizeof(relay
->from
.mask
.ip
.address
));
2616 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2617 sizeof(relay
->from
.mask
.ip
.netmask
));
2621 * Skip value and trailing whitespace...
2624 for (; *value
; value
++)
2625 if (isspace(*value
))
2628 while (isspace(*value
))
2631 if (!strncasecmp(value
, "to ", 3))
2634 * Strip leading "to"...
2639 while (isspace(*value
))
2644 * Get "to" address and port...
2647 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2650 * Only IPv4 addresses are supported...
2653 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2654 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2659 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2661 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2663 if (relay
->from
.type
== AUTH_IP
)
2664 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2665 relay
->from
.mask
.ip
.address
[0] >> 24,
2666 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2667 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2668 relay
->from
.mask
.ip
.address
[0] & 255,
2669 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2670 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2671 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2672 relay
->from
.mask
.ip
.netmask
[0] & 255);
2674 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2676 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2677 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2682 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2685 httpAddrFreeList(addrlist
);
2689 if (relay
->from
.type
== AUTH_NAME
)
2690 free(relay
->from
.mask
.name
.name
);
2692 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2696 else if (!strcasecmp(line
, "BrowsePoll"))
2699 * BrowsePoll address[:port]
2702 char *portname
; /* Port name */
2703 int portnum
; /* Port number */
2704 struct servent
*service
; /* Service */
2708 * Extract the port name from the address...
2711 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2715 if (isdigit(*portname
& 255))
2716 portnum
= atoi(portname
);
2717 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2718 portnum
= ntohs(service
->s_port
);
2721 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2727 portnum
= ippPort();
2730 * Add the poll entry...
2734 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2736 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2740 cupsdLogMessage(CUPSD_LOG_ERROR
,
2741 "Unable to allocate BrowsePoll at line %d - %s.",
2742 linenum
, strerror(errno
));
2750 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2752 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2753 pollp
->port
= portnum
;
2755 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2758 else if (!strcasecmp(line
, "DefaultAuthType"))
2761 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2764 if (!strcasecmp(value
, "basic"))
2765 DefaultAuthType
= AUTH_BASIC
;
2766 else if (!strcasecmp(value
, "digest"))
2767 DefaultAuthType
= AUTH_DIGEST
;
2768 else if (!strcasecmp(value
, "basicdigest"))
2769 DefaultAuthType
= AUTH_BASICDIGEST
;
2771 else if (!strcasecmp(value
, "negotiate"))
2772 DefaultAuthType
= AUTH_NEGOTIATE
;
2773 #endif /* HAVE_GSSAPI */
2776 cupsdLogMessage(CUPSD_LOG_WARN
,
2777 "Unknown default authorization type %s on line %d.",
2783 else if (!strcasecmp(line
, "DefaultEncryption"))
2786 * DefaultEncryption {Never,IfRequested,Required}
2789 if (!value
|| !strcasecmp(value
, "never"))
2790 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2791 else if (!strcasecmp(value
, "required"))
2792 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2793 else if (!strcasecmp(value
, "ifrequested"))
2794 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2797 cupsdLogMessage(CUPSD_LOG_WARN
,
2798 "Unknown default encryption %s on line %d.",
2803 #endif /* HAVE_SSL */
2805 else if (!strcasecmp(line
, "Krb5Keytab"))
2807 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2810 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2811 gsskrb5_register_acceptor_identity(value
);
2813 cupsdSetEnv("KRB5_KTNAME", value
);
2814 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2816 #endif /* HAVE_GSSAPI */
2817 else if (!strcasecmp(line
, "User"))
2820 * User ID to run as...
2823 if (value
&& isdigit(value
[0] & 255))
2825 int uid
= atoi(value
);
2828 cupsdLogMessage(CUPSD_LOG_ERROR
,
2829 "Will not use User 0 as specified on line %d "
2830 "for security reasons. You must use a non-"
2831 "privileged account instead.",
2838 struct passwd
*p
; /* Password information */
2841 p
= getpwnam(value
);
2846 cupsdLogMessage(CUPSD_LOG_ERROR
,
2847 "Will not use User %s (UID=0) as specified on line "
2848 "%d for security reasons. You must use a non-"
2849 "privileged account instead.",
2855 cupsdLogMessage(CUPSD_LOG_ERROR
,
2856 "Unknown User \"%s\" on line %d, ignoring!",
2860 cupsdLogMessage(CUPSD_LOG_ERROR
,
2861 "User directive on line %d missing the username!",
2864 else if (!strcasecmp(line
, "Group"))
2867 * Group ID to run as...
2870 if (isdigit(value
[0]))
2871 Group
= atoi(value
);
2875 group
= getgrnam(value
);
2878 Group
= group
->gr_gid
;
2880 cupsdLogMessage(CUPSD_LOG_ERROR
,
2881 "Unknown Group \"%s\" on line %d, ignoring!",
2885 else if (!strcasecmp(line
, "SystemGroup"))
2888 * SystemGroup (admin) group(s)...
2891 if (!parse_groups(value
))
2892 cupsdLogMessage(CUPSD_LOG_ERROR
,
2893 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2896 else if (!strcasecmp(line
, "HostNameLookups"))
2899 * Do hostname lookups?
2902 if (!strcasecmp(value
, "off"))
2903 HostNameLookups
= 0;
2904 else if (!strcasecmp(value
, "on"))
2905 HostNameLookups
= 1;
2906 else if (!strcasecmp(value
, "double"))
2907 HostNameLookups
= 2;
2909 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2912 else if (!strcasecmp(line
, "LogLevel"))
2915 * Amount of logging to do...
2918 if (!strcasecmp(value
, "debug2"))
2919 LogLevel
= CUPSD_LOG_DEBUG2
;
2920 else if (!strcasecmp(value
, "debug"))
2921 LogLevel
= CUPSD_LOG_DEBUG
;
2922 else if (!strcasecmp(value
, "info"))
2923 LogLevel
= CUPSD_LOG_INFO
;
2924 else if (!strcasecmp(value
, "notice"))
2925 LogLevel
= CUPSD_LOG_NOTICE
;
2926 else if (!strcasecmp(value
, "warn"))
2927 LogLevel
= CUPSD_LOG_WARN
;
2928 else if (!strcasecmp(value
, "error"))
2929 LogLevel
= CUPSD_LOG_ERROR
;
2930 else if (!strcasecmp(value
, "crit"))
2931 LogLevel
= CUPSD_LOG_CRIT
;
2932 else if (!strcasecmp(value
, "alert"))
2933 LogLevel
= CUPSD_LOG_ALERT
;
2934 else if (!strcasecmp(value
, "emerg"))
2935 LogLevel
= CUPSD_LOG_EMERG
;
2936 else if (!strcasecmp(value
, "none"))
2937 LogLevel
= CUPSD_LOG_NONE
;
2939 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2942 else if (!strcasecmp(line
, "PrintcapFormat"))
2945 * Format of printcap file?
2948 if (!strcasecmp(value
, "bsd"))
2949 PrintcapFormat
= PRINTCAP_BSD
;
2950 else if (!strcasecmp(value
, "solaris"))
2951 PrintcapFormat
= PRINTCAP_SOLARIS
;
2953 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2956 else if (!strcasecmp(line
, "ServerTokens"))
2959 * Set the string used for the Server header...
2962 struct utsname plat
; /* Platform info */
2967 if (!strcasecmp(value
, "ProductOnly"))
2968 cupsdSetString(&ServerHeader
, "CUPS");
2969 else if (!strcasecmp(value
, "Major"))
2970 cupsdSetString(&ServerHeader
, "CUPS/1");
2971 else if (!strcasecmp(value
, "Minor"))
2972 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2973 else if (!strcasecmp(value
, "Minimal"))
2974 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2975 else if (!strcasecmp(value
, "OS"))
2976 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2977 else if (!strcasecmp(value
, "Full"))
2978 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2980 else if (!strcasecmp(value
, "None"))
2981 cupsdClearString(&ServerHeader
);
2983 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2986 else if (!strcasecmp(line
, "PassEnv"))
2989 * PassEnv variable [... variable]
2994 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2995 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2998 if (value
[valuelen
])
3000 value
[valuelen
] = '\0';
3004 cupsdSetEnv(value
, NULL
);
3006 for (value
+= valuelen
; *value
; value
++)
3007 if (!isspace(*value
) || *value
!= ',')
3011 else if (!strcasecmp(line
, "SetEnv"))
3014 * SetEnv variable value
3017 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3025 while (isspace(*valueptr
& 255))
3028 cupsdSetEnv(value
, valueptr
);
3031 cupsdLogMessage(CUPSD_LOG_ERROR
,
3032 "Missing value for SetEnv directive on line %d.",
3038 * Find a simple variable in the list...
3041 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3042 if (!strcasecmp(line
, var
->name
))
3048 * Unknown directive! Output an error message and continue...
3051 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3058 case CUPSD_VARTYPE_INTEGER
:
3060 cupsdLogMessage(CUPSD_LOG_ERROR
,
3061 "Missing integer value for %s on line %d!",
3066 char *units
; /* Units */
3069 n
= strtol(value
, &units
, 0);
3071 if (units
&& *units
)
3073 if (tolower(units
[0] & 255) == 'g')
3074 n
*= 1024 * 1024 * 1024;
3075 else if (tolower(units
[0] & 255) == 'm')
3077 else if (tolower(units
[0] & 255) == 'k')
3079 else if (tolower(units
[0] & 255) == 't')
3084 cupsdLogMessage(CUPSD_LOG_ERROR
,
3085 "Bad negative integer value for %s on line %d!",
3088 *((int *)var
->ptr
) = n
;
3092 case CUPSD_VARTYPE_BOOLEAN
:
3094 cupsdLogMessage(CUPSD_LOG_ERROR
,
3095 "Missing boolean value for %s on line %d!",
3097 else if (!strcasecmp(value
, "true") ||
3098 !strcasecmp(value
, "on") ||
3099 !strcasecmp(value
, "enabled") ||
3100 !strcasecmp(value
, "yes") ||
3102 *((int *)var
->ptr
) = TRUE
;
3103 else if (!strcasecmp(value
, "false") ||
3104 !strcasecmp(value
, "off") ||
3105 !strcasecmp(value
, "disabled") ||
3106 !strcasecmp(value
, "no") ||
3107 !strcasecmp(value
, "0"))
3108 *((int *)var
->ptr
) = FALSE
;
3110 cupsdLogMessage(CUPSD_LOG_ERROR
,
3111 "Unknown boolean value %s on line %d.",
3115 case CUPSD_VARTYPE_STRING
:
3116 cupsdSetString((char **)var
->ptr
, value
);
3127 * 'read_location()' - Read a <Location path> definition.
3130 static int /* O - New line number or 0 on error */
3131 read_location(cups_file_t
*fp
, /* I - Configuration file */
3132 char *location
, /* I - Location name/path */
3133 int linenum
) /* I - Current line number */
3135 cupsd_location_t
*loc
, /* New location */
3136 *parent
; /* Parent location */
3137 char line
[HTTP_MAX_BUFFER
],
3139 *value
, /* Value for directive */
3140 *valptr
; /* Pointer into value */
3143 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3146 parent
->limit
= AUTH_LIMIT_ALL
;
3149 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3152 * Decode the directive...
3155 if (!strcasecmp(line
, "</Location>"))
3157 else if (!strcasecmp(line
, "<Limit") ||
3158 !strcasecmp(line
, "<LimitExcept"))
3162 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3166 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3172 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3177 if (!strcmp(value
, "ALL"))
3178 loc
->limit
= AUTH_LIMIT_ALL
;
3179 else if (!strcmp(value
, "GET"))
3180 loc
->limit
|= AUTH_LIMIT_GET
;
3181 else if (!strcmp(value
, "HEAD"))
3182 loc
->limit
|= AUTH_LIMIT_HEAD
;
3183 else if (!strcmp(value
, "OPTIONS"))
3184 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3185 else if (!strcmp(value
, "POST"))
3186 loc
->limit
|= AUTH_LIMIT_POST
;
3187 else if (!strcmp(value
, "PUT"))
3188 loc
->limit
|= AUTH_LIMIT_PUT
;
3189 else if (!strcmp(value
, "TRACE"))
3190 loc
->limit
|= AUTH_LIMIT_TRACE
;
3192 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3195 for (value
= valptr
; isspace(*value
& 255); value
++);
3198 if (!strcasecmp(line
, "<LimitExcept"))
3199 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3201 parent
->limit
&= ~loc
->limit
;
3203 else if (!strcasecmp(line
, "</Limit>"))
3205 else if (!parse_aaa(loc
, line
, value
, linenum
))
3207 cupsdLogMessage(CUPSD_LOG_ERROR
,
3208 "Unknown Location directive %s on line %d.",
3214 cupsdLogMessage(CUPSD_LOG_ERROR
,
3215 "Unexpected end-of-file at line %d while reading location!",
3223 * 'read_policy()' - Read a <Policy name> definition.
3226 static int /* O - New line number or 0 on error */
3227 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3228 char *policy
, /* I - Location name/path */
3229 int linenum
) /* I - Current line number */
3231 int i
; /* Looping var */
3232 cupsd_policy_t
*pol
; /* Policy */
3233 cupsd_location_t
*op
; /* Policy operation */
3234 int num_ops
; /* Number of IPP operations */
3235 ipp_op_t ops
[100]; /* Operations */
3236 char line
[HTTP_MAX_BUFFER
],
3238 *value
, /* Value for directive */
3239 *valptr
; /* Pointer into value */
3243 * Create the policy...
3246 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3250 * Read from the file...
3256 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3259 * Decode the directive...
3262 if (!strcasecmp(line
, "</Policy>"))
3265 cupsdLogMessage(CUPSD_LOG_WARN
,
3266 "Missing </Limit> before </Policy> on line %d!",
3271 else if (!strcasecmp(line
, "<Limit") && !op
)
3275 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3280 * Scan for IPP operation names...
3287 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3292 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3294 if (!strcasecmp(value
, "All"))
3295 ops
[num_ops
] = IPP_ANY_OPERATION
;
3296 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3297 cupsdLogMessage(CUPSD_LOG_ERROR
,
3298 "Bad IPP operation name \"%s\" on line %d!",
3304 cupsdLogMessage(CUPSD_LOG_ERROR
,
3305 "Too many operations listed on line %d!",
3308 for (value
= valptr
; isspace(*value
& 255); value
++);
3312 * If none are specified, apply the policy to all operations...
3317 ops
[0] = IPP_ANY_OPERATION
;
3322 * Add a new policy for the first operation...
3325 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3327 else if (!strcasecmp(line
, "</Limit>") && op
)
3330 * Finish the current operation limit...
3336 * Copy the policy to the other operations...
3339 for (i
= 1; i
< num_ops
; i
++)
3340 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3347 cupsdLogMessage(CUPSD_LOG_ERROR
,
3348 "Missing <Limit ops> directive before %s on line %d.",
3352 else if (!parse_aaa(op
, line
, value
, linenum
))
3355 cupsdLogMessage(CUPSD_LOG_ERROR
,
3356 "Unknown Policy Limit directive %s on line %d.",
3359 cupsdLogMessage(CUPSD_LOG_ERROR
,
3360 "Unknown Policy directive %s on line %d.",
3367 cupsdLogMessage(CUPSD_LOG_ERROR
,
3368 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3376 * End of "$Id: conf.c 6649 2007-07-11 21:46:42Z mike $".