]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_config.c
9e1ef0ddd55508d96d426da8c7aa230a2b686884
[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 are freed
46  */
47 void configfree(AFPObj *obj, DSI *dsi)
48 {
49     DSI *p, *q;
50
51     afp_options_free(&obj->options);
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     }
64     /* the master loaded the volumes for zeroconf, get rid of that */
65     unload_volumes();
66 }
67
68 /*!
69  * Get everything running
70  */
71 int configinit(AFPObj *obj)
72 {
73     EC_INIT;
74     DSI *dsi, **next = &obj->dsi;
75     char *p = NULL, *q = NULL;
76
77     LOG(log_debug, logtype_afpd, "DSIConfigInit: hostname: %s, listen: %s, port: %s",
78         obj->options.hostname,
79         obj->options.listen ? obj->options.listen : "(default: hostname)",
80         obj->options.port);
81
82     /* obj->options->listen is of the from "IP[:port][,IP:[PORT], ...]" */
83     /* obj->options->port is the default port to listen (548) */
84
85     if (obj->options.listen) {
86         EC_NULL( q = p = strdup(obj->options.listen) );
87         EC_NULL( p = strtok(p, ",") );
88     }
89
90     while (1) {
91         if ((dsi = dsi_init(obj, obj->options.hostname, p, obj->options.port)) == NULL)
92             break;
93
94         status_init(obj, dsi);
95         *next = dsi;
96         next = &dsi->next;
97
98         LOG(log_note, logtype_afpd, "Netatalk AFP/TCP listening on %s:%d",
99             getip_string((struct sockaddr *)&dsi->server),
100             getip_port((struct sockaddr *)&dsi->server));
101
102         if (p)
103             /* p is NULL if ! obj->options.listen */
104             p = strtok(NULL, ",");
105         if (!p)
106             break;
107     }
108
109     if (obj->dsi == NULL)
110         EC_FAIL;
111
112     auth_load(obj->options.uampath, obj->options.uamlist);
113     set_signature(&obj->options);
114
115 #ifdef HAVE_LDAP
116     /* Parse afp_ldap.conf */
117     acl_ldap_readconfig(obj->iniconfig);
118 #endif /* HAVE_LDAP */
119
120     /* Now register with zeroconf, we also need the volumes for that */
121     if (! (obj->options.flags & OPTION_NOZEROCONF)) {
122         load_volumes(obj);
123         zeroconf_register(obj);
124     }
125
126 EC_CLEANUP:
127     if (q)
128         free(q);
129     EC_EXIT;
130 }