~ubuntu-branches/ubuntu/karmic/dante/karmic

« back to all changes in this revision

Viewing changes to dlib/method_uname.c

  • Committer: Bazaar Package Importer
  • Author(s): Thijs Kinkhorst
  • Date: 2006-10-19 12:09:39 UTC
  • mfrom: (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20061019120939-t818x24e2tn8be5k
Tags: 1.1.18-2.1
* Non-maintainer upload for RC bug.
* Make sure changelogs are installed into all packages (Closes: #393568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003
3
 
 *      Inferno Nettverk A/S, Norway.  All rights reserved.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions
7
 
 * are met:
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.
18
 
 *
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.
29
 
 *
30
 
 * Inferno Nettverk A/S requests users of this software to return to
31
 
 *
32
 
 *  Software Distribution Coordinator  or  sdc@inet.no
33
 
 *  Inferno Nettverk A/S
34
 
 *  Oslo Research Park
35
 
 *  Gaustadall�en 21
36
 
 *  NO-0349 Oslo
37
 
 *  Norway
38
 
 *
39
 
 * any improvements or extensions that they make and grant Inferno Nettverk A/S
40
 
 * the rights to redistribute these changes.
41
 
 *
42
 
 */
43
 
 
44
 
#include "common.h"
45
 
 
46
 
static const char rcsid[] =
47
 
"$Id: method_uname.c,v 1.36 2003/07/01 13:21:30 michaels Exp $";
48
 
 
49
 
int
50
 
clientmethod_uname(s, host, version)
51
 
        int s;
52
 
        const struct sockshost_t *host;
53
 
        int version;
54
 
{
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.                    */
65
 
        ];
66
 
        unsigned char response[ 1 /* version.   */
67
 
                                                                 +      1 /* status.    */
68
 
        ];
69
 
 
70
 
 
71
 
        if (memcmp(&unamehost, host, sizeof(unamehost)) != 0)
72
 
                unameisok = 0;  /* not same host as cache was gotten for. */
73
 
 
74
 
        switch (version) {
75
 
                case SOCKS_V5:
76
 
                        break;
77
 
 
78
 
                default:
79
 
                        SERRX(version);
80
 
        }
81
 
 
82
 
        /* fill in request. */
83
 
 
84
 
        offset = request;
85
 
 
86
 
        *offset++ = (unsigned char)SOCKS_UNAMEVERSION;
87
 
 
88
 
        if (!unameisok) {
89
 
                if ((name = (unsigned char *)socks_getusername(host, (char *)offset + 1,
90
 
                MAXNAMELEN)) == NULL) {
91
 
                        swarn("%s: could not determine username of client", function);
92
 
                        return -1;
93
 
                }
94
 
 
95
 
                SASSERTX(strlen((char *)name) < sizeof(uname.name));
96
 
                strcpy((char *)uname.name, (char *)name);
97
 
        }
98
 
        else {
99
 
                name = uname.name;
100
 
                strcpy((char *)offset + 1, (char *)name);
101
 
        }
102
 
 
103
 
        /* first byte gives length. */
104
 
        *offset = (unsigned char)strlen((char *)name);
105
 
        OCTETIFY(*offset);
106
 
        offset += *offset + 1;
107
 
 
108
 
        if (!unameisok) {
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);
112
 
                        return -1;
113
 
                }
114
 
 
115
 
                SASSERTX(strlen((char *)password) < sizeof(uname.password));
116
 
                strcpy((char *)uname.password, (char *)password);
117
 
        }
118
 
        else {
119
 
                password = uname.password;
120
 
                strcpy((char *)offset + 1, (char *)password);
121
 
        }
122
 
 
123
 
        /* first byte gives length. */
124
 
        *offset = (unsigned char)strlen((char *)password);
125
 
        OCTETIFY(*offset);
126
 
        offset += *offset + 1;
127
 
 
128
 
        if (writen(s, request, (size_t)(offset - request), NULL)
129
 
        != offset - request) {
130
 
                swarn("%s: writen()", function);
131
 
                return -1;
132
 
        }
133
 
 
134
 
        if (readn(s, response, sizeof(response), NULL) != sizeof(response)) {
135
 
                swarn("%s: readn()", function);
136
 
                return -1;
137
 
        }
138
 
 
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]);
142
 
                return -1;
143
 
        }
144
 
 
145
 
        if (response[UNAME_STATUS] == 0) { /* server accepted. */
146
 
                unamehost = *host;
147
 
                unameisok = 1;
148
 
        }
149
 
 
150
 
        return response[UNAME_STATUS];
151
 
}