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

« back to all changes in this revision

Viewing changes to unix/xc/programs/xsm/lock.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: lock.c,v 1.4 2001/02/09 02:05:59 xorgcvs Exp $ */
 
2
/******************************************************************************
 
3
 
 
4
Copyright 1994, 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 in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
Except as contained in this notice, the name of The Open Group shall not be
 
23
used in advertising or otherwise to promote the sale, use or other dealings
 
24
in this Software without prior written authorization from The Open Group.
 
25
******************************************************************************/
 
26
/* $XFree86: xc/programs/xsm/lock.c,v 3.5 2002/05/31 18:46:14 dawes Exp $ */
 
27
 
 
28
#include "xsm.h"
 
29
#include "lock.h"
 
30
#include "choose.h"
 
31
#include <sys/types.h>
 
32
 
 
33
 
 
34
static char *
 
35
GetPath(void)
 
36
{
 
37
    char *path = (char *) getenv ("SM_SAVE_DIR");
 
38
 
 
39
    if (!path)
 
40
    {
 
41
        path = (char *) getenv ("HOME");
 
42
        if (!path)
 
43
            path = ".";
 
44
    }
 
45
 
 
46
    return (path);
 
47
}
 
48
 
 
49
 
 
50
Status
 
51
LockSession(char *session_name, Bool write_id)
 
52
{
 
53
    char *path;
 
54
    char lock_file[PATH_MAX];
 
55
    char temp_lock_file[PATH_MAX];
 
56
    Status status;
 
57
    int fd;
 
58
 
 
59
    path = GetPath ();
 
60
 
 
61
#ifndef __UNIXOS2__
 
62
    sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
 
63
    sprintf (temp_lock_file, "%s/.XSMtlock-%s", path, session_name);
 
64
#else
 
65
    sprintf (temp_lock_file, "%s/%s.slk", path, session_name);
 
66
#endif
 
67
 
 
68
    if ((fd = creat (temp_lock_file, 0444)) < 0)
 
69
        return (0);
 
70
 
 
71
    if ((write_id &&
 
72
        (write (fd, networkIds, strlen (networkIds)) != strlen (networkIds))) ||
 
73
        (write (fd, "\n", 1) != 1))
 
74
    {
 
75
        close (fd);
 
76
        return (0);
 
77
    }
 
78
 
 
79
    close (fd);
 
80
 
 
81
#ifndef __UNIXOS2__
 
82
    status = 1;
 
83
 
 
84
    if (link (temp_lock_file, lock_file) < 0)
 
85
        status = 0;
 
86
 
 
87
    if (unlink (temp_lock_file) < 0)
 
88
        status = 0;
 
89
#else
 
90
    status = 0;
 
91
#endif
 
92
 
 
93
    return (status);
 
94
}
 
95
 
 
96
 
 
97
void
 
98
UnlockSession(char *session_name)
 
99
{
 
100
    char *path;
 
101
    char lock_file[PATH_MAX];
 
102
 
 
103
    path = GetPath ();
 
104
 
 
105
    sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
 
106
 
 
107
    unlink (lock_file);
 
108
}
 
109
 
 
110
 
 
111
char *
 
112
GetLockId(char *session_name)
 
113
{
 
114
    char *path;
 
115
    FILE *fp;
 
116
    char lock_file[PATH_MAX];
 
117
    char buf[256];
 
118
    char *ret;
 
119
 
 
120
    path = GetPath ();
 
121
 
 
122
    sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
 
123
 
 
124
    if ((fp = fopen (lock_file, "r")) == NULL)
 
125
    {
 
126
        return (NULL);
 
127
    }
 
128
 
 
129
    buf[0] = '\0';
 
130
    fscanf (fp, "%s\n", buf);
 
131
    ret = XtNewString (buf);
 
132
 
 
133
    fclose (fp);
 
134
 
 
135
    return (ret);
 
136
}
 
137
 
 
138
 
 
139
Bool
 
140
CheckSessionLocked(char *session_name, Bool get_id, char **id_ret)
 
141
{
 
142
    if (get_id)
 
143
        *id_ret = GetLockId (session_name);
 
144
 
 
145
    if (!LockSession (session_name, False))
 
146
        return (1);
 
147
 
 
148
    UnlockSession (session_name);
 
149
    return (0);
 
150
}
 
151
 
 
152
 
 
153
void
 
154
UnableToLockSession(char *session_name)
 
155
{
 
156
    /*
 
157
     * We should popup a dialog here giving error.
 
158
     */
 
159
 
 
160
#ifdef XKB
 
161
    XkbStdBell(XtDisplay(topLevel),XtWindow(topLevel),0,XkbBI_Failure);
 
162
#else
 
163
    XBell (XtDisplay (topLevel), 0);
 
164
#endif
 
165
    sleep (2);
 
166
 
 
167
    ChooseSession ();
 
168
}