I get this error always
Server is unwilling to perform
and my code is the next:
echo "Checking ...";
$username = $_POST["username"];
$passwd = $_POST["passwd"];
$host = 'myhost.co.uk';
$port = 389;
$dn = 'uid='.$username.',cn=nssproxy,ou=users,dc=co,dc=uk';
// conexion a ldap
$conn = ldap_connect( "ldap://".$host.":389") ;
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($conn, LDAP_OPT_REFERRALS, 0);
// match de usuario y password
$bind = ldap_bind( $conn, $dn, $password );
if ($bind){
echo "OK";
}
else {
echo "NO OK";
}
echo ldap_error($conn);
Why I have this error? I'm always testing with any user, this script return same error.
Thanks in advance.
So I searched Google for Server is unwilling to performand the first result says:
C.1.4. ldap_*: server is unwilling to perform
slapd will return an unwilling to perform error if the backend holding the target entry does not support the given operation.
The password backend is only willing to perform searches. It will return an unwilling to perform error for all other operations.
The shell backend is configurable and may support a limited subset of operations. Check for other errors indicating a shortage of resources required by the directory server. i.e. you may have a full disk etc
ldap_mod_replace() [function.ldap-mod-replace]: Modify: Server is unwilling to perform has some requirements as well
One possibility is what I did... I misconfigured /etc/ldap.conf, and added binddn where I meant to put rootbinddn, and that caused this message.
I had this error. Ldap on virtual machine on windows server 2019 on 10.0.0.14 IP.
I managed to connect and bind successfuly, but this error occurs when ldap_add().
My solution was to check $record array parameters that i want to save.
I this set of properties work for me:
$r = ldap_add($this->LdapConn, 'CN=user 3,'.$this->Branch, array(
'cn' => 'user 3',
'name' => 'test',
'sn' => 'asd',
'instanceType' => '4',
'objectCategory'=> 'CN=Person,CN=Schema,CN=Configuration,DC=test-domain,DC=com',
'mail' => 'mai222222l#mail2.com',
'objectclass'=>array(
'top',
'user',
'person',
'organizationalPerson'
)
));
Note that ldap_add() second parameter is path (dn) to entry and this can cause problem.
Path(dn) must be current branch + entry
For me current branch was 'CN=Users,DC=test-domain,DC=com' and full path mean dn = "CN=user 3,CN=Users,DC=test-domain,DC=com"
Note that this first part cn=user 3 must be the same as in bellow array.
My distinguish names (dc) was incorrect.
Related
I use MySQL 5.7.17 on AWS RDS.
I encountered a strange behavior and I am looking for an explanation.
In short: I try to connect over SSL, with settings that I think should cause the connection to FAIL, but it succeeds!
The following PHP code succeeds to connect to the RDS instance over SSL:
<?
$HOST = "something.amazonaws.com";
$USER = "myuser";
$PASS = "mypass";
$connectionString = "mysql:host={$HOST};charset=utf8";
$options = [ ];
$options[PDO::MYSQL_ATTR_SSL_CA] = "LITERALLY THIS TEXT. DEFINITELY NOT A CERTIFICATE!";
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
$conn = new \PDO($connectionString, $USER, $PASS, $options);
$sql = "SHOW STATUS LIKE 'Ssl_cipher'";
$stmt = $conn->prepare($sql);
$stmt->execute([ ]);
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
$rows = $stmt->fetchAll();
print_r($rows);
The result I get:
Array
(
[0] => Array
(
[Variable_name] => Ssl_cipher
[Value] => AES256-SHA
)
)
Also, I found three pem files in /etc/ca-certificates/rds-mysql. I thought that PHP might be going there for some reason, so I deleted them, but the SSL connection still succeeds.
Note: if I delete the line that says $options[PDO::MYSQL_ATTR_SSL_CA] = "LITERALLY THIS TEXT. DEFINITELY NOT A CERTIFICATE!"; - it does NOT connect over SSL. So it appears that this option does have some impact.
My question is: how come it succeeds?
I've successfully connected to a remote IBM i DB2 database (AS400) from my local Windows PC via PHP. I'm using the IBM Data Server Client in conjunction with the db2_* functions in PHP. The problem I'm having is that despite my library list being set properly, it is not being used for unqualified table names. Instead it uses the current user name as the library. However, when I qualify the table names everything works like a charm.
I've confirmed that my library list is actually changing when I create the connection by querying QSYS2.LIBRARY_LIST_INFO.
$database = '<database name>';
$user = '<user name>';
$password = '<password';
$port = <port>;
$options['i5_naming'] = DB2_I5_NAMING_ON;
$options['autocommit'] = DB2_AUTOCOMMIT_OFF;
$options['i5_libl'] = 'MYLIB YOURLIB ANYLIB';
$conn = db2_connect($database, $user, $password, $options);
if ($conn) {
echo "Connection succeeded."; //It succeeds
}
else {
echo db2_conn_error()." | ".db2_conn_errormsg()."<br />";
echo "Connection failed.";
}
$sql = "SELECT * FROM QSYS2.LIBRARY_LIST_INFO";
//Works and proves my library list reflects
//what I passed in when creating the connection.
//$sql = "SELECT * FROM LIBRARY_LIST_INFO";
//Generates: "42S02 : [IBM][CLI Driver][AS] SQL0204N "<user name>.LIBRARY_LIST_INFO" is an undefined name. SQLSTATE=42704 SQLCODE=-204"
//where <user name> is the username used to connect to the DB.
//It should be using the library list specified when creating the connection though.
//This holds true for any table from any library including those specified
//when creating the connection (which includes QSYS2).
$stmt = db2_prepare($conn, $sql);
$result = db2_execute($stmt);
if($result){
while($row = db2_fetch_assoc($stmt)){
echo "<pre>";
var_dump($row); //In addition to entries for QSYS, QSYS2, QUSRSYS and QHLPSYS I get entries for MYLIB, YOURLIB and ANYLIB.
echo "</pre>";
}
}else{
echo "failed<br />";
echo db2_stmt_error()." : ".db2_stmt_errormsg()."<br />";
}
Has anyone ever run into this while enabling i5_naming when connecting to a remote DB2 server? I'm not really sure why it wouldn't be using my library list as the PHP manual states "Unqualified files are resolved using the library list for the job." when enabled. http://php.net/manual/en/function.db2-connect.php
I finally solved this after opening a PMR with IBM. All I had to do was apply the latest Fix Pack for DB2 Connect Personal Edition.
Suggested Fix Packs for DB2 Connect:
http://www-01.ibm.com/support/docview.wss?rs=71&uid=swg21321001
Basically the DB2 Connect version I had was released prior to 2013. It was in 2013 IBM added two tier support by adding the i5_naming option. So my DB2 Connect setup was effectively ignoring the option I was passing. So that explains why the other options still went through. On the DB side, since it didn't receive a value for i5_naming - it remained as the default.
I have an LDAP annuary working on Active Directory (Win Server 2008). I try to connect to this AD with PHP (and LDAP lib) and retrieve all distributions lists from a specific OU.
The connection and authentication is working, but when I want to retrieve the lists from OU, I dont have any results (rights are OK and in local it's working too, without PHP)
Here is my code :
$ldap_host = "ip.add.re.ss";
$ldap_dn = "OU=Listes,DC=domain,DC=tld"; // all there infos are ok
$base_dn = "DC=domain,DC=tld";
$ldap = ldap_connect($ldap_host);
$user = 'username'; $password = '';
$filter="(sAMAccountName=recette)";
$filter="(&(objectClass=user)(objectCategory=person)(OU=Lists))";
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS,0);
ldap_bind($ldap, $user, $password);
$results = ldap_search($ldap,$base_dn, $filter);
$member_list = ldap_get_entries($ldap, $results);
If I delete the OU=Lists, it's working, I have results, but the one I want. Then, when I add the OU=Lists, I don't have any results.
Can you help me please? Thanks.
You said you are trying to "Retrieve Distributions lists" and yet your LDAP filter is to retrieve users which have the attribute ou=Lists:
(&(objectClass=user)(objectCategory=person)(OU=Lists))
Try an LDAP filter as:
(&(objectCategory=Group)(proxyAddresses=*))
more like these are at:
http://ldapwiki.com/wiki/Active%20Directory%20Group%20Related%20Searches
I have codeigniter configured to use multiple databases. For some customers, we need to query an additional database so this is a matter of:
if( isConfigured(database) )
foo();
However, the attempts I have made have either given the same result whether or not the db is configured in databases.php, or throws an error.
I have attempted the following:
if( $this->load->database('optional') == FALSE )
Which raises the error You have specified an invalid database connection group
try( $this->load->database('optional') )
{
foo();
}
catch(Exception $e)
{
doNothing();
}
Which raises the same error
The documentation states that $this->load->database('optional', TRUE) returns the connection ID however I cannot check this as the code errors out before returning a value.
I was expecting to be able to check whether or not a property had been set, e.g. $this->config->item('db')['optional'] but this would be largely guesswork to determine how to access the correct property
I have also looked into the dbutil class but this only applies to databases which have already established a connection.
$db['db1']['hostname'] = 'localhost';
$db['db1']['username'] = 'root';
$db['db1']['password'] = '';
$db['db1']['database'] = 'mydatabase';
$db['db1']['dbdriver'] = 'mysql';
$db['db1']['dbprefix'] = '';
$this->load->database('db1',TRUE);
I'm trying to write php script that would:
connect to mysql
create database
create user and password
add user to database
import prepared sql file to database
The thing is that it'll be on shared host (and I'm trying to make it universal and work with different hosts). I guess database and db user will be prefixed with my account name (what I use for ftp, to login to control panel, etc) on shared hosts? Something like mylogin_dbname and mylogin_dbuser. It's visible for example in cpanel - when I add database I enter its name and after it's created cpanel shows it as mylogin_somedb. How do I make my script work with this on multiple different shared hosts - add my prefix automatically depending on my main login?
Now working with such code (don't have a clue if it works, that's just what came to my mind):
<?php
mysql_connect("host", "user", "password"); // Connection to MySQL
$query = "CREATE DATABASE somedb;
USE somedb;
SOURCE path/to/sqlfile.sql;
CREATE USER someuser IDENTIFIED BY PASSWORD 'somepass';
GRANT SELECT,INSERT,UPDATE,DELETE ON somedb.* TO 'someuser'#'host';";
$arr= explode( ';', $query );
foreach( $arr as $command )
{
mysql_query( $command );
}
mysql_close(); // Disconnection from MySQL
?>
KISS principle: just use phpMyAdmin? It's almost certainly installed. If it's not, install it.
Its import capability is magnificent. If your database is by any chance too big, gzip it. If it's still to big, try splitting it up in a few pieces. I doubt you need to transfer it as a single big transaction. Do you?
After the explanation in first comment, well, here goes. This is my very simplistic script which does what you want. Except it doesn't take a look at the separators: one query == one line.
<link rel="stylesheet" href="style/contents.css"/>
<?
function timesanitize($v) {
if ($v > 0)
return round($v, 4);
else
return 0;
}
$startmt = microtime();
include_once 'include/db.php';
$f = fopen("db.sql","r");
echo dbGetEngine() . "<br>";
echo "<ul>";
do {
$l = rtrim(fgets($f));
if (strlen($l) == 0)
continue;
if (substr($l, 0, 1) == '#')
continue;
$l = str_replace(
array("\\n"),
array("\n"),
$l);
if (dbGetEngine() == "pgsql")
$l = str_replace(
array("IF NOT EXISTS", "LONGBLOB"),
array("", "TEXT"),
$l);
try {
echo "<li>".nl2br(htmlspecialchars($l));
$mt = microtime();
$db->query($l);
echo "<ul><li>ok - " . timesanitize(microtime() - $mt) . "</ul>";
} catch (PDOException $e) {
echo "<ul><li>".$e->getMessage() . "</ul>";
}
} while (!feof($f));
fclose($f);
echo 'total: ' . timesanitize(microtime() - $startmt);
?>
It also outputs a small statistic of how long each query took. It's based around PDO; I believe PDO was introduced in PHP5.1 or PHP5.2. I think it should be trivial to modify it to work directly with mysql_*() functions, if for some reason you prefer that.
And once again: yes, I know it sucks. But as long as it Works For Me (tm), and possibly You... :-)
To complete the code, here are include/db.php and a sample include/config.php:
include/db.php:
<?
include_once 'include/config.php';
try {
$attribs =
array(
PDO::ATTR_PERSISTENT => $config['db']['persistent'],
PDO::ATTR_ERRMODE => $config['db']['errormode']
);
$db = new PDO(
$config['db']['uri'],
$config['db']['user'],
$config['db']['pass'],
$attribs
);
$db->query("SET NAMES 'utf8'");
$db->query("SET CHARACTER SET 'utf8'");
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
function dbGetEngine() {
global $config;
return substr($config['db']['uri'], 0, strpos($config['db']['uri'], ':'));
}
?>
include/config.php:
<?
//$config['db']['uri'] = 'sqlite:' . realpath('.') . '/site.db'; // PDO's database access URI
$config['db']['uri'] = 'mysql:host=localhost;dbname=sitedb'; // server should be : 195.78.32.7
//$config['db']['uri'] = 'pgsql:host=localhost;dbname=sitedb';
$config['db']['user'] = 'user_goes_here'; // database username
$config['db']['pass'] = 'pass_goes_here'; // database password
$config['db']['persistent'] = false; // should the connection be persistent
$config['db']['errormode'] = PDO::ERRMODE_EXCEPTION; // PDO's error mode
?>
Included are sample connection strings for SQLite, MySQL and PostgreSQL.
The fact that this is on a shared host shouldn't make that much of a difference in my opinion. Whatever your environment, you'll have to use your username and either the database name gets prefixed with that or it doesn't according to hosting setup. That said it is probably smart to adopt a naming convention with your username as a prefix or some other prefix naming convention.
As to what you're trying to do I have some suggestions:
You should run each statement separately (as you do) but add error checking between each step so you don't attempt to source the file if the database wasn't created for instance.
Maybe create separate functions for each kind of operation and send in parameters for the values. This would clean up the code in the longer run.
If you have a situation where something is automatically prefixed to the name you provide and you have to detect the final name, you can probably do a "show databases;" query and search for the name you gave in the results. Then use the complete name for the resulting queries.
Use mysql_error()
http://us3.php.net/manual/en/function.mysql-error.php
So you can see what went wrong.
eg:
if (mysql_query( $command ) === false) {
echo mysql_error();
die;
}
The same for mysql_connect()
if (($link = mysql_connect("host", "user", "password")) === false) {
echo mysql_error();
die;
}
You have to make sure the user you are using has privileges to create databases.
For CPanel I believe you have to use your account username and pass. Then like you said prefix your db name with your username, or it will fail to create.
Regarding import, if upload limit is an issue, there are at least one alternative to phpMyAdmin that allows you to select a file on the webserver instead of uploading it. For example adminer (adminer.org) allows that. In adminer, click "SQL command" and then click "from server"