]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_config.c
Fix build
[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, *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     EC_NULL( q = p = strdup(obj->options.listen) );
86     EC_NULL( p = strtok(p, ",") );
87
88     while (p) {
89         if ((dsi = dsi_init(obj, obj->options.hostname, p, obj->options.port)) == NULL)
90             break;
91
92         status_init(obj, dsi);
93         *next = dsi;
94         next = &dsi->next;
95
96         LOG(log_note, logtype_afpd, "Netatalk AFP/TCP listening on %s:%d",
97             getip_string((struct sockaddr *)&dsi->server),
98             getip_port((struct sockaddr *)&dsi->server));
99
100         p = strtok(NULL, ",");
101     }
102
103     if (obj->dsi == NULL)
104         EC_FAIL;
105
106     auth_load(obj->options.uampath, obj->options.uamlist);
107     set_signature(&obj->options);
108
109 #ifdef HAVE_LDAP
110     /* Parse afp_ldap.conf */
111     acl_ldap_readconfig(obj->iniconfig);
112 #endif /* HAVE_LDAP */
113
114     /* Now register with zeroconf, we also need the volumes for that */
115     if (! (obj->options.flags & OPTION_NOZEROCONF)) {
116         load_volumes(obj);
117         zeroconf_register(obj);
118     }
119
120 EC_CLEANUP:
121     if (q)
122         free(q);
123     EC_EXIT;
124 }