Disable access to the administrator plugin when plugin is disabled in config.
[squirrelmail.git] / functions / abook_local_file.php
index ee1584052eb6186f542d78bebe754b955eab0bf7..6dca53eb0a99e07315997449e8c6461e60aac156 100644 (file)
@@ -26,6 +26,7 @@
  *                checking file permissions.
  * ? writeable => allow writing into address book. Used only when
  *                detect_writeable is set to false.
+ * ? listing   => enable/disable listing
  *</pre>
  * NOTE. This class should not be used directly. Use the
  *       "AddressBook" class instead.
@@ -70,6 +71,11 @@ class abook_local_file extends addressbook_backend {
      * @var bool
      */
     var $writeable = false;
+    /**
+     * controls listing of address book
+     * @var bool
+     */
+    var $listing = true;
     /**
      * Umask of the file
      * @var string
@@ -113,6 +119,9 @@ class abook_local_file extends addressbook_backend {
             if(!empty($param['writeable'])) {
                 $this->writeable = $param['writeable'];
             }
+            if(isset($param['listing'])) {
+                $this->listing = $param['listing'];
+            }
 
             $this->open(true);
         } else {
@@ -132,7 +141,7 @@ class abook_local_file extends addressbook_backend {
         $this->error = '';
         $file   = $this->filename;
         $create = $this->create;
-        $fopenmode = ($this->writeable ? 'a+' : 'r');
+        $fopenmode = (($this->writeable && is_writable($file)) ? 'a+' : 'r');
 
         /* Return true is file is open and $new is unset */
         if($this->filehandle && !$new) {
@@ -315,6 +324,11 @@ class abook_local_file extends addressbook_backend {
      */
     function list_addr() {
         $res = array();
+
+        if(isset($this->listing) && !$this->listing) {
+            return array();
+        }
+
         $this->open();
         @rewind($this->filehandle);
 
@@ -343,8 +357,8 @@ class abook_local_file extends addressbook_backend {
         /* See if user exists already */
         $ret = $this->lookup($userdata['nickname']);
         if(!empty($ret)) {
-            return $this->set_error(sprintf(_("User '%s' already exist"),
-                   $ret['nickname']));
+            return $this->set_error(sprintf(_("User %s already exists"),
+                        '&quot;' . $ret['nickname'] . '&quot;'));
         }
 
         /* Here is the data to write */
@@ -436,8 +450,8 @@ class abook_local_file extends addressbook_backend {
         /* See if user exists */
         $ret = $this->lookup($alias);
         if(empty($ret)) {
-            return $this->set_error(sprintf(_("User '%s' does not exist"),
-                $alias));
+            return $this->set_error(sprintf(_("User %s does not exist"),
+                        '&quot;' . $alias . '&quot;'));
         }
 
         /* Lock the file to make sure we're the only process working