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); }
static CSA_return_code _DtCmsCreateCallog(char *user, cms_create_args *args, _DtCmsCalendar **newcal) { CSA_return_code stat; _DtCmsCalendar *cal; int i, index; char datestr[80]; char *calname; char *log; char *username; cms_attribute_value val; cms_access_entry aentry; int nidx = 0, oidx = 0; char *name, *owner; /* * if calendar name is a user name, make sure that * it's the same as the sender. */ calname = _DtCmGetPrefix(args->cal, '@'); username = _DtCmGetPrefix(user, '@'); if (_DtCmIsUserName(calname) && strcmp(calname, username)) { free(calname); free(username); return (CSA_E_NO_AUTHORITY); } log = _DtCmsGetLogFN(calname); free(calname); free(username); /* create internal calendar data structure */ if ((cal = _DtCmsMakeCalendar(user, args->cal)) == NULL) { free(log); return (CSA_E_INSUFFICIENT_MEMORY); } /* fill in information */ _csa_tick_to_iso8601(time(0), datestr); if ((stat = _DtCm_set_string_attrval(datestr, &cal->attrs[CSA_CAL_ATTR_DATE_CREATED_I].value, CSA_VALUE_DATE_TIME)) != CSA_SUCCESS) { _DtCmsFreeCalendar(cal); free(log); return (stat); } /* initialize access list to be "WORLD", VIEW_PUBLIC */ aentry.user = WORLD; aentry.rights = CSA_VIEW_PUBLIC_ENTRIES; aentry.next = NULL; val.item.access_list_value = &aentry; val.type = CSA_VALUE_ACCESS_LIST; if ((stat = _DtCmUpdateAccessListAttrVal(&val, &cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value)) != CSA_SUCCESS) { _DtCmsFreeCalendar(cal); free(log); return (stat); } /* set product identifier */ if ((stat = _DtCm_set_string_attrval(_DtCM_PRODUCT_IDENTIFIER, &cal->attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value, CSA_VALUE_STRING)) != CSA_SUCCESS) { _DtCmsFreeCalendar(cal); free(log); return (stat); } /* set CSA version */ if ((stat = _DtCm_set_string_attrval(_DtCM_SPEC_VERSION_SUPPORTED, &cal->attrs[CSA_CAL_ATTR_VERSION_I].value, CSA_VALUE_STRING)) != CSA_SUCCESS) { _DtCmsFreeCalendar(cal); free(log); return (stat); } /* we dont use the values specified by client */ for (i = 0; i < args->num_attrs; i++) { if (strcmp(args->attrs[i].name.name, CSA_CAL_ATTR_CALENDAR_NAME) == 0) { nidx = i; name = args->attrs[i].name.name; args->attrs[i].name.name = NULL; } else if (strcmp(args->attrs[i].name.name, CSA_CAL_ATTR_CALENDAR_OWNER) == 0) { oidx = i; owner = args->attrs[i].name.name; args->attrs[i].name.name = NULL; } } /* initialize calendar attribute with info provided by caller */ if ((stat = _DtCmUpdateAttributes(args->num_attrs, args->attrs, &cal->num_attrs, &cal->attrs, &cal->cal_tbl, B_TRUE, NULL, B_FALSE)) != CSA_SUCCESS) { _DtCmsFreeCalendar(cal); free(log); return (stat); } if (nidx) args->attrs[nidx].name.name = name; if (oidx) args->attrs[oidx].name.name = owner; /* use passed in char set if client does not supply one */ if (cal->attrs[CSA_CAL_ATTR_CHARACTER_SET_I].value == NULL && args->char_set && *args->char_set != NULL) { if ((stat = _DtCm_set_string_attrval(args->char_set, &cal->attrs[CSA_CAL_ATTR_CHARACTER_SET_I].value, CSA_VALUE_STRING)) != CSA_SUCCESS) { _DtCmsFreeCalendar(cal); free(log); return (stat); } } /* create file */ if ((stat = _DtCmsCreateLogV2(user, log)) != CSA_SUCCESS) { _DtCmsFreeCalendar(cal); free(log); return (stat); } /* dump file */ if ((stat = _DtCmsAppendCalAttrsByFN(log, cal->num_attrs, cal->attrs)) != CSA_SUCCESS) { free(log); unlink(log); _DtCmsFreeCalendar(cal); return (stat); } free(log); _DtCmsPutInCalList(cal); *newcal = cal; return (stat); }