--- ldapdata.module	2008-08-21 16:34:35.000000000 -0500
+++ ldapdata.module.new	2008-08-21 16:44:54.000000000 -0500
@@ -420,6 +420,56 @@ function ldapdata_user_categories(&$user
 }
 
 /**
+ * Implements hook_form_alter() 
+ */
+function ldapdata_form_alter($form_id, &$form) {
+  global $user;
+  global $ldapdata_ldap;
+
+  $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');
+
+  switch($form_id) {
+    case 'user_edit':
+      // Check for ldap user
+      if ($user->ldap_authentified) {
+        if ($mapping_type == LDAP_MAP_ATTRIBUTES_READ_ONLY) {
+
+          // Get all profile fields
+          $profile_categories = profile_categories();
+          $profile_fields = array();
+
+          foreach ($profile_categories as $category) {
+            $result = _profile_get_fields($category['name'], $register = FALSE);
+            while ($field = db_fetch_object($result)) {
+            $profile_fields[] = $field;
+            }
+          }
+
+          // Get fields that are being mapped from lDAP
+          $ldap_drupal_reverse_mappings = _ldapdata_reverse_mappings($user->ldap_config);
+          $ldap_drupal_mappings = array_flip($ldap_drupal_reverse_mappings);
+
+          // Compare against mapped fields list
+          $mapped_fields = array();
+
+          foreach ($profile_fields as $field ) {
+            if (in_array($field->fid, $ldap_drupal_mappings)) {
+              $mapped_fields[] = $field;
+            }
+          }
+
+          foreach ($mapped_fields as $field) {
+            if ($form[$field->category][$field->name]) {
+              $form[$field->category][$field->name]['#disabled'] = TRUE;
+            }
+          }
+        }
+        break;
+      }
+  }
+}
+              
+/**
  * Only used for editable LDAP attributes with no Drupal equivalents
  */
 function ldapdata_user_form(&$user, $category) {
@@ -912,4 +962,4 @@ function theme_ldapdata_ldap_attribute($
 }
 
 
-?>
\ No newline at end of file
+?>
