~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/proxymngr/config.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: config.c,v 1.4 2001/02/09 02:05:34 xorgcvs Exp $ */
 
2
 
 
3
/*
 
4
Copyright 1996, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included
 
13
in all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
21
OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall
 
24
not be used in advertising or otherwise to promote the sale, use or
 
25
other dealings in this Software without prior written authorization
 
26
from The Open Group.
 
27
*/
 
28
/* $XFree86: xc/programs/proxymngr/config.c,v 1.7 2001/12/14 20:01:01 dawes Exp $ */
 
29
 
 
30
#include <stdlib.h>
 
31
 
 
32
#include "pmint.h"
 
33
#include "config.h"
 
34
 
 
35
static Bool
 
36
getnextline (
 
37
char    **pbuf,
 
38
int     *plen,
 
39
FILE    *f)
 
40
 
 
41
{
 
42
    int c, i;
 
43
 
 
44
    i = 0;
 
45
    while(1)
 
46
    {
 
47
        if (i+2 > *plen)
 
48
        {
 
49
            if (*plen)
 
50
                *plen *= 2;
 
51
            else
 
52
                *plen = BUFSIZ;
 
53
            if (*pbuf)
 
54
                *pbuf = (char *) realloc (*pbuf, *plen + 1);
 
55
            else
 
56
                *pbuf = (char *) malloc (*plen + 1);
 
57
            if (! *pbuf) {
 
58
                fprintf (stderr, "Memory allocation failure reading config file\n");
 
59
                return 0;
 
60
            }
 
61
        }
 
62
        c = getc (f);
 
63
        if (c == EOF)
 
64
            break;
 
65
        (*pbuf)[i++] = c;
 
66
        if (c == '\n') {
 
67
            i--;
 
68
            break;
 
69
        }
 
70
    }
 
71
    (*pbuf)[i] = '\0';
 
72
    return i;
 
73
}
 
74
 
 
75
 
 
76
#ifdef NEED_STRCASECMP
 
77
int
 
78
ncasecmp (str1, str2, n)
 
79
    char *str1, *str2;
 
80
    int n;
 
81
{
 
82
    char buf1[512],buf2[512];
 
83
    char c, *s;
 
84
    register int i;
 
85
 
 
86
    for (i=0, s = buf1; i < n && (c = *str1++); i++) {
 
87
        if (isupper(c))
 
88
            c = tolower(c);
 
89
        if (i>510)
 
90
            break;
 
91
        *s++ = c;
 
92
    }
 
93
    *s = '\0';
 
94
    for (i=0, s = buf2; i < n && (c = *str2++); i++) {
 
95
        if (isupper(c))
 
96
            c = tolower(c);
 
97
        if (i>510)
 
98
            break;
 
99
        *s++ = c;
 
100
    }
 
101
    *s = '\0';
 
102
    return (strncmp(buf1, buf2, n));
 
103
}
 
104
#endif /* NEED_STRCASECMP */
 
105
 
 
106
 
 
107
Status
 
108
GetConfig (
 
109
    char *configFile,
 
110
    char *serviceName,
 
111
    Bool *managed,
 
112
    char **startCommand,
 
113
    char **proxyAddress)
 
114
 
 
115
{
 
116
    FILE *fp;
 
117
    int found = 0;
 
118
    char *buf, *p;
 
119
    int buflen, n;
 
120
 
 
121
    *startCommand = *proxyAddress = NULL;
 
122
 
 
123
    fp = fopen (configFile, "r");
 
124
 
 
125
    if (!fp)
 
126
        return 0;
 
127
 
 
128
    buf = NULL;
 
129
    buflen = 0;
 
130
    n = strlen (serviceName);
 
131
 
 
132
    while (!found && getnextline (&buf, &buflen, fp))
 
133
    {
 
134
        if (buf[0] == '!')
 
135
            continue;
 
136
 
 
137
        if (!(ncasecmp (buf, serviceName, n) == 0 && buf[n] == ' '))
 
138
            continue;
 
139
 
 
140
        /* found the right config line */
 
141
        p = buf + n + 1;
 
142
        while (*p == ' ')
 
143
            p++;
 
144
        if (ncasecmp (p, "managed", 7) == 0)
 
145
        {
 
146
            *managed = 1;
 
147
            p += 7;
 
148
        }
 
149
        else if (ncasecmp (p, "unmanaged", 9) == 0)
 
150
        {
 
151
            *managed = 0;
 
152
            p += 9;
 
153
        }
 
154
        else
 
155
        {
 
156
            fprintf (stderr, "Error in config file at line \"%s\"\n", buf);
 
157
            break;
 
158
        }
 
159
 
 
160
        while (*p == ' ')
 
161
            p++;
 
162
 
 
163
        if (*managed)
 
164
        {
 
165
            n = strlen (p);
 
166
            *startCommand = (char *) malloc (n + 2);
 
167
            if (! *startCommand) {
 
168
                fprintf (stderr,
 
169
                         "Memory allocation failed for service \"%s\"\n",
 
170
                         serviceName);
 
171
                break;
 
172
            }
 
173
            strcpy (*startCommand, p);
 
174
            (*startCommand)[n] = '&';
 
175
            (*startCommand)[n + 1] = '\0';
 
176
        }
 
177
        else
 
178
        {
 
179
            *proxyAddress = (char *) malloc (strlen (p) + 1);
 
180
            if (! *proxyAddress) {
 
181
                fprintf (stderr,
 
182
                         "Memory allocation failed for service \"%s\" at %s\n",
 
183
                         serviceName, p);
 
184
                break;
 
185
            }
 
186
            strcpy (*proxyAddress, p);
 
187
        }
 
188
 
 
189
        found = 1;
 
190
    }
 
191
 
 
192
    if (buf)
 
193
        free (buf);
 
194
 
 
195
    fclose (fp);
 
196
    return found;
 
197
}
 
198
 
 
199
 
 
200
 
 
201