diff options
| author | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-09-04 19:26:41 -0400 |
|---|---|---|
| committer | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-09-04 19:26:41 -0400 |
| commit | 83f35dcf4b07be4fd20179b05ee55b3874dc2c16 (patch) | |
| tree | c0eeda182a243e2a0b8bdb63638a57e26c75185a /src | |
| parent | 5bd8318b7fbf98d409e5c2fa9255b96d185d670f (diff) | |
| download | slapi-nis-83f35dcf4b07be4fd20179b05ee55b3874dc2c16.tar.gz slapi-nis-83f35dcf4b07be4fd20179b05ee55b3874dc2c16.tar.xz slapi-nis-83f35dcf4b07be4fd20179b05ee55b3874dc2c16.zip | |
- add operational attributes to synthetic group and set entries, too
- add the "numsubordinates" and "hassubordinates" operational
attributes, too
Diffstat (limited to 'src')
| -rw-r--r-- | src/back-sch.c | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/src/back-sch.c b/src/back-sch.c index 02bbdae..719f4eb 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -209,6 +209,40 @@ backend_entry_free_entry_data(void *p) free(data); } +/* Add operational attributes to a synthetic entry. */ +static void +backend_set_operational_attributes(Slapi_Entry *e, + struct plugin_state *state, + time_t timestamp, + int n_subordinates) +{ + struct tm timestamp_tm; + char timestamp_str[4 + 2 + 2 + 2 + 2 + 2 + 2]; /* YYYYMMDDHHMMSSZ\0 */ + /* Set operational attributes. Do it first so that if users of the + * plugin want to override the values using the configuration, they + * can. */ + if (gmtime_r(×tamp, ×tamp_tm) == ×tamp_tm) { + sprintf(timestamp_str, "%04d%02d%02d%02d%02d%02dZ", + timestamp_tm.tm_year + 1900, + timestamp_tm.tm_mon + 1, + timestamp_tm.tm_mday, + timestamp_tm.tm_hour, + timestamp_tm.tm_min, + timestamp_tm.tm_sec); + slapi_entry_add_string(e, "createTimestamp", timestamp_str); + slapi_entry_add_string(e, "modifyTimestamp", timestamp_str); + } + slapi_entry_add_string(e, "creatorsName", state->plugin_base); + slapi_entry_add_string(e, "modifiersName", state->plugin_base); + slapi_entry_add_string(e, "entryDN", slapi_entry_get_dn_const(e)); + if (n_subordinates > 0) { + slapi_entry_add_string(e, "hassubordinates", "TRUE"); + snprintf(timestamp_str, sizeof(timestamp_str), "%ld", + (long) n_subordinates); + slapi_entry_add_string(e, "numsubordinates", timestamp_str); + } +} + /* Given a map-entry directory entry, determine a key, a value, and extra data * to be stored in the map cache, and add them to the map cache. */ void @@ -223,9 +257,6 @@ backend_set_entry(Slapi_Entry *e, struct backend_set_data *data) Slapi_DN *e_dn, *sdn; Slapi_RDN *srdn; Slapi_Value *value; - struct tm nowtm; - time_t nowt; - char now[4 + 2 + 2 + 2 + 2 + 2 + 2]; /* YYYYMMDDHHMMSSZ\0 */ plugin_id = data->common.state->plugin_desc->spd_id; e_dn = slapi_entry_get_sdn(e); @@ -252,23 +283,9 @@ backend_set_entry(Slapi_Entry *e, struct backend_set_data *data) slapi_entry_set_sdn(entry, sdn); slapi_sdn_free(&sdn); slapi_ch_free((void **) &dn); - /* Set operational attributes. Do it first so that if users of the - * plugin want to override the values using the configuration, they - * can. */ - nowt = time(NULL); - if (gmtime_r(&nowt, &nowtm) == &nowtm) { - sprintf(now, "%04d%02d%02d%02d%02d%02dZ", - nowtm.tm_year + 1900, nowtm.tm_mon + 1, nowtm.tm_mday, - nowtm.tm_hour, nowtm.tm_min, nowtm.tm_sec); - slapi_entry_add_string(entry, "createTimestamp", now); - slapi_entry_add_string(entry, "modifyTimestamp", now); - } - slapi_entry_add_string(entry, "creatorsName", - data->common.state->plugin_base); - slapi_entry_add_string(entry, "modifiersName", - data->common.state->plugin_base); - slapi_entry_add_string(entry, "entryDN", - slapi_entry_get_dn_const(entry)); + /* Set operational attributes here so that they can be overridden. */ + backend_set_operational_attributes(entry, data->common.state, + time(NULL), 0); /* Iterate through the set of attributes. */ if (data->attribute_format != NULL) { value = slapi_value_new(); @@ -628,7 +645,7 @@ backend_search_set_cb(const char *group, const char *set, bool_t flag, struct backend_search_cbdata *cbdata; struct backend_set_data *set_data; Slapi_Entry *set_entry; - int result; + int result, n_entries; const char *ndn; cbdata = cb_data; @@ -642,6 +659,14 @@ backend_search_set_cb(const char *group, const char *set, bool_t flag, slapi_entry_add_string(set_entry, "objectClass", "extensibleObject"); slapi_entry_set_sdn(set_entry, set_data->container_sdn); + map_rdlock(); + n_entries = map_data_get_map_size(cbdata->state, + set_data->common.group, + set_data->common.set); + map_unlock(); + backend_set_operational_attributes(set_entry, + cbdata->state, time(NULL), + n_entries); if (!slapi_entry_rdn_values_present(set_entry)) { slapi_entry_add_rdn_values(set_entry); } @@ -699,7 +724,7 @@ backend_search_group_cb(const char *group, void *cb_data) struct backend_search_cbdata *cbdata; Slapi_DN *group_dn; Slapi_Entry *group_entry; - int result; + int result, n_maps; cbdata = cb_data; @@ -710,6 +735,11 @@ backend_search_group_cb(const char *group, void *cb_data) slapi_entry_add_string(group_entry, "objectClass", "extensibleObject"); slapi_entry_set_sdn(group_entry, group_dn); + map_rdlock(); + n_maps = map_data_get_domain_size(cbdata->state, group); + map_unlock(); + backend_set_operational_attributes(group_entry, cbdata->state, + time(NULL), n_maps); if (!slapi_entry_rdn_values_present(group_entry)) { slapi_entry_add_rdn_values(group_entry); } |
