Creates a .forward file for users if they enter an email.

pull/5/head
Jacob Parker 14 years ago
parent fe9af9994e
commit dd895884a9
  1. 5
      ceo/members.py
  2. 12
      ceo/urwid/newmember.py
  3. 1
      src/ceo.proto
  4. 18
      src/homedir.c
  5. 2
      src/homedir.h
  6. 4
      src/op-adduser.c

@ -109,7 +109,7 @@ def connected():
### Members ###
def create_member(username, password, name, program):
def create_member(username, password, name, program, email):
"""
Creates a UNIX user account with options tailored to CSC members.
@ -118,6 +118,7 @@ def create_member(username, password, name, program):
password - the desired UNIX password
name - the member's real name
program - the member's program of study
email - email to place in .forward
Exceptions:
InvalidArgument - on bad account attributes provided
@ -142,6 +143,7 @@ def create_member(username, password, name, program):
request.password = password
request.realname = name
request.program = program
request.email = email
out = remote.run_remote('adduser', request.SerializeToString())
@ -391,6 +393,7 @@ def create_club(username, name):
request.type = ceo_pb2.AddUser.CLUB
request.username = username
request.realname = name
out = remote.run_remote('adduser', request.SerializeToString())
response = ceo_pb2.AddUserResponse()

@ -1,4 +1,4 @@
import ldap, urwid
import ldap, urwid #, re
from ceo import members, terms, uwldap
from ceo.urwid.widgets import *
from ceo.urwid.window import *
@ -51,7 +51,8 @@ class InfoPage(WizardPanel):
def init_widgets(self):
self.name = SingleEdit("Full name: ")
self.program = SingleEdit("Program of Study: ")
self.userid = LdapFilterWordEdit(uwldap.uri(), uwldap.base(), 'uid',
self.email = SingleEdit("Email: ")
self.userid = LdapFilterWordEdit(uwldap.uri(), uwldap.base(), 'uid',
{'cn':self.name, 'ou':self.program}, "Username: ")
self.widgets = [
urwid.Text( "Member Information" ),
@ -59,6 +60,7 @@ class InfoPage(WizardPanel):
self.userid,
self.name,
self.program,
self.email,
urwid.Divider(),
urwid.Text("Notes:"),
urwid.Text("- Make sure to check ID (watcard, drivers license)"),
@ -68,7 +70,7 @@ class InfoPage(WizardPanel):
self.state['userid'] = self.userid.get_edit_text()
self.state['name'] = self.name.get_edit_text()
self.state['program'] = self.program.get_edit_text()
self.state['email'] = self.email.get_edit_text()
if len( self.state['userid'] ) < 3:
self.focus_widget( self.userid )
set_status("Username is too short")
@ -173,10 +175,10 @@ class EndPage(WizardPanel):
problem = None
try:
if self.utype == 'member':
members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'] )
members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'], self.state['email'] )
members.register( self.state['userid'], terms.current() )
elif self.utype == 'clubuser':
members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'] )
members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'], self.state['email'] )
members.register_nonmember( self.state['userid'], terms.current() )
elif self.utype == 'club':
members.create_club( self.state['userid'], self.state['name'] )

@ -16,6 +16,7 @@ message AddUser {
optional string password = 3;
optional string realname = 4;
optional string program = 5;
optional string email = 6;
}
message AddUserResponse {

@ -27,7 +27,7 @@ static int set_acl(char *dir, char *acl_text, acl_type_t type) {
return 0;
}
int ceo_create_home(char *homedir, char *skel, uid_t uid, gid_t gid, char *access_acl, char *default_acl) {
int ceo_create_home(char *homedir, char *skel, uid_t uid, gid_t gid, char *access_acl, char *default_acl, char *email) {
int mask;
DIR *skeldir;
struct dirent *skelent;
@ -131,11 +131,25 @@ int ceo_create_home(char *homedir, char *skel, uid_t uid, gid_t gid, char *acces
closedir(skeldir);
if (email && strlen(email) >0) {
char dest[PATH_MAX];
snprintf(dest, sizeof(dest), "%s/%s", homedir, ".forward");
int destfd = open(dest, O_WRONLY|O_CREAT|O_EXCL, 0644);
if (write(destfd, email, sizeof(char)*strlen(email)) < 0) {
warnpe ("write");
}
if (fchown(destfd, uid, gid))
errorpe("chown: %s", dest);
close(destfd);
}
if (chown(homedir, uid, gid)) {
errorpe("failed to chown %s", homedir);
return -1;
}
umask(mask);
return 0;

@ -2,4 +2,4 @@
#define CLUB_ACL "u::rwx,g::r-x,o::r-x,g:%d:rwx,m::rwx"
int ceo_create_home(char *homedir, char *skel, uid_t uid, gid_t gid, char *access_acl, char *default_acl);
int ceo_create_home(char *homedir, char *skel, uid_t uid, gid_t gid, char *access_acl, char *default_acl, char *email);

@ -171,7 +171,7 @@ static int32_t addmember(Ceo__AddUser *in, Ceo__AddUserResponse *out) {
else
response_message(out, 0, "successfully created ldap group");
if ((home_stat = ceo_create_home(homedir, member_home_skel, id, id, NULL, NULL)))
if ((home_stat = ceo_create_home(homedir, member_home_skel, id, id, NULL, NULL, in->email)))
response_message(out, EHOME, "unable to create home directory for %s", in->username);
else
response_message(out, 0, "successfully created home directory");
@ -215,7 +215,7 @@ static int32_t addclub(Ceo__AddUser *in, Ceo__AddUserResponse *out) {
else
response_message(out, 0, "successfully created ldap sudoers");
if ((home_stat = ceo_create_home(homedir, club_home_skel, id, id, acl, acl)))
if ((home_stat = ceo_create_home(homedir, club_home_skel, id, id, acl, acl, NULL)))
response_message(out, EHOME, "unable to create home directory for %s", in->username);
else
response_message(out, 0, "successfully created home directory");

Loading…
Cancel
Save