2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
19 #include <sys/types.h>
22 #include <netinet/in.h>
23 #endif /* AFS_NT40_ENV */
26 #include <sys/statfs.h>
31 #include <afs/dirpath.h>
36 #include <rx/rx_globals.h>
38 #include <afs/cellconfig.h>
41 #include <afs/afsint.h>
45 * \brief Get the appropriate type of ubik client structure out from the system.
48 ugen_ClientInit(int noAuthFlag, const char *confDir, char *cellName, afs_int32 sauth,
49 struct ubik_client **uclientp,
50 int (*secproc) (struct rx_securityClass *, afs_int32),
51 char *funcName, afs_int32 gen_rxkad_level,
52 afs_int32 maxservers, char *serviceid, afs_int32 deadtime,
53 afs_uint32 server, afs_uint32 port, afs_int32 usrvid)
55 afs_int32 code, scIndex, i;
56 struct afsconf_cell info;
57 struct afsconf_dir *tdir;
58 struct ktc_principal sname;
59 struct ktc_token ttoken;
60 struct rx_securityClass *sc;
61 /* This must change if VLDB_MAXSERVERS becomes larger than MAXSERVERS */
62 static struct rx_connection *serverconns[MAXSERVERS];
67 fprintf(stderr, "%s: could not initialize rx.\n", funcName);
70 rx_SetRxDeadTime(deadtime);
72 if (sauth) { /* -localauth */
73 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
76 "%s: Could not process files in configuration directory (%s).\n",
77 funcName, AFSDIR_SERVER_ETC_DIRPATH);
80 code = afsconf_ClientAuth(tdir, &sc, &scIndex); /* sets sc,scIndex */
84 "%s: Could not get security object for -localAuth\n",
89 afsconf_GetCellInfo(tdir, tdir->cellName, serviceid,
94 "%s: can't find cell %s's hosts in %s/%s\n",
95 funcName, cellName, AFSDIR_SERVER_ETC_DIRPATH,
96 AFSDIR_CELLSERVDB_FILE);
99 } else { /* not -localauth */
100 tdir = afsconf_Open(confDir);
103 "%s: Could not process files in configuration directory (%s).\n",
109 code = afsconf_GetLocalCell(tdir, cellstr, sizeof(cellstr));
112 "%s: can't get local cellname, check %s/%s\n",
113 funcName, confDir, AFSDIR_THISCELL_FILE);
120 afsconf_GetCellInfo(tdir, cellName, serviceid, &info);
123 "%s: can't find cell %s's hosts in %s/%s\n",
124 funcName, cellName, confDir, AFSDIR_CELLSERVDB_FILE);
127 if (noAuthFlag) /* -noauth */
129 else { /* not -noauth */
130 strcpy(sname.cell, info.name);
131 sname.instance[0] = 0;
132 strcpy(sname.name, "afs");
133 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
134 if (code) { /* did not get ticket */
136 "%s: Could not get afs tokens, running unauthenticated.\n",
139 } else { /* got a ticket */
141 if ((ttoken.kvno < 0) || (ttoken.kvno > 256)) {
143 "%s: funny kvno (%d) in ticket, proceeding\n",
144 funcName, ttoken.kvno);
151 sc = rxnull_NewClientSecurityObject();
154 sc = rxkad_NewClientSecurityObject(gen_rxkad_level,
156 ttoken.kvno, ttoken.ticketLen,
160 fprintf(stderr, "%s: unsupported security index %d\n",
169 if (secproc) /* tell UV module about default authentication */
170 (*secproc) (sc, scIndex);
172 serverconns[0] = rx_NewConnection(server, port,
173 usrvid, sc, scIndex);
175 if (info.numServers > maxservers) {
177 "%s: info.numServers=%d (> maxservers=%d)\n",
178 funcName, info.numServers, maxservers);
181 for (i = 0; i < info.numServers; i++) {
183 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
184 info.hostAddr[i].sin_port, usrvid,
188 /* Are we just setting up connections, or is this really ubik stuff? */
191 code = ubik_ClientInit(serverconns, uclientp);
193 fprintf(stderr, "%s: ubik client init failed.\n", funcName);