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