2 * "$Id: conf.c,v 1.145 2004/04/20 13:34:49 mike Exp $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2004 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 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
31 * required by SSLSetCertificate.
35 * Include necessary headers...
44 # include <Security/SecureTransport.h>
45 # include <Security/SecIdentitySearch.h>
46 #endif /* HAVE_CDSASSL */
50 #endif /* HAVE_VSYSLOG */
54 * Possibly missing network definitions...
58 # define INADDR_NONE 0xffffffff
59 #endif /* !INADDR_NONE */
63 * Configuration variable structure...
68 char *name
; /* Name of variable */
69 void *ptr
; /* Pointer to variable */
70 int type
; /* Type (int, string, address) */
82 static var_t variables
[] =
84 { "AccessLog", &AccessLog
, VAR_STRING
},
85 { "AutoPurgeJobs", &JobAutoPurge
, VAR_BOOLEAN
},
86 { "BrowseInterval", &BrowseInterval
, VAR_INTEGER
},
87 { "BrowsePort", &BrowsePort
, VAR_INTEGER
},
88 { "BrowseShortNames", &BrowseShortNames
, VAR_BOOLEAN
},
89 { "BrowseTimeout", &BrowseTimeout
, VAR_INTEGER
},
90 { "Browsing", &Browsing
, VAR_BOOLEAN
},
91 { "Classification", &Classification
, VAR_STRING
},
92 { "ClassifyOverride", &ClassifyOverride
, VAR_BOOLEAN
},
93 { "ConfigFilePerm", &ConfigFilePerm
, VAR_INTEGER
},
94 { "DataDir", &DataDir
, VAR_STRING
},
95 { "DefaultCharset", &DefaultCharset
, VAR_STRING
},
96 { "DefaultLanguage", &DefaultLanguage
, VAR_STRING
},
97 { "DocumentRoot", &DocumentRoot
, VAR_STRING
},
98 { "ErrorLog", &ErrorLog
, VAR_STRING
},
99 { "FaxRetryLimit", &FaxRetryLimit
, VAR_INTEGER
},
100 { "FaxRetryInterval", &FaxRetryInterval
, VAR_INTEGER
},
101 { "FileDevice", &FileDevice
, VAR_BOOLEAN
},
102 { "FilterLimit", &FilterLimit
, VAR_INTEGER
},
103 { "FilterNice", &FilterNice
, VAR_INTEGER
},
104 { "FontPath", &FontPath
, VAR_STRING
},
105 { "HideImplicitMembers", &HideImplicitMembers
, VAR_BOOLEAN
},
106 { "ImplicitClasses", &ImplicitClasses
, VAR_BOOLEAN
},
107 { "ImplicitAnyClasses", &ImplicitAnyClasses
, VAR_BOOLEAN
},
108 { "KeepAliveTimeout", &KeepAliveTimeout
, VAR_INTEGER
},
109 { "KeepAlive", &KeepAlive
, VAR_BOOLEAN
},
110 { "LimitRequestBody", &MaxRequestSize
, VAR_INTEGER
},
111 { "ListenBackLog", &ListenBackLog
, VAR_INTEGER
},
112 { "LogFilePerm", &LogFilePerm
, VAR_INTEGER
},
113 { "MaxClients", &MaxClients
, VAR_INTEGER
},
114 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
115 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
116 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
117 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
118 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
119 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
120 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
121 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
122 { "PageLog", &PageLog
, VAR_STRING
},
123 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
124 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
125 { "Printcap", &Printcap
, VAR_STRING
},
126 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
127 { "RemoteRoot", &RemoteRoot
, VAR_STRING
},
128 { "RequestRoot", &RequestRoot
, VAR_STRING
},
129 { "RIPCache", &RIPCache
, VAR_STRING
},
130 { "RunAsUser", &RunAsUser
, VAR_BOOLEAN
},
131 { "RootCertDuration", &RootCertDuration
, VAR_INTEGER
},
132 { "ServerAdmin", &ServerAdmin
, VAR_STRING
},
133 { "ServerBin", &ServerBin
, VAR_STRING
},
135 { "ServerCertificate", &ServerCertificate
, VAR_STRING
},
136 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
137 { "ServerKey", &ServerKey
, VAR_STRING
},
138 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
139 #endif /* HAVE_SSL */
140 { "ServerName", &ServerName
, VAR_STRING
},
141 { "ServerRoot", &ServerRoot
, VAR_STRING
},
142 { "TempDir", &TempDir
, VAR_STRING
},
143 { "Timeout", &Timeout
, VAR_INTEGER
}
145 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
152 static int read_configuration(cups_file_t
*fp
);
153 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
154 static int get_address(char *value
, unsigned defaddress
, int defport
,
155 struct sockaddr_in
*address
);
158 static CFArrayRef
CDSAGetServerCerts();
159 #endif /* HAVE_CDSASSL */
163 * 'ReadConfiguration()' - Read the cupsd.conf file.
166 int /* O - 1 on success, 0 otherwise */
167 ReadConfiguration(void)
169 int i
; /* Looping var */
170 cups_file_t
*fp
; /* Configuration file */
171 int status
; /* Return status */
172 char temp
[1024], /* Temporary buffer */
173 *slash
; /* Directory separator */
174 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
176 char *language
; /* Language string */
177 struct passwd
*user
; /* Default user */
178 struct group
*group
; /* Default group */
179 char *old_serverroot
, /* Old ServerRoot */
180 *old_requestroot
; /* Old RequestRoot */
184 * Shutdown the server...
190 * Save the old root paths...
193 old_serverroot
= NULL
;
194 SetString(&old_serverroot
, ServerRoot
);
195 old_requestroot
= NULL
;
196 SetString(&old_requestroot
, RequestRoot
);
199 * Reset the server configuration data...
202 DeleteAllLocations();
220 for (i
= 0; i
< NumRelays
; i
++)
221 if (Relays
[i
].from
.type
== AUTH_NAME
)
222 free(Relays
[i
].from
.mask
.name
.name
);
229 if (NumListeners
> 0)
240 gethostname(temp
, sizeof(temp
));
241 SetString(&ServerName
, temp
);
242 SetStringf(&ServerAdmin
, "root@%s", temp
);
243 SetString(&ServerBin
, CUPS_SERVERBIN
);
244 SetString(&RequestRoot
, CUPS_REQUESTS
);
245 SetString(&DocumentRoot
, CUPS_DOCROOT
);
246 SetString(&DataDir
, CUPS_DATADIR
);
247 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
248 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
249 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
250 SetString(&Printcap
, "/etc/printcap");
251 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
252 SetString(&FontPath
, CUPS_FONTPATH
);
253 SetString(&RemoteRoot
, "remroot");
255 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
256 if ((slash
= strrchr(temp
, '/')) != NULL
)
259 SetString(&ServerRoot
, temp
);
261 ClearString(&Classification
);
262 ClassifyOverride
= 0;
266 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
268 SetString(&ServerCertificate
, "ssl/server.crt");
269 SetString(&ServerKey
, "ssl/server.key");
270 # endif /* HAVE_CDSASSL */
271 #endif /* HAVE_SSL */
273 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
275 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
278 SetString(&DefaultLanguage
, language
);
279 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
281 SetString(&RIPCache
, "8m");
283 if (getenv("TMPDIR") == NULL
)
284 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
286 SetString(&TempDir
, getenv("TMPDIR"));
289 * Find the default system group: "sys", "system", or "root"...
292 group
= getgrnam(CUPS_DEFAULT_GROUP
);
299 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
300 Group
= group
->gr_gid
;
309 SetString(&SystemGroups
[0], group
->gr_name
);
314 SetString(&SystemGroups
[0], "unknown");
320 * Find the default user...
323 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
324 User
= 1; /* Force to a non-priviledged account */
334 ConfigFilePerm
= 0640;
338 FaxRetryInterval
= 300;
343 HostNameLookups
= FALSE
;
344 ImplicitClasses
= TRUE
;
345 ImplicitAnyClasses
= FALSE
;
346 HideImplicitMembers
= TRUE
;
348 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
349 ListenBackLog
= SOMAXCONN
;
352 MaxClientsPerHost
= 0;
353 MaxLogSize
= 1024 * 1024;
354 MaxPrinterHistory
= 10;
356 RootCertDuration
= 300;
358 Timeout
= DEFAULT_TIMEOUT
;
360 BrowseInterval
= DEFAULT_INTERVAL
;
361 BrowsePort
= ippPort();
362 BrowseProtocols
= BROWSE_CUPS
;
363 BrowseShortNames
= TRUE
;
364 BrowseTimeout
= DEFAULT_TIMEOUT
;
367 JobHistory
= DEFAULT_HISTORY
;
368 JobFiles
= DEFAULT_FILES
;
372 MaxJobsPerPrinter
= 0;
376 * Read the configuration file...
379 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
382 status
= read_configuration(fp
);
395 * Use the default system group if none was supplied in cupsd.conf...
398 if (NumSystemGroups
== 0)
402 * Get the access control list for browsing...
405 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
408 * Open the system log for cupsd if necessary...
412 if (strcmp(AccessLog
, "syslog") == 0 ||
413 strcmp(ErrorLog
, "syslog") == 0 ||
414 strcmp(PageLog
, "syslog") == 0)
415 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
416 #endif /* HAVE_VSYSLOG */
419 * Log the configuration file that was used...
422 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
425 * Check that we have at least one listen/port line; if not, report this
426 * as an error and exit!
429 if (NumListeners
== 0)
435 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
441 kill(getpid(), SIGTERM
);
445 * Set the default locale using the language and charset...
448 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
451 * Update all relative filenames to include the full path from ServerRoot...
454 if (DocumentRoot
[0] != '/')
455 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
457 if (RequestRoot
[0] != '/')
458 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
460 if (ServerBin
[0] != '/')
461 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
464 if (ServerCertificate
[0] != '/')
465 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
467 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
468 chown(ServerCertificate
, RunUser
, Group
);
469 chmod(ServerCertificate
, ConfigFilePerm
);
471 if (ServerKey
[0] != '/')
472 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
474 chown(ServerKey
, RunUser
, Group
);
475 chmod(ServerKey
, ConfigFilePerm
);
476 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
477 #endif /* HAVE_SSL */
480 * Make sure that ServerRoot and the config files are owned and
481 * writable by the user and group in the cupsd.conf file...
484 chown(ServerRoot
, RunUser
, Group
);
485 chmod(ServerRoot
, 0775);
487 snprintf(temp
, sizeof(temp
), "%s/certs", ServerRoot
);
488 chown(temp
, RunUser
, Group
);
491 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
492 chown(temp
, RunUser
, Group
);
495 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
496 chown(temp
, RunUser
, Group
);
499 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
500 chown(temp
, RunUser
, Group
);
501 chmod(temp
, ConfigFilePerm
);
503 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
504 chown(temp
, RunUser
, Group
);
508 chmod(temp
, ConfigFilePerm
);
509 #endif /* __APPLE__ */
511 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
512 chown(temp
, RunUser
, Group
);
516 chmod(temp
, ConfigFilePerm
);
517 #endif /* __APPLE__ */
519 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
520 chown(temp
, User
, Group
);
524 * Make sure the request and temporary directories have the right
528 chown(RequestRoot
, RunUser
, Group
);
529 chmod(RequestRoot
, 0710);
531 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
534 * Only update ownership and permissions if the CUPS temp directory
535 * is under the spool directory...
538 chown(TempDir
, RunUser
, Group
);
539 chmod(TempDir
, 01770);
543 * Check the MaxClients setting, and then allocate memory for it...
546 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
549 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
552 MaxClients
= MaxFDs
/ 3;
555 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
557 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
558 MaxClients
, strerror(errno
));
562 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
564 if (Classification
&& strcasecmp(Classification
, "none") == 0)
565 ClearString(&Classification
);
568 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
571 * Update the MaxClientsPerHost value, as needed...
574 if (MaxClientsPerHost
<= 0)
575 MaxClientsPerHost
= MaxClients
;
577 if (MaxClientsPerHost
> MaxClients
)
578 MaxClientsPerHost
= MaxClients
;
580 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
584 * If we are doing a full reload or the server root has changed, flush
585 * the jobs, printers, etc. and start from scratch...
588 if (NeedReload
== RELOAD_ALL
||
589 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
590 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
592 LogMessage(L_INFO
, "Full reload is required.");
602 DefaultPrinter
= NULL
;
616 if (MimeDatabase
!= NULL
)
617 mimeDelete(MimeDatabase
);
621 for (i
= 0; i
< NumMimeTypes
; i
++)
622 free((void *)MimeTypes
[i
]);
628 * Read the MIME type and conversion database...
631 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
633 MimeDatabase
= mimeNew();
634 mimeMerge(MimeDatabase
, ServerRoot
, temp
);
637 * Create a list of MIME types for the document-format-supported
641 NumMimeTypes
= MimeDatabase
->num_types
;
642 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
645 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
647 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
649 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
650 MimeDatabase
->types
[i
]->type
);
652 MimeTypes
[i
] = strdup(type
);
655 if (i
< NumMimeTypes
)
656 MimeTypes
[i
] = strdup("application/octet-stream");
662 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
666 * Load printers and classes...
675 * Load devices and PPDs...
678 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
681 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
685 * Load queued jobs...
690 LogMessage(L_INFO
, "Full reload complete.");
696 LogMessage(L_INFO
, "Partial reload complete.");
700 * Reset the reload state...
703 NeedReload
= RELOAD_NONE
;
705 ClearString(&old_serverroot
);
706 ClearString(&old_requestroot
);
709 * Startup the server and return...
719 * 'read_configuration()' - Read a configuration file.
722 static int /* O - 1 on success, 0 on failure */
723 read_configuration(cups_file_t
*fp
) /* I - File to read from */
725 int i
; /* Looping var */
726 int linenum
; /* Current line number */
727 int len
; /* Length of line */
728 char line
[HTTP_MAX_BUFFER
], /* Line from file */
729 name
[256], /* Parameter name */
730 *nameptr
, /* Pointer into name */
731 *value
; /* Pointer to value */
732 int valuelen
; /* Length of value */
733 var_t
*var
; /* Current variable */
734 unsigned address
, /* Address value */
735 netmask
; /* Netmask value */
736 int ip
[4], /* IP address components */
737 ipcount
, /* Number of components provided */
738 mask
[4]; /* IP netmask components */
739 dirsvc_relay_t
*relay
; /* Relay data */
740 dirsvc_poll_t
*poll
; /* Polling data */
741 struct sockaddr_in polladdr
; /* Polling address */
742 location_t
*location
; /* Browse location */
743 cups_file_t
*incfile
; /* Include file */
744 char incname
[1024]; /* Include filename */
745 static unsigned netmasks
[4] = /* Standard netmasks... */
755 * Loop through each line in the file...
760 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
765 * Skip comment lines...
772 * Strip trailing whitespace, if any...
777 while (len
> 0 && isspace(line
[len
- 1]))
784 * Extract the name from the beginning of the line...
787 for (value
= line
; isspace(*value
); value
++);
789 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
790 nameptr
< (name
+ sizeof(name
) - 1);)
791 *nameptr
++ = *value
++;
794 while (isspace(*value
))
801 * Decode the directive...
804 if (strcasecmp(name
, "Include") == 0)
811 strlcpy(incname
, value
, sizeof(incname
));
813 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
815 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
816 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
817 incname
, strerror(errno
));
820 read_configuration(incfile
);
821 cupsFileClose(incfile
);
824 else if (strcasecmp(name
, "<Location") == 0)
830 if (line
[len
- 1] == '>')
832 line
[len
- 1] = '\0';
834 linenum
= read_location(fp
, value
, linenum
);
840 LogMessage(L_ERROR
, "ReadConfiguration() Syntax error on line %d.",
845 else if (strcasecmp(name
, "Port") == 0 ||
846 strcasecmp(name
, "Listen") == 0)
849 * Add a listening address to the list...
852 listener_t
*temp
; /* New listeners array */
855 if (NumListeners
== 0)
856 temp
= malloc(sizeof(listener_t
));
858 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
862 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
863 name
, linenum
, strerror(errno
));
868 temp
+= NumListeners
;
870 memset(temp
, 0, sizeof(listener_t
));
872 if (get_address(value
, INADDR_ANY
, IPP_PORT
, &(temp
->address
)))
874 LogMessage(L_INFO
, "Listening to %x:%d",
875 (unsigned)ntohl(temp
->address
.sin_addr
.s_addr
),
876 ntohs(temp
->address
.sin_port
));
880 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
884 else if (strcasecmp(name
, "SSLPort") == 0 ||
885 strcasecmp(name
, "SSLListen") == 0)
888 * Add a listening address to the list...
891 listener_t
*temp
; /* New listeners array */
894 if (NumListeners
== 0)
895 temp
= malloc(sizeof(listener_t
));
897 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
901 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
902 name
, linenum
, strerror(errno
));
907 temp
+= NumListeners
;
909 if (get_address(value
, INADDR_ANY
, IPP_PORT
, &(temp
->address
)))
911 LogMessage(L_INFO
, "Listening to %x:%d (SSL)",
912 (unsigned)ntohl(temp
->address
.sin_addr
.s_addr
),
913 ntohs(temp
->address
.sin_port
));
914 temp
->encryption
= HTTP_ENCRYPT_ALWAYS
;
918 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
921 #endif /* HAVE_SSL */
922 else if (strcasecmp(name
, "BrowseAddress") == 0)
925 * Add a browse address to the list...
928 dirsvc_addr_t
*temp
; /* New browse address array */
931 if (NumBrowsers
== 0)
932 temp
= malloc(sizeof(dirsvc_addr_t
));
934 temp
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
938 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
939 linenum
, strerror(errno
));
946 memset(temp
, 0, sizeof(dirsvc_addr_t
));
948 if (strcasecmp(value
, "@LOCAL") == 0)
951 * Send browse data to all local interfaces...
954 strcpy(temp
->iface
, "*");
957 else if (strncasecmp(value
, "@IF(", 4) == 0)
960 * Send browse data to the named interface...
963 strlcpy(temp
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
965 nameptr
= temp
->iface
+ strlen(temp
->iface
) - 1;
971 else if (get_address(value
, INADDR_NONE
, BrowsePort
, &(temp
->to
)))
973 LogMessage(L_INFO
, "Sending browsing info to %x:%d",
974 (unsigned)ntohl(temp
->to
.sin_addr
.s_addr
),
975 ntohs(temp
->to
.sin_port
));
980 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
983 else if (strcasecmp(name
, "BrowseOrder") == 0)
986 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
989 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
990 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
992 if (location
== NULL
)
993 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
994 else if (strncasecmp(value
, "deny", 4) == 0)
995 location
->order_type
= AUTH_ALLOW
;
996 else if (strncasecmp(value
, "allow", 5) == 0)
997 location
->order_type
= AUTH_DENY
;
999 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1002 else if (strcasecmp(name
, "BrowseProtocols") == 0)
1005 * "BrowseProtocol name [... name]"
1008 BrowseProtocols
= 0;
1012 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1013 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1016 if (value
[valuelen
])
1018 value
[valuelen
] = '\0';
1022 if (strcasecmp(value
, "cups") == 0)
1023 BrowseProtocols
|= BROWSE_CUPS
;
1024 else if (strcasecmp(value
, "slp") == 0)
1025 BrowseProtocols
|= BROWSE_SLP
;
1026 else if (strcasecmp(value
, "ldap") == 0)
1027 BrowseProtocols
|= BROWSE_LDAP
;
1028 else if (strcasecmp(value
, "all") == 0)
1029 BrowseProtocols
|= BROWSE_ALL
;
1032 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1037 for (value
+= valuelen
; *value
; value
++)
1038 if (!isspace(*value
) || *value
!= ',')
1042 else if (strcasecmp(name
, "BrowseAllow") == 0 ||
1043 strcasecmp(name
, "BrowseDeny") == 0)
1046 * BrowseAllow [From] host/ip...
1047 * BrowseDeny [From] host/ip...
1050 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1051 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1053 if (location
== NULL
)
1054 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1057 if (strncasecmp(value
, "from ", 5) == 0)
1060 * Strip leading "from"...
1065 while (isspace(*value
))
1070 * Figure out what form the allow/deny address takes:
1081 * nnn.nnn.nnn.nnn/mm
1082 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1085 if (strcasecmp(value
, "all") == 0)
1091 if (strcasecmp(name
, "BrowseAllow") == 0)
1092 AllowIP(location
, 0, 0);
1094 DenyIP(location
, 0, 0);
1096 else if (strcasecmp(value
, "none") == 0)
1102 if (strcasecmp(name
, "BrowseAllow") == 0)
1103 AllowIP(location
, ~0, 0);
1105 DenyIP(location
, ~0, 0);
1107 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1110 * Host or domain name...
1113 if (value
[0] == '*')
1116 if (strcasecmp(name
, "BrowseAllow") == 0)
1117 AllowHost(location
, value
);
1119 DenyHost(location
, value
);
1124 * One of many IP address forms...
1127 memset(ip
, 0, sizeof(ip
));
1128 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1129 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1131 if ((value
= strchr(value
, '/')) != NULL
)
1134 memset(mask
, 0, sizeof(mask
));
1135 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1136 mask
+ 2, mask
+ 3))
1139 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1142 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1143 mask
[2]) << 8) | mask
[3];
1146 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1148 netmask
= 0xffffffff;
1153 netmask
= netmasks
[ipcount
- 1];
1155 if ((address
& ~netmask
) != 0)
1157 LogMessage(L_WARN
, "Discarding extra bits in %s address %08x for netmask %08x...",
1158 name
, address
, netmask
);
1162 if (strcasecmp(name
, "BrowseAllow") == 0)
1163 AllowIP(location
, address
, netmask
);
1165 DenyIP(location
, address
, netmask
);
1169 else if (strcasecmp(name
, "BrowseRelay") == 0)
1172 * BrowseRelay [from] source [to] destination
1176 relay
= malloc(sizeof(dirsvc_relay_t
));
1178 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1182 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1183 linenum
, strerror(errno
));
1190 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1192 if (strncasecmp(value
, "from ", 5) == 0)
1195 * Strip leading "from"...
1200 while (isspace(*value
))
1205 * Figure out what form the from address takes:
1214 * nnn.nnn.nnn.nnn/mm
1215 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1218 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1221 * Host or domain name...
1224 if (value
[0] == '*')
1227 relay
->from
.type
= AUTH_NAME
;
1228 relay
->from
.mask
.name
.name
= strdup(value
);
1229 relay
->from
.mask
.name
.length
= strlen(value
);
1234 * One of many IP address forms...
1237 memset(ip
, 0, sizeof(ip
));
1238 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1239 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1241 for (; *value
; value
++)
1242 if (*value
== '/' || isspace(*value
))
1248 memset(mask
, 0, sizeof(mask
));
1249 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1250 mask
+ 2, mask
+ 3))
1253 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1256 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1257 mask
[2]) << 8) | mask
[3];
1260 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1262 netmask
= 0xffffffff;
1267 netmask
= netmasks
[ipcount
- 1];
1269 relay
->from
.type
= AUTH_IP
;
1270 relay
->from
.mask
.ip
.address
= address
;
1271 relay
->from
.mask
.ip
.netmask
= netmask
;
1275 * Skip value and trailing whitespace...
1278 for (; *value
; value
++)
1279 if (isspace(*value
))
1282 while (isspace(*value
))
1285 if (strncasecmp(value
, "to ", 3) == 0)
1288 * Strip leading "to"...
1293 while (isspace(*value
))
1298 * Get "to" address and port...
1301 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, &(relay
->to
)))
1303 if (relay
->from
.type
== AUTH_NAME
)
1304 LogMessage(L_INFO
, "Relaying from %s to %x:%d",
1305 relay
->from
.mask
.name
.name
,
1306 (unsigned)ntohl(relay
->to
.sin_addr
.s_addr
),
1307 ntohs(relay
->to
.sin_port
));
1309 LogMessage(L_INFO
, "Relaying from %x/%x to %x:%d",
1310 relay
->from
.mask
.ip
.address
, relay
->from
.mask
.ip
.netmask
,
1311 (unsigned)ntohl(relay
->to
.sin_addr
.s_addr
),
1312 ntohs(relay
->to
.sin_port
));
1318 if (relay
->from
.type
== AUTH_NAME
)
1319 free(relay
->from
.mask
.name
.name
);
1321 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1324 else if (strcasecmp(name
, "BrowsePoll") == 0)
1327 * BrowsePoll address[:port]
1331 poll
= malloc(sizeof(dirsvc_poll_t
));
1333 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1337 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1338 linenum
, strerror(errno
));
1346 * Get poll address and port...
1349 if (get_address(value
, INADDR_NONE
, ippPort(), &polladdr
))
1351 LogMessage(L_INFO
, "Polling %x:%d",
1352 (unsigned)ntohl(polladdr
.sin_addr
.s_addr
),
1353 ntohs(polladdr
.sin_port
));
1356 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1358 address
= ntohl(polladdr
.sin_addr
.s_addr
);
1360 sprintf(poll
->hostname
, "%d.%d.%d.%d", address
>> 24,
1361 (address
>> 16) & 255, (address
>> 8) & 255, address
& 255);
1362 poll
->port
= ntohs(polladdr
.sin_port
);
1365 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1367 else if (strcasecmp(name
, "User") == 0)
1370 * User ID to run as...
1373 if (isdigit(value
[0]))
1377 struct passwd
*p
; /* Password information */
1380 p
= getpwnam(value
);
1385 LogMessage(L_WARN
, "ReadConfiguration() Unknown username \"%s\"",
1389 else if (strcasecmp(name
, "Group") == 0)
1392 * Group ID to run as...
1395 if (isdigit(value
[0]))
1396 Group
= atoi(value
);
1399 struct group
*g
; /* Group information */
1402 g
= getgrnam(value
);
1407 LogMessage(L_WARN
, "ReadConfiguration() Unknown groupname \"%s\"",
1411 else if (strcasecmp(name
, "SystemGroup") == 0)
1414 * System (admin) group(s)...
1417 char *valueptr
; /* Pointer into value */
1420 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1422 for (valueptr
= value
; *valueptr
; valueptr
++)
1423 if (isspace(*valueptr
) || *valueptr
== ',')
1429 SetString(SystemGroups
+ i
, value
);
1433 while (*value
== ',' || isspace(*value
))
1438 NumSystemGroups
= i
;
1440 else if (strcasecmp(name
, "HostNameLookups") == 0)
1443 * Do hostname lookups?
1446 if (strcasecmp(value
, "off") == 0)
1447 HostNameLookups
= 0;
1448 else if (strcasecmp(value
, "on") == 0)
1449 HostNameLookups
= 1;
1450 else if (strcasecmp(value
, "double") == 0)
1451 HostNameLookups
= 2;
1453 LogMessage(L_WARN
, "ReadConfiguration() Unknown HostNameLookups %s on line %d.",
1456 else if (strcasecmp(name
, "LogLevel") == 0)
1459 * Amount of logging to do...
1462 if (strcasecmp(value
, "debug2") == 0)
1463 LogLevel
= L_DEBUG2
;
1464 else if (strcasecmp(value
, "debug") == 0)
1466 else if (strcasecmp(value
, "info") == 0)
1468 else if (strcasecmp(value
, "notice") == 0)
1469 LogLevel
= L_NOTICE
;
1470 else if (strcasecmp(value
, "warn") == 0)
1472 else if (strcasecmp(value
, "error") == 0)
1474 else if (strcasecmp(value
, "crit") == 0)
1476 else if (strcasecmp(value
, "alert") == 0)
1478 else if (strcasecmp(value
, "emerg") == 0)
1480 else if (strcasecmp(value
, "none") == 0)
1483 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1485 else if (strcasecmp(name
, "PrintcapFormat") == 0)
1488 * Format of printcap file?
1491 if (strcasecmp(value
, "bsd") == 0)
1492 PrintcapFormat
= PRINTCAP_BSD
;
1493 else if (strcasecmp(value
, "solaris") == 0)
1494 PrintcapFormat
= PRINTCAP_SOLARIS
;
1496 LogMessage(L_WARN
, "ReadConfiguration() Unknown PrintcapFormat %s on line %d.",
1502 * Find a simple variable in the list...
1505 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1506 if (strcasecmp(name
, var
->name
) == 0)
1512 * Unknown directive! Output an error message and continue...
1515 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", name
,
1525 char *units
; /* Units */
1528 n
= strtol(value
, &units
, 0);
1530 if (units
&& *units
)
1532 if (tolower(units
[0] & 255) == 'g')
1533 n
*= 1024 * 1024 * 1024;
1534 else if (tolower(units
[0] & 255) == 'm')
1536 else if (tolower(units
[0] & 255) == 'k')
1538 else if (tolower(units
[0] & 255) == 't')
1542 *((int *)var
->ptr
) = n
;
1547 if (strcasecmp(value
, "true") == 0 ||
1548 strcasecmp(value
, "on") == 0 ||
1549 strcasecmp(value
, "enabled") == 0 ||
1550 strcasecmp(value
, "yes") == 0 ||
1552 *((int *)var
->ptr
) = TRUE
;
1553 else if (strcasecmp(value
, "false") == 0 ||
1554 strcasecmp(value
, "off") == 0 ||
1555 strcasecmp(value
, "disabled") == 0 ||
1556 strcasecmp(value
, "no") == 0 ||
1557 strcasecmp(value
, "0") == 0)
1558 *((int *)var
->ptr
) = FALSE
;
1560 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1565 SetString((char **)var
->ptr
, value
);
1576 * 'read_location()' - Read a <Location path> definition.
1579 static int /* O - New line number or 0 on error */
1580 read_location(cups_file_t
*fp
, /* I - Configuration file */
1581 char *location
, /* I - Location name/path */
1582 int linenum
) /* I - Current line number */
1584 int i
; /* Looping var */
1585 location_t
*loc
, /* New location */
1586 *parent
; /* Parent location */
1587 int len
; /* Length of line */
1588 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1589 name
[256], /* Configuration directive */
1590 *nameptr
, /* Pointer into name */
1591 *value
, /* Value for directive */
1592 *valptr
; /* Pointer into value */
1593 unsigned address
, /* Address value */
1594 netmask
; /* Netmask value */
1595 int ip
[4], /* IP address components */
1596 ipcount
, /* Number of components provided */
1597 mask
[4]; /* IP netmask components */
1598 static unsigned netmasks
[4] = /* Standard netmasks... */
1607 if ((parent
= AddLocation(location
)) == NULL
)
1610 parent
->limit
= AUTH_LIMIT_ALL
;
1613 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1618 * Skip comment lines...
1625 * Strip trailing whitespace, if any...
1630 while (len
> 0 && isspace(line
[len
- 1] & 255))
1637 * Extract the name from the beginning of the line...
1640 for (value
= line
; isspace(*value
& 255); value
++);
1642 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
& 255) &&
1643 nameptr
< (name
+ sizeof(name
) - 1);)
1644 *nameptr
++ = *value
++;
1647 while (isspace(*value
& 255))
1650 if (name
[0] == '\0')
1654 * Decode the directive...
1657 if (strcasecmp(name
, "</Location>") == 0)
1659 else if (strcasecmp(name
, "<Limit") == 0 ||
1660 strcasecmp(name
, "<LimitExcept") == 0)
1662 if ((loc
= CopyLocation(&parent
)) == NULL
)
1668 for (valptr
= value
;
1669 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
1675 if (strcmp(value
, "ALL") == 0)
1676 loc
->limit
= AUTH_LIMIT_ALL
;
1677 else if (strcmp(value
, "GET") == 0)
1678 loc
->limit
|= AUTH_LIMIT_GET
;
1679 else if (strcmp(value
, "HEAD") == 0)
1680 loc
->limit
|= AUTH_LIMIT_HEAD
;
1681 else if (strcmp(value
, "OPTIONS") == 0)
1682 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1683 else if (strcmp(value
, "POST") == 0)
1684 loc
->limit
|= AUTH_LIMIT_POST
;
1685 else if (strcmp(value
, "PUT") == 0)
1686 loc
->limit
|= AUTH_LIMIT_PUT
;
1687 else if (strcmp(value
, "TRACE") == 0)
1688 loc
->limit
|= AUTH_LIMIT_TRACE
;
1690 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1693 for (value
= valptr
; isspace(*value
& 255) || *value
== '>'; value
++);
1696 if (strcasecmp(name
, "<LimitExcept") == 0)
1697 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1699 parent
->limit
&= ~loc
->limit
;
1701 else if (strcasecmp(name
, "</Limit>") == 0)
1703 else if (strcasecmp(name
, "Encryption") == 0)
1706 * "Encryption xxx" - set required encryption level...
1709 if (strcasecmp(value
, "never") == 0)
1710 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1711 else if (strcasecmp(value
, "always") == 0)
1713 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1714 "Using \"required\" instead.", value
, linenum
);
1716 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1718 else if (strcasecmp(value
, "required") == 0)
1719 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1720 else if (strcasecmp(value
, "ifrequested") == 0)
1721 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1723 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1726 else if (strcasecmp(name
, "Order") == 0)
1729 * "Order Deny,Allow" or "Order Allow,Deny"...
1732 if (strncasecmp(value
, "deny", 4) == 0)
1733 loc
->order_type
= AUTH_ALLOW
;
1734 else if (strncasecmp(value
, "allow", 5) == 0)
1735 loc
->order_type
= AUTH_DENY
;
1737 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1740 else if (strcasecmp(name
, "Allow") == 0 ||
1741 strcasecmp(name
, "Deny") == 0)
1744 * Allow [From] host/ip...
1745 * Deny [From] host/ip...
1748 if (strncasecmp(value
, "from", 4) == 0)
1751 * Strip leading "from"...
1756 while (isspace(*value
& 255))
1761 * Figure out what form the allow/deny address takes:
1772 * nnn.nnn.nnn.nnn/mm
1773 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1776 if (strcasecmp(value
, "all") == 0)
1782 if (strcasecmp(name
, "Allow") == 0)
1787 else if (strcasecmp(value
, "none") == 0)
1793 if (strcasecmp(name
, "Allow") == 0)
1794 AllowIP(loc
, ~0, 0);
1798 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1801 * Host or domain name...
1804 if (value
[0] == '*')
1807 if (strcasecmp(name
, "Allow") == 0)
1808 AllowHost(loc
, value
);
1810 DenyHost(loc
, value
);
1815 * One of many IP address forms...
1818 memset(ip
, 0, sizeof(ip
));
1819 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1820 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1822 if ((value
= strchr(value
, '/')) != NULL
)
1825 memset(mask
, 0, sizeof(mask
));
1826 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1827 mask
+ 2, mask
+ 3))
1830 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1833 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1834 mask
[2]) << 8) | mask
[3];
1837 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1839 netmask
= 0xffffffff;
1844 netmask
= netmasks
[ipcount
- 1];
1846 if ((address
& ~netmask
) != 0)
1848 LogMessage(L_WARN
, "Discarding extra bits in %s address %08x for netmask %08x...",
1849 name
, address
, netmask
);
1853 if (strcasecmp(name
, "Allow") == 0)
1854 AllowIP(loc
, address
, netmask
);
1856 DenyIP(loc
, address
, netmask
);
1859 else if (strcasecmp(name
, "AuthType") == 0)
1862 * AuthType {none,basic,digest,basicdigest}
1865 if (strcasecmp(value
, "none") == 0)
1867 loc
->type
= AUTH_NONE
;
1868 loc
->level
= AUTH_ANON
;
1870 else if (strcasecmp(value
, "basic") == 0)
1872 loc
->type
= AUTH_BASIC
;
1874 if (loc
->level
== AUTH_ANON
)
1875 loc
->level
= AUTH_USER
;
1877 else if (strcasecmp(value
, "digest") == 0)
1879 loc
->type
= AUTH_DIGEST
;
1881 if (loc
->level
== AUTH_ANON
)
1882 loc
->level
= AUTH_USER
;
1884 else if (strcasecmp(value
, "basicdigest") == 0)
1886 loc
->type
= AUTH_BASICDIGEST
;
1888 if (loc
->level
== AUTH_ANON
)
1889 loc
->level
= AUTH_USER
;
1892 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1895 else if (strcasecmp(name
, "AuthClass") == 0)
1898 * AuthClass anonymous, user, system, group
1901 if (strcasecmp(value
, "anonymous") == 0)
1903 loc
->type
= AUTH_NONE
;
1904 loc
->level
= AUTH_ANON
;
1906 else if (strcasecmp(value
, "user") == 0)
1907 loc
->level
= AUTH_USER
;
1908 else if (strcasecmp(value
, "group") == 0)
1909 loc
->level
= AUTH_GROUP
;
1910 else if (strcasecmp(value
, "system") == 0)
1912 loc
->level
= AUTH_GROUP
;
1915 * Use the default system group if none is defined so far...
1918 if (NumSystemGroups
== 0)
1919 NumSystemGroups
= 1;
1921 for (i
= 0; i
< NumSystemGroups
; i
++)
1922 AddName(loc
, SystemGroups
[i
]);
1925 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1928 else if (strcasecmp(name
, "AuthGroupName") == 0)
1929 AddName(loc
, value
);
1930 else if (strcasecmp(name
, "Require") == 0)
1933 * Apache synonym for AuthClass and AuthGroupName...
1937 * Require valid-user
1938 * Require group names
1939 * Require user names
1942 for (valptr
= value
;
1943 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
1949 if (strcasecmp(value
, "valid-user") == 0 ||
1950 strcasecmp(value
, "user") == 0)
1951 loc
->level
= AUTH_USER
;
1952 else if (strcasecmp(value
, "group") == 0)
1953 loc
->level
= AUTH_GROUP
;
1956 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
1962 * Get the list of names from the line...
1965 for (value
= valptr
; *value
;)
1967 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1972 AddName(loc
, value
);
1974 for (value
= valptr
; isspace(*value
& 255); value
++);
1977 else if (strcasecmp(name
, "Satisfy") == 0)
1979 if (strcasecmp(value
, "all") == 0)
1980 loc
->satisfy
= AUTH_SATISFY_ALL
;
1981 else if (strcasecmp(value
, "any") == 0)
1982 loc
->satisfy
= AUTH_SATISFY_ANY
;
1984 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
1988 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
1997 * 'get_address()' - Get an address + port number from a line.
2000 static int /* O - 1 if address good, 0 if bad */
2001 get_address(char *value
, /* I - Value string */
2002 unsigned defaddress
, /* I - Default address */
2003 int defport
, /* I - Default port */
2004 struct sockaddr_in
*address
) /* O - Socket address */
2006 char hostname
[256], /* Hostname or IP */
2007 portname
[256]; /* Port number or name */
2008 struct hostent
*host
; /* Host address */
2009 struct servent
*port
; /* Port number */
2013 * Initialize the socket address to the defaults...
2016 memset(address
, 0, sizeof(struct sockaddr_in
));
2017 address
->sin_family
= AF_INET
;
2018 address
->sin_addr
.s_addr
= htonl(defaddress
);
2019 address
->sin_port
= htons(defport
);
2022 * Try to grab a hostname and port number...
2025 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2028 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2031 * Hostname is a port number...
2034 strlcpy(portname
, hostname
, sizeof(portname
));
2043 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2048 * Decode the hostname and port number as needed...
2051 if (hostname
[0] && strcmp(hostname
, "*"))
2053 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2055 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2056 hstrerror(h_errno
));
2060 memcpy(&(address
->sin_addr
), host
->h_addr
, host
->h_length
);
2061 address
->sin_port
= htons(defport
);
2064 if (portname
[0] != '\0')
2066 if (isdigit(portname
[0] & 255))
2067 address
->sin_port
= htons(atoi(portname
));
2070 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2072 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2077 address
->sin_port
= htons(port
->s_port
);
2087 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2088 * required by SSLSetCertificate.
2090 * For now we assumes that there is exactly one SecIdentity in the
2091 * keychain - i.e. there is exactly one matching cert/private key pair.
2092 * In the future we will search a keychain for a SecIdentity matching a
2093 * specific criteria. We also skip the operation of adding additional
2094 * non-signing certs from the keychain to the CFArrayRef.
2096 * To create a self-signed certificate for testing use the certtool.
2097 * Executing the following as root will do it:
2099 * certtool c c v k=CUPS
2103 CDSAGetServerCerts(void)
2105 OSStatus err
; /* Error info */
2106 SecKeychainRef kcRef
; /* Keychain reference */
2107 SecIdentitySearchRef srchRef
; /* Search reference */
2108 SecIdentityRef identity
; /* Identity */
2109 CFArrayRef ca
; /* Certificate array */
2116 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2119 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2120 ServerCertificate
, err
);
2124 * Search for "any" identity matching specified key use;
2125 * in this app, we expect there to be exactly one.
2128 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2132 "Cannot find signing key in keychain \"%s\", error %d",
2133 ServerCertificate
, err
);
2136 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2140 "Cannot find signing key in keychain \"%s\", error %d",
2141 ServerCertificate
, err
);
2144 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2145 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2149 * Found one. Place it in a CFArray.
2150 * TBD: snag other (non-identity) certs from keychain and add them
2154 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2157 LogMessage(L_ERROR
, "CFArrayCreate error");
2160 /*CFRelease(identity);*/
2163 /*CFRelease(srchRef);*/
2166 /*CFRelease(kcRef);*/
2171 #endif /* HAVE_CDSASSL */
2175 * End of "$Id: conf.c,v 1.145 2004/04/20 13:34:49 mike Exp $".