]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_config.c
Fix volume loading in afpd session
[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 #include <atalk/netatalk_conf.h>
30 #include <atalk/fce_api.h>
31
32 #ifdef HAVE_LDAP
33 #include <atalk/ldapconfig.h>
34 #endif
35
36 #include "afp_config.h"
37 #include "uam_auth.h"
38 #include "status.h"
39 #include "volume.h"
40 #include "afp_zeroconf.h"
41
42
43 /*!
44  * Free and cleanup config and DSI
45  *
46  * "dsi" can be NULL in which case all DSI objects and the config object is freed,
47  * otherwise its an afpd session child and only any unneeded DSI objects are freed
48  */
49 void configfree(AFPObj *obj, DSI *dsi)
50 {
51     DSI *p, *q;
52
53     if (!dsi) {
54         /* Master afpd reloading config */
55         auth_unload();
56         if (! (obj->options.flags & OPTION_NOZEROCONF)) {
57             zeroconf_deregister();
58         }
59     }
60
61     unload_volumes(obj);
62
63     /* Master and child releasing unneeded DSI handles */
64     for (p = obj->dsi; p; p = q) {
65         q = p->next;
66         if (p == dsi)
67             continue;
68         dsi_free(p);
69         free(p);
70     }
71     obj->dsi = NULL;
72
73     /* afpd session child passes dsi handle to obj handle */
74     if (dsi) {
75         dsi->next = NULL;
76         obj->dsi = dsi;
77     }
78 }
79
80 /*!
81  * Get everything running
82  */
83 int configinit(AFPObj *obj)
84 {
85     EC_INIT;
86     DSI *dsi, **next = &obj->dsi;
87     char *p = NULL, *q = NULL, *savep;
88     const char *r;
89
90     auth_load(obj->options.uampath, obj->options.uamlist);
91     set_signature(&obj->options);
92 #ifdef HAVE_LDAP
93     acl_ldap_freeconfig();
94 #endif /* HAVE_LDAP */
95
96     LOG(log_debug, logtype_afpd, "DSIConfigInit: hostname: %s, listen: %s, port: %s",
97         obj->options.hostname,
98         obj->options.listen ? obj->options.listen : "(default: hostname)",
99         obj->options.port);
100
101     /* obj->options->listen is of the from "IP[:port][,IP:[PORT], ...]" */
102     /* obj->options->port is the default port to listen (548) */
103
104     if (obj->options.listen) {
105         EC_NULL( q = p = strdup(obj->options.listen) );
106         EC_NULL( p = strtok_r(p, ", ", &savep) );
107     }
108
109     while (1) {
110         if ((dsi = dsi_init(obj, obj->options.hostname, p, obj->options.port)) == NULL)
111             break;
112
113         status_init(obj, dsi);
114         *next = dsi;
115         next = &dsi->next;
116         dsi->AFPobj = obj;
117
118         LOG(log_note, logtype_afpd, "Netatalk AFP/TCP listening on %s:%d",
119             getip_string((struct sockaddr *)&dsi->server),
120             getip_port((struct sockaddr *)&dsi->server));
121
122         if (p)
123             /* p is NULL if ! obj->options.listen */
124             p = strtok_r(NULL, ", ", &savep);
125         if (!p)
126             break;
127     }
128
129 #ifdef HAVE_LDAP
130     /* Parse afp.conf */
131     acl_ldap_readconfig(obj->iniconfig);
132 #endif /* HAVE_LDAP */
133
134     /* Now register with zeroconf, we also need the volumes for that */
135     if (! (obj->options.flags & OPTION_NOZEROCONF)) {
136         load_volumes(obj);
137         zeroconf_register(obj);
138     }
139
140     if ((r = iniparser_getstring(obj->iniconfig, INISEC_GLOBAL, "fce listener", NULL))) {
141                 LOG(log_note, logtype_afpd, "Adding FCE listener: %s", r);
142                 fce_add_udp_socket(r);
143     }
144     if ((r = iniparser_getstring(obj->iniconfig, INISEC_GLOBAL, "fce coalesce", NULL))) {
145                 LOG(log_note, logtype_afpd, "Fce coalesce: %s", r);
146                 fce_set_coalesce(r);
147     }
148     if ((r = iniparser_getstring(obj->iniconfig, INISEC_GLOBAL, "fce events", NULL))) {
149                 LOG(log_note, logtype_afpd, "Fce events: %s", r);
150                 fce_set_events(r);
151     }
152
153 EC_CLEANUP:
154     if (q)
155         free(q);
156     EC_EXIT;
157 }