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

« back to all changes in this revision

Viewing changes to unix/vncserver

  • 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
1
#!/usr/bin/env perl
2
2
#
 
3
#  Copyright (C) 2004-2006 Ola Lundqvist <opal@debian.org>
3
4
#  Copyright (C) 2002-2005 RealVNC Ltd.
4
5
#  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
5
6
#
23
24
# vncserver - wrapper script to start an X VNC server.
24
25
#
25
26
 
 
27
# This file was heavily edited by Ola Lundqvist <opal@debian.org> using
 
28
# options from vnc package.
 
29
# Most modifications are written by Marcus.Brinkmann@ruhr-uni-bochum.de and
 
30
# now incorporated by Ola.
 
31
 
 
32
# Please report all errors to Debian and not to ORL.
 
33
 
26
34
#
27
35
# First make sure we're operating in a sane environment.
28
36
#
35
43
 
36
44
$geometry = "1024x768";
37
45
$depth = 16;
38
 
$vncJavaFiles = (((-d "/usr/share/vnc/classes") && "/usr/share/vnc/classes") ||
 
46
$vncJavaFiles = (((-d "/usr/share/vnc-java") && "/usr/share/vnc-java") ||
 
47
                 ((-d "/usr/share/vnc/classes") && "/usr/share/vnc/classes") ||
39
48
                 ((-d "/usr/local/vnc/classes") && "/usr/local/vnc/classes"));
 
49
 
40
50
$vncUserDir = "$ENV{HOME}/.vnc";
41
51
$xauthorityFile = "$ENV{XAUTHORITY}" || "$ENV{HOME}/.Xauthority";
42
52
 
49
59
       "[ -r \$HOME/.Xresources ] && xrdb \$HOME/.Xresources\n".
50
60
       "xsetroot -solid grey\n".
51
61
       "vncconfig -iconic &\n".
52
 
       "xterm -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n".
53
 
       "twm &\n");
 
62
       "x-terminal-emulator -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n".
 
63
       "x-window-manager &\n");
 
64
 
 
65
######## Adding configuration possibility ################
 
66
$Config_file = "/etc/vnc.conf";
 
67
&ReadConfigFile();
 
68
$Config_file = "$ENV{HOME}/.vncrc";
 
69
&ReadConfigFile();
 
70
 
 
71
if (!$XFConfigPath) {
 
72
  foreach ("/etc/X11/xorg.conf", "/etc/X11/XF86Config-4", "/etc/X11/XF86Config" ){
 
73
    $XFConfigPath = $_;
 
74
    last if ( -e $XFConfigPath );
 
75
  }
 
76
}
 
77
if (!$fontPath) {
 
78
  &ReadXFConfigFont;
 
79
}
 
80
if (!$fontPath) {
 
81
  $fontPath = "/usr/X11R6/lib/X11/fonts/Type1/,".
 
82
              "/usr/X11R6/lib/X11/fonts/Speedo/,".
 
83
              "/usr/X11R6/lib/X11/fonts/misc/,".
 
84
              "/usr/X11R6/lib/X11/fonts/75dpi/,".
 
85
              "/usr/X11R6/lib/X11/fonts/100dpi/,".
 
86
              "/usr/share/fonts/X11/misc/,".
 
87
              "/usr/share/fonts/X11/Type1/,".
 
88
              "/usr/share/fonts/X11/75dpi/,".
 
89
              "/usr/share/fonts/X11/100dpi/"
 
90
}
 
91
if (!$colorPath) {
 
92
  &ReadXFConfigColor;
 
93
}
 
94
if (!$colorPath) {
 
95
  foreach ("/etc/X11/rgb", "/usr/share/X11/rgb", "/usr/X11R6/lib/X11/rgb"){
 
96
      $colorPath = $_;
 
97
      last if ( -e "${colorPath}.txt" );
 
98
  }
 
99
}
 
100
 
 
101
##########################################################
 
102
 
 
103
$vncUserDirUnderTmp = ($vncUserDir =~ m|^/tmp/.+|) ? 1 : 0;
 
104
$xstartup = ($vncUserDirUnderTmp) ?
 
