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

« back to all changes in this revision

Viewing changes to dlib/userio.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: userio.c,v 1.23 2003/07/01 13:21:33 michaels Exp $";
48
 
 
49
 
/* ARGSUSED */
50
 
char *
51
 
socks_getusername(host, buf, buflen)
52
 
        const struct sockshost_t *host;
53
 
        char *buf;
54
 
        size_t buflen;
55
 
{
56
 
        const char *function = "socks_getusername()";
57
 
        char *name;
58
 
 
59
 
        if ((name = getenv("SOCKS_USERNAME"))   != NULL
60
 
        ||  (name = getenv("SOCKS_USER"))               != NULL
61
 
        ||  (name = getenv("SOCKS5_USER"))              != NULL)
62
 
                ;
63
 
        else if ((name = getlogin()) != NULL)
64
 
                ;
65
 
        else {
66
 
                struct passwd *pw;
67
 
 
68
 
                if ((pw = getpwuid(getuid())) != NULL)
69
 
                        name = pw->pw_name;
70
 
        }
71
 
 
72
 
        if (name == NULL)
73
 
                return NULL;
74
 
 
75
 
        if (strlen(name) >= buflen) {
76
 
                swarnx("%s: socks username %d characters too long, truncated",
77
 
                function, (strlen(name) + 1) - buflen);
78
 
                name[buflen - 1] = NUL;
79
 
        }
80
 
 
81
 
        strcpy(buf, name);
82
 
 
83
 
        return buf;
84
 
}
85
 
 
86
 
char *
87
 
socks_getpassword(host, user, buf, buflen)
88
 
        const struct sockshost_t *host;
89
 
        const char *user;
90
 
        char *buf;
91
 
        size_t buflen;
92
 
{
93
 
        const char *function = "socks_getpassword()";
94
 
        char *password;
95
 
 
96
 
        if ((password = getenv("SOCKS_PASSWORD"))               != NULL
97
 
        ||  (password = getenv("SOCKS_PASSWD"))         != NULL
98
 
        ||  (password = getenv("SOCKS5_PASSWD"))                != NULL)
99
 
                ;
100
 
        else {
101
 
                char prompt[256 + MAXSOCKSHOSTSTRING];
102
 
                char hstring[MAXSOCKSHOSTSTRING];
103
 
 
104
 
                snprintfn(prompt, sizeof(prompt), "%s@%s sockspassword: ",
105
 
                user, sockshost2string(host, hstring, sizeof(hstring)));
106
 
                password = getpass(prompt);
107
 
        }
108
 
 
109
 
        if (password == NULL)
110
 
                return NULL;
111
 
 
112
 
        if (strlen(password) >= buflen) {
113
 
                swarnx("%s: socks password %d characters too long, truncated",
114
 
                function, (strlen(password) + 1) - buflen);
115
 
                password[buflen - 1] = NUL;
116
 
        }
117
 
 
118
 
        strcpy(buf, password);
119
 
        bzero(password, strlen(password));
120
 
 
121
 
        return buf;
122
 
}