posixGroup Patch

Aaron Collins <[email protected]> Thu, 21 Jul 2005 11:27:58 -1000
Newsgroups gmane.mail.qmail.ldap.phpqladmin
Organization Ehawaii.gov
Message-ID <[email protected]>
--Boundary-00=_eNB4CcTqoPLO3oP
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Here's the posixGroup patch

-- 
Aaron Collins
Systems Administrator /
Release Engineer
Hawaii Information Consortium
[email protected]
808-587-4213

--Boundary-00=_eNB4CcTqoPLO3oP
Content-Type: text/x-diff;
  charset="utf-8";
  name="posixGroup.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="posixGroup.patch"

Index: phpQLAdmin/user_detail.php
===================================================================
RCS file: /var/cvs/phpQLAdmin/user_detail.php,v
retrieving revision 2.93
diff -u -r2.93 user_detail.php
--- phpQLAdmin/user_detail.php	11 Jun 2005 12:20:00 -0000	2.93
+++ phpQLAdmin/user_detail.php	21 Jul 2005 21:19:11 -0000
@@ -104,6 +104,7 @@
 // uses 'objectClass: pilotPerson' -> http://rfc-1274.rfcindex.net/
 $attribs = array("cn"					=> pql_get_define("PQL_ATTR_CN"),
 				 "sn"					=> pql_get_define("PQL_ATTR_SN"),
+                                 "givenname"            => pql_get_define("PQL_ATTR_GIVENNAME"),
 				 "uidnumber"			=> pql_get_define("PQL_ATTR_QMAILUID"),
 				 "gidnumber"			=> pql_get_define("PQL_ATTR_QMAILGID"),
 				 "loginshell"			=> pql_get_define("PQL_ATTR_LOGINSHELL"),
@@ -114,6 +115,7 @@
 				 "mailhost"				=> pql_get_define("PQL_ATTR_MAILHOST"),
 				 "homedirectory"		=> pql_get_define("PQL_ATTR_HOMEDIR"),
 				 "roomnumber"			=> pql_get_define("PQL_ATTR_ROOMNUMBER"),
+                                 "o"                    => pql_get_define("PQL_ATTR_O"),
 				 "telephonenumber"		=> pql_get_define("PQL_ATTR_TELEPHONENUMBER"),
 				 "homephone"			=> pql_get_define("PQL_ATTR_HOMEPHONE"),
 				 "homepostaladdress"	=> pql_get_define("PQL_ATTR_HOMEPOSTALADDRESS"),
@@ -121,6 +123,13 @@
 				 "personaltitle"		=> pql_get_define("PQL_ATTR_PERSONALTITLE"),
 				 "mobile"				=> pql_get_define("PQL_ATTR_MOBILE"),
 				 "pager"				=> pql_get_define("PQL_ATTR_PAGER"),
+                                 "sambasid"             => pql_get_define("PQL_ATTR_SAMBASID"),
+                                 "sambaprofilepath"     => pql_get_define("PQL_ATTR_SAMBAPROFILEPATH"),
+                                 "sambahomedrive"       => pql_get_define("PQL_ATTR_SAMBAHOMEDRIVE"),
+                                 "sambahomepath"        => pql_get_define("PQL_ATTR_SAMBAHOMEPATH"),
+                                 "sambadomainname"      => pql_get_define("PQL_ATTR_SAMBADOMAINNAME"),
+                                 "sambalogonscript"     => pql_get_define("PQL_ATTR_SAMBALOGONSCRIPT"),
+                                 "sambauserworkstations"        => pql_get_define("PQL_ATTR_SAMBAUSERWORKSTATIONS"),
 				 "startwithadvancedmode"=> pql_get_define("PQL_ATTR_START_ADVANCED"));
 foreach($attribs as $key => $attrib) {
 	if($attrib == pql_get_define("PQL_CONF_REFERENCE_USERS_WITH", $_GET["rootdn"]))
@@ -192,17 +201,12 @@
 // If this user have a username (ie, 'uid') then let's see if this user is member
 // of more groups (listed in the 'memberUid' attribute).
 if($uid) {
-	$memberuid = array();
-	foreach($_SESSION["BASE_DN"] as $base) {
-		$base  = urldecode($base);
-// BUG: This won't work - wrong params!!
-		$muids = pql_search($_pql->ldap_linkid, $base,
-							pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")."=".$uid,
-							pql_get_define("PQL_ATTR_CN"));
-
-		for($i=0; isset($muids[$i]); $i++)
-		  $memberuid[] = $muids[$i];
-	}
+        $memberuid = array();
+        foreach($_SESSION["BASE_DN"] as $base) {
+                $base  = pql_get_define("PQL_CONF_SUBTREE_GROUPS") .', '. $_REQUEST['domain'];
+                $memberuid = pql_search($_pql->ldap_linkid, $base,
+                                                        pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")."=".$uid);
+        }
 }
 // }}}
 
@@ -215,13 +219,20 @@
   $objectclasses = array($objectclasses);
 }
 foreach($objectclasses as $oc) {
-	if(eregi('qmailGroup', $oc))
-	  $USER_IS_GROUP = 1;
+        if(eregi('qmailGroup', $oc))
+          $USER_IS_GROUP = 1;
+        if(eregi('sambaSamAccount', $oc))
+          $USER_IS_SAMBA = 1;
 }
 // }}}
 
 // {{{ Setup the buttons
 $buttons = array('basic'			=> 'User data');
+// {{If they had the objectClass, then show them the menu
+if($USER_IS_SAMBA) {
+        $smb = array('samba'                    => 'Samba Settings');
+        $buttons = $buttons + $smb;
+}
 if(!$USER_IS_GROUP) {
 	$new = array('personal'			=> 'Personal details',
 				 'status'			=> 'Account status',
@@ -259,12 +270,13 @@
 	$buttons = $buttons + $new;
 }
 
-pql_generate_button($buttons, "user=".$url["user"]); echo "  <br>\n";
+pql_generate_button($buttons, "user=".$url["user"]); echo "  <br>\n\n";
 // }}}
 
 // {{{ Load the correct view page
 if($_GET["view"] == 'basic')					include("./tables/user_details-basic.inc");
 if($_GET["view"] == 'personal')					include("./tables/user_details-personal.inc");
+if($_GET["view"] == 'samba')                                    include("./tables/user_details-samba.inc");
 if($_GET["view"] == 'email')					include("./tables/user_details-email.inc");
 if($_GET["view"] == 'status')					include("./tables/user_details-status.inc");
 if($_GET["view"] == 'delivery')					include("./tables/user_details-delivery.inc");
Index: phpQLAdmin/user_edit_attribute.php
===================================================================
RCS file: /var/cvs/phpQLAdmin/user_edit_attribute.php,v
retrieving revision 2.56
diff -u -r2.56 user_edit_attribute.php
--- phpQLAdmin/user_edit_attribute.php	9 Jun 2005 15:05:36 -0000	2.56
+++ phpQLAdmin/user_edit_attribute.php	21 Jul 2005 21:19:11 -0000
@@ -100,6 +100,7 @@
 	  attribute_print_form();
     }
 } elseif(($_REQUEST["submit"] == 3) and (($_REQUEST["attrib"] == 'dnmember') or
+										 ($_REQUEST["attrib"] == 'memberuid') or
 										 ($_REQUEST["attrib"] == 'dnmoderator') or
 										 ($_REQUEST["attrib"] == 'dnsender'))) {
   attribute_print_form($_REQUEST["action"]);
Index: phpQLAdmin/include/attrib.additionalgroup.inc
===================================================================
RCS file: /var/cvs/phpQLAdmin/include/attrib.additionalgroup.inc,v
retrieving revision 2.9
diff -u -r2.9 attrib.additionalgroup.inc
--- phpQLAdmin/include/attrib.additionalgroup.inc	31 Jan 2005 11:39:44 -0000	2.9
+++ phpQLAdmin/include/attrib.additionalgroup.inc	21 Jul 2005 21:19:14 -0000
@@ -39,16 +39,20 @@
 	$filter .= ")";
 
 	foreach($_SESSION["BASE_DN"] as $base) {
+		//added by Aaron collins 7-12-2005 I'm cheating in building the base
+		if(pql_get_define("PQL_CONF_SUBTREE_GROUPS")){
+			$base  = pql_get_define("PQL_CONF_SUBTREE_GROUPS") .', '. $_REQUEST['domain'];
+		}else{
+			$base  =  $_REQUEST['domain'];
+		}
 		// Get all the groups in this root DN.
 		$grps = pql_search($_pql->ldap_linkid, $base, $filter);
 		if(is_array($grps)) {
 			for($i=0; $i < count($grps); $i++) {
 				$is_member = 0;
 				
-				// Get additional members in this group
-				$additional = pql_get_attribute($_pql->ldap_linkid, $grps[$i],
-												pql_get_define("PQL_ATTR_ADDITIONAL_GROUP"));
-				
+				$additional = $grps[$i]['memberuid'];	
+				$_REQUEST["uid"] = $_GET['uid'];
 				// Make sure the user isn't part of this group
 				for($j=0; $j < count($additional); $j++) {
 					if($additional[$j] == $_REQUEST["uid"])
@@ -56,11 +60,9 @@
 				}
 				
 				if(!$is_member) {
-					// Get the group name for this group
-					$groupname = pql_get_attribute($_pql->ldap_linkid, $grps[$i], pql_get_define("PQL_ATTR_CN"));
-					$groups[$groupname[0]]["DN"] = $grps[$i];
+					$groups[$grps[$i]['cn']]["DN"] = $grps[$i]['dn'];
 					
-					$groups[$groupname[0]]["MEMBERS"] = $additional;
+					$groups[$grps[$i]['cn']]["MEMBERS"] = $additional;
 				}
 			}
 		}
@@ -82,7 +84,12 @@
 <?php
 		$links = array();
 		for($i=0; $i< count($data["MEMBERS"]); $i++) {
-			$new = array("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Current member: ".$data["MEMBERS"][$i] => '');
+			if(is_array($data["MEMBERS"])){
+				$uniquemember = $data["MEMBERS"][$i];
+			}else{
+				$uniquemember = $data["MEMBERS"];
+			}
+			$new = array("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Current member: ".$uniquemember => '');
 			$links = $links + $new;
 		}
 
@@ -102,6 +109,7 @@
     <input type="hidden" name="domain"   value="<?=urlencode($_REQUEST["domain"])?>">
     <input type="hidden" name="rootdn"   value="<?=urlencode($_REQUEST["rootdn"])?>">
     <input type="hidden" name="user"     value="<?=urlencode($_REQUEST["user"])?>">
+    <input type="hidden" name="uid"     value="<?=urlencode($_REQUEST["uid"])?>">
     <input type="hidden" name="attrib"   value="<?=$_REQUEST["attrib"]?>">
     <input type="hidden" name="view"     value="<?=$_REQUEST["view"]?>">
     <input type="hidden" name="action"   value="<?=$_REQUEST["action"]?>">
@@ -130,26 +138,16 @@
 
 	  case "delete":
 		// Setup the search filter to get the exact DN of the group
-		$filter  = "(&($attrib_name=" . $_REQUEST["uid"] . ")(".pql_get_define("PQL_ATTR_CN")
-		  ."=".$_REQUEST[$attrib_name]."))";
 
-		// Get the DN of the group we're removing the user from
-		foreach($_SESSION["BASE_DN"] as $base) {
-			if(!isset($group)) {
-				$group = pql_search($_pql->ldap_linkid, $base, $filter);
-				$group = $group[0];
-			}
-		}
-
-		if(pql_modify_attribute($_pql->ldap_linkid, $group, $attrib_name, $_REQUEST["uid"], ''))
+		if(pql_modify_attribute($_pql->ldap_linkid, $_REQUEST['group'], $attrib_name, $_REQUEST["memberuid"], ''))
 		  $msg = pql_complete_constant($LANG->_('Successfully removed %user% from %what% %group%'),
 									   array('what'  => $LANG->_('additional group'),
-											 'user'  => $_REQUEST["uid"],
-											 'group' => $_REQUEST[$attrib_name]));
+											 'user'  => $_REQUEST["memberuid"],
+											 'group' => $_REQUEST['group']));
 		else
 		  $msg = pql_complete_constant($LANG->_('Failed to remove %user% from %what%'),
 									   array('what' => $LANG->_('additional group'),
-											 'user'  => $_REQUEST["uid"])) . ": " . pql_format_error(0);
+											 'user'  => $_REQUEST["memberuid"])) . ": " . pql_format_error(0);
 
 		attribute_forward($msg);
 		break;