105
  "$ENV{HOME}/.vncstartup" : "$vncUserDir/xstartup";
 
106
$xstartup = $vncStartup if ($vncStartup);
 
107
 
 
108
unless ($xauthorityFile) {
 
109
    if ($vncUserDirUnderTmp) {
 
110
        $xauthorityFile = "$vncUserDir/.Xauthority";
 
111
    } else {
 
112
        $xauthorityFile = "$ENV{HOME}/.Xauthority";
 
113
    }
 
114
}
54
115
 
55
116
chop($host = `uname -n`);
56
117
 
58
119
# Check command line options
59
120
 
60
121
&ParseOptions("-geometry",1,"-depth",1,"-pixelformat",1,"-name",1,"-kill",1,
61
 
              "-nohttpd",0,
62
 
              "-help",0,"-h",0,"--help",0);
 
122
              "-help",0,"-h",0,"--help",0,
 
123
              "-clean",0, "-fp",1,
 
124
              "-alwaysshared",0, "-nevershared",0,
 
125
              "-httpport",1,"-basehttpport",1);
63
126
 
64
127
&Usage() if ($opt{'-help'} || $opt{'-h'} || $opt{'--help'});
65
128
 
66
129
&Kill() if ($opt{'-kill'});
67
130
 
 
131
$useClasses = 0;
 
132
if (defined $vncJavaFiles) {
 
133
  if(-d $vncJavaFiles) {
 
134
      $useClasses = 1;
 
135
  }
 
136
}
 
137
 
68
138
# Uncomment this line if you want default geometry, depth and pixelformat
69
139
# to match the current X display:
70
140
# &GetXDisplayDefaults();
79
149
if ($opt{'-pixelformat'}) {
80
150
    $pixelformat = $opt{'-pixelformat'};
81
151
}
82
 
if ($opt{'-nohttpd'}) {
83
 
    $nohttpd = 1;
84
 
  }
85
 
else {
86
 
    $nohttpd = 0;
 
152
 
 
153
if ($opt{'-fp'}) {
 
154
    @fontPathElements = split(/\s*,\s*/, "$opt{'-fp'}");
 
155
 
 
156
    $fontPath = '';
 
157
 
 
158
    foreach $i (0.."$#fontPathElements") {
 
159
       $tempFontPath = $fontPathElements[$i];
 
160
       if ($tempFontPath !~ m!^[^/]*/[^/]*:\d+$!) {
 
161
           $tempFontPath =~ s/:unscaled$//;
 
162
           if (-r "$tempFontPath/fonts.dir") {
 
163
               $fontPath .= "$fontPathElements[$i],";
 
164
           }
 
165
       } else {
 
166
           $fontPath .= "$fontPathElements[$i],";
 
167
       }
 
168
    }
 
169
    chop $fontPath;
87
170
}
88
171
 
89
172
&CheckGeometryAndDepth();
90
173
 
91
 
 
92
174
# Create the user's vnc directory if necessary.
93
175
 
94
176
if (!(-e $vncUserDir)) {
96
178
        die "$prog: Could not create $vncUserDir.\n";
97
179
    }
98
180
}
99
 
    
 
181
 
 
182
($z,$z,$mode) = lstat("$vncUserDir");
 
183
if (!-d _ || !-o _ || ($vncUserDirUnderTmp && ($mode & 0777) != 0700)) {
 
184
    die "$prog: Wrong type or access mode of $vncUserDir.\n";
 
185
}
 
186
 
100
187
# Make sure the user has a password.
101
188
 
