LDAP Account Manager\n"; echo "\n"; echo "\n"; StatusMessage("ERROR", _('You left the attribute value blank. Please go back and try again.'), ''); echo ""; exit; } // special case for binary attributes (like jpegPhoto and userCertificate): // we must go read the data from the file and override $val with the binary data // Secondly, we must check if the ";binary" option has to be appended to the name // of the attribute. if( $is_binary_val ) { if (( 0 == $_FILES['val']['size'] ) || (! is_uploaded_file( $_FILES['val']['tmp_name'] ))) { echo $_SESSION['header']; echo "LDAP Account Manager\n"; echo "\n"; echo "\n"; StatusMessage("ERROR", _('File upload failed!'), ''); echo ""; exit; } $file = $_FILES['val']['tmp_name']; $f = fopen( $file, 'r' ); $binary_data = fread( $f, filesize( $file ) ); fclose( $f ); $val = $binary_data; if( is_binary_option_required( $attr ) ) $attr .=";binary"; } // Automagically hash new userPassword attributes according to the // chosen in config.php. if( 0 == strcasecmp( $attr, 'userpassword' ) ) { $val = pwd_hash($val); } elseif(0 == strcasecmp( $attr , 'sambalmpassword') ) { $val = lmPassword($val); } elseif (0 == strcasecmp( $attr , 'sambantpassword' )) { $val = ntPassword($val); } $ds = $_SESSION['ldap']->server; $new_entry = array( $attr => $val ); $result = @ldap_mod_add( $ds, $dn, $new_entry ); if( $result ) header( "Location: edit.php?dn=$encoded_dn&modified_attrs[]=$encoded_attr" ); else { echo $_SESSION['header']; echo "LDAP Account Manager\n"; echo "\n"; echo "\n"; StatusMessage("ERROR", _('Failed to add the attribute.'), ldap_error($ds)); echo ""; exit; } // check if we need to append the ;binary option to the name // of some binary attribute function is_binary_option_required( $attr ){ // list of the binary attributes which need the ";binary" option $binary_attributes_with_options = array( // Superior: Ldapv3 Syntaxes (1.3.6.1.4.1.1466.115.121.1) '1.3.6.1.4.1.1466.115.121.1.8' => "userCertificate", '1.3.6.1.4.1.1466.115.121.1.8' => "caCertificate", '1.3.6.1.4.1.1466.115.121.1.10' => "crossCertificatePair", '1.3.6.1.4.1.1466.115.121.1.9' => "certificateRevocationList", '1.3.6.1.4.1.1466.115.121.1.9' => "authorityRevocationList", // Superior: Netscape Ldap attributes types (2.16.840.1.113730.3.1) '2.16.840.1.113730.3.1.40' => "userSMIMECertificate" ); // quick check by attr name (short circuits the schema check if possible) //foreach( $binary_attributes_with_options as $oid => $name ) //if( 0 == strcasecmp( $attr, $name ) ) //return true; $schema_attr = get_schema_attribute( $attr ); if( ! $schema_attr ) return false; $syntax = $schema_attr->getSyntaxOID(); if( isset( $binary_attributes_with_options[ $syntax ] ) ) return true; return false; } ?>