]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_config.c
Merge remote branch 'sf/branch-allea' into branch-allea
[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 all linked DSI objects from config
45  *
46  * Preserve object pointed to by "dsi".
47  * "dsi" can be NULL in which case all DSI objects _and_ the options object are freed 
48  */
49 void configfree(AFPObj *obj, DSI *dsi)
50 {
51     DSI *p, *q;
52
53     for (p = obj->dsi; p; p = q) {
54         q = p->next;
55         if (p == dsi)
56             continue;
57         close(p->socket);
58         free(p);
59     }
60     if (dsi) {
61         dsi->next = NULL;
62         obj->dsi = dsi;
63     } else {
64         afp_options_free(&obj->options);
65     }
66
67     /* the master loaded the volumes for zeroconf, get rid of that */
68     unload_volumes();
69 }
70
71 /*!
72  * Get everything running
73  */
74 int configinit(AFPObj *obj)
75 {
76     EC_INIT;
77     DSI *dsi, **next = &obj->dsi;
78     char *p = NULL, *q = NULL;
79     const char *r;
80
81     auth_load(obj->options.uampath, obj->options.uamlist);
82     set_signature(&obj->options);
83
84     LOG(log_debug, logtype_afpd, "DSIConfigInit: hostname: %s, listen: %s, port: %s",
85         obj->options.hostname,
86         obj->options.listen ? obj->options.listen : "(default: hostname)",
87         obj->options.port);
88
89     /* obj->options->listen is of the from "IP[:port][,IP:[PORT], ...]" */
90     /* obj->options->port is the default port to listen (548) */
91
92     if (obj->options.listen) {
93         EC_NULL( q = p = strdup(obj->options.listen) );
94         EC_NULL( p = strtok(p, ", ") );
95     }
96
97     while (1) {
98         if ((dsi = dsi_init(obj, obj->options.hostname, p, obj->options.port)) == NULL)
99             break;
100
101         status_init(obj, dsi);
102         *next = dsi;
103         next = &dsi->next;
104
105         LOG(log_note, logtype_afpd, "Netatalk AFP/TCP listening on %s:%d",
106             getip_string((struct sockaddr *)&dsi->server),
107             getip_port((struct sockaddr *)&dsi->server));
108
109         if (p)
110             /* p is NULL if ! obj->options.listen */
111             p = strtok(NULL, ", ");
112         if (!p)
113             break;
114     }
115
116     if (obj->dsi == NULL)
117         EC_FAIL;
118
119 #ifdef HAVE_LDAP
120     /* Parse afp.conf */
121     acl_ldap_readconfig(obj->iniconfig);
122 #endif /* HAVE_LDAP */
123
124     /* Now register with zeroconf, we also need the volumes for that */
125     if (! (obj->options.flags & OPTION_NOZEROCONF)) {
126         load_volumes(obj, NULL);
127         zeroconf_register(obj);
128     }
129
130     if ((r = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fcelistener", NULL))) {
131                 LOG(log_note, logtype_afpd, "Adding FCE listener: %s", r);
132                 fce_add_udp_socket(r);
133     }
134     if ((r = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fcecoalesce", NULL))) {
135                 LOG(log_note, logtype_afpd, "Fce coalesce: %s", r);
136                 fce_set_coalesce(r);
137     }
138     if ((r = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fceevents", NULL))) {
139                 LOG(log_note, logtype_afpd, "Fce events: %s", r);
140                 fce_set_events(r);
141     }
142
143
144 EC_CLEANUP:
145     if (q)
146         free(q);
147     EC_EXIT;
148 }