]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_config.c
f859637942f5e7ce8ebee2c3afc1bcf3d51ee5fc
[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->dsi);
59         free(p);
60     }
61     if (dsi) {
62         dsi->next = NULL;
63         obj->dsi = dsi;
64     }
65     /* the master loaded the volumes for zeroconf, get rid of that */
66     unload_volumes();
67 }
68
69 /*!
70  * Get everything running
71  */
72 int configinit(AFPObj *obj)
73 {
74     EC_INIT;
75     DSI *dsi, **next = &obj->dsi;
76     char *p, *q = NULL;
77
78     LOG(log_debug, logtype_afpd, "DSIConfigInit: hostname: %s, listen: %s, port: %s",
79         obj->options->hostname,
80         obj->options->listen ? obj->options->listen : "(default: hostname)",
81         obj->options->port);
82
83     /* obj->options->listen is of the from "IP[:port][,IP:[PORT], ...]" */
84     /* obj->options->port is the default port to listen (548) */
85
86     EC_NULL( q = p = strdup(obj->options->listen) );
87     EC_NULL( p = strtok(p, ',') );
88
89     while (p) {
90         if ((dsi = dsi_init(obj, obj->options->hostname, p, obj->options->port)) == NULL)
91             break;
92
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     status_init(obj);
108     set_signature(obj->options);
109
110 #ifdef HAVE_LDAP
111     /* Parse afp_ldap.conf */
112     acl_ldap_readconfig(AFPObj->iniconfig);
113 #endif /* HAVE_LDAP */
114
115     /* Now register with zeroconf, we also need the volumes for that */
116     if (! (AFPObj->options.flags & OPTION_NOZEROCONF)) {
117         load_volumes(AFPObj);
118         zeroconf_register(AFPObj);
119     }
120
121 EC_CLEANUP:
122     if (q)
123         free(q);
124     EC_EXIT;
125 }