#
# setflags.pl - Sets Imail flags from the registry
#    jalvarez@prw.net  05/15/2000
#
# Usage:
#    perl setflags.pl username hostname flagvalue
# Flag values:
#       1 0x0001  Account access disabled
#       2 0x0002  Hide from information services
#       4 0x0004  User cannot change password
#     128 0x0080  Allow web access
#     256 0x0100  Host administrator
#     512 0x0200  Imail System administrator
#    1024 0x0400  List administrator
#    4096 0x1000  User cannot modify LDAP attributes
# Example:
#    perl setflags.pl administrator mail.domain.com 1414
#    Old Flags: 1414   New flags: 1414
# 1414 translates to 1024 (List administrator) +
#                     256 (Host administrator) +
#                     128 (Allow web access) +
#                       4 (User can not change password) +
#                       2 (hide from information services)

use Win32::registry;

$user = $ARGV[0];
$domain = $ARGV[1];
$flags = $ARGV[2];

$key = "SOFTWARE\\Ipswitch\\Imail\\Domains\\$domain\\Users\\$user";

$HKEY_LOCAL_MACHINE->Open($key, $hkey) or
    die "Can't find registry for $user\@$domain";

$hkey->GetValues($userdata);
$old = $userdata->{'Flags'}[2];
$hkey->SetValueEx('Flags', '', 4, $flags); # REG_DWORD = 4
$hkey->GetValues($userdata);

print "Old Flags: $old   New Flags: $userdata->{'Flags'}[2]";