@@ -163,12 +161,14 @@
 
 		for($i=0; $i < $amount; $i++) {
 			$var_name = $attrib_name . "_$i";
+			print "Looking for $var_name<br>\n";
 			if($_POST[$var_name]) 
 			  $groups[] = $_POST[$var_name];
 		}
-
+		$_REQUEST["uid"] = $_POST['uid'];
 		$msg = '';
 		for($i=0; $i< count($groups); $i++) {
+			print "Atleast one group<br>";
 			if(pql_modify_attribute($_pql->ldap_linkid, $groups[$i], $attrib_name, '', $_REQUEST["uid"])) {
 				$msg .= pql_complete_constant($LANG->_('Successfully added user %user% to group %group%<br>'),
 											  array('user' => $_REQUEST["uid"], 'group' => $groups[$i]));
Index: phpQLAdmin/include/pql_write.inc
===================================================================
RCS file: /var/cvs/phpQLAdmin/include/pql_write.inc,v
retrieving revision 2.31
diff -u -r2.31 pql_write.inc
--- phpQLAdmin/include/pql_write.inc	13 Jun 2005 12:03:17 -0000	2.31
+++ phpQLAdmin/include/pql_write.inc	21 Jul 2005 21:19:36 -0000
@@ -409,7 +409,9 @@
 	// }}}
     
 	// {{{ If this is a 'system' account, create the Group object
-	if($type == "system" and $entry[pql_get_define("PQL_ATTR_QMAILGID")]) {
+	if(in_array('posixaccount', $entry[pql_get_define("PQL_ATTR_OBJECTCLASS")]) and 
+	   $entry[pql_get_define("PQL_ATTR_QMAILGID")]) 
+	{
 		// Remember this for the NEW entry object...
 		$gidnr   = $entry[pql_get_define("PQL_ATTR_QMAILGID")];
 		$rdnattr = $entry[pql_get_define("PQL_CONF_REFERENCE_USERS_WITH", $rootdn)];
@@ -436,6 +438,12 @@
 	}
 	// }}}
 	
+        if(file_exists($_SESSION["path"]."/.DEBUG_ME")) {
+                echo "DNs added: ";
+                printr($dns);
+                die();
+        }
+
     return $dns;
 }
 
@@ -447,7 +455,6 @@
 // ------------------------------------------------
 
 // {{{ pql_user_del(ldap, domain, user, delete_forwards)
-
 // Delete a user from the LDAP database
 function pql_user_del($ldap, $domain, $user, $delete_forwards) {
 	$linkid = $ldap->ldap_linkid;
Index: phpQLAdmin/tables/user_details-basic.inc
===================================================================
RCS file: /var/cvs/phpQLAdmin/tables/user_details-basic.inc,v
retrieving revision 1.23
diff -u -r1.23 user_details-basic.inc
--- phpQLAdmin/tables/user_details-basic.inc	19 Apr 2005 04:44:32 -0000	1.23
+++ phpQLAdmin/tables/user_details-basic.inc	21 Jul 2005 21:19:49 -0000
@@ -52,6 +52,19 @@
 
 <?php }
 
+?>
+      <tr class="<?php pql_format_table(); ?>">
+        <td class="title"><?=$LANG->_('Firstname')?></td>
+        <td><?=$givenname?></td>
+        <td><a href="user_edit_attribute.php?rootdn=<?=$url["rootdn"]?>&domain=<?=$url["domain"]?>&attrib=givenname&user=<?=$url["user"]?>&view=<?=$_GET["view"]?>&oldvalue=<?=$givenname?>"><img src="images/edit.png" width="12" height="12" alt="<?=$LANG->_('Change First name')?>" border="0"></a></td>
+      </tr>
+      <tr class="<?php pql_format_table(); ?>">
+        <td class="title"><?=$LANG->_('Lastname')?></td>
+        <td><?=$sn?></td>
+        <td><a href="user_edit_attribute.php?rootdn=<?=$url["rootdn"]?>&domain=<?=$url["domain"]?>&attrib=sn&user=<?=$url["user"]?>&view=<?=$_GET["view"]?>&oldvalue=<?=$sn?>"><img src="images/edit.png" width="12" height="12" alt="<?=$LANG->_('Change last name')?>" border="0"></a></td>
+      </tr>
+<?php
+
 // {{{ Surname and Lastname
 // - Can/'should' be multi-valued, hence pql_format_table_single()
 $class=pql_format_table(0);
@@ -104,19 +117,21 @@
 
       <tr class="<?php pql_format_table(); ?>">
         <td class="title"><?=$LANG->_('Additional group(s)')?></td>
-<?php if(isset($memberuid[1])) {
+<?php if(isset($memberuid)) {
+
 		$new_tr = 0;
+                $username = $$ref;
 		foreach($memberuid as $muid) {
-			$muid = pql_maybe_idna_decode($muid);
+			//$muid = pql_maybe_idna_decode($muid);
 
 			if($new_tr) {
 ?>
       <tr class="<?php pql_format_table(); ?>">
         <td class="title"></td>
 <?php		} ?>
-        <td><?=$muid?></td>
+        <td><?= $muid['cn'] ?></td>
         <td>
-          <a href="user_edit_attribute.php?rootdn=<?=$url["rootdn"]?>&domain=<?=$url["domain"]?>&user=<?=$url["user"]?>&attrib=<?=pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")?>&<?=pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")?>=<?=$muid?>&submit=4&action=delete&view=<?=$_REQUEST["view"]?>"><img src="images/del.png" width="12" height="12" alt="<?=$LANG->_('Remove user from group')?>" border="0"></a>
+          <a href="user_edit_attribute.php?rootdn=<?=$url["rootdn"]?>&domain=<?=$url["domain"]?>&user=<?=$url["user"]?>&attrib=<?=pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")?>&<?=pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")?>=<?=$username?>&group=<?= $muid['dn'] ?>&submit=4&action=delete&view=<?=$_REQUEST["view"]?>"><img src="images/del.png" width="12" height="12" alt="<?=$LANG->_('Remove user from group')?>" border="0"></a>
         </td>
 <?php		$new_tr = 1;
 		} // if new_tr
@@ -124,12 +139,12 @@
       <tr class="<?php pql_format_table(); ?>">
         <td class="title"></td>
         <td colspan="4">
-          <a href="user_edit_attribute.php?rootdn=<?=$url["rootdn"]?>&domain=<?=$url["domain"]?>&user=<?=$url["user"]?>&attrib=<?=pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")?>&submit=3&action=add&view=<?=$_REQUEST["view"]?>"><?php echo pql_complete_constant($LANG->_('Add %what%'), array('what' => $LANG->_('additional group'))); ?></a>
+          <a href="user_edit_attribute.php?rootdn=<?=$url["rootdn"]?>&domain=<?=$url["domain"]?>&user=<?=$url["user"]?>&attrib=<?=pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")?>&uid=<?=$username?>&submit=3&action=add&view=<?=$_REQUEST["view"]?>"><?php echo pql_complete_constant($LANG->_('Add %what%'), array('what' => $LANG->_('additional group'))); ?></a>
         </td>
       </tr>
 <?php } else { ?>
         <td colspan="4">
-          <a href="user_edit_attribute.php?rootdn=<?=$url["rootdn"]?>&domain=<?=$url["domain"]?>&user=<?=$url["user"]?>&attrib=<?=pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")?>&submit=3&action=add&view=<?=$_REQUEST["view"]?>"><?php echo pql_complete_constant($LANG->_('Add %what%'), array('what' => $LANG->_('additional group'))); ?></a>
+          <a href="user_edit_attribute.php?rootdn=<?=$url["rootdn"]?>&domain=<?=$url["domain"]?>&user=<?=$url["user"]?>&attrib=<?=pql_get_define("PQL_ATTR_ADDITIONAL_GROUP")?>&uid=<?=$username?>&submit=3&action=add&view=<?=$_REQUEST["view"]?>"><?php echo pql_complete_constant($LANG->_('Add %what%'), array('what' => $LANG->_('additional group'))); ?></a>
         </td>
 <?php }
 	}
