gdipuseradd.pl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/perl
  2. #####################################################
  3. # gdipuseradd.pl
  4. #
  5. # This script adds a user to the GnuDIP database.
  6. #
  7. # Return codes:
  8. # 0 - success
  9. # 1 - user already exists
  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: gdipuseradd.pl { -h | [-p password] [-m email] user domain }
  36. usage: Add GnuDIP user \"user\" within domain \"domain\" with
  37. usage: password \"password\" and (optionally) E-mail address \"email\".
  38. usage: -h: Print this usage message.
  39. usage: -p: Specify clear text password. The stored password will the MD5
  40. usage: hash of this value. Password is disabled if not specified.
  41. usage: -m: Specify E-mail address.
  42. EOQ
  43. }
  44. use vars qw/ $opt_h $opt_p $opt_m /;
  45. if (!getopts('hp:m:')) {
  46. usage();
  47. exit 2;
  48. }
  49. if ($opt_h) {
  50. usage();
  51. exit;
  52. }
  53. if (@ARGV ne 2) {
  54. usage();
  55. exit 2;
  56. }
  57. # hash reference for gdipmaint routine
  58. my %mainthash;
  59. my $maintinfo = \%mainthash;
  60. $$maintinfo{'username'} = $ARGV[0];
  61. $$maintinfo{'domain'} = $ARGV[1];
  62. $$maintinfo{'password'} = $opt_p;
  63. $$maintinfo{'email'} = $opt_m;
  64. # get preferences from config file
  65. $conf = getconf();
  66. # do it
  67. exit maintadd($maintinfo);