README 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. -----------------------------------------------------------------------
  2. Password Plugin for Roundcube
  3. -----------------------------------------------------------------------
  4. Plugin that adds a possibility to change user password using many
  5. methods (drivers) via Settings/Password tab.
  6. -----------------------------------------------------------------------
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see http://www.gnu.org/licenses/.
  17. @author Aleksander Machniak <alec@alec.pl>
  18. @author <see driver files for driver authors>
  19. -----------------------------------------------------------------------
  20. 1. Configuration
  21. 2. Drivers
  22. 2.1. Database (sql)
  23. 2.2. Cyrus/SASL (sasl)
  24. 2.3. Poppassd/Courierpassd (poppassd)
  25. 2.4. LDAP (ldap)
  26. 2.5. DirectAdmin Control Panel (directadmin)
  27. 2.6. cPanel
  28. 2.6.1. cPanel WHM (cpanel)
  29. 2.6.2. cPanel Webmail (cpanel_webmail)
  30. 2.7. XIMSS/Communigate (ximms)
  31. 2.8. Virtualmin (virtualmin)
  32. 2.9. hMailServer (hmail)
  33. 2.10. PAM (pam)
  34. 2.11. Chpasswd (chpasswd)
  35. 2.12. LDAP - no PEAR (ldap_simple)
  36. 2.13. XMail (xmail)
  37. 2.14. Pw (pw_usermod)
  38. 2.15. domainFACTORY (domainfactory)
  39. 2.16. DBMail (dbmail)
  40. 2.17. Expect (expect)
  41. 2.18. Samba (smb)
  42. 2.19. Vpopmail daemon (vpopmaild)
  43. 2.20. Plesk (Plesk RPC-API)
  44. 2.21. Kpasswd
  45. 3. Driver API
  46. 4. Sudo setup
  47. 1. Configuration
  48. ----------------
  49. Copy config.inc.php.dist to config.inc.php and set the options as described
  50. within the file.
  51. 2. Drivers
  52. ----------
  53. Password plugin supports many password change mechanisms which are
  54. handled by included drivers. Just pass driver name in 'password_driver' option.
  55. 2.1. Database (sql)
  56. -------------------
  57. You can specify which database to connect by 'password_db_dsn' option and
  58. what SQL query to execute by 'password_query'. See config.inc.php.dist file for
  59. more info.
  60. Example implementations of an update_passwd function:
  61. - This is for use with LMS (http://lms.org.pl) database and postgres:
  62. CREATE OR REPLACE FUNCTION update_passwd(hash text, account text) RETURNS integer AS $$
  63. DECLARE
  64. res integer;
  65. BEGIN
  66. UPDATE passwd SET password = hash
  67. WHERE login = split_part(account, '@', 1)
  68. AND domainid = (SELECT id FROM domains WHERE name = split_part(account, '@', 2))
  69. RETURNING id INTO res;
  70. RETURN res;
  71. END;
  72. $$ LANGUAGE plpgsql SECURITY DEFINER;
  73. - This is for use with a SELECT update_passwd(%o,%c,%u) query
  74. Updates the password only when the old password matches the MD5 password
  75. in the database
  76. CREATE FUNCTION update_password (oldpass text, cryptpass text, user text) RETURNS text
  77. MODIFIES SQL DATA
  78. BEGIN
  79. DECLARE currentsalt varchar(20);
  80. DECLARE error text;
  81. SET error = 'incorrect current password';
  82. SELECT substring_index(substr(user.password,4),_latin1'$',1) INTO currentsalt FROM users WHERE username=user;
  83. SELECT '' INTO error FROM users WHERE username=user AND password=ENCRYPT(oldpass,currentsalt);
  84. UPDATE users SET password=cryptpass WHERE username=user AND password=ENCRYPT(oldpass,currentsalt);
  85. RETURN error;
  86. END
  87. Example SQL UPDATEs:
  88. - Plain text passwords:
  89. UPDATE users SET password=%p WHERE username=%u AND password=%o AND domain=%h LIMIT 1
  90. - Crypt text passwords:
  91. UPDATE users SET password=%c WHERE username=%u LIMIT 1
  92. - Use a MYSQL crypt function (*nix only) with random 8 character salt
  93. UPDATE users SET password=ENCRYPT(%p,concat(_utf8'$1$',right(md5(rand()),8),_utf8'$')) WHERE username=%u LIMIT 1
  94. - MD5 stored passwords:
  95. UPDATE users SET password=MD5(%p) WHERE username=%u AND password=MD5(%o) LIMIT 1
  96. 2.2. Cyrus/SASL (sasl)
  97. ----------------------
  98. Cyrus SASL database authentication allows your Cyrus+Roundcube
  99. installation to host mail users without requiring a Unix Shell account!
  100. This driver only covers the "sasldb" case when using Cyrus SASL. Kerberos
  101. and PAM authentication mechanisms will require other techniques to enable
  102. user password manipulations.
  103. Cyrus SASL includes a shell utility called "saslpasswd" for manipulating
  104. user passwords in the "sasldb" database. This plugin attempts to use
  105. this utility to perform password manipulations required by your webmail
  106. users without any administrative interaction. Unfortunately, this
  107. scheme requires that the "saslpasswd" utility be run as the "cyrus"
  108. user - kind of a security problem since we have chosen to SUID a small
  109. script which will allow this to happen.
  110. This driver is based on the Squirrelmail Change SASL Password Plugin.
  111. See http://www.squirrelmail.org/plugin_view.php?id=107 for details.
  112. Installation:
  113. Change into the helpers directory. Edit the chgsaslpasswd.c file as is
  114. documented within it.
  115. Compile the wrapper program:
  116. gcc -o chgsaslpasswd chgsaslpasswd.c
  117. Chown the compiled chgsaslpasswd binary to the cyrus user and group
  118. that your browser runs as, then chmod them to 4550.
  119. For example, if your cyrus user is 'cyrus' and the apache server group is
  120. 'nobody' (I've been told Redhat runs Apache as user 'apache'):
  121. chown cyrus:nobody chgsaslpasswd
  122. chmod 4550 chgsaslpasswd
  123. Stephen Carr has suggested users should try to run the scripts on a test
  124. account as the cyrus user eg;
  125. su cyrus -c "./chgsaslpasswd -p test_account"
  126. This will allow you to make sure that the script will work for your setup.
  127. Should the script not work, make sure that:
  128. 1) the user the script runs as has access to the saslpasswd|saslpasswd2
  129. file and proper permissions
  130. 2) make sure the user in the chgsaslpasswd.c file is set correctly.
  131. This could save you some headaches if you are the paranoid type.
  132. 2.3. Poppassd/Courierpassd (poppassd)
  133. -------------------------------------
  134. You can specify which host to connect to via 'password_pop_host' and
  135. what port via 'password_pop_port'. See config.inc.php.dist file for more info.
  136. 2.4. LDAP (ldap)
  137. ----------------
  138. See config.inc.php.dist file. Requires PEAR::Net_LDAP2 package.
  139. 2.5. DirectAdmin Control Panel (directadmin)
  140. --------------------------------------------
  141. You can specify which host to connect to via 'password_directadmin_host' (don't
  142. forget to use tcp:// or ssl://) and what port via 'password_direactadmin_port'.
  143. The password enforcement with plenty customization can be done directly by
  144. DirectAdmin, please see http://www.directadmin.com/features.php?id=910
  145. See config.inc.php.dist file for more info.
  146. 2.6. cPanel
  147. -----------
  148. cPanel offers various APIs. The `cpanel` driver is configured with and admin
  149. account. It can change user's passwords without access to the current password.
  150. See the next section.
  151. The `cpanel_webmail` driver authenticates as the current user and does not need
  152. an admin account. See 2.6.2.
  153. 2.6.1. cPanel WHM (cpanel)
  154. --------------------------
  155. Install cPanel XMLAPI Client Class into Roundcube program/lib directory
  156. or any other place in PHP include path. You can get the class from
  157. https://raw.github.com/CpanelInc/xmlapi-php/master/xmlapi.php
  158. You can configure parameters for connection to cPanel's API interface.
  159. See config.inc.php.dist file for more info.
  160. 2.6.2. cPanel Webmail (cpanel_webmail)
  161. --------------------------------------
  162. Specify the host to connect to via 'password_webmail_cpanel_host'. This driver
  163. comes with a minimal UAPI implementation and does not use the external xmlapi
  164. class. It requires php-curl extension.
  165. See config.inc.php.dist file for more info.
  166. 2.7. XIMSS/Communigate (ximms)
  167. ------------------------------
  168. You can specify which host and port to connect to via 'password_ximss_host'
  169. and 'password_ximss_port'. See config.inc.php.dist file for more info.
  170. 2.8. Virtualmin (virtualmin)
  171. ----------------------------
  172. As in sasl driver this one allows to change password using shell
  173. utility called "virtualmin". See helpers/chgvirtualminpasswd.c for
  174. installation instructions. See also config.inc.php.dist file.
  175. 2.9. hMailServer (hmail)
  176. ------------------------
  177. Requires PHP COM (Windows only). For access to hMail server on remote host
  178. you'll need to define 'hmailserver_remote_dcom' and 'hmailserver_server'.
  179. See config.inc.php.dist file for more info.
  180. 2.10. PAM (pam)
  181. ---------------
  182. This driver is for changing passwords of shell users authenticated with PAM.
  183. Requires PECL's PAM exitension to be installed (http://pecl.php.net/package/PAM).
  184. 2.11. Chpasswd (chpasswd)
  185. -------------------------
  186. Driver that adds functionality to change the systems user password via
  187. the 'chpasswd' command. See config.inc.php.dist file.
  188. Attached wrapper script (helpers/chpass-wrapper.py) restricts password changes
  189. to uids >= 1000 and can deny requests based on a blacklist.
  190. 2.12. LDAP - no PEAR (ldap_simple)
  191. -----------------------------------
  192. It's rewritten ldap driver that doesn't require the Net_LDAP2 PEAR extension.
  193. It uses directly PHP's ldap module functions instead (as Roundcube does).
  194. This driver is fully compatible with the ldap driver, but
  195. does not require (or uses) the
  196. $config['password_ldap_force_replace'] variable.
  197. Other advantages:
  198. * Connects only once with the LDAP server when using the search user.
  199. * Does not read the DN, but only replaces the password within (that is
  200. why the 'force replace' is always used).
  201. 2.13. XMail (xmail)
  202. -----------------------------------
  203. Driver for XMail (www.xmailserver.org). See config.inc.php.dist file
  204. for configuration description.
  205. 2.14. Pw (pw_usermod)
  206. -----------------------------------
  207. Driver to change the systems user password via the 'pw usermod' command.
  208. See config.inc.php.dist file for configuration description.
  209. 2.15. domainFACTORY (domainfactory)
  210. -----------------------------------
  211. Driver for the hosting provider domainFACTORY (www.df.eu).
  212. No configuration options.
  213. 2.16. DBMail (dbmail)
  214. -----------------------------------
  215. Driver that adds functionality to change the users DBMail password.
  216. It only works with dbmail-users on the same host where Roundcube runs
  217. and requires shell access and gcc in order to compile the binary
  218. (see instructions in chgdbmailusers.c file).
  219. See config.inc.php.dist file for configuration description.
  220. Note: DBMail users can also use sql driver.
  221. 2.17. Expect (expect)
  222. -----------------------------------
  223. Driver to change user password via the 'expect' command.
  224. See config.inc.php.dist file for configuration description.
  225. 2.18. Samba (smb)
  226. -----------------------------------
  227. Driver to change Samba user password via the 'smbpasswd' command.
  228. See config.inc.php.dist file for configuration description.
  229. 2.19. Vpopmail daemon (vpopmaild)
  230. -----------------------------------
  231. Driver for the daemon of vpopmail. Vpopmail is used with qmail to
  232. enable virtual users that are saved in a database and not in /etc/passwd.
  233. Set $config['password_vpopmaild_host'] to the host where vpopmaild runs.
  234. Set $config['password_vpopmaild_port'] to the port of vpopmaild.
  235. Set $config['password_vpopmaild_timeout'] to the timeout used for the TCP
  236. connection to vpopmaild (You may want to set it higher on busy servers).
  237. 2.20. Plesk (Plesk RPC-API)
  238. ---------------------------
  239. Driver for changing Passwords via Plesk RPC-API. This Driver also works with
  240. Parallels Plesk Automation (PPA).
  241. You need to allow the IP of the Roundcube-Server for RPC-Calls in the Panel.
  242. Set $config['password_plesk_host'] to the Hostname / IP where Plesk runs
  243. Set your Admin or RPC User: $config['password_plesk_user']
  244. Set the Password of the User: $config['password_plesk_pass']
  245. Set $config['password_plesk_rpc_port'] for the RPC-Port. Usually its 8443
  246. Set the RPC-Path in $config['password_plesk_rpc_path']. Normally this is: enterprise/control/agent.php.
  247. 2.21. Kpasswd
  248. -----------------------------------
  249. Driver to change the password in Kerberos environments via the 'kpasswd' command.
  250. See config.inc.php.dist file for configuration description.
  251. 3. Driver API
  252. -------------
  253. Driver file (<driver_name>.php) must define rcube_<driver_name>_password class
  254. with public save() method that has two arguments. First - current password, second - new password.
  255. This method should return PASSWORD_SUCCESS on success or any of PASSWORD_CONNECT_ERROR,
  256. PASSWORD_CRYPT_ERROR, PASSWORD_ERROR when driver was unable to change password.
  257. Extended result (as a hash-array with 'message' and 'code' items) can be returned
  258. too. See existing drivers in drivers/ directory for examples.
  259. 4. Sudo setup
  260. -------------
  261. Some drivers that execute system commands (like chpasswd) require use of sudo command.
  262. Here's a sample for CentOS 7:
  263. # cat <<END >/etc/sudoers.d/99-roundcubemail
  264. apache ALL=NOPASSWD:/usr/sbin/chpasswd
  265. Defaults:apache !requiretty
  266. <<END
  267. Note: on different systems the username (here 'apache') may be different, e.g. www.
  268. Note: on some systems the disabling tty line may not be needed.