Index: phpQLAdmin/tables/user_details-group.inc
===================================================================
RCS file: /var/cvs/phpQLAdmin/tables/user_details-group.inc,v
retrieving revision 1.6
diff -u -r1.6 user_details-group.inc
--- phpQLAdmin/tables/user_details-group.inc	7 Mar 2005 06:48:05 -0000	1.6
+++ phpQLAdmin/tables/user_details-group.inc	21 Jul 2005 21:19:49 -0000
@@ -46,8 +46,8 @@
 	  if(!is_array($value))
 		$$key  = array($value);
 	  else
-		$$key  = $value;
-	}
+	$$key  = $value;
+}
 }
 
 $url_tmp    = "user_edit_attribute.php?rootdn=".$url["rootdn"]."&domain=".$url["domain"]."&user=".$url["user"]."&";
Index: phpQLAdmin/tables/user_details-personal.inc
===================================================================
RCS file: /var/cvs/phpQLAdmin/tables/user_details-personal.inc,v
retrieving revision 1.5
diff -u -r1.5 user_details-personal.inc
--- phpQLAdmin/tables/user_details-personal.inc	14 Feb 2004 15:31:53 -0000	1.5
+++ phpQLAdmin/tables/user_details-personal.inc	21 Jul 2005 21:19:49 -0000
@@ -1,5 +1,12 @@
   <table cellspacing="0" cellpadding="3" border="0">
     <th colspan="3" align="left"><?=$LANG->_('Personal details')?></th>
+
+      <tr class="<?php pql_format_table(); ?>">
+        <td class="title"><?=$LANG->_('Company/Organization')?></td>
+        <td><?php if($o) { echo $o; } else { echo $LANG->_('Not set'); }?></td>
+        <td><?=$o_link?></td>
+      </tr>
+
       <tr class="<?php pql_format_table(); ?>">
         <td class="title"><?=$LANG->_('Title')?></td>
         <td><?php if($personaltitle) { echo $personaltitle; } else { echo $LANG->_('Not set'); }?></td>


--Boundary-00=_eNB4CcTqoPLO3oP
Content-Type: text/plain; charset=us-ascii

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
--Boundary-00=_eNB4CcTqoPLO3oP--