102
189
($z,$z,$mode) = stat("$vncUserDir/passwd");
103
190
if (!(-e "$vncUserDir/passwd") || ($mode & 077)) {
104
191
    warn "\nYou will require a password to access your desktops.\n\n";
105
 
    system("vncpasswd -q $vncUserDir/passwd"); 
 
192
    system("vncpasswd $vncUserDir/passwd"); 
106
193
    if (($? >> 8) != 0) {
107
194
        exit 1;
108
195
    }
142
229
 
143
230
# Now start the X VNC Server
144
231
 
145
 
$cmd = "Xvnc :$displayNumber";
 
232
$cmd = "Xvnc4 :$displayNumber";
146
233
$cmd .= " -desktop " . &quotedString($desktopName);
147
 
$cmd .= " -httpd $vncJavaFiles" if ($vncJavaFiles && ! $nohttpd);
 
234
if ($useClasses) {
 
235
  $cmd .= " -httpd $vncJavaFiles";
 
236
  print ("Found $vncJavaFiles for http connections.\n");
 
237
  if ($opt{'-httpport'}) {
 
238
    $cmd .= " -httpport $opt{'-httpport'}";
 
239
    print ("Listening to $opt{'-httpport'} for http connections.\n");
 
240
  }
 
241
  elsif ($opt{'-basehttpport'}) {
 
242
    my $v = $opt{'-basehttpport'} + $displayNumber;
 
243
    print ("Listening to $v for http connections.\n");
 
244
    $cmd .= " -httpport $v";
 
245
  }
 
246
}
148
247
$cmd .= " -auth $xauthorityFile";
149
248
$cmd .= " -geometry $geometry" if ($geometry);
150
249
$cmd .= " -depth $depth" if ($depth);
159
258
# $cmd .= " -fp /usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/";
160
259
# $cmd .= " -co /usr/lib/X11/rgb";
161
260
#
 
261
$cmd .= " -fp $fontPath" if ($fontPath);
 
262
$cmd .= " -co $colorPath" if ($colorPath);
 
263
$cmd .= " -alwaysshared" if ($opt{'-alwaysshared'});
 
264
$cmd .= " -nevershared" if ($opt{'-nevershared'});
162
265
 
163
266
foreach $arg (@ARGV) {
164
267
    $cmd .= " " . &quotedString($arg);
170
273
$pidFile = "$vncUserDir/$host:$displayNumber.pid";
171
274
system("$cmd & echo \$! >$pidFile");
172
275
 
173
 
# Give Xvnc a chance to start up
 
276
# Give Xvnc4 a chance to start up
174
277
 
175
278
sleep(3); 
176
279
 
178
281
 
179
282
# Create the user's xstartup script if necessary.
180
283
 
181
 
if (!(-e "$vncUserDir/xstartup")) {
182
 
    warn "Creating default startup script $vncUserDir/xstartup\n";
183
 
    open(XSTARTUP, ">$vncUserDir/xstartup");
 
284
if (!(-e "$xstartup")) {
 
285
    warn "Creating default startup script $xstartup\n";
 
286
    open(XSTARTUP, ">$xstartup");
184
287
    print XSTARTUP $defaultXStartup;
185
288
    close(XSTARTUP);
186
 
    chmod 0755, "$vncUserDir/xstartup";
 
289
    chmod 0755, "$xstartup";
187
290
}
188
291
 
189
292
# Run the X startup script.
190
293
 
191
 
warn "Starting applications specified in $vncUserDir/xstartup\n";
 
294
warn "Starting applications specified in $xstartup\n";
192
295
warn "Log file is $desktopLog\n\n";
193
296
 
194
297
# If the unix domain socket exists then use that (DISPLAY=:n) otherwise use
203
306
}
204
307
$ENV{VNCDESKTOP}= $desktopName;
205
308
 
206
 
system("$vncUserDir/xstartup >> " . &quotedString($desktopLog) . " 2>&1 &");
 
309
system("$xstartup >> " . &quotedString($desktopLog) . " 2>&1 &");
207
310
 
208
311
exit;
209
312
 
 
313
############################ Debian functions #################################
 
314
# I thank Manoj for the code below.
 
315
#
 
316
# ReadConfigFile reads in a config file and sets variables according to it.
 
317
#
 
318
 
 
319
sub ReadConfigFile
 
320
{
 
321
  open(CONFIG, "$Config_file") || return;
 
322
  my $lineno = 0;
 
323
  while (<CONFIG>) {
 
324
      chomp;
 
325
      $lineno++;
 
326
      s/\#.*//og;
 
327
      next if /^\s*$/og;
 
328
      $_ .= ";" unless /;\s*$/;
 
329
      if (/^\s*([^=]+)\s*=\s*(\S.*)$/o) {
 
330
          my $ret = eval "$1=$2";
 
331
          if ($@) {
 
332
              print STDERR "Error parsing config file $Config_file!\n";
 
333
              print STDERR "$lineno:$_\n";
 
334
          }
 
335
      }
 
336
  }
 
337
}
 
338
 
 
339
sub ReadXFConfigFont
 
340
{
 
341
  open(CONFIG, "$XFConfigPath") || return;
 
342
  my $lineno = 0;
 
343
  while (<CONFIG>) {
 
344
      chomp;
 
345
      $lineno++;
 
346
      s/\#.*//og;
 
347
      next if /^\s*$/og;
 
348
      if (/^\s*FontPath\s*"(\S.*)"\s*$/o) {
 
349
          $fontPath .= "," if $fontPath;
 
350
          $fontPath .= $1;
 
351
      }
 
352
  }
 
353
}
 
354
 
 
355
sub ReadXFConfigColor
 
356
{
 
357
  open(CONFIG, "$XFConfigPath") || return;
 
358
  my $lineno = 0;
 
359
  while (<CONFIG> && !$colorPath) {
 
360
      chomp;
 
361
      $lineno++;
 
362
      s/\#.*//og;
 
363
      next if /^\s*$/og;
 
364
      if (/^\s*RgbPath\s*"(\S.*)"\s*$/o) {
 
365
          $colorPath = $1;
 
366
      }
 
367
  }
 
368
}
 
369
 
 
370
 
 
371
########## End of debian functions ###########
 
372
 
210
373
 
211
374
###############################################################################
212
375
#
420
583
 
421
584
sub Usage
422
585
{
423
 
    die("\nusage: $prog [:<number>] [-nohttpd] [-name <desktop-name>] [-depth <depth>]\n".
424
 
        "                 [-geometry <width>x<height>]\n".
425
 
        "                 [-pixelformat rgbNNN|bgrNNN]\n".
426
 
        "                 <Xvnc-options>...\n\n".
427
 
        "       $prog -kill <X-display>\n\n");
 
586
    die("VNC4 server\n".
 
587
       "\n".
 
588
       "Usage: $prog [<OPTIONS>] [:<DISPLAY#>]\n".
 
589
       "       $prog -kill :<DISPLAY#>\n".
 
590
       "\n".
 
591
       "<OPTIONS> are Xvnc4 options, or:\n".
 
592
       "\n".
 
593
       "        -name <DESKTOP-NAME>\n".
 
594
       "        -depth <DEPTH>\n".
 
595
       "        -geometry <WIDTH>x<HEIGHT>\n".
 
596
       "        -httpport number\n".
 
597
       "        -basehttpport number\n".
 
598
       "        -alwaysshared\n".
 
599
       "        -nevershared\n".
 
600
       "        -pixelformat rgb<NNN>\n".
 
601
       "        -pixelformat bgr<NNN>\n".
 
602
       "        <Xvnc4-options>...\n".
 
603
       "\n".
 
604
       "See vnc4server and Xvnc4 manual pages for more information.\n");
428
605
}
429
606
 
430
607
 
448
625
 
449
626
    if (! -r $pidFile) {
450
627
        die "\nCan't find file $pidFile\n".
451
 
            "You'll have to kill the Xvnc process manually\n\n";
 
628
            "You'll have to kill the Xvnc4 process manually\n\n";
452
629
    }
453
630
 
454
631
    $SIG{'HUP'} = 'IGNORE';
455
632
    chop($pid = `cat $pidFile`);
456
 
    warn "Killing Xvnc process ID $pid\n";
 
633
    warn "Killing Xvnc4 process ID $pid\n";
457
634
    system("kill $pid");
458
635
    unlink $pidFile;
459
636
    exit;
523
700
    #
524
701
 
525
702
 cmd:
526
 
    foreach $cmd ("uname","xauth","Xvnc","vncpasswd") {
 
703
    foreach $cmd ("uname","xauth","Xvnc4","vncpasswd") {
527
704
        for (split(/:/,$ENV{PATH})) {
528
705
            if (-x "$_/$cmd") {
529
706
                next cmd;