Code

Fixed . and _ problem
[gosa.git] / gosa-core / include / class_gosaSupportDaemon.inc
index b10d506dcd3ca3e1fe54727aee84344a1ea39607..e4772236c32bf787a90ecef02f241493a4e3ce7e 100644 (file)
@@ -1217,6 +1217,13 @@ class gosaSupportDaemon
   {
     $res = array();  
 
+    /* Check if the given server is a valid mac address
+     */
+    if(!tests::is_mac($server)){
+      trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
+      return($ret);
+    }
+
     /* Prepare request event 
      */ 
     $xml_msg = 
@@ -1235,7 +1242,7 @@ class gosaSupportDaemon
       @pram   String The name of the requested principal. (e.g. peter@EXAMPLE.DE)
       @return Array  A list containing the names of all configured principals.
    */
-  public function krb5_get_principal($name)
+  public function krb5_get_principal($server,$name)
   {
     $ret = array();
 
@@ -1246,6 +1253,13 @@ class gosaSupportDaemon
       return($ret);
     }
 
+    /* Check if the given server is a valid mac address
+     */
+    if(!tests::is_mac($server)){
+      trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
+      return($ret);
+    }
+
     /* Prepare request event 
      */ 
     $xml_msg = 
@@ -1266,7 +1280,7 @@ class gosaSupportDaemon
       @pram   String The name of the principal to update. (e.g. peter@EXAMPLE.DE)
       @return Boolean   TRUE on success else FALSE. 
    */
-  public function krb5_set_principal($name,$values)
+  public function krb5_set_principal($server,$name,$values)
   {
     $ret = FALSE;  
 
@@ -1281,6 +1295,13 @@ class gosaSupportDaemon
       return($ret);
     }
 
+    /* Check if the given server is a valid mac address
+     */
+    if(!tests::is_mac($server)){
+      trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
+      return($ret);
+    }
+
     $attrs = "";
     foreach($values as $name => $value){
       if(empty($name) || is_numeric($name)){
@@ -1301,7 +1322,7 @@ class gosaSupportDaemon
       "<target>GOSA</target>".
       "</xml>";
 
-    return($this->_send($xml_msg,TRUE));
+    return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
   }
 
 
@@ -1310,7 +1331,7 @@ class gosaSupportDaemon
       @pram   String The name of the principal. (e.g. peter@EXAMPLE.DE)
       @return Boollean   TRUE on success else FALSE
    */
-  public function krb5_del_principal($name)
+  public function krb5_del_principal($server,$name)
   {
     $ret = FALSE;  
 
@@ -1321,6 +1342,13 @@ class gosaSupportDaemon
       return($ret);
     }
 
+    /* Check if the given server is a valid mac address
+     */
+    if(!tests::is_mac($server)){
+      trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
+      return($ret);
+    }
+
     /* Prepare request event 
      */ 
     $xml_msg = 
@@ -1330,9 +1358,8 @@ class gosaSupportDaemon
       "<source>GOSA</source>".
       "<target>GOSA</target>".
       "</xml>";
-
     
-    return($this->_send($xml_msg,TRUE));
+    return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
   }
 
 
@@ -1344,6 +1371,13 @@ class gosaSupportDaemon
   {
     $res = array();  
 
+    /* Check if the given server is a valid mac address
+     */
+    if(!tests::is_mac($server)){
+      trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
+      return($ret);
+    }
+
     /* Prepare request event 
      */ 
     $xml_msg = 
@@ -1406,8 +1440,9 @@ class gosaSupportDaemon
 
     /* Possible attributes */
     $attrs = array("MASK","POLICY","PW_HISTORY_NUM","PW_MAX_LIFE",
-        "PW_MIN_CLASSES","PW_MIN_LENGTH","PW_MIN_LIFE","REF_COUNT");
+        "PW_MIN_CLASSES","PW_MIN_LENGTH","PW_MIN_LIFE","POLICY_REFCNT");
 
+  
     $tmp = $this->_send($xml_msg,TRUE);
     if(isset($tmp['XML'])){
       foreach($attrs as $attr){
@@ -1422,13 +1457,14 @@ class gosaSupportDaemon
   }
 
   
-  /*! \brief  Creates/Updates a given policy with a set of configuration settings.
+  /*! \brief  Creates a new policy with a given set of configuration settings.
               For a list of configurable attributes have a look at 'krb5_get_policy()'.
               (Uses the GOsa support daemon instead of the ldap database.)
       @pram   String The name of the policy to update.
+      @pram   Array  The attributes to update
       @return Boolean   TRUE on success else FALSE. 
    */
-  public function krb5_set_policy($name,$values)
+  public function krb5_add_policy($server,$name,$values)
   {
     $ret = FALSE;  
 
@@ -1443,29 +1479,92 @@ class gosaSupportDaemon
       return($ret);
     }
 
+    /* Check if the given server is a valid mac address
+     */
+    if(!tests::is_mac($server)){
+      trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
+      return($ret);
+    }
+
+
     /* Transform array into <xml>
      */
     $attrs = "";
-    foreach($values as $name => $value){
-      if(empty($name) || is_numeric($name)){
-        trigger_error("Invalid policy configuration attribute given '".$name."=".$value."'.");
+    foreach($values as $id => $value){
+      if(empty($id) || is_numeric($id)){
+        trigger_error("Invalid policy configuration attribute given '".$id."=".$value."'.");
         return($ret);
       }
-      $attrs = "<$name>$value</$name>\n";
+      $attrs.= "<$id>$value</$id>\n";
     }
 
     /* Prepare request event 
      */ 
     $xml_msg = 
       "<xml>".
-      "<header>gosa_krb5_set_policy</header>".
+      "<header>gosa_krb5_create_policy</header>".
       "<policy>".$name."</policy>".
       $attrs.
       "<source>GOSA</source>".
-      "<target>GOSA</target>".
+      "<target>".$server."</target>".
       "</xml>";
 
-    return($this->_send($xml_msg,TRUE));
+    return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
+  }
+
+
+  /*! \brief  Updates a given policy with a set of configuration settings.
+              For a list of configurable attributes have a look at 'krb5_get_policy()'.
+              (Uses the GOsa support daemon instead of the ldap database.)
+      @pram   String The name of the policy to update.
+      @return Boolean   TRUE on success else FALSE. 
+   */
+  public function krb5_set_policy($server,$name,$values)
+  {
+    $ret = FALSE;  
+
+    /* Check if the given name is a valid request value 
+     */
+    if(!is_string($name) || empty($name)){
+      trigger_error("The given policy name is not of type string or it is empty.");
+      return($ret);
+    }
+    if(!is_array($values) || !count($values)){
+      trigger_error("No valid policy settings given. The parameter must be of type array and must contain at least one entry");
+      return($ret);
+    }
+
+    /* Check if the given server is a valid mac address
+     */
+    if(!tests::is_mac($server)){
+      trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
+      return($ret);
+    }
+
+    /* Transform array into <xml>
+     */
+    $attrs = "";
+    foreach($values as $id => $value){
+      if(preg_match("/^policy$/i",$id)) continue;
+      if(empty($id) || is_numeric($id)){
+        trigger_error("Invalid policy configuration attribute given '".$id."=".$value."'.");
+        return($ret);
+      }
+      $attrs.= "<$id>$value</$id>\n";
+    }
+
+    /* Prepare request event 
+     */ 
+    $xml_msg = 
+      "<xml>".
+      "<header>gosa_krb5_modify_policy</header>".
+      "<policy>".$name."</policy>".
+      $attrs.
+      "<source>GOSA</source>".
+      "<target>".$server."</target>".
+      "</xml>";
+
+    return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
   }
 
   
@@ -1473,10 +1572,17 @@ class gosaSupportDaemon
               (Uses the GOsa support daemon instead of the ldap database.)
       @return Boolean  TRUE on success else FALSE
    */
-  public function krb5_del_policy($name)
+  public function krb5_del_policy($server,$name)
   {
     $ret = FALSE;
 
+    /* Check if the given server is a valid mac address
+     */
+    if(!tests::is_mac($server)){
+      trigger_error("The given server address '".$server."' is invalid, it must be a valid mac address");
+      return($ret);
+    }
+
     /* Check if the given name is a valid request value 
      */
     if(!is_string($name) || empty($name)){
@@ -1493,7 +1599,7 @@ class gosaSupportDaemon
       "<source>GOSA</source>".
       "<target>GOSA</target>".
       "</xml>";
-    return($this->_send($xml_msg,TRUE));
+    return($this->_send($xml_msg,TRUE) == TRUE && !$this->is_error());
   }
 
 }