ubik: Tidy up header includes
[openafs.git] / src / ubik / uinit.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <afs/stds.h>
13
14 #include <roken.h>
15
16 #ifdef AFS_AIX_ENV
17 # include <sys/statfs.h>
18 #endif
19
20 #include <afs/dirpath.h>
21 #include <lock.h>
22 #include <rx/xdr.h>
23 #include <rx/rx.h>
24 #include <rx/rx_globals.h>
25 #include <afs/auth.h>
26 #include <afs/cellconfig.h>
27 #include <afs/keys.h>
28 #include <ubik.h>
29 #include <afs/afsint.h>
30 #include <afs/cmd.h>
31
32 /*!
33  * \brief Get the appropriate type of ubik client structure out from the system.
34  */
35 afs_int32
36 ugen_ClientInit(int noAuthFlag, const char *confDir, char *cellName, afs_int32 sauth,
37                struct ubik_client **uclientp,
38                int (*secproc) (struct rx_securityClass *, afs_int32),
39                char *funcName, afs_int32 gen_rxkad_level,
40                afs_int32 maxservers, char *serviceid, afs_int32 deadtime,
41                afs_uint32 server, afs_uint32 port, afs_int32 usrvid)
42 {
43     afs_int32 code, secFlags, i;
44     afs_int32 scIndex;
45     struct afsconf_cell info;
46     struct afsconf_dir *tdir;
47     struct rx_securityClass *sc;
48     /* This must change if VLDB_MAXSERVERS becomes larger than MAXSERVERS */
49     static struct rx_connection *serverconns[MAXSERVERS];
50     const char *confdir;
51
52     code = rx_Init(0);
53     if (code) {
54         fprintf(stderr, "%s: could not initialize rx.\n", funcName);
55         return code;
56     }
57     rx_SetRxDeadTime(deadtime);
58
59     secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
60     if (sauth) {
61         secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
62         confdir = AFSDIR_SERVER_ETC_DIRPATH;
63     } else {
64         confdir = AFSDIR_CLIENT_ETC_DIRPATH;
65     }
66
67     if (noAuthFlag) {
68         secFlags |= AFSCONF_SECOPTS_NOAUTH;
69     }
70
71     tdir = afsconf_Open(confdir);
72     if (!tdir) {
73         fprintf(stderr,
74                 "%s: Could not process files in configuration directory (%s).\n",
75                 funcName, confdir);
76         return -1;
77     }
78
79     if (sauth)
80         cellName = tdir->cellName;
81
82     code = afsconf_GetCellInfo(tdir, cellName, serviceid, &info);
83     if (code) {
84         afsconf_Close(tdir);
85         fprintf(stderr, "%s: can't find cell %s's hosts in %s/%s\n",
86                 funcName, cellName, confdir, AFSDIR_CELLSERVDB_FILE);
87         return -1;
88     }
89     code = afsconf_PickClientSecObj(tdir, secFlags, &info, cellName, &sc,
90                                     &scIndex, NULL);
91     if (code) {
92         fprintf(stderr, "%s: can't create client security object", funcName);
93         return -1;
94     }
95     if (scIndex == RX_SECIDX_NULL && !noAuthFlag) {
96         fprintf(stderr,
97                 "%s: Could not get afs tokens, running unauthenticated.\n",
98                 funcName);
99     }
100
101     afsconf_Close(tdir);
102
103     if (secproc)        /* tell UV module about default authentication */
104         (*secproc) (sc, scIndex);
105     if (server) {
106         serverconns[0] = rx_NewConnection(server, port,
107                                           usrvid, sc, scIndex);
108     } else {
109         if (info.numServers > maxservers) {
110             fprintf(stderr,
111                     "%s: info.numServers=%d (> maxservers=%d)\n",
112                     funcName, info.numServers, maxservers);
113             return -1;
114         }
115         for (i = 0; i < info.numServers; i++) {
116             if (!info.hostAddr[i].sin_port && port)
117                 info.hostAddr[i].sin_port = port;
118             serverconns[i] =
119                 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
120                                  info.hostAddr[i].sin_port, usrvid,
121                                  sc, scIndex);
122         }
123     }
124     /* Are we just setting up connections, or is this really ubik stuff? */
125     if (uclientp) {
126         *uclientp = 0;
127         code = ubik_ClientInit(serverconns, uclientp);
128         if (code) {
129             fprintf(stderr, "%s: ubik client init failed.\n", funcName);
130             return code;
131         }
132     }
133     return 0;
134 }
135
136