Creates a .forward file for users if they enter an email.
authorJacob Parker <j3parker@uwaterloo.ca>
Sat, 22 Aug 2009 20:09:12 +0000 (16:09 -0400)
committerJacob Parker <j3parker@uwaterloo.ca>
Sat, 22 Aug 2009 20:09:12 +0000 (16:09 -0400)
ceo/members.py
ceo/urwid/newmember.py
src/ceo.proto
src/homedir.c
src/homedir.h
src/op-adduser.c

index 5b85a4b..fbec163 100644 (file)
@@ -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()
index 7c5e20e..6a8725d 100644 (file)
@@ -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'] )
index 386bc77..9507583 100644 (file)
@@ -16,6 +16,7 @@ message AddUser {
   optional string password = 3;
   optional string realname = 4;
   optional string program = 5;
+  optional string email = 6;
 }
 
 message AddUserResponse {
index bf17ba6..9d54486 100644 (file)
@@ -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;
index 9dc8b54..63ed38e 100644 (file)
@@ -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);
index 060f385..df7eefd 100644 (file)
@@ -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");