]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_config.c
Merge sf
[netatalk.git] / etc / afpd / afp_config.c
1 /*
2  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif /* HAVE_CONFIG_H */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <errno.h>
14 #include <string.h>
15 #include <unistd.h>
16 #include <ctype.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20
21 #include <atalk/logger.h>
22 #include <atalk/util.h>
23 #include <atalk/dsi.h>
24 #include <atalk/afp.h>
25 #include <atalk/compat.h>
26 #include <atalk/server_child.h>
27 #include <atalk/globals.h>
28 #include <atalk/errchk.h>
29
30 #ifdef HAVE_LDAP
31 #include <atalk/ldapconfig.h>
32 #endif
33
34 #include "afp_config.h"
35 #include "uam_auth.h"
36 #include "status.h"
37 #include "volume.h"
38 #include "afp_zeroconf.h"
39
40
41 /*!
42  * Free and cleanup all linked DSI objects from config
43  *
44  * Preserve object pointed to by "dsi".
45  * "dsi" can be NULL in which case all DSI objects _and_ the options object are freed 
46  */
47 void configfree(AFPObj *obj, DSI *dsi)
48 {
49     DSI *p, *q;
50
51     for (p = obj->dsi; p; p = q) {
52         q = p->next;
53         if (p == dsi)
54             continue;
55         close(p->socket);
56         free(p);
57     }
58     if (dsi) {
59         dsi->next = NULL;
60         obj->dsi = dsi;
61     } else {
62         afp_options_free(&obj->options);
63     }
64
65     /* the master loaded the volumes for zeroconf, get rid of that */
66     unload_volumes();
67 }
68
69 /*!
70  * Get everything running
71  */
72 int configinit(AFPObj *obj)
73 {
74     EC_INIT;
75     DSI *dsi, **next = &obj->dsi;
76     char *p = NULL, *q = NULL;
77
78     auth_load(obj->options.uampath, obj->options.uamlist);
79     set_signature(&obj->options);
80
81     LOG(log_debug, logtype_afpd, "DSIConfigInit: hostname: %s, listen: %s, port: %s",
82         obj->options.hostname,
83         obj->options.listen ? obj->options.listen : "(default: hostname)",
84         obj->options.port);
85
86     /* obj->options->listen is of the from "IP[:port][,IP:[PORT], ...]" */
87     /* obj->options->port is the default port to listen (548) */
88
89     if (obj->options.listen) {
90         EC_NULL( q = p = strdup(obj->options.listen) );
91         EC_NULL( p = strtok(p, ", ") );
92     }
93
94     while (1) {
95         if ((dsi = dsi_init(obj, obj->options.hostname, p, obj->options.port)) == NULL)
96             break;
97
98         status_init(obj, dsi);
99         *next = dsi;
100         next = &dsi->next;
101
102         LOG(log_note, logtype_afpd, "Netatalk AFP/TCP listening on %s:%d",
103             getip_string((struct sockaddr *)&dsi->server),
104             getip_port((struct sockaddr *)&dsi->server));
105
106         if (p)
107             /* p is NULL if ! obj->options.listen */
108             p = strtok(NULL, ", ");
109         if (!p)
110             break;
111     }
112
113     if (obj->dsi == NULL)
114         EC_FAIL;
115
116 #ifdef HAVE_LDAP
117     /* Parse afp_ldap.conf */
118     acl_ldap_readconfig(obj->iniconfig);
119 #endif /* HAVE_LDAP */
120
121     /* Now register with zeroconf, we also need the volumes for that */
122     if (! (obj->options.flags & OPTION_NOZEROCONF)) {
123         load_volumes(obj);
124         zeroconf_register(obj);
125     }
126
127     if ((p = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fcelistener", NULL))) {
128                 LOG(log_note, logtype_afpd, "Adding FCE listener: %s", p);
129                 fce_add_udp_socket(p);
130     }
131     if ((p = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fcecoalesce", NULL))) {
132                 LOG(log_note, logtype_afpd, "Fce coalesce: %s", p);
133                 fce_set_coalesce(p);
134     }
135     if ((p = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fceevents", NULL))) {
136                 LOG(log_note, logtype_afpd, "Fce events: %s", p);
137                 fce_set_events(p);
138     }
139
140
141 EC_CLEANUP:
142     if (q)
143         free(q);
144     EC_EXIT;
145 }