/* * owner should point to a buffer big enough to hold the owner name * We test whether the calendar name is a user name, if so, the * owner will be the same as the calendar name. * Otherwise, we don't know the owner. */ static CSA_return_code _get_owner_from_old_cal(Calendar *cal, char *owner) { char *calname; if ((calname = _DtCmGetPrefix(cal->name, '@')) == NULL) return (CSA_E_INSUFFICIENT_MEMORY); if (_DtCmIsUserName(calname) == B_TRUE) strcpy(owner, calname); else *owner = '\0'; free(calname); return (CSA_SUCCESS); }
/* * return user name of file owner * If the calendar name is the same as a user account name, the * calendar name is return; otherwise, the owner name is derived from * the owner of the calendar file */ static CSA_return_code get_file_owner(char *calname, char **owner) { struct stat info; struct passwd *pw; char buf[BUFSIZ]; char *log; int res; if (calname == NULL || owner == NULL) return (CSA_E_FAILURE); *owner = NULL; if (_DtCmIsUserName(calname) == B_TRUE) { strcpy(buf, calname); } else { if ((log = _DtCmsGetLogFN(calname)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY); res = stat(log, &info); free(log); if (res == 0) { if (pw = getpwuid(info.st_uid)) strcpy(buf, pw->pw_name); else return (CSA_E_FAILURE); } else return(CSA_X_DT_E_BACKING_STORE_PROBLEM); } if (((*owner) = (char *)strdup(buf)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY); else return (CSA_SUCCESS); }
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); }