home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / realvncpasswd < prev    next >
Encoding:
Text File  |  2007-03-08  |  3.7 KB  |  167 lines

  1. #!/usr/bin/perl
  2. #
  3. #  Copyright (C) 1998 Marcus Brinkmann. This is derived from vncserver.
  4. #
  5. #  This is free software; you can redistribute it and/or modify
  6. #  it under the terms of the GNU General Public License as published by
  7. #  the Free Software Foundation; either version 2 of the License, or
  8. #  (at your option) any later version.
  9. #
  10. #  This software is distributed in the hope that it will be useful,
  11. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #  GNU General Public License for more details.
  14. #
  15. #  You should have received a copy of the GNU General Public License
  16. #  along with this software; if not, write to the Free Software
  17. #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  18. #  USA.
  19. #
  20.  
  21. #
  22. # vncpasswd - wrapper script to start vncpasswd.real.
  23. #
  24.  
  25. use File::Path;
  26. use File::Basename;
  27.  
  28. #
  29. # Get the program name
  30. #
  31.  
  32. $vncPasswdCmd = "/usr/bin/realvncpasswd.real";
  33.  
  34. ($prog) = ($0 =~ m|([^/]+)$|);
  35.  
  36. if (!defined($ENV{HOME})) {
  37.     die "$prog: The HOME environment variable is not set.\n";
  38. }
  39.  
  40. die "couldn't find executable $vncPasswdCmd" unless (-x "$vncPasswdCmd");
  41.  
  42. # Source in configuration files, first the site wide one and then the
  43. # user specific one.
  44.  
  45. $Config_file = "/etc/vnc.conf";
  46. &ReadConfigFile();
  47. $Config_file = "$ENV{HOME}/.vncrc";
  48. &ReadConfigFile();
  49.  
  50. if (!$vncUserDir) {
  51.   $vncUserDir = "$ENV{HOME}/.vnc";
  52. }
  53. if (!$vncPasswdFile) {
  54.   $vncPasswdFile = $vncUserDir . "/passwd";
  55. }
  56.  
  57. &ParseOptions("-help",0);
  58.  
  59. &Usage() if ($opt{'-help'} || @ARGV > 1);
  60.  
  61. if ($ARGV[0]) {
  62.     $vncPasswdFile = $ARGV[0];
  63. }
  64.  
  65. $vncPasswdDir = dirname($vncPasswdFile);
  66. #I use this extra variable to keep vncUserDir pure.
  67.  
  68. if (!(-d $vncPasswdDir)) {
  69. # Create the password file's parent directories if necessary.
  70.     if (-e $vncPasswdDir) {
  71.         die "$prog: Could not create $vncPasswdDir, file exists but is not a directory.\n";
  72.     }
  73.     if (!mkpath ($vncPasswdDir, 0, 0755)) {
  74.        die "$prog: Could not create $vncPasswdDir.\n";
  75.     }
  76. }
  77.  
  78. system("$vncPasswdCmd $vncPasswdFile");
  79. if (($? >> 8) != 0) {
  80.     exit 1;
  81. }
  82.  
  83. exit;
  84.  
  85. #########################################################################
  86. #
  87. # code submitted from Manoj Srivastava. Thank you, Manoj!
  88. #
  89. # ReadConfigFile reads in a config file and sets variables according to it.
  90. #
  91.  
  92. sub ReadConfigFile
  93. {
  94.   open(CONFIG, "$Config_file") || return;
  95.   my $lineno = 0;
  96.   while (<CONFIG>) {
  97.       chomp;
  98.       $lineno++;
  99.       s/\#.*//og;
  100.       next if /^\s*$/og;
  101.       $_ .= ";" unless /;\s*$/;
  102.       if (/^\s*([^=]+)\s*=\s*(\S.*)$/o) {
  103.           my $ret = eval "$1=$2";
  104.           if ($@) {
  105.               print STDERR "Error parsing config file $Config_file!\n";
  106.               print STDERR "$lineno:$_\n";
  107.           }
  108.       }
  109.   }
  110. }
  111.  
  112. #
  113. # Usage
  114. #
  115.  
  116. sub Usage
  117. {
  118.     die("usage: $prog [passwdFile]\n");
  119. }
  120.  
  121.  
  122. #
  123. # ParseOptions takes a list of possible options and a boolean indicating
  124. # whether the option has a value following, and sets up an associative array
  125. # %opt of the values of the options given on the command line. It removes all
  126. # the arguments it uses from @ARGV and returns them in @optArgs.
  127. #
  128.  
  129. sub ParseOptions
  130. {
  131.     local (@optval) = @_;
  132.     local ($opt, @opts, %valFollows, @newargs);
  133.  
  134.     while (@optval) {
  135.     $opt = shift(@optval);
  136.     push(@opts,$opt);
  137.     $valFollows{$opt} = shift(@optval);
  138.     }
  139.  
  140.     @optArgs = ();
  141.     %opt = ();
  142.  
  143.     arg: while ($arg = shift(@ARGV)) {
  144.     foreach $opt (@opts) {
  145.         if ($arg eq $opt) {
  146.         push(@optArgs, $arg);
  147.         if ($valFollows{$opt}) {
  148.             if (@ARGV == 0) {
  149.             &Usage();
  150.             }
  151.             $opt{$opt} = shift(@ARGV);
  152.             push(@optArgs, $opt{$opt});
  153.         } else {
  154.             $opt{$opt} = 1;
  155.         }
  156.         next arg;
  157.         }
  158.     }
  159.     push(@newargs,$arg);
  160.     }
  161.  
  162.     @ARGV = @newargs;
  163. }
  164.  
  165.  
  166.  
  167.