gdipusermod.pl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/perl
  2. #####################################################
  3. # gdipusermod.pl
  4. #
  5. # This script modifies a user in the GnuDIP database.
  6. #
  7. # Return codes:
  8. # 0 - success
  9. # 1 - user does not exist
  10. # 2 - configuration problem
  11. #
  12. # See COPYING for licensing information.
  13. #
  14. #####################################################
  15. # PERL modules
  16. use strict;
  17. use Getopt::Std;
  18. # global variables
  19. use vars qw($conf $gnudipdir);
  20. # locate ourselves
  21. use FindBin;
  22. BEGIN {
  23. $gnudipdir = '';
  24. if ($FindBin::Bin =~ /(.*)\/.+?/) {
  25. $gnudipdir = $1;
  26. }
  27. }
  28. use lib "$gnudipdir/lib";
  29. # GnuDIP common subroutines
  30. use gdipmaint;
  31. use gdiplinemode;
  32. # process command line
  33. sub usage {
  34. print STDERR <<"EOQ";
  35. usage: gdipusermod.pl { -h | \
  36. usage: [-m email] [-p password] [-x rawpassword] \
  37. usage: [-w {YES|NO}] [-y {YES|NO}] [-r] \
  38. usage: user domain }
  39. usage: Modify GnuDIP user \"user\" within domain \"domain\".
  40. usage: -h: Print this usage message.
  41. usage: -m: Specify E-mail address.
  42. usage: -p: Specify clear text password. The stored password will
  43. usage: the MD5 hash of this value.
  44. usage: -x: Specify the hashed password. This will be stored as
  45. usage: password hash value without any change.
  46. usage: -w: Allow ("YES") or disallow ("NO") wild cards.
  47. usage: -y: Allow ("YES") or disallow ("NO") MX records.
  48. usage: -r: Remove all DNS information.
  49. EOQ
  50. }
  51. use vars qw/ $opt_h $opt_m $opt_p $opt_x $opt_w $opt_y $opt_r/;
  52. if (!getopts('hrm:p:x:w:y:')) {
  53. usage();
  54. exit 2;
  55. }
  56. if ($opt_h) {
  57. usage();
  58. exit;
  59. }
  60. if (@ARGV ne 2) {
  61. usage();
  62. exit 2;
  63. }
  64. # hash reference for gdipmaint routine
  65. my %mainthash;
  66. my $maintinfo = \%mainthash;
  67. $$maintinfo{'username'} = $ARGV[0];
  68. $$maintinfo{'domain'} = $ARGV[1];
  69. $$maintinfo{'password'} = $opt_p;
  70. $$maintinfo{'hashedpw'} = $opt_x;
  71. $$maintinfo{'email'} = $opt_m;
  72. $$maintinfo{'allowwild'} = $opt_w;
  73. $$maintinfo{'allowmx'} = $opt_y;
  74. $$maintinfo{'removedns'} = 'YES' if $opt_r;
  75. # get preferences from config file
  76. $conf = getconf();
  77. # do it
  78. exit maintmod($maintinfo);