+sub cyrus_insert {
+ my( $username, $quota ) = @_;
+
+ warn "cyrus_insert: starting for user $username, quota $quota\n";
+
+ warn "cyrus_insert: connecting to $cyrus_server\n";
+ my $client = Cyrus::IMAP::Admin->new($cyrus_server);
+
+ warn "cyrus_insert: authentication as $cyrus_admin_user\n";
+ $client->authenticate(
+ -user => $cyrus_admin_user,
+ -mechanism => "login",
+ -password => $cyrus_admin_pass
+ );
+
+ warn "cyrus_insert: creating user.$username\n";
+ my $rc = $client->create("user.$username");
+ my $error = $client->error;
+ die "cyrus_insert: error creating user.$username: $error" if $error;
+
+ warn "cyrus_insert: setacl user.$username, $username => all\n";
+ $rc = $client->setacl("user.$username", $username => 'all' );
+ $error = $client->error;
+ die "cyrus_insert: error setacl user.$username: $error" if $error;
+
+ if ( $quota ) {
+ warn "cyrus_insert: setquota user.$username, STORAGE => $quota\n";
+ $rc = $client->setquota("user.$username", 'STORAGE' => $quota );
+ $error = $client->error;
+ die "cyrus_insert: error setquota user.$username: $error" if $error;
+ }
+
+ 1;
+}
+
+sub icradius_rc_insert {
+ my( $username, $password, %radcheck ) = @_;
+
+ my $sth = $icradius_dbh->prepare(
+ "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ".
+ join(", ", map { $icradius_dbh->quote($_) } (
+ '',
+ $username,
+ "Password",
+ $password,
+ ) ). " )"
+ );
+ $sth->execute or die "can't insert into radcheck table: ". $sth->errstr;
+
+ foreach my $attribute ( keys %radcheck ) {
+ my $sth = $icradius_dbh->prepare(
+ "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ".
+ join(", ", map { $icradius_dbh->quote($_) } (
+ '',
+ $username,
+ $attribute,
+ $radcheck{$attribute},
+ ) ). " )"
+ );
+ $sth->execute or die "can't insert into radcheck table: ". $sth->errstr;
+ }
+
+ 1;
+}
+
+sub icradius_rr_insert {
+ my( $username, $password, %radreply ) = @_;
+
+ foreach my $attribute ( keys %radreply ) {
+ my $sth = $icradius_dbh->prepare(
+ "INSERT INTO radreply ( id, UserName, Attribute, Value ) VALUES ( ".
+ join(", ", map { $icradius_dbh->quote($_) } (
+ '',
+ $username,
+ $attribute,
+ $radreply{$attribute},
+ ) ). " )"
+ );
+ $sth->execute or die "can't insert into radreply table: ". $sth->errstr;
+ }
+
+ 1;
+}
+