2
* Copyright (c) 1997, 1998, 1999, 2000, 2001
3
* Inferno Nettverk A/S, Norway. All rights reserved.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. The above copyright notice, this list of conditions and the following
9
* disclaimer must appear in all copies of the software, derivative works
10
* or modified versions, and any portions thereof, aswell as in all
11
* supporting documentation.
12
* 2. All advertising materials mentioning features or use of this software
13
* must display the following acknowledgement:
14
* This product includes software developed by
15
* Inferno Nettverk A/S, Norway.
16
* 3. The name of the author may not be used to endorse or promote products
17
* derived from this software without specific prior written permission.
19
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
* Inferno Nettverk A/S requests users of this software to return to
32
* Software Distribution Coordinator or sdc@inet.no
33
* Inferno Nettverk A/S
39
* any improvements or extensions that they make and grant Inferno Nettverk A/S
40
* the rights to redistribute these changes.
46
static const char rcsid[] =
47
"$Id: method_uname.c,v 1.35 2001/12/12 14:42:12 karls Exp $";
50
clientmethod_uname(s, host, version)
52
const struct sockshost_t *host;
55
const char *function = "clientmethod_uname()";
56
static struct authmethod_uname_t uname; /* cached userinfo. */
57
static struct sockshost_t unamehost; /* host cache was gotten for. */
58
static int unameisok; /* cached data is ok? */
59
unsigned char *offset, *name, *password;
60
unsigned char request[ 1 /* version. */
61
+ 1 /* username length. */
62
+ MAXNAMELEN /* username. */
63
+ 1 /* password length. */
64
+ MAXPWLEN /* password. */
66
unsigned char response[ 1 /* version. */
71
if (memcmp(&unamehost, host, sizeof(unamehost)) != 0)
72
unameisok = 0; /* not same host as cache was gotten for. */
82
/* fill in request. */
86
*offset++ = (unsigned char)SOCKS_UNAMEVERSION;
89
if ((name = (unsigned char *)socks_getusername(host, (char *)offset + 1,
90
MAXNAMELEN)) == NULL) {
91
swarn("%s: could not determine username of client", function);
95
SASSERTX(strlen((char *)name) < sizeof(uname.name));
96
strcpy((char *)uname.name, (char *)name);
100
strcpy((char *)offset + 1, (char *)name);
103
/* first byte gives length. */
104
*offset = (unsigned char)strlen((char *)name);
106
offset += *offset + 1;
109
if ((password = (unsigned char *)socks_getpassword(host, (char *)name,
110
(char *)offset + 1, MAXPWLEN)) == NULL) {
111
swarn("%s: could not determine password of client", function);
115
SASSERTX(strlen((char *)password) < sizeof(uname.password));
116
strcpy((char *)uname.password, (char *)password);
119
password = uname.password;
120
strcpy((char *)offset + 1, (char *)password);
123
/* first byte gives length. */
124
*offset = (unsigned char)strlen((char *)password);
126
offset += *offset + 1;
128
if (writen(s, request, (size_t)(offset - request), NULL)
129
!= offset - request) {
130
swarn("%s: writen()", function);
134
if (readn(s, response, sizeof(response), NULL) != sizeof(response)) {
135
swarn("%s: readn()", function);
139
if (request[UNAME_VERSION] != response[UNAME_VERSION]) {
140
swarnx("%s: sent v%d, got v%d",
141
function, request[UNAME_VERSION], response[UNAME_VERSION]);
145
if (response[UNAME_STATUS] == 0) { /* server accepted. */
150
return response[UNAME_STATUS];