2 * "$Id: conf.c,v 1.77.2.40 2003/04/23 18:55:28 mike Exp $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * ReadConfiguration() - Read the cupsd.conf file.
27 * read_configuration() - Read a configuration file.
28 * read_location() - Read a <Location path> definition.
29 * get_address() - Get an address + port number from a line.
30 * get_addr_and_mask() - Get an IP address and netmask.
31 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
32 * required by SSLSetCertificate.
36 * Include necessary headers...
45 # include <Security/SecureTransport.h>
46 # include <Security/SecIdentitySearch.h>
47 #endif /* HAVE_CDSASSL */
51 #endif /* HAVE_VSYSLOG */
55 * Possibly missing network definitions...
59 # define INADDR_NONE 0xffffffff
60 #endif /* !INADDR_NONE */
64 * Some OS's don't have hstrerror(), most notably Solaris...
67 #ifndef HAVE_HSTRERROR
68 const char * /* O - Error string */
69 cups_hstrerror(int error
) /* I - Error number */
71 static const char * const errors
[] =
76 "Unrecoverable lookup error.",
77 "No data associated with name."
81 if (error
< 0 || error
> 4)
82 return ("Unknown hostname lookup error.");
84 return (errors
[error
]);
88 * AIX doesn't provide a prototype but does provide the function...
90 extern const char *hstrerror(int);
91 #endif /* !HAVE_HSTRERROR */
95 * Configuration variable structure...
100 char *name
; /* Name of variable */
101 void *ptr
; /* Pointer to variable */
102 int type
; /* Type (int, string, address) */
105 #define VAR_INTEGER 0
107 #define VAR_BOOLEAN 2
114 static var_t variables
[] =
116 { "AccessLog", &AccessLog
, VAR_STRING
},
117 { "AutoPurgeJobs", &JobAutoPurge
, VAR_BOOLEAN
},
118 { "BrowseInterval", &BrowseInterval
, VAR_INTEGER
},
119 { "BrowsePort", &BrowsePort
, VAR_INTEGER
},
120 { "BrowseShortNames", &BrowseShortNames
, VAR_BOOLEAN
},
121 { "BrowseTimeout", &BrowseTimeout
, VAR_INTEGER
},
122 { "Browsing", &Browsing
, VAR_BOOLEAN
},
123 { "Classification", &Classification
, VAR_STRING
},
124 { "ClassifyOverride", &ClassifyOverride
, VAR_BOOLEAN
},
125 { "ConfigFilePerm", &ConfigFilePerm
, VAR_INTEGER
},
126 { "DataDir", &DataDir
, VAR_STRING
},
127 { "DefaultCharset", &DefaultCharset
, VAR_STRING
},
128 { "DefaultLanguage", &DefaultLanguage
, VAR_STRING
},
129 { "DocumentRoot", &DocumentRoot
, VAR_STRING
},
130 { "ErrorLog", &ErrorLog
, VAR_STRING
},
131 { "FaxRetryLimit", &FaxRetryLimit
, VAR_INTEGER
},
132 { "FaxRetryInterval", &FaxRetryInterval
, VAR_INTEGER
},
133 { "FileDevice", &FileDevice
, VAR_BOOLEAN
},
134 { "FilterLimit", &FilterLimit
, VAR_INTEGER
},
135 { "FilterNice", &FilterNice
, VAR_INTEGER
},
136 { "FontPath", &FontPath
, VAR_STRING
},
137 { "HideImplicitMembers", &HideImplicitMembers
, VAR_BOOLEAN
},
138 { "ImplicitClasses", &ImplicitClasses
, VAR_BOOLEAN
},
139 { "ImplicitAnyClasses", &ImplicitAnyClasses
, VAR_BOOLEAN
},
140 { "KeepAliveTimeout", &KeepAliveTimeout
, VAR_INTEGER
},
141 { "KeepAlive", &KeepAlive
, VAR_BOOLEAN
},
142 { "LimitRequestBody", &MaxRequestSize
, VAR_INTEGER
},
143 { "ListenBackLog", &ListenBackLog
, VAR_INTEGER
},
144 { "LogFilePerm", &LogFilePerm
, VAR_INTEGER
},
145 { "MaxActiveJobs", &MaxActiveJobs
, VAR_INTEGER
},
146 { "MaxClients", &MaxClients
, VAR_INTEGER
},
147 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
148 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
149 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
150 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
151 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
152 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
153 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
154 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
155 { "PageLog", &PageLog
, VAR_STRING
},
156 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
157 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
158 { "Printcap", &Printcap
, VAR_STRING
},
159 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
160 { "RemoteRoot", &RemoteRoot
, VAR_STRING
},
161 { "RequestRoot", &RequestRoot
, VAR_STRING
},
162 { "RIPCache", &RIPCache
, VAR_STRING
},
163 { "RunAsUser", &RunAsUser
, VAR_BOOLEAN
},
164 { "RootCertDuration", &RootCertDuration
, VAR_INTEGER
},
165 { "ServerAdmin", &ServerAdmin
, VAR_STRING
},
166 { "ServerBin", &ServerBin
, VAR_STRING
},
168 { "ServerCertificate", &ServerCertificate
, VAR_STRING
},
169 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
170 { "ServerKey", &ServerKey
, VAR_STRING
},
171 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
172 #endif /* HAVE_SSL */
173 { "ServerName", &ServerName
, VAR_STRING
},
174 { "ServerRoot", &ServerRoot
, VAR_STRING
},
175 { "TempDir", &TempDir
, VAR_STRING
},
176 { "Timeout", &Timeout
, VAR_INTEGER
}
178 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
181 static unsigned ones
[4] =
183 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
185 static unsigned zeros
[4] =
187 0x00000000, 0x00000000, 0x00000000, 0x00000000
191 static CFArrayRef
CDSAGetServerCerts();
192 #endif /* HAVE_CDSASSL */
199 static int read_configuration(cups_file_t
*fp
);
200 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
201 static int get_address(const char *value
, unsigned defaddress
, int defport
,
202 int deffamily
, http_addr_t
*address
);
203 static int get_addr_and_mask(const char *value
, unsigned *ip
,
208 * 'ReadConfiguration()' - Read the cupsd.conf file.
211 int /* O - 1 on success, 0 otherwise */
212 ReadConfiguration(void)
214 int i
; /* Looping var */
215 cups_file_t
*fp
; /* Configuration file */
216 int status
; /* Return status */
217 char temp
[1024], /* Temporary buffer */
218 *slash
; /* Directory separator */
219 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
221 char *language
; /* Language string */
222 struct passwd
*user
; /* Default user */
223 struct group
*group
; /* Default group */
224 int run_user
; /* User that will be running cupsd */
225 char *old_serverroot
, /* Old ServerRoot */
226 *old_requestroot
; /* Old RequestRoot */
230 * Shutdown the server...
236 * Save the old root paths...
239 old_serverroot
= NULL
;
240 SetString(&old_serverroot
, ServerRoot
);
241 old_requestroot
= NULL
;
242 SetString(&old_requestroot
, RequestRoot
);
245 * Reset the server configuration data...
248 DeleteAllLocations();
266 for (i
= 0; i
< NumRelays
; i
++)
267 if (Relays
[i
].from
.type
== AUTH_NAME
)
268 free(Relays
[i
].from
.mask
.name
.name
);
275 if (NumListeners
> 0)
286 gethostname(temp
, sizeof(temp
));
287 SetString(&ServerName
, temp
);
288 SetStringf(&ServerAdmin
, "root@%s", temp
);
289 SetString(&ServerBin
, CUPS_SERVERBIN
);
290 SetString(&RequestRoot
, CUPS_REQUESTS
);
291 SetString(&DocumentRoot
, CUPS_DOCROOT
);
292 SetString(&DataDir
, CUPS_DATADIR
);
293 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
294 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
295 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
296 SetString(&Printcap
, "/etc/printcap");
297 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
298 SetString(&FontPath
, CUPS_FONTPATH
);
299 SetString(&RemoteRoot
, "remroot");
301 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
302 if ((slash
= strrchr(temp
, '/')) != NULL
)
305 SetString(&ServerRoot
, temp
);
307 ClearString(&Classification
);
308 ClassifyOverride
= 0;
312 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
314 SetString(&ServerCertificate
, "ssl/server.crt");
315 SetString(&ServerKey
, "ssl/server.key");
316 # endif /* HAVE_CDSASSL */
317 #endif /* HAVE_SSL */
319 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
321 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
324 SetString(&DefaultLanguage
, language
);
325 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
327 SetString(&RIPCache
, "8m");
329 if (getenv("TMPDIR") == NULL
)
330 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
332 SetString(&TempDir
, getenv("TMPDIR"));
335 * Find the default system group: "sys", "system", or "root"...
338 group
= getgrnam(CUPS_DEFAULT_GROUP
);
345 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
346 Group
= group
->gr_gid
;
355 SetString(&SystemGroups
[0], group
->gr_name
);
360 SetString(&SystemGroups
[0], "unknown");
366 * Find the default user...
369 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
370 User
= 1; /* Force to a non-priviledged account */
380 ConfigFilePerm
= 0640;
384 FaxRetryInterval
= 300;
389 HostNameLookups
= FALSE
;
390 ImplicitClasses
= TRUE
;
391 ImplicitAnyClasses
= FALSE
;
392 HideImplicitMembers
= TRUE
;
394 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
395 ListenBackLog
= SOMAXCONN
;
398 MaxClientsPerHost
= 0;
399 MaxLogSize
= 1024 * 1024;
400 MaxPrinterHistory
= 10;
402 RootCertDuration
= 300;
404 Timeout
= DEFAULT_TIMEOUT
;
406 BrowseInterval
= DEFAULT_INTERVAL
;
407 BrowsePort
= ippPort();
408 BrowseProtocols
= BROWSE_CUPS
;
409 BrowseShortNames
= TRUE
;
410 BrowseTimeout
= DEFAULT_TIMEOUT
;
413 JobHistory
= DEFAULT_HISTORY
;
414 JobFiles
= DEFAULT_FILES
;
418 MaxJobsPerPrinter
= 0;
423 * Read the configuration file...
426 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
429 status
= read_configuration(fp
);
442 * Use the default system group if none was supplied in cupsd.conf...
445 if (NumSystemGroups
== 0)
449 * Get the access control list for browsing...
452 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
455 * Open the system log for cupsd if necessary...
459 if (strcmp(AccessLog
, "syslog") == 0 ||
460 strcmp(ErrorLog
, "syslog") == 0 ||
461 strcmp(PageLog
, "syslog") == 0)
462 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
463 #endif /* HAVE_VSYSLOG */
466 * Log the configuration file that was used...
469 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
472 * Update all relative filenames to include the full path from ServerRoot...
475 if (DocumentRoot
[0] != '/')
476 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
478 if (RequestRoot
[0] != '/')
479 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
481 if (ServerBin
[0] != '/')
482 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
485 if (ServerCertificate
[0] != '/')
486 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
488 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
489 chown(ServerCertificate
, run_user
, Group
);
490 chmod(ServerCertificate
, ConfigFilePerm
);
492 if (ServerKey
[0] != '/')
493 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
495 chown(ServerKey
, run_user
, Group
);
496 chmod(ServerKey
, ConfigFilePerm
);
497 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
498 #endif /* HAVE_SSL */
501 * Make sure that ServerRoot and the config files are owned and
502 * writable by the user and group in the cupsd.conf file...
505 chown(ServerRoot
, run_user
, Group
);
506 chmod(ServerRoot
, 0775);
508 snprintf(temp
, sizeof(temp
), "%s/certs", ServerRoot
);
509 chown(temp
, run_user
, Group
);
512 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
513 chown(temp
, run_user
, Group
);
516 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
517 chown(temp
, run_user
, Group
);
520 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
521 chown(temp
, run_user
, Group
);
522 chmod(temp
, ConfigFilePerm
);
524 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
525 chown(temp
, run_user
, Group
);
529 chmod(temp
, ConfigFilePerm
);
530 #endif /* __APPLE__ */
532 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
533 chown(temp
, run_user
, Group
);
537 chmod(temp
, ConfigFilePerm
);
538 #endif /* __APPLE__ */
540 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
541 chown(temp
, User
, Group
);
545 * Make sure the request and temporary directories have the right
549 chown(RequestRoot
, run_user
, Group
);
550 chmod(RequestRoot
, 0710);
552 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
555 * Only update ownership and permissions if the CUPS temp directory
556 * is under the spool directory...
559 chown(TempDir
, run_user
, Group
);
560 chmod(TempDir
, 01770);
564 * Check the MaxClients setting, and then allocate memory for it...
567 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
570 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
573 MaxClients
= MaxFDs
/ 3;
576 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
578 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
579 MaxClients
, strerror(errno
));
583 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
586 * Check the MaxActiveJobs setting; limit to 1/3 the available
587 * file descriptors, since we need a pipe for each job...
590 if (MaxActiveJobs
> (MaxFDs
/ 3))
591 MaxActiveJobs
= MaxFDs
/ 3;
593 if (Classification
&& strcasecmp(Classification
, "none") == 0)
594 ClearString(&Classification
);
597 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
600 * Update the MaxClientsPerHost value, as needed...
603 if (MaxClientsPerHost
<= 0)
604 MaxClientsPerHost
= MaxClients
;
606 if (MaxClientsPerHost
> MaxClients
)
607 MaxClientsPerHost
= MaxClients
;
609 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
613 * If we are doing a full reload or the server root has changed, flush
614 * the jobs, printers, etc. and start from scratch...
617 if (NeedReload
== RELOAD_ALL
||
618 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
619 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
621 LogMessage(L_INFO
, "Full reload is required.");
631 DefaultPrinter
= NULL
;
645 if (MimeDatabase
!= NULL
)
646 mimeDelete(MimeDatabase
);
650 for (i
= 0; i
< NumMimeTypes
; i
++)
651 free((void *)MimeTypes
[i
]);
657 * Read the MIME type and conversion database...
660 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
662 MimeDatabase
= mimeNew();
663 mimeMerge(MimeDatabase
, ServerRoot
, temp
);
666 * Create a list of MIME types for the document-format-supported
670 NumMimeTypes
= MimeDatabase
->num_types
;
671 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
674 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
676 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
678 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
679 MimeDatabase
->types
[i
]->type
);
681 MimeTypes
[i
] = strdup(type
);
684 if (i
< NumMimeTypes
)
685 MimeTypes
[i
] = strdup("application/octet-stream");
691 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
695 * Load printers and classes...
702 * Load devices and PPDs...
705 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
708 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
712 * Load queued jobs...
717 LogMessage(L_INFO
, "Full reload complete.");
720 LogMessage(L_INFO
, "Partial reload complete.");
723 * Reset the reload state...
726 NeedReload
= RELOAD_NONE
;
728 ClearString(&old_serverroot
);
729 ClearString(&old_requestroot
);
732 * Startup the server and return...
742 * 'read_configuration()' - Read a configuration file.
745 static int /* O - 1 on success, 0 on failure */
746 read_configuration(cups_file_t
*fp
) /* I - File to read from */
748 int i
; /* Looping var */
749 int linenum
; /* Current line number */
750 int len
; /* Length of line */
751 char line
[HTTP_MAX_BUFFER
], /* Line from file */
752 name
[256], /* Parameter name */
753 *nameptr
, /* Pointer into name */
754 *value
; /* Pointer to value */
755 int valuelen
; /* Length of value */
756 var_t
*var
; /* Current variable */
757 unsigned ip
[4], /* Address value */
758 mask
[4]; /* Netmask value */
759 dirsvc_relay_t
*relay
; /* Relay data */
760 dirsvc_poll_t
*poll
; /* Polling data */
761 http_addr_t polladdr
; /* Polling address */
762 location_t
*location
; /* Browse location */
763 cups_file_t
*incfile
; /* Include file */
764 char incname
[1024]; /* Include filename */
768 * Loop through each line in the file...
773 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
778 * Skip comment lines...
785 * Strip trailing whitespace, if any...
790 while (len
> 0 && isspace(line
[len
- 1]))
797 * Extract the name from the beginning of the line...
800 for (value
= line
; isspace(*value
); value
++);
802 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
803 nameptr
< (name
+ sizeof(name
) - 1);)
804 *nameptr
++ = *value
++;
807 while (isspace(*value
))
814 * Decode the directive...
817 if (strcasecmp(name
, "Include") == 0)
824 strlcpy(incname
, value
, sizeof(incname
));
826 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
828 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
829 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
830 incname
, strerror(errno
));
833 read_configuration(incfile
);
834 cupsFileClose(incfile
);
837 else if (strcasecmp(name
, "<Location") == 0)
843 if (line
[len
- 1] == '>')
845 line
[len
- 1] = '\0';
847 linenum
= read_location(fp
, value
, linenum
);
853 LogMessage(L_ERROR
, "ReadConfiguration() Syntax error on line %d.",
858 else if (strcasecmp(name
, "Port") == 0 ||
859 strcasecmp(name
, "Listen") == 0)
862 * Add a listening address to the list...
865 listener_t
*temp
; /* New listeners array */
868 if (NumListeners
== 0)
869 temp
= malloc(sizeof(listener_t
));
871 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
875 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
876 name
, linenum
, strerror(errno
));
881 temp
+= NumListeners
;
883 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(temp
->address
)))
885 httpAddrString(&(temp
->address
), line
, sizeof(line
));
888 if (temp
->address
.addr
.sa_family
== AF_INET6
)
889 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", line
,
890 ntohs(temp
->address
.ipv6
.sin6_port
));
892 #endif /* AF_INET6 */
893 LogMessage(L_INFO
, "Listening to %s:%d", line
,
894 ntohs(temp
->address
.ipv4
.sin_port
));
898 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
902 else if (strcasecmp(name
, "SSLPort") == 0 ||
903 strcasecmp(name
, "SSLListen") == 0)
906 * Add a listening address to the list...
909 listener_t
*temp
; /* New listeners array */
912 if (NumListeners
== 0)
913 temp
= malloc(sizeof(listener_t
));
915 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
919 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
920 name
, linenum
, strerror(errno
));
925 temp
+= NumListeners
;
927 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(temp
->address
)))
929 httpAddrString(&(temp
->address
), line
, sizeof(line
));
932 if (temp
->address
.addr
.sa_family
== AF_INET6
)
933 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", line
,
934 ntohs(temp
->address
.ipv6
.sin6_port
));
936 #endif /* AF_INET6 */
937 LogMessage(L_INFO
, "Listening to %s:%d", line
,
938 ntohs(temp
->address
.ipv4
.sin_port
));
939 temp
->encryption
= HTTP_ENCRYPT_ALWAYS
;
943 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
946 #endif /* HAVE_SSL */
947 else if (strcasecmp(name
, "BrowseAddress") == 0)
950 * Add a browse address to the list...
953 dirsvc_addr_t
*temp
; /* New browse address array */
956 if (NumBrowsers
== 0)
957 temp
= malloc(sizeof(dirsvc_addr_t
));
959 temp
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
963 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
964 linenum
, strerror(errno
));
971 memset(temp
, 0, sizeof(dirsvc_addr_t
));
973 if (strcasecmp(value
, "@LOCAL") == 0)
976 * Send browse data to all local interfaces...
979 strcpy(temp
->iface
, "*");
982 else if (strncasecmp(value
, "@IF(", 4) == 0)
985 * Send browse data to the named interface...
988 strlcpy(temp
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
990 nameptr
= temp
->iface
+ strlen(temp
->iface
) - 1;
996 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(temp
->to
)))
998 httpAddrString(&(temp
->to
), line
, sizeof(line
));
1001 if (temp
->to
.addr
.sa_family
== AF_INET6
)
1002 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", line
,
1003 ntohs(temp
->to
.ipv6
.sin6_port
));
1005 #endif /* AF_INET6 */
1006 LogMessage(L_INFO
, "Sending browsing info to %s:%d", line
,
1007 ntohs(temp
->to
.ipv4
.sin_port
));
1012 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1015 else if (strcasecmp(name
, "BrowseOrder") == 0)
1018 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1021 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1022 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1024 if (location
== NULL
)
1025 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1026 else if (strncasecmp(value
, "deny", 4) == 0)
1027 location
->order_type
= AUTH_ALLOW
;
1028 else if (strncasecmp(value
, "allow", 5) == 0)
1029 location
->order_type
= AUTH_DENY
;
1031 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1034 else if (strcasecmp(name
, "BrowseProtocols") == 0)
1037 * "BrowseProtocol name [... name]"
1040 BrowseProtocols
= 0;
1044 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1045 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1048 if (value
[valuelen
])
1050 value
[valuelen
] = '\0';
1054 if (strcasecmp(value
, "cups") == 0)
1055 BrowseProtocols
|= BROWSE_CUPS
;
1056 else if (strcasecmp(value
, "slp") == 0)
1057 BrowseProtocols
|= BROWSE_SLP
;
1058 else if (strcasecmp(value
, "ldap") == 0)
1059 BrowseProtocols
|= BROWSE_LDAP
;
1060 else if (strcasecmp(value
, "all") == 0)
1061 BrowseProtocols
|= BROWSE_ALL
;
1064 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1069 for (value
+= valuelen
; *value
; value
++)
1070 if (!isspace(*value
) || *value
!= ',')
1074 else if (strcasecmp(name
, "BrowseAllow") == 0 ||
1075 strcasecmp(name
, "BrowseDeny") == 0)
1078 * BrowseAllow [From] host/ip...
1079 * BrowseDeny [From] host/ip...
1082 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1083 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1085 if (location
== NULL
)
1086 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1089 if (strncasecmp(value
, "from ", 5) == 0)
1092 * Strip leading "from"...
1097 while (isspace(*value
))
1102 * Figure out what form the allow/deny address takes:
1113 * nnn.nnn.nnn.nnn/mm
1114 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1117 if (strcasecmp(value
, "all") == 0)
1123 if (strcasecmp(name
, "BrowseAllow") == 0)
1124 AllowIP(location
, zeros
, zeros
);
1126 DenyIP(location
, zeros
, zeros
);
1128 else if (strcasecmp(value
, "none") == 0)
1134 if (strcasecmp(name
, "BrowseAllow") == 0)
1135 AllowIP(location
, ones
, zeros
);
1137 DenyIP(location
, ones
, zeros
);
1139 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1142 * Host or domain name...
1145 if (value
[0] == '*')
1148 if (strcasecmp(name
, "BrowseAllow") == 0)
1149 AllowHost(location
, value
);
1151 DenyHost(location
, value
);
1156 * One of many IP address forms...
1159 if (!get_addr_and_mask(value
, ip
, mask
))
1161 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1166 if (strcasecmp(name
, "BrowseAllow") == 0)
1167 AllowIP(location
, ip
, mask
);
1169 DenyIP(location
, ip
, mask
);
1173 else if (strcasecmp(name
, "BrowseRelay") == 0)
1176 * BrowseRelay [from] source [to] destination
1180 relay
= malloc(sizeof(dirsvc_relay_t
));
1182 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1186 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1187 linenum
, strerror(errno
));
1194 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1196 if (strncasecmp(value
, "from ", 5) == 0)
1199 * Strip leading "from"...
1204 while (isspace(*value
))
1209 * Figure out what form the from address takes:
1218 * nnn.nnn.nnn.nnn/mm
1219 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1222 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1225 * Host or domain name...
1228 if (value
[0] == '*')
1231 relay
->from
.type
= AUTH_NAME
;
1232 relay
->from
.mask
.name
.name
= strdup(value
);
1233 relay
->from
.mask
.name
.length
= strlen(value
);
1238 * One of many IP address forms...
1241 if (!get_addr_and_mask(value
, ip
, mask
))
1243 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1248 relay
->from
.type
= AUTH_IP
;
1249 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1250 sizeof(relay
->from
.mask
.ip
.address
));
1251 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1252 sizeof(relay
->from
.mask
.ip
.netmask
));
1256 * Skip value and trailing whitespace...
1259 for (; *value
; value
++)
1260 if (isspace(*value
))
1263 while (isspace(*value
))
1266 if (strncasecmp(value
, "to ", 3) == 0)
1269 * Strip leading "to"...
1274 while (isspace(*value
))
1279 * Get "to" address and port...
1282 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1284 httpAddrString(&(relay
->to
), line
, sizeof(line
));
1286 if (relay
->from
.type
== AUTH_IP
)
1287 snprintf(name
, sizeof(name
), "%u.%u.%u.%u/%u.%u.%u.%u",
1288 relay
->from
.mask
.ip
.address
[0],
1289 relay
->from
.mask
.ip
.address
[1],
1290 relay
->from
.mask
.ip
.address
[2],
1291 relay
->from
.mask
.ip
.address
[3],
1292 relay
->from
.mask
.ip
.netmask
[0],
1293 relay
->from
.mask
.ip
.netmask
[1],
1294 relay
->from
.mask
.ip
.netmask
[2],
1295 relay
->from
.mask
.ip
.netmask
[3]);
1298 strncpy(name
, relay
->from
.mask
.name
.name
, sizeof(name
) - 1);
1299 name
[sizeof(name
) - 1] = '\0';
1303 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1304 LogMessage(L_INFO
, "Relaying from %s to %s:%d", name
, line
,
1305 ntohs(relay
->to
.ipv6
.sin6_port
));
1307 #endif /* AF_INET6 */
1308 LogMessage(L_INFO
, "Relaying from %s to %s:%d", name
, line
,
1309 ntohs(relay
->to
.ipv4
.sin_port
));
1315 if (relay
->from
.type
== AUTH_NAME
)
1316 free(relay
->from
.mask
.name
.name
);
1318 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1321 else if (strcasecmp(name
, "BrowsePoll") == 0)
1324 * BrowsePoll address[:port]
1328 poll
= malloc(sizeof(dirsvc_poll_t
));
1330 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1334 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1335 linenum
, strerror(errno
));
1343 * Get poll address and port...
1346 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1349 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1351 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1354 if (polladdr
.addr
.sa_family
== AF_INET6
)
1355 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1357 #endif /* AF_INET6 */
1358 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1360 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1363 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1365 else if (strcasecmp(name
, "User") == 0)
1368 * User ID to run as...
1371 if (isdigit(value
[0]))
1375 struct passwd
*p
; /* Password information */
1378 p
= getpwnam(value
);
1383 LogMessage(L_WARN
, "ReadConfiguration() Unknown username \"%s\"",
1387 else if (strcasecmp(name
, "Group") == 0)
1390 * Group ID to run as...
1393 if (isdigit(value
[0]))
1394 Group
= atoi(value
);
1397 struct group
*g
; /* Group information */
1400 g
= getgrnam(value
);
1405 LogMessage(L_WARN
, "ReadConfiguration() Unknown groupname \"%s\"",
1409 else if (strcasecmp(name
, "SystemGroup") == 0)
1412 * System (admin) group(s)...
1415 char *valueptr
; /* Pointer into value */
1418 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1420 for (valueptr
= value
; *valueptr
; valueptr
++)
1421 if (isspace(*valueptr
) || *valueptr
== ',')
1427 SetString(SystemGroups
+ i
, value
);
1431 while (*value
== ',' || isspace(*value
))
1436 NumSystemGroups
= i
;
1438 else if (strcasecmp(name
, "HostNameLookups") == 0)
1441 * Do hostname lookups?
1444 if (strcasecmp(value
, "off") == 0)
1445 HostNameLookups
= 0;
1446 else if (strcasecmp(value
, "on") == 0)
1447 HostNameLookups
= 1;
1448 else if (strcasecmp(value
, "double") == 0)
1449 HostNameLookups
= 2;
1451 LogMessage(L_WARN
, "ReadConfiguration() Unknown HostNameLookups %s on line %d.",
1454 else if (strcasecmp(name
, "LogLevel") == 0)
1457 * Amount of logging to do...
1460 if (strcasecmp(value
, "debug2") == 0)
1461 LogLevel
= L_DEBUG2
;
1462 else if (strcasecmp(value
, "debug") == 0)
1464 else if (strcasecmp(value
, "info") == 0)
1466 else if (strcasecmp(value
, "notice") == 0)
1467 LogLevel
= L_NOTICE
;
1468 else if (strcasecmp(value
, "warn") == 0)
1470 else if (strcasecmp(value
, "error") == 0)
1472 else if (strcasecmp(value
, "crit") == 0)
1474 else if (strcasecmp(value
, "alert") == 0)
1476 else if (strcasecmp(value
, "emerg") == 0)
1478 else if (strcasecmp(value
, "none") == 0)
1481 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1483 else if (strcasecmp(name
, "PrintcapFormat") == 0)
1486 * Format of printcap file?
1489 if (strcasecmp(value
, "bsd") == 0)
1490 PrintcapFormat
= PRINTCAP_BSD
;
1491 else if (strcasecmp(value
, "solaris") == 0)
1492 PrintcapFormat
= PRINTCAP_SOLARIS
;
1494 LogMessage(L_WARN
, "ReadConfiguration() Unknown PrintcapFormat %s on line %d.",
1500 * Find a simple variable in the list...
1503 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1504 if (strcasecmp(name
, var
->name
) == 0)
1510 * Unknown directive! Output an error message and continue...
1513 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", name
,
1523 char *units
; /* Units */
1526 n
= strtol(value
, &units
, 0);
1528 if (units
&& *units
)
1530 if (tolower(units
[0]) == 'g')
1531 n
*= 1024 * 1024 * 1024;
1532 else if (tolower(units
[0]) == 'm')
1534 else if (tolower(units
[0]) == 'k')
1536 else if (tolower(units
[0]) == 't')
1540 *((int *)var
->ptr
) = n
;
1545 if (strcasecmp(value
, "true") == 0 ||
1546 strcasecmp(value
, "on") == 0 ||
1547 strcasecmp(value
, "enabled") == 0 ||
1548 strcasecmp(value
, "yes") == 0 ||
1550 *((int *)var
->ptr
) = TRUE
;
1551 else if (strcasecmp(value
, "false") == 0 ||
1552 strcasecmp(value
, "off") == 0 ||
1553 strcasecmp(value
, "disabled") == 0 ||
1554 strcasecmp(value
, "no") == 0 ||
1555 strcasecmp(value
, "0") == 0)
1556 *((int *)var
->ptr
) = FALSE
;
1558 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1563 SetString((char **)var
->ptr
, value
);
1574 * 'read_location()' - Read a <Location path> definition.
1577 static int /* O - New line number or 0 on error */
1578 read_location(cups_file_t
*fp
, /* I - Configuration file */
1579 char *location
, /* I - Location name/path */
1580 int linenum
) /* I - Current line number */
1582 int i
; /* Looping var */
1583 location_t
*loc
, /* New location */
1584 *parent
; /* Parent location */
1585 int len
; /* Length of line */
1586 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1587 name
[256], /* Configuration directive */
1588 *nameptr
, /* Pointer into name */
1589 *value
, /* Value for directive */
1590 *valptr
; /* Pointer into value */
1591 unsigned ip
[4], /* IP address components */
1592 mask
[4]; /* IP netmask components */
1595 if ((parent
= AddLocation(location
)) == NULL
)
1598 parent
->limit
= AUTH_LIMIT_ALL
;
1601 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1606 * Skip comment lines...
1613 * Strip trailing whitespace, if any...
1618 while (len
> 0 && isspace(line
[len
- 1]))
1625 * Extract the name from the beginning of the line...
1628 for (value
= line
; isspace(*value
); value
++);
1630 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
1631 nameptr
< (name
+ sizeof(name
) - 1);)
1632 *nameptr
++ = *value
++;
1635 while (isspace(*value
))
1638 if (name
[0] == '\0')
1642 * Decode the directive...
1645 if (strcasecmp(name
, "</Location>") == 0)
1647 else if (strcasecmp(name
, "<Limit") == 0 ||
1648 strcasecmp(name
, "<LimitExcept") == 0)
1650 if ((loc
= CopyLocation(&parent
)) == NULL
)
1656 for (valptr
= value
;
1657 !isspace(*valptr
) && *valptr
!= '>' && *valptr
;
1663 if (strcmp(value
, "ALL") == 0)
1664 loc
->limit
= AUTH_LIMIT_ALL
;
1665 else if (strcmp(value
, "GET") == 0)
1666 loc
->limit
|= AUTH_LIMIT_GET
;
1667 else if (strcmp(value
, "HEAD") == 0)
1668 loc
->limit
|= AUTH_LIMIT_HEAD
;
1669 else if (strcmp(value
, "OPTIONS") == 0)
1670 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1671 else if (strcmp(value
, "POST") == 0)
1672 loc
->limit
|= AUTH_LIMIT_POST
;
1673 else if (strcmp(value
, "PUT") == 0)
1674 loc
->limit
|= AUTH_LIMIT_PUT
;
1675 else if (strcmp(value
, "TRACE") == 0)
1676 loc
->limit
|= AUTH_LIMIT_TRACE
;
1678 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1681 for (value
= valptr
; isspace(*value
) || *value
== '>'; value
++);
1684 if (strcasecmp(name
, "<LimitExcept") == 0)
1685 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1687 parent
->limit
&= ~loc
->limit
;
1689 else if (strcasecmp(name
, "</Limit>") == 0)
1691 else if (strcasecmp(name
, "Encryption") == 0)
1694 * "Encryption xxx" - set required encryption level...
1697 if (strcasecmp(value
, "never") == 0)
1698 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1699 else if (strcasecmp(value
, "always") == 0)
1701 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1702 "Using \"required\" instead.", value
, linenum
);
1704 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1706 else if (strcasecmp(value
, "required") == 0)
1707 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1708 else if (strcasecmp(value
, "ifrequested") == 0)
1709 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1711 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1714 else if (strcasecmp(name
, "Order") == 0)
1717 * "Order Deny,Allow" or "Order Allow,Deny"...
1720 if (strncasecmp(value
, "deny", 4) == 0)
1721 loc
->order_type
= AUTH_ALLOW
;
1722 else if (strncasecmp(value
, "allow", 5) == 0)
1723 loc
->order_type
= AUTH_DENY
;
1725 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1728 else if (strcasecmp(name
, "Allow") == 0 ||
1729 strcasecmp(name
, "Deny") == 0)
1732 * Allow [From] host/ip...
1733 * Deny [From] host/ip...
1736 if (strncasecmp(value
, "from", 4) == 0)
1739 * Strip leading "from"...
1744 while (isspace(*value
))
1749 * Figure out what form the allow/deny address takes:
1760 * nnn.nnn.nnn.nnn/mm
1761 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1764 if (strcasecmp(value
, "all") == 0)
1770 if (strcasecmp(name
, "Allow") == 0)
1771 AllowIP(loc
, zeros
, zeros
);
1773 DenyIP(loc
, zeros
, zeros
);
1775 else if (strcasecmp(value
, "none") == 0)
1781 if (strcasecmp(name
, "Allow") == 0)
1782 AllowIP(loc
, ones
, zeros
);
1784 DenyIP(loc
, ones
, zeros
);
1786 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1789 * Host or domain name...
1792 if (value
[0] == '*')
1795 if (strcasecmp(name
, "Allow") == 0)
1796 AllowHost(loc
, value
);
1798 DenyHost(loc
, value
);
1803 * One of many IP address forms...
1806 if (!get_addr_and_mask(value
, ip
, mask
))
1808 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1813 if (strcasecmp(name
, "Allow") == 0)
1814 AllowIP(loc
, ip
, mask
);
1816 DenyIP(loc
, ip
, mask
);
1819 else if (strcasecmp(name
, "AuthType") == 0)
1822 * AuthType {none,basic,digest,basicdigest}
1825 if (strcasecmp(value
, "none") == 0)
1827 loc
->type
= AUTH_NONE
;
1828 loc
->level
= AUTH_ANON
;
1830 else if (strcasecmp(value
, "basic") == 0)
1832 loc
->type
= AUTH_BASIC
;
1834 if (loc
->level
== AUTH_ANON
)
1835 loc
->level
= AUTH_USER
;
1837 else if (strcasecmp(value
, "digest") == 0)
1839 loc
->type
= AUTH_DIGEST
;
1841 if (loc
->level
== AUTH_ANON
)
1842 loc
->level
= AUTH_USER
;
1844 else if (strcasecmp(value
, "basicdigest") == 0)
1846 loc
->type
= AUTH_BASICDIGEST
;
1848 if (loc
->level
== AUTH_ANON
)
1849 loc
->level
= AUTH_USER
;
1852 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1855 else if (strcasecmp(name
, "AuthClass") == 0)
1858 * AuthClass anonymous, user, system, group
1861 if (strcasecmp(value
, "anonymous") == 0)
1863 loc
->type
= AUTH_NONE
;
1864 loc
->level
= AUTH_ANON
;
1866 else if (strcasecmp(value
, "user") == 0)
1867 loc
->level
= AUTH_USER
;
1868 else if (strcasecmp(value
, "group") == 0)
1869 loc
->level
= AUTH_GROUP
;
1870 else if (strcasecmp(value
, "system") == 0)
1872 loc
->level
= AUTH_GROUP
;
1875 * Use the default system group if none is defined so far...
1878 if (NumSystemGroups
== 0)
1879 NumSystemGroups
= 1;
1881 for (i
= 0; i
< NumSystemGroups
; i
++)
1882 AddName(loc
, SystemGroups
[i
]);
1885 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1888 else if (strcasecmp(name
, "AuthGroupName") == 0)
1889 AddName(loc
, value
);
1890 else if (strcasecmp(name
, "Require") == 0)
1893 * Apache synonym for AuthClass and AuthGroupName...
1897 * Require valid-user
1898 * Require group names
1899 * Require user names
1902 for (valptr
= value
;
1903 !isspace(*valptr
) && *valptr
!= '>' && *valptr
;
1909 if (strcasecmp(value
, "valid-user") == 0 ||
1910 strcasecmp(value
, "user") == 0)
1911 loc
->level
= AUTH_USER
;
1912 else if (strcasecmp(value
, "group") == 0)
1913 loc
->level
= AUTH_GROUP
;
1916 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
1922 * Get the list of names from the line...
1925 for (value
= valptr
; *value
;)
1927 for (valptr
= value
; !isspace(*valptr
) && *valptr
; valptr
++);
1932 AddName(loc
, value
);
1934 for (value
= valptr
; isspace(*value
); value
++);
1937 else if (strcasecmp(name
, "Satisfy") == 0)
1939 if (strcasecmp(value
, "all") == 0)
1940 loc
->satisfy
= AUTH_SATISFY_ALL
;
1941 else if (strcasecmp(value
, "any") == 0)
1942 loc
->satisfy
= AUTH_SATISFY_ANY
;
1944 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
1948 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
1957 * 'get_address()' - Get an address + port number from a line.
1960 static int /* O - 1 if address good, 0 if bad */
1961 get_address(const char *value
, /* I - Value string */
1962 unsigned defaddress
, /* I - Default address */
1963 int defport
, /* I - Default port */
1964 int deffamily
, /* I - Default family */
1965 http_addr_t
*address
) /* O - Socket address */
1967 char hostname
[256], /* Hostname or IP */
1968 portname
[256]; /* Port number or name */
1969 struct hostent
*host
; /* Host address */
1970 struct servent
*port
; /* Port number */
1974 * Initialize the socket address to the defaults...
1977 memset(address
, 0, sizeof(http_addr_t
));
1980 if (deffamily
== AF_INET6
)
1982 address
->ipv6
.sin6_family
= AF_INET6
;
1983 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
1984 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
1985 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
1986 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
1987 address
->ipv6
.sin6_port
= htons(defport
);
1990 #endif /* AF_INET6 */
1992 address
->ipv4
.sin_family
= AF_INET
;
1993 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
1994 address
->ipv4
.sin_port
= htons(defport
);
1998 * Try to grab a hostname and port number...
2001 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2004 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2007 * Hostname is a port number...
2010 strlcpy(portname
, hostname
, sizeof(portname
));
2021 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2026 * Decode the hostname and port number as needed...
2029 if (hostname
[0] && strcmp(hostname
, "*") != 0)
2031 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2033 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2034 hstrerror(h_errno
));
2038 httpAddrLoad(host
, defport
, 0, address
);
2041 if (portname
[0] != '\0')
2043 if (isdigit(portname
[0]))
2046 if (address
->addr
.sa_family
== AF_INET6
)
2047 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2049 #endif /* AF_INET6 */
2050 address
->ipv4
.sin_port
= htons(atoi(portname
));
2054 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2056 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2063 if (address
->addr
.sa_family
== AF_INET6
)
2064 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2066 #endif /* AF_INET6 */
2067 address
->ipv4
.sin_port
= htons(port
->s_port
);
2077 * 'get_addr_and_mask()' - Get an IP address and netmask.
2080 static int /* O - 1 on success, 0 on failure */
2081 get_addr_and_mask(const char *value
, /* I - String from config file */
2082 unsigned *ip
, /* O - Address value */
2083 unsigned *mask
) /* O - Mask value */
2085 int i
, /* Looping var */
2086 family
, /* Address family */
2087 ipcount
; /* Count of fields in address */
2088 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2090 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2091 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2092 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2093 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2098 * Get the address...
2101 memset(ip
, 0, sizeof(unsigned) * 4);
2103 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2107 * See if we have any values > 255; if so, this is an IPv6 address only.
2110 for (i
= 0; i
< ipcount
; i
++)
2116 #endif /* AF_INET6 */
2118 if ((value
= strchr(value
, '/')) != NULL
)
2121 * Get the netmask value(s)...
2125 memset(mask
, 0, sizeof(unsigned) * 4);
2126 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2127 mask
+ 2, mask
+ 3))
2134 if (family
== AF_INET6
)
2139 mask
[0] = 0xffffffff;
2141 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2144 mask
[1] = 0xffffffff;
2148 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2151 mask
[1] = 0xffffffff;
2155 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2160 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2163 #endif /* AF_INET6 */
2168 mask
[0] = 0xffffffff;
2170 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2173 mask
[1] = 0xffffffff;
2177 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2180 mask
[1] = 0xffffffff;
2184 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2189 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2200 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2208 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2209 * required by SSLSetCertificate.
2211 * For now we assumes that there is exactly one SecIdentity in the
2212 * keychain - i.e. there is exactly one matching cert/private key pair.
2213 * In the future we will search a keychain for a SecIdentity matching a
2214 * specific criteria. We also skip the operation of adding additional
2215 * non-signing certs from the keychain to the CFArrayRef.
2217 * To create a self-signed certificate for testing use the certtool.
2218 * Executing the following as root will do it:
2220 * certtool c c v k=CUPS
2224 CDSAGetServerCerts(void)
2226 OSStatus err
; /* Error info */
2227 SecKeychainRef kcRef
; /* Keychain reference */
2228 SecIdentitySearchRef srchRef
; /* Search reference */
2229 SecIdentityRef identity
; /* Identity */
2230 CFArrayRef ca
; /* Certificate array */
2237 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2240 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2241 ServerCertificate
, err
);
2245 * Search for "any" identity matching specified key use;
2246 * in this app, we expect there to be exactly one.
2249 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2253 "Cannot find signing key in keychain \"%s\", error %d",
2254 ServerCertificate
, err
);
2257 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2261 "Cannot find signing key in keychain \"%s\", error %d",
2262 ServerCertificate
, err
);
2265 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2266 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2270 * Found one. Place it in a CFArray.
2271 * TBD: snag other (non-identity) certs from keychain and add them
2275 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2278 LogMessage(L_ERROR
, "CFArrayCreate error");
2281 /*CFRelease(identity);*/
2284 /*CFRelease(srchRef);*/
2287 /*CFRelease(kcRef);*/
2292 #endif /* HAVE_CDSASSL */
2296 * End of "$Id: conf.c,v 1.77.2.40 2003/04/23 18:55:28 mike Exp $".