/* * FUNCTION : makeNISObject() * * DESCRIPTION: Sets up a nis Object in the DIT. * * GIVEN : * Case 1: Both 'domain' and 'dn' are non-NULL * Create nisDomainObject with the given information * Case 2: Only 'domain' is non-NULL * Obtain the 'dn' from the nisLDAPdomainContext list * Create nisDomainObject with the above information * Case 3: Only 'dn' is non-NULL * Create an object with the 'dn' * Here we guess the objectclass attribute, based on * oc_lookup table * Case 4: Both 'domain' and 'dn' are NULL * Error * * RETURNS : SUCCESS = It worked * FAILURE = There was a problem. */ suc_code makeNISObject(char *domain, char *dn) { __nis_rule_value_t *rv; __nis_ldap_search_t *ls; int i, rc, nr, add_rc; char *val; char *myself = "makeNISObject"; if (!dn && !domain) return (FAILURE); /* * If only 'domain' name is provided, then * try to find dn from the nisLDAPdomainContext * list generated by the parser */ if (!dn) { for (i = 0; i < ypDomains.numDomains; i++) { if (ypDomains.domainLabels[i] == 0) continue; if (strcasecmp(domain, ypDomains.domainLabels[i]) == 0) { dn = ypDomains.domains[i]; break; } } if (!dn) return (FAILURE); } /* * If only 'dn' is given, then it means that the * caller simply wants to a create an entry for * that 'dn'. * * If 'domain' is given, then check if the 'dn' * has already been set up as a nis domain object. * If not, see if we can make it become one. */ if (domain) { /* * Check to see if the nis domain object has * already been set up */ ls = buildLdapSearch(dn, LDAP_SCOPE_BASE, 0, 0, "objectclass=*", 0, 0, 0); if (ls == 0) { logmsg(MSG_NOTIMECHECK, LOG_ERR, "%s: Unable to create ldapSearch " "request for dn: %s", myself, dn); return (FAILURE); } nr = -1; rv = ldapSearch(ls, &nr, 0, &rc); freeLdapSearch(ls); if (rc == LDAP_SUCCESS) { val = findVal("nisDomain", rv, mit_ldap); if (val != NULL) { /* * Yes, nis domain object found. Check * to see if the domain names match. * If so, we are done. If not, log * a warning message, and return SUCCESS. */ if (strcasecmp(val, domain) == 0) { freeRuleValue(rv, nr); return (SUCCESS); } else { logmsg(MSG_NOTIMECHECK, LOG_WARNING, "%s: Entry (dn: %s) already " "contains a nis domain name " "(%s). The domain name (%s) " "is not added.", myself, dn, val, domain); freeRuleValue(rv, nr); return (SUCCESS); } } else { freeRuleValue(rv, nr); /* * Entry for the 'dn' exists, but it * is not a nis domain object yet. * Add the nisDoamin attribute and * the nisDomainObject objectclass to * the entry. */ if ((rv = initRuleValue(1, 0)) == 0) return (FAILURE); if (addSAttr2RuleValue("nisDomain", domain, rv) == -1) { freeRuleValue(rv, 1); return (FAILURE); } rc = ldapModify(dn, rv, "objectclass=nisDomainObject", 0); freeRuleValue(rv, 1); if (rc == LDAP_SUCCESS) { logmsg(MSG_NOTIMECHECK, LOG_INFO, "%s: entry (dn: %s) " "modified to be an " "nis domain object", myself, dn); return (SUCCESS); } else { logmsg(MSG_NOTIMECHECK, LOG_ERR, "%s: unable to modify " "entry (dn: %s) to be " "a nis domain object: " "ldapModify error %d (%s)", myself, dn, rc, ldap_err2string(rc)); return (FAILURE); } } } else { /* search for 'dn' failed */ freeRuleValue(rv, nr); /* * It is OK if no such object, otherwise * log an error. */ if (rc != LDAP_NO_SUCH_OBJECT) { logmsg(MSG_NOTIMECHECK, LOG_ERR, "%s: unable to retrieve " "entry (dn: %s): " "ldapSearch error %d (%s)", myself, dn, rc, ldap_err2string(rc)); return (FAILURE); } } /* * If the 'dn' is actually the naming context of * the DIT, we should be able to make it a nis domain * object without worrying about missing parent * entries. If unable to add the entry for the 'dn' * due to missing parent entries, fall through * to create them and then add the nis domain object. */ if (addNISObject(domain, dn, &add_rc) == SUCCESS) return (SUCCESS); else if (add_rc != LDAP_NO_SUCH_OBJECT) return (FAILURE); } /* Create parent */ if (addParent(dn, NULL) == FAILURE) return (FAILURE); if (addNISObject(domain, dn, NULL) == FAILURE) return (FAILURE); return (SUCCESS); }
void PatchRecord::addParent( const std::string& parentTypeName, int versionNo ) { uint typeId = ReflectionType::generateId( parentTypeName ); addParent( typeId, versionNo ); }