static CSA_return_code init_cal_attrs(_DtCmsCalendar *cal) { int i; /* initialize the calendar with predefined attribute names */ if ((cal->attrs = (cms_attribute *)calloc(1, sizeof(cms_attribute)*(_DtCm_cal_name_tbl->size + 1))) == NULL) { return (CSA_E_INSUFFICIENT_MEMORY); } for (i = 1; i <= _DtCm_cal_name_tbl->size; i++) { if ((cal->attrs[i].name.name = strdup(_DtCm_cal_name_tbl->names[i])) == NULL) { _DtCm_free_cms_attributes(i, cal->attrs); free(cal->attrs); return (CSA_E_INSUFFICIENT_MEMORY); } cal->attrs[i].name.num = i; } cal->num_attrs = _DtCm_cal_name_tbl->size; return (CSA_SUCCESS); }
extern CSA_return_code _DtCmsGetCalAttrsByName( _DtCmsCalendar *cal, uint num_names, cms_attr_name *names, uint *num_attrs_r, cms_attribute **attrs_r) { CSA_return_code stat = CSA_SUCCESS; int i, j, index; cms_attribute *attrs; if ((attrs = calloc(1, sizeof(cms_attribute)*num_names)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY); /* get attributes */ for (i = 0, j = 0; i < num_names; i++) { if (names[i].name == NULL) continue; if (names[i].num <= 0) index = names[i].num = _DtCm_get_index_from_table( cal->cal_tbl, names[i].name); if (index > 0) { if (index <= _DtCM_DEFINED_CAL_ATTR_SIZE) { if (_CSA_cal_attr_info[index].fst_vers <= cal->fversion || index == CSA_CAL_ATTR_CALENDAR_SIZE_I) { stat = cal->getattrfuncs[index](cal, index, &attrs[j]); } } else if (cal->attrs && cal->attrs[index].value) { stat = _DtCm_copy_cms_attribute(&attrs[j], &cal->attrs[index], B_TRUE); } if (stat != CSA_SUCCESS) { _DtCm_free_cms_attributes(j, attrs); free(attrs); return (stat); } else if (attrs[j].name.name) j++; } } if (j > 0) { *num_attrs_r = j; *attrs_r = attrs; } else { *num_attrs_r = 0; *attrs_r = NULL; free(attrs); } return (CSA_SUCCESS); }
extern void _DtCmsFreeCalendar(_DtCmsCalendar *cal) { _DtCmsCalendar *clist, *prev; if (cal == NULL) return; for (clist = calendar_list, prev = NULL; clist != NULL; clist = clist->next) { if (clist == cal) { if (prev == NULL) calendar_list = clist->next; else prev->next = clist->next; break; } else prev = clist; } if (cal->calendar) free(cal->calendar); if (cal->owner) free(cal->owner); if (cal->fversion == 1) { _DtCm_free_access_list4(GET_R_ACCESS ((cal))); _DtCm_free_access_list4(GET_W_ACCESS ((cal))); _DtCm_free_access_list4(GET_D_ACCESS ((cal))); _DtCm_free_access_list4(GET_X_ACCESS ((cal))); _DtCm_free_access_list4(cal->alist); } else { if (cal->cal_tbl != _DtCm_cal_name_tbl) _DtCm_free_name_table(cal->cal_tbl); if (cal->entry_tbl != _DtCm_entry_name_tbl) _DtCm_free_name_table(cal->entry_tbl); if (cal->types) free(cal->types); if (cal->num_attrs) { _DtCm_free_cms_attributes(cal->num_attrs + 1, cal->attrs); free(cal->attrs); } } if (cal->tree) rb_destroy(cal->tree, NULL); if (cal->list) hc_destroy(cal->list, NULL); }
extern cms_open_res * cms_open_calendar_5_svc(cms_open_args *args, struct svc_req *svcrq) { static cms_open_res res; static char sversion[80]; _DtCmsCalendar *cal; char *user; if (debug) fprintf(stderr, "cms_open_calendar_5_svc called\n"); if (res.num_attrs > 0) { _DtCm_free_cms_attributes(res.num_attrs, res.attrs); free(res.attrs); res.num_attrs = 0; } /* check parameter */ if (args->cal == NULL) { res.stat = CSA_E_INVALID_PARAMETER; return (&res); } if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user, &res.user_access, &cal)) == CSA_SUCCESS) { res.svr_vers = TABLEVERS; if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) { res.file_vers = cal->fversion; } else { /* old format data */ res.file_vers = _DtCM_FIRST_EXTENSIBLE_DATA_VERSION - 1; } /* return attribute names */ res.stat = _DtCmsGetAllCalAttrs(cal, &res.num_attrs, &res.attrs, B_FALSE); } if (res.stat == CSA_SUCCESS) { /* do callbacks */ cal->rlist = _DtCmsDoOpenCalCallback(cal->rlist, cal->calendar, user, args->pid); } return (&res); }
extern cms_get_cal_attr_res * cms_get_calendar_attr_5_svc(cms_get_cal_attr_args *args, struct svc_req *svcrq) { static cms_get_cal_attr_res res; _DtCmsCalendar *cal; char *user; uint access; if (debug) fprintf(stderr, "cms_get_calendar_attr_5_svc called\n"); if (res.num_attrs > 0) { _DtCm_free_cms_attributes(res.num_attrs, res.attrs); free(res.attrs); res.num_attrs = 0; } if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user, &access, &cal)) != CSA_SUCCESS) return (&res); if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION && !_DTCMS_HAS_VIEW_CALENDAR_ATTR_ACCESS(access)) { res.stat = CSA_E_NO_AUTHORITY; return (&res); } if (args->num_names > 0) res.stat = _DtCmsGetCalAttrsByName(cal, args->num_names, args->names, &res.num_attrs, &res.attrs); else res.stat = _DtCmsGetAllCalAttrs(cal, &res.num_attrs, &res.attrs, B_TRUE); return (&res); }
extern CSA_return_code _DtCmsUpdateCalAttributesAndLog( _DtCmsCalendar *cal, uint numsrc, cms_attribute *srcattrs, uint access) { CSA_return_code stat = CSA_SUCCESS; uint i, oldnum = 0; cms_attribute *oldattrs = NULL; char *log; /* we didn't use _DtCmUpdateAttributes because we need * to check access rights here */ /* copy original attributes for rollback if update fails */ if (cal->attrs && (stat = _DtCm_copy_cms_attributes(cal->num_attrs, cal->attrs, &oldnum, &oldattrs)) != CSA_SUCCESS) return (stat); for (i = 0; i < numsrc && stat == CSA_SUCCESS; i++) { if (srcattrs[i].name.name == NULL) continue; if (srcattrs[i].name.num <= 0) srcattrs[i].name.num = _DtCm_get_index_from_table( cal->cal_tbl, srcattrs[i].name.name); if (srcattrs[i].name.num < 0) { if (!_DTCMS_HAS_INSERT_CALENDAR_ATTR_ACCESS(access)) stat = CSA_E_NO_AUTHORITY; else { if ((stat = _DtCmExtendNameTable( srcattrs[i].name.name, 0, 0, _DtCm_cal_name_tbl, _DtCM_DEFINED_CAL_ATTR_SIZE, _CSA_calendar_attribute_names, &cal->cal_tbl, NULL)) == CSA_SUCCESS) { srcattrs[i].name.num = cal->cal_tbl->size; stat = _DtCmGrowAttrArray( &cal->num_attrs, &cal->attrs, &srcattrs[i]); } } } else if (!_DTCMS_HAS_CHANGE_CALENDAR_ATTR_ACCESS(access)) { stat = CSA_E_NO_AUTHORITY; } else { cms_attribute_value val; if (srcattrs[i].name.num == CSA_CAL_ATTR_ACCESS_LIST_I && srcattrs[i].value == NULL) { val.type = CSA_VALUE_ACCESS_LIST; val.item.access_list_value = NULL; srcattrs[i].value = &val; } stat = _DtCmUpdateAttribute(&srcattrs[i], &cal->attrs[srcattrs[i].name.num]); } } if (stat == CSA_SUCCESS) { log = _DtCmsGetLogFN(cal->calendar); /* dump file */ stat = _DtCmsAppendCalAttrsByFN(log, cal->num_attrs, cal->attrs); free(log); } if (stat == CSA_SUCCESS) { cal->modified = B_TRUE; _DtCm_free_cms_attributes(oldnum + 1, oldattrs); free(oldattrs); } else { _DtCm_free_cms_attributes(cal->num_attrs+1, cal->attrs); free(cal->attrs); cal->num_attrs = oldnum; cal->attrs = oldattrs; } return (stat); }
extern CSA_return_code _DtCmsGetAllCalAttrs( _DtCmsCalendar *cal, uint *num_attrs_r, cms_attribute **attrs_r, boolean_t returnall) { CSA_return_code stat = CSA_SUCCESS; cms_attribute *attrs, *cattrs = cal->attrs; int i, j, num_cal_attrs = cal->num_attrs; num_cal_attrs = cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ? cal->num_attrs : _DtCM_OLD_CAL_ATTR_SIZE; if ((attrs = calloc(1, sizeof(cms_attribute)*num_cal_attrs)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY); if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) { /* first element is not used */ for (i = 1, j = 0; i <= num_cal_attrs; i++) { if (i <= _DtCM_DEFINED_CAL_ATTR_SIZE) { if ((stat = cal->getattrfuncs[i](cal, i, &attrs[j])) != CSA_SUCCESS) { _DtCm_free_cms_attributes(j, attrs); free(attrs); return (stat); } else if (attrs[j].name.name) j++; } else if (cattrs[i].value) { if (returnall) { stat = _DtCm_copy_cms_attribute( &attrs[j], &cal->attrs[i], B_TRUE); } else { /* just return the attribute name */ if (attrs[j].name.name = strdup( cattrs[i].name.name)) { attrs[j].name.num = cattrs[i].name.num; } else stat =CSA_E_INSUFFICIENT_MEMORY; } if (stat == CSA_SUCCESS) j++; else { _DtCm_free_cms_attributes(j, attrs); free(attrs); return (stat); } } } } else { for (i = 1, j = 0; i <= _DtCM_DEFINED_CAL_ATTR_SIZE; i++) { if (_CSA_cal_attr_info[i].fst_vers <= cal->fversion || i == CSA_CAL_ATTR_CALENDAR_SIZE_I) { if ((stat = cal->getattrfuncs[i](cal, i, &attrs[j])) != CSA_SUCCESS) { _DtCm_free_cms_attributes(j, attrs); free(attrs); return (stat); } else if (attrs[j].name.name) j++; } } } if (j > 0) { *num_attrs_r = j; *attrs_r = attrs; } else { *num_attrs_r = 0; *attrs_r = NULL; free(attrs); } return (CSA_SUCCESS); }