2
0

rpccalls.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: rpccalls.c /main/1 1996/04/21 19:24:20 drk $ */
  24. /*
  25. * (c) Copyright 1993, 1994 Hewlett-Packard Company
  26. * (c) Copyright 1993, 1994 International Business Machines Corp.
  27. * (c) Copyright 1993, 1994 Novell, Inc.
  28. * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  29. */
  30. /*****************************************************************************
  31. * interface to cm rpc calls
  32. * - this files make calls to v5 backend
  33. * - calls to v4 and before are implemented in table.c
  34. *****************************************************************************/
  35. #include <EUSCompat.h>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <netdb.h> /* define MAXHOSTNAMELEN */
  40. #include <sys/utsname.h> /* SYS_NMLN */
  41. #include <unistd.h>
  42. #ifdef SunOS
  43. #include <sys/systeminfo.h>
  44. #endif
  45. #include "debug.h"
  46. #include "rtable4.h"
  47. #include "cm.h"
  48. #include "attr.h"
  49. #include "connection.h"
  50. #include "convert5-4.h"
  51. #include "convert4-5.h"
  52. #include "rpccalls.h"
  53. #include "table.h"
  54. #include "agent.h"
  55. #include "cmcb.h"
  56. #include "cmsdata.h"
  57. #include "iso8601.h"
  58. #include "misc.h"
  59. #include "updateattrs.h"
  60. #include "free.h"
  61. #include "lutil.h"
  62. #include "laccess.h"
  63. #include "match.h"
  64. extern u_long _DtCm_transient;
  65. static char *nullstr = "";
  66. /*****************************************************************************
  67. * forward declaration of static functions
  68. *****************************************************************************/
  69. static CSA_return_code csa2cmsattrs(CSA_uint32 num_attrs, CSA_attribute *csaattrs,
  70. CSA_enum *ops, CSA_uint32 *newnum,
  71. cms_attribute **newattrs, CSA_enum **newops);
  72. static void free_cmsattrs(CSA_uint32 num_attrs, cms_attribute *attrs);
  73. static CSA_return_code csa2cmsnames(CSA_uint32 num_names, char **reminder_names,
  74. CSA_uint32 *newnum, cms_attr_name **newnames);
  75. static CSA_return_code _GetV4UserAccess(Calendar *cal, cms_access_entry *alist);
  76. /*****************************************************************************
  77. * extern functions used in the library
  78. *****************************************************************************/
  79. extern CSA_return_code
  80. _DtCm_rpc_open_calendar(Calendar *cal)
  81. {
  82. _DtCm_Client_Info *ci=NULL;
  83. CSA_return_code stat;
  84. DP(("rpccalls.c: _DtCm_rpc_open_calendar\n"));
  85. if (cal == NULL)
  86. return (CSA_E_INVALID_PARAMETER);
  87. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  88. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  89. return (stat);
  90. }
  91. cal->conn.ci = ci;
  92. cal->conn.retry = B_TRUE;
  93. if (ci->vers_out == TABLEVERS) {
  94. cms_open_args arg;
  95. cms_open_res *res;
  96. arg.cal = cal->name;
  97. arg.pid = getpid();
  98. res = cms_open_calendar_5(&arg, &cal->conn);
  99. if (res != NULL) {
  100. if ((stat = res->stat) == CSA_SUCCESS) {
  101. cal->rpc_version = res->svr_vers;
  102. cal->file_version = res->file_vers;
  103. cal->access = res->user_access;
  104. }
  105. xdr_free((xdrproc_t)xdr_cms_open_res, (char *)res);
  106. } else {
  107. stat = (cal->conn.stat == RPC_SUCCESS) ?
  108. CSA_E_SERVICE_UNAVAILABLE :
  109. _DtCm_clntstat_to_csastat(cal->conn.stat);
  110. }
  111. } else {
  112. _DtCm_libentry *entries;
  113. cms_access_entry *alist;
  114. cal->rpc_version = ci->vers_out;
  115. cal->file_version = ci->vers_out - 1;
  116. /*
  117. * call lookup_range to check the existence of
  118. * the calendar
  119. */
  120. if ((stat = _DtCm_table_lookup_range(cal, 0, 0, B_TRUE, 0, 0,
  121. 0, 0, NULL, NULL, &entries)) == CSA_SUCCESS) {
  122. if (entries) _DtCm_free_libentries(entries);
  123. if ((stat = _DtCm_table_get_access(cal, &alist))
  124. == CSA_SUCCESS) {
  125. stat = _GetV4UserAccess(cal, alist);
  126. _DtCm_free_cms_access_entry(alist);
  127. }
  128. }
  129. }
  130. return (stat);
  131. }
  132. extern CSA_return_code
  133. _DtCm_rpc_create_calendar(
  134. Calendar *cal,
  135. CSA_uint32 num_attrs,
  136. CSA_attribute * attrs)
  137. {
  138. _DtCm_Client_Info *ci=NULL;
  139. CSA_return_code stat = CSA_SUCCESS;
  140. DP(("rpccalls.c: _DtCm_rpc_create_calendar\n"));
  141. if (cal == NULL)
  142. return (CSA_E_INVALID_PARAMETER);
  143. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  144. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  145. return (stat);
  146. }
  147. cal->conn.ci = ci;
  148. cal->conn.retry = B_FALSE;
  149. if (ci->vers_out == TABLEVERS) {
  150. cms_create_args args;
  151. CSA_return_code *res;
  152. CSA_uint32 num_cmsattrs;
  153. cms_attribute *cmsattrs;
  154. if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
  155. &cmsattrs, NULL)) != CSA_SUCCESS)
  156. return (stat);
  157. args.cal = cal->name;
  158. args.char_set = nullstr;
  159. args.pid = getpid();
  160. args.num_attrs = num_cmsattrs;
  161. args.attrs = cmsattrs;
  162. res = cms_create_calendar_5(&args, &cal->conn);
  163. if (num_cmsattrs) free_cmsattrs(num_cmsattrs, cmsattrs);
  164. if (res != NULL) {
  165. stat = *res;
  166. } else {
  167. stat = (cal->conn.stat == RPC_SUCCESS) ?
  168. CSA_E_SERVICE_UNAVAILABLE :
  169. _DtCm_clntstat_to_csastat(cal->conn.stat);
  170. }
  171. } else if (ci->vers_out == TABLEVERS_4) {
  172. if ((stat = _DtCm_table_create(cal))
  173. == CSA_SUCCESS && num_attrs > 0) {
  174. int i;
  175. /*
  176. * for old backends, the only settable
  177. * calendar attribute is access list
  178. */
  179. for (i = num_attrs - 1; i >= 0; i--) {
  180. if (attrs[i].name)
  181. break;
  182. }
  183. if (attrs[i].value == NULL)
  184. stat = _DtCm_table_set_access(cal, NULL);
  185. else
  186. stat = _DtCm_table_set_access(cal,
  187. attrs[i].value->item.access_list_value);
  188. }
  189. } else if (ci->vers_out < TABLEVERS_4) {
  190. _DtCm_libentry *entries;
  191. char *ptr, *owner;
  192. /* check to make sure user is not creating a calendar
  193. * using another user's name
  194. */
  195. if (ptr = strchr(cal->name, '@')) *ptr = '\0';
  196. if (_DtCmIsUserName(cal->name) == B_TRUE) {
  197. if ((owner = _DtCmGetUserName()) == NULL)
  198. stat = CSA_E_FAILURE;
  199. if (strcmp(cal->name, owner))
  200. stat = CSA_E_NO_AUTHORITY;
  201. } else
  202. stat = CSA_E_INVALID_PARAMETER;
  203. if (ptr) *ptr = '@';
  204. /*
  205. * for v2 and v3 servers, calling a lookup routine has
  206. * the side effect of having a calendar created
  207. * the calendar
  208. */
  209. if (stat == CSA_SUCCESS &&
  210. (stat = _DtCm_table_lookup_range(cal, 0, 0, B_TRUE, 0, 0,
  211. 0, 0, NULL, NULL, &entries)) == CSA_SUCCESS) {
  212. if (entries) _DtCm_free_libentries(entries);
  213. }
  214. }
  215. return (stat);
  216. }
  217. extern CSA_return_code
  218. _DtCm_rpc_delete_calendar(Calendar *cal)
  219. {
  220. CSA_return_code stat;
  221. _DtCm_Client_Info *ci;
  222. DP(("rpccalls.c: _DtCm_rpc_delete_calendar\n"));
  223. if (cal == NULL)
  224. return (CSA_E_INVALID_PARAMETER);
  225. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  226. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  227. return (stat);
  228. }
  229. cal->conn.ci = ci;
  230. cal->conn.retry = B_FALSE;
  231. if (ci->vers_out == TABLEVERS) {
  232. cms_remove_args arg;
  233. CSA_return_code *res;
  234. arg.cal = cal->name;
  235. arg.pid = getpid();
  236. res = cms_remove_calendar_5(&arg, &cal->conn);
  237. if (res != NULL) {
  238. stat = *res;
  239. } else {
  240. stat = (cal->conn.stat == RPC_SUCCESS) ?
  241. CSA_E_SERVICE_UNAVAILABLE :
  242. _DtCm_clntstat_to_csastat(cal->conn.stat);
  243. }
  244. } else
  245. stat = CSA_E_NOT_SUPPORTED;
  246. return (stat);
  247. }
  248. extern CSA_return_code
  249. _DtCm_rpc_register_client(Calendar *cal, unsigned long update_type)
  250. {
  251. CSA_return_code stat;
  252. _DtCm_Client_Info *ci = NULL;
  253. DP(("rpccalls.c: _DtCm_rpc_register_client\n"));
  254. if (cal == NULL)
  255. return (CSA_E_INVALID_PARAMETER);
  256. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  257. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  258. return (stat);
  259. }
  260. cal->conn.ci = ci;
  261. cal->conn.retry = B_TRUE;
  262. return (_DtCm_do_registration(&cal->conn, cal->name, update_type));
  263. }
  264. extern CSA_return_code
  265. _DtCm_rpc_unregister_client(Calendar *cal, unsigned long update_type)
  266. {
  267. CSA_return_code stat;
  268. _DtCm_Client_Info *ci = NULL;
  269. DP(("rpccalls.c: _DtCm_rpc_unregister_client\n"));
  270. if (cal == NULL)
  271. return (CSA_E_INVALID_PARAMETER);
  272. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  273. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  274. return (stat);
  275. }
  276. cal->conn.ci = ci;
  277. cal->conn.retry = B_TRUE;
  278. return (_DtCm_do_unregistration(&cal->conn, cal->name, update_type));
  279. }
  280. extern CSA_return_code
  281. _DtCm_rpc_lookup_reminder(
  282. Calendar *cal,
  283. time_t tick,
  284. CSA_uint32 num_names,
  285. char **reminder_names,
  286. CSA_uint32 *num_rems,
  287. CSA_reminder_reference **rems)
  288. {
  289. _DtCm_Client_Info *ci=NULL;
  290. CSA_return_code stat = CSA_SUCCESS;
  291. DP(("rpccalls.c: _DtCm_rpc_lookup_reminder\n"));
  292. if (cal == NULL || num_rems == 0 || rems == NULL)
  293. return (CSA_E_INVALID_PARAMETER);
  294. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  295. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  296. return (stat);
  297. }
  298. cal->conn.ci = ci;
  299. cal->conn.retry = B_TRUE;
  300. if (ci->vers_out == TABLEVERS) {
  301. cms_reminder_args args;
  302. cms_reminder_res *res;
  303. CSA_uint32 num_cmsnames;
  304. cms_attr_name *cmsnames;
  305. if ((stat = csa2cmsnames(num_names, reminder_names,
  306. &num_cmsnames, &cmsnames)) != CSA_SUCCESS)
  307. return (stat);
  308. args.cal = cal->name;
  309. args.tick = tick;
  310. args.num_names = num_cmsnames;
  311. args.names = cmsnames;
  312. res = cms_lookup_reminder_5(&args, &cal->conn);
  313. if (cmsnames)
  314. free(cmsnames);
  315. if (res != NULL) {
  316. if ((stat = res->stat) == CSA_SUCCESS)
  317. stat = _DtCm_cms2csa_reminder_ref(res->rems,
  318. num_rems, rems);
  319. } else {
  320. stat = (cal->conn.stat == RPC_SUCCESS) ?
  321. CSA_E_SERVICE_UNAVAILABLE :
  322. _DtCm_clntstat_to_csastat(cal->conn.stat);
  323. }
  324. } else {
  325. stat = _DtCm_table_lookup_reminder(cal, num_names,
  326. reminder_names, num_rems, rems);
  327. }
  328. return(stat);
  329. }
  330. /*
  331. * Lookup calendar entries.
  332. * If it's an old server, will try to match the attributes in the library;
  333. * but if attrlist contains attributes not supported by the old backend,
  334. * will just return CSA_E_UNSUPPORTED_ATTRIBUTE.
  335. */
  336. extern CSA_return_code
  337. _DtCm_rpc_lookup_entries(
  338. Calendar *cal,
  339. CSA_uint32 num_attrs,
  340. CSA_attribute * attrs,
  341. CSA_enum *ops,
  342. _DtCm_libentry **elist_r)
  343. {
  344. _DtCm_Client_Info *ci=NULL;
  345. CSA_return_code stat = CSA_SUCCESS;
  346. DP(("rpccalls.c: _DtCm_rpc_lookup_entries\n"));
  347. if (cal == NULL)
  348. return (CSA_E_INVALID_PARAMETER);
  349. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  350. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  351. return (stat);
  352. }
  353. cal->conn.ci = ci;
  354. cal->conn.retry = B_TRUE;
  355. *elist_r = NULL;
  356. if (ci->vers_out == TABLEVERS) {
  357. cms_lookup_entries_args args;
  358. cms_entries_res *res;
  359. CSA_uint32 num_cmsattrs;
  360. cms_attribute *cmsattrs;
  361. CSA_enum *newops;
  362. if ((stat = csa2cmsattrs(num_attrs, attrs, ops, &num_cmsattrs,
  363. &cmsattrs, &newops)) != CSA_SUCCESS)
  364. return (stat);
  365. args.cal = cal->name;
  366. args.char_set = nullstr;
  367. args.num_attrs = num_cmsattrs;
  368. args.attrs = cmsattrs;
  369. args.ops = newops;
  370. res = cms_lookup_entries_5(&args, &cal->conn);
  371. free_cmsattrs(num_cmsattrs, cmsattrs);
  372. if (newops) free(newops);
  373. if (res != NULL) {
  374. if ((stat = res->stat) == CSA_SUCCESS) {
  375. stat = _DtCmCmsentriesToLibentries(
  376. &cal->entry_tbl, res->entries, elist_r);
  377. }
  378. xdr_free((xdrproc_t)xdr_cms_entries_res, (char *)res);
  379. } else {
  380. stat = (cal->conn.stat == RPC_SUCCESS) ?
  381. CSA_E_SERVICE_UNAVAILABLE :
  382. _DtCm_clntstat_to_csastat(cal->conn.stat);
  383. }
  384. } else {
  385. time_t start1, start2, end1, end2;
  386. long id;
  387. boolean_t no_start_time_range;
  388. boolean_t no_end_time_range;
  389. boolean_t no_match;
  390. CSA_uint32 hnum;
  391. cms_attribute *hattrs;
  392. CSA_enum *hops;
  393. cms_key key;
  394. _DtCm_libentry *entry;
  395. /* hash the matching criteria */
  396. if ((stat = _DtCmHashCriteria(cal->entry_tbl, num_attrs, attrs,
  397. NULL, ops, &no_match, &no_start_time_range,
  398. &no_end_time_range, &start1, &start2, &end1, &end2, &id,
  399. &hnum, &hattrs, &hops)) == CSA_E_INVALID_ATTRIBUTE)
  400. {
  401. return (CSA_SUCCESS);
  402. } else if (stat != CSA_SUCCESS || no_match == B_TRUE) {
  403. return (stat);
  404. }
  405. if (id > 0 && no_start_time_range && no_end_time_range) {
  406. /* get the key for the first event */
  407. key.id = 0;
  408. if ((stat = _DtCm_table_lookup_key_range(cal, NULL, id,
  409. _DtCM_BOT, _DtCM_EOT, &key, NULL)) == CSA_SUCCESS &&
  410. key.id > 0) {
  411. /* get the detail */
  412. if ((stat = _DtCm_make_libentry(NULL, &entry))
  413. == CSA_SUCCESS) {
  414. entry->e->key = key;
  415. if ((stat = _DtCm_table_lookup(cal,
  416. entry)) == CSA_SUCCESS)
  417. *elist_r = entry;
  418. else
  419. _DtCm_free_libentries(entry);
  420. }
  421. }
  422. } else {
  423. stat = _DtCm_table_lookup_range(cal, start1, start2,
  424. no_end_time_range, end1, end2,
  425. id, hnum, hattrs, hops, elist_r);
  426. }
  427. _DtCmFreeHashedArrays(hnum, hattrs, hops);
  428. }
  429. return(stat);
  430. }
  431. extern CSA_return_code
  432. _DtCm_rpc_enumerate_sequence(
  433. Calendar *cal,
  434. _DtCm_libentry *entry,
  435. time_t start,
  436. time_t end,
  437. _DtCm_libentry **elist_r)
  438. {
  439. _DtCm_Client_Info *ci=NULL;
  440. CSA_return_code stat = CSA_SUCCESS;
  441. DP(("rpccalls.c: _DtCm_rpc_enumerate_sequence\n"));
  442. if (cal == NULL)
  443. return (CSA_E_INVALID_PARAMETER);
  444. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  445. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  446. return (stat);
  447. }
  448. cal->conn.ci = ci;
  449. cal->conn.retry = B_TRUE;
  450. *elist_r = NULL;
  451. if (ci->vers_out == TABLEVERS) {
  452. cms_enumerate_args args;
  453. cms_entries_res *res;
  454. args.cal = cal->name;
  455. args.id = entry->e->key.id;
  456. args.start = start;
  457. args.end = end;
  458. res = cms_enumerate_sequence_5(&args, &cal->conn);
  459. if (res != NULL) {
  460. if ((stat = res->stat) == CSA_SUCCESS) {
  461. stat = _DtCmCmsentriesToLibentries(
  462. &cal->entry_tbl, res->entries, elist_r);
  463. }
  464. xdr_free((xdrproc_t)xdr_cms_entries_res, (char *)res);
  465. } else {
  466. stat = (cal->conn.stat == RPC_SUCCESS) ?
  467. CSA_E_SERVICE_UNAVAILABLE :
  468. _DtCm_clntstat_to_csastat(cal->conn.stat);
  469. }
  470. } else {
  471. stat = _DtCm_table_lookup_key_range(cal, entry, 0, start, end,
  472. NULL, elist_r);
  473. }
  474. return(stat);
  475. }
  476. extern CSA_return_code
  477. _DtCm_rpc_lookup_entry_by_id(Calendar *cal, _DtCm_libentry *entry)
  478. {
  479. _DtCm_Client_Info *ci=NULL;
  480. CSA_return_code stat = CSA_SUCCESS;
  481. DP(("rpccalls.c: _DtCm_rpc_lookup_entry_by_id\n"));
  482. if (cal == NULL)
  483. return (CSA_E_INVALID_PARAMETER);
  484. if ((stat = _DtCm_create_tcp_client(cal->location,
  485. (cal->file_version < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
  486. TABLEVERS_4 : TABLEVERS), _DtCM_LONG_TIMEOUT, &ci))
  487. != CSA_SUCCESS) {
  488. return (stat);
  489. }
  490. cal->conn.ci = ci;
  491. cal->conn.retry = B_TRUE;
  492. if (ci->vers_out == TABLEVERS) {
  493. cms_get_entry_attr_args args;
  494. cms_get_entry_attr_res *res;
  495. /*
  496. * the entry reference id is filled in already
  497. * otherwise, we would not be in this routine
  498. */
  499. args.cal = cal->name;
  500. args.num_keys = 1;
  501. args.keys = &entry->e->key;
  502. args.num_names = 0;
  503. args.names = NULL;
  504. res = cms_get_entry_attr_5(&args, &cal->conn);
  505. if (res != NULL) {
  506. if (res->entries) {
  507. if ((stat = res->entries->stat) == CSA_SUCCESS)
  508. {
  509. if ((stat = _DtCmUpdateAttributes(
  510. res->entries->num_attrs,
  511. res->entries->attrs,
  512. &entry->e->num_attrs,
  513. &entry->e->attrs,
  514. &cal->entry_tbl, B_FALSE,
  515. NULL, B_TRUE)) == CSA_SUCCESS)
  516. {
  517. entry->filled = B_TRUE;
  518. }
  519. }
  520. } else
  521. stat = res->stat;
  522. } else {
  523. stat = (cal->conn.stat == RPC_SUCCESS) ?
  524. CSA_E_SERVICE_UNAVAILABLE :
  525. _DtCm_clntstat_to_csastat(cal->conn.stat);
  526. }
  527. if (res) xdr_free((xdrproc_t)xdr_cms_get_entry_attr_res, (char *)res);
  528. } else {
  529. stat = _DtCm_table_lookup(cal, entry);
  530. }
  531. return(stat);
  532. }
  533. extern CSA_return_code
  534. _DtCm_rpc_get_cal_attrs(Calendar *cal, int index, CSA_uint32 num_names, char **names)
  535. {
  536. _DtCm_Client_Info *ci;
  537. CSA_return_code stat = CSA_SUCCESS;
  538. cms_attribute_value val;
  539. DP(("rpccalls.c: _DtCm_rpc_get_cal_attrs\n"));
  540. if (cal == NULL)
  541. return (CSA_E_INVALID_PARAMETER);
  542. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  543. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  544. return (stat);
  545. }
  546. cal->conn.ci = ci;
  547. cal->conn.retry = B_TRUE;
  548. if (ci->vers_out == TABLEVERS) {
  549. cms_get_cal_attr_args arg;
  550. cms_get_cal_attr_res *res;
  551. CSA_uint32 num_cmsnames;
  552. cms_attr_name *cmsnames;
  553. if ((stat = csa2cmsnames(num_names, names,
  554. &num_cmsnames, &cmsnames)) != CSA_SUCCESS)
  555. return (stat);
  556. arg.cal = cal->name;
  557. arg.num_names = num_cmsnames;
  558. arg.names = cmsnames;
  559. res = cms_get_calendar_attr_5(&arg, &cal->conn);
  560. if (res != NULL) {
  561. if ((stat = res->stat) == CSA_SUCCESS) {
  562. if ((stat = _DtCmUpdateAttributes(
  563. res->num_attrs, res->attrs, &cal->num_attrs,
  564. &cal->attrs, &cal->cal_tbl, B_TRUE, NULL,
  565. B_TRUE)) == CSA_SUCCESS)
  566. cal->got_attrs = B_TRUE;
  567. }
  568. xdr_free((xdrproc_t)xdr_cms_get_cal_attr_res, (char *)res);
  569. } else {
  570. stat = (cal->conn.stat == RPC_SUCCESS) ?
  571. CSA_E_SERVICE_UNAVAILABLE :
  572. _DtCm_clntstat_to_csastat(cal->conn.stat);
  573. }
  574. } else {
  575. switch (index) {
  576. case CSA_CAL_ATTR_ACCESS_LIST_I:
  577. if ((stat = _DtCm_table_get_access(cal,
  578. &val.item.access_list_value)) == CSA_SUCCESS) {
  579. val.type = CSA_VALUE_ACCESS_LIST;
  580. stat = _DtCmUpdateAccessListAttrVal(&val,
  581. &cal->attrs\
  582. [CSA_CAL_ATTR_ACCESS_LIST_I].value);
  583. _DtCm_free_cms_access_entry(val.item.\
  584. access_list_value);
  585. }
  586. break;
  587. case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
  588. if ((stat = _DtCm_table_size(cal,
  589. (int*)&val.item.uint32_value)) == CSA_SUCCESS) {
  590. val.type = CSA_VALUE_UINT32;
  591. stat = _DtCmUpdateSint32AttrVal(&val,
  592. &cal->attrs\
  593. [CSA_CAL_ATTR_NUMBER_ENTRIES_I].value);
  594. }
  595. break;
  596. }
  597. }
  598. return(stat);
  599. }
  600. extern CSA_return_code
  601. _DtCm_rpc_set_cal_attrs(Calendar *cal, CSA_uint32 num_attrs, CSA_attribute * attrs)
  602. {
  603. _DtCm_Client_Info *ci;
  604. CSA_return_code stat = CSA_SUCCESS;
  605. DP(("rpccalls.c: _DtCm_rpc_set_cal_attrs\n"));
  606. if (cal == NULL || attrs == NULL)
  607. return (CSA_E_INVALID_PARAMETER);
  608. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  609. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
  610. {
  611. return (stat);
  612. }
  613. cal->conn.ci = ci;
  614. cal->conn.retry = B_FALSE;
  615. if (ci->vers_out == TABLEVERS) {
  616. CSA_return_code *res;
  617. cms_set_cal_attr_args args;
  618. CSA_uint32 num_cmsattrs;
  619. cms_attribute *cmsattrs;
  620. if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
  621. &cmsattrs, NULL)) != CSA_SUCCESS)
  622. return (stat);
  623. if (num_cmsattrs == 0)
  624. return (CSA_E_INVALID_PARAMETER);
  625. args.cal = cal->name;
  626. args.pid = getpid();
  627. args.num_attrs = num_cmsattrs;
  628. args.attrs = cmsattrs;
  629. res = cms_set_calendar_attr_5(&args, &cal->conn);
  630. free_cmsattrs(num_cmsattrs, cmsattrs);
  631. if (res != NULL) {
  632. stat = *res;
  633. if (stat == CSA_SUCCESS) {
  634. _DtCm_free_cms_attribute_values(cal->num_attrs,
  635. cal->attrs);
  636. }
  637. } else {
  638. stat = (cal->conn.stat == RPC_SUCCESS) ?
  639. CSA_E_SERVICE_UNAVAILABLE :
  640. _DtCm_clntstat_to_csastat(cal->conn.stat);
  641. }
  642. } else {
  643. int i;
  644. /*
  645. * CSA_CAL_ATTR_ACCESS_LIST is the only settable attribute
  646. */
  647. for (i = num_attrs - 1; i >= 0; i--) {
  648. if (attrs[i].name)
  649. break;
  650. }
  651. if (attrs[i].value == NULL)
  652. stat = _DtCm_table_set_access(cal, NULL);
  653. else
  654. stat = _DtCm_table_set_access(cal,
  655. attrs[i].value->item.access_list_value);
  656. }
  657. return (stat);
  658. }
  659. extern CSA_return_code
  660. _DtCm_rpc_insert_entry(
  661. Calendar *cal,
  662. CSA_uint32 num_attrs,
  663. CSA_attribute * attrs,
  664. _DtCm_libentry **entry_r)
  665. {
  666. _DtCm_Client_Info *ci = NULL;
  667. CSA_return_code stat = CSA_SUCCESS;
  668. DP(("rpccalls.c: _DtCm_rpc_insert_entry;\n"));
  669. if (cal == NULL || num_attrs == 0 || attrs == NULL || entry_r == NULL)
  670. return (CSA_E_INVALID_PARAMETER);
  671. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  672. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
  673. {
  674. return (stat);
  675. }
  676. cal->conn.ci = ci;
  677. cal->conn.retry = B_FALSE;
  678. if (ci->vers_out == TABLEVERS) {
  679. cms_entry_res *res;
  680. cms_insert_args args;
  681. CSA_uint32 num_cmsattrs;
  682. cms_attribute *cmsattrs;
  683. if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
  684. &cmsattrs, NULL)) != CSA_SUCCESS)
  685. return (stat);
  686. if (num_cmsattrs == 0)
  687. return (CSA_E_INVALID_PARAMETER);
  688. args.cal = cal->name;
  689. args.pid = getpid();
  690. args.num_attrs = num_cmsattrs;
  691. args.attrs = cmsattrs;
  692. res = cms_insert_entry_5(&args, &cal->conn);
  693. free_cmsattrs(num_cmsattrs, cmsattrs);
  694. if (res != NULL) {
  695. if ((stat = res->stat) == CSA_SUCCESS) {
  696. stat = _DtCmCmsentriesToLibentries(
  697. &cal->entry_tbl, res->entry, entry_r);
  698. }
  699. xdr_free((xdrproc_t)xdr_cms_entry_res, (char *)res);
  700. } else {
  701. stat = (cal->conn.stat == RPC_SUCCESS) ?
  702. CSA_E_SERVICE_UNAVAILABLE :
  703. _DtCm_clntstat_to_csastat(cal->conn.stat);
  704. }
  705. } else {
  706. stat = _DtCm_table_insert(cal, num_attrs, attrs, entry_r);
  707. }
  708. return(stat);
  709. }
  710. extern CSA_return_code
  711. _DtCm_rpc_update_entry(
  712. Calendar *cal,
  713. _DtCm_libentry *oentry,
  714. CSA_uint32 num_attrs,
  715. CSA_attribute * attrs,
  716. CSA_enum scope,
  717. _DtCm_libentry **nentry)
  718. {
  719. _DtCm_Client_Info *ci = NULL;
  720. CSA_return_code stat = CSA_SUCCESS;
  721. DP(("rpccalls.c: _DtCm_rpc_update_entry\n"));
  722. if (cal == NULL || oentry == NULL)
  723. return (CSA_E_INVALID_PARAMETER);
  724. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  725. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
  726. {
  727. return (stat);
  728. }
  729. cal->conn.ci = ci;
  730. cal->conn.retry = B_FALSE;
  731. if (ci->vers_out == TABLEVERS) {
  732. cms_entry_res *res;
  733. cms_update_args args;
  734. CSA_uint32 num_cmsattrs;
  735. cms_attribute *cmsattrs;
  736. if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
  737. &cmsattrs, NULL)) != CSA_SUCCESS)
  738. return (stat);
  739. if (num_cmsattrs == 0)
  740. return (CSA_E_INVALID_PARAMETER);
  741. args.cal = cal->name;
  742. args.pid = getpid();
  743. args.entry = oentry->e->key;
  744. args.scope = scope;
  745. args.num_attrs = num_cmsattrs;
  746. args.attrs = cmsattrs;
  747. res = cms_update_entry_5(&args, &cal->conn);
  748. free_cmsattrs(num_cmsattrs, cmsattrs);
  749. if (res != NULL) {
  750. if ((stat = res->stat) == CSA_SUCCESS) {
  751. stat = _DtCmCmsentriesToLibentries(
  752. &cal->entry_tbl, res->entry, nentry);
  753. }
  754. xdr_free((xdrproc_t)xdr_cms_entry_res, (char *)res);
  755. } else {
  756. stat = (cal->conn.stat == RPC_SUCCESS) ?
  757. CSA_E_SERVICE_UNAVAILABLE :
  758. _DtCm_clntstat_to_csastat(cal->conn.stat);
  759. }
  760. } else {
  761. stat = _DtCm_table_update(cal, oentry, num_attrs, attrs,
  762. scope, nentry);
  763. }
  764. return(stat);
  765. }
  766. extern CSA_return_code
  767. _DtCm_rpc_delete_entry(
  768. Calendar *cal,
  769. _DtCm_libentry *entry,
  770. CSA_enum scope)
  771. {
  772. _DtCm_Client_Info *ci = NULL;
  773. CSA_return_code stat = CSA_SUCCESS;
  774. DP(("rpccalls.c: _DtCm_rpc_delete_entry\n"));
  775. if (cal == NULL || entry == NULL)
  776. return (CSA_E_INVALID_PARAMETER);
  777. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  778. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
  779. {
  780. return (stat);
  781. }
  782. cal->conn.ci = ci;
  783. cal->conn.retry = B_FALSE;
  784. if (ci->vers_out == TABLEVERS) {
  785. CSA_return_code *res;
  786. cms_delete_args args;
  787. args.cal = cal->name;
  788. args.pid = getpid();
  789. args.entry = entry->e->key;
  790. args.scope = scope;
  791. res = cms_delete_entry_5(&args, &cal->conn);
  792. if (res != NULL) {
  793. stat = *res;
  794. } else {
  795. stat = (cal->conn.stat == RPC_SUCCESS) ?
  796. CSA_E_SERVICE_UNAVAILABLE :
  797. _DtCm_clntstat_to_csastat(cal->conn.stat);
  798. }
  799. } else {
  800. stat = _DtCm_table_delete(cal, entry, scope);
  801. }
  802. return(stat);
  803. }
  804. extern CSA_return_code
  805. _DtCm_rpc_list_calendar_attributes(
  806. Calendar *cal,
  807. CSA_uint32 *number_names,
  808. char ***names_r)
  809. {
  810. _DtCm_Client_Info *ci = NULL;
  811. CSA_return_code stat = CSA_SUCCESS;
  812. DP(("rpccalls.c: _DtCm_rpc_list_calendar_attributes\n"));
  813. if (cal == NULL)
  814. return (CSA_E_INVALID_PARAMETER);
  815. if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
  816. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  817. return (stat);
  818. }
  819. cal->conn.ci = ci;
  820. cal->conn.retry = B_TRUE;
  821. if (ci->vers_out == TABLEVERS) {
  822. cms_enumerate_calendar_attr_res *res;
  823. char **names;
  824. int i;
  825. *number_names = 0;
  826. *names_r = NULL;
  827. res = cms_enumerate_calendar_attr_5(&cal->name, &cal->conn);
  828. if (res != NULL) {
  829. if ((stat = res->stat) == CSA_SUCCESS && res->num_names)
  830. {
  831. if (names = _DtCm_alloc_character_pointers(
  832. res->num_names)) {
  833. for (i = 0; i < res->num_names; i++) {
  834. if ((names[i] = strdup(
  835. res->names[i].name))
  836. == NULL) {
  837. _DtCm_free(names);
  838. return (CSA_E_INSUFFICIENT_MEMORY);
  839. }
  840. }
  841. *number_names = res->num_names;
  842. *names_r = names;
  843. }
  844. }
  845. } else {
  846. stat = (cal->conn.stat == RPC_SUCCESS) ?
  847. CSA_E_SERVICE_UNAVAILABLE :
  848. _DtCm_clntstat_to_csastat(cal->conn.stat);
  849. }
  850. } else {
  851. stat = CSA_E_NOT_SUPPORTED;
  852. }
  853. return(stat);
  854. }
  855. extern CSA_return_code
  856. _DtCm_rpc_list_calendars(
  857. char *location,
  858. CSA_uint32 *number_names,
  859. CSA_calendar_user **names_r)
  860. {
  861. _DtCm_Client_Info *ci = NULL;
  862. CSA_return_code stat = CSA_SUCCESS;
  863. _DtCm_Connection conn;
  864. DP(("rpccalls.c: _DtCm_rpc_list_calendars\n"));
  865. if ((stat = _DtCm_create_tcp_client(location, TABLEVERS,
  866. _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
  867. return (stat);
  868. }
  869. conn.ci = ci;
  870. conn.retry = B_TRUE;
  871. if (ci->vers_out == TABLEVERS) {
  872. cms_list_calendars_res *res;
  873. CSA_calendar_user *names;
  874. int i;
  875. *number_names = 0;
  876. *names_r = NULL;
  877. res = cms_list_calendars_5(NULL, &conn);
  878. if (res != NULL) {
  879. if ((stat = res->stat) == CSA_SUCCESS && res->num_names)
  880. {
  881. if (names = _DtCm_alloc_calendar_users(
  882. res->num_names)) {
  883. for (i = 0; i < res->num_names; i++) {
  884. if ((names[i].calendar_address =
  885. strdup(res->names[i]))
  886. == NULL) {
  887. _DtCm_free(names);
  888. return (CSA_E_INSUFFICIENT_MEMORY);
  889. }
  890. }
  891. *number_names = res->num_names;
  892. *names_r = names;
  893. }
  894. }
  895. } else {
  896. stat = (conn.stat == RPC_SUCCESS) ?
  897. CSA_E_SERVICE_UNAVAILABLE :
  898. _DtCm_clntstat_to_csastat(conn.stat);
  899. }
  900. } else {
  901. stat = CSA_E_NOT_SUPPORTED;
  902. }
  903. return(stat);
  904. }
  905. extern CSA_return_code
  906. _DtCm_do_unregistration(
  907. _DtCm_Connection *conn,
  908. char *cal,
  909. unsigned long update_type)
  910. {
  911. CSA_return_code stat;
  912. if (conn->ci->vers_out == TABLEVERS) {
  913. cms_register_args args;
  914. CSA_return_code *res;
  915. args.cal = cal;
  916. args.update_type = update_type;
  917. args.prognum = _DtCm_transient;
  918. args.versnum = AGENTVERS_2;
  919. args.procnum = update_callback;
  920. args.pid = getpid();
  921. res = cms_unregister_5(&args, conn);
  922. if (res != NULL) {
  923. stat = *res;
  924. } else {
  925. stat = (conn->stat == RPC_SUCCESS) ?
  926. CSA_E_SERVICE_UNAVAILABLE :
  927. _DtCm_clntstat_to_csastat(conn->stat);
  928. }
  929. } else {
  930. stat = _DtCm_table_unregister_target(conn, cal);
  931. }
  932. if (stat == CSA_SUCCESS)
  933. _DtCm_remove_registration(conn->ci, cal);
  934. return (stat);
  935. }
  936. extern CSA_return_code
  937. _DtCm_do_registration(
  938. _DtCm_Connection *conn,
  939. char *cal,
  940. unsigned long update_type)
  941. {
  942. CSA_return_code stat;
  943. if (conn->ci->vers_out == TABLEVERS) {
  944. cms_register_args args;
  945. CSA_return_code *res;
  946. args.cal = cal;
  947. args.update_type = update_type;
  948. args.prognum = _DtCm_transient;
  949. args.versnum = AGENTVERS_2;
  950. args.procnum = update_callback;
  951. args.pid = getpid();
  952. res = cms_register_5(&args, conn);
  953. if (res != NULL)
  954. stat = *res;
  955. else {
  956. stat = (conn->stat == RPC_SUCCESS) ?
  957. CSA_E_SERVICE_UNAVAILABLE :
  958. _DtCm_clntstat_to_csastat(conn->stat);
  959. }
  960. } else {
  961. stat = _DtCm_table_register_target(conn, cal);
  962. }
  963. if (stat == CSA_SUCCESS) {
  964. if ((stat = _DtCm_add_registration(conn->ci, cal, update_type))
  965. != CSA_SUCCESS) {
  966. (void) _DtCm_do_unregistration(conn, cal, update_type);
  967. }
  968. }
  969. return (stat);
  970. }
  971. /*****************************************************************************
  972. * static functions used within the file
  973. *****************************************************************************/
  974. /*
  975. * Newnum is initialized to 0 and newattrs to NULL when num_attrs == 0
  976. */
  977. static CSA_return_code
  978. csa2cmsattrs(
  979. CSA_uint32 num_attrs,
  980. CSA_attribute *csaattrs,
  981. CSA_enum *ops,
  982. CSA_uint32 *newnum,
  983. cms_attribute **newattrs,
  984. CSA_enum **newops)
  985. {
  986. CSA_return_code stat = CSA_SUCCESS;
  987. cms_attribute *cmsattrs;
  988. CSA_enum *ops_r = NULL;
  989. CSA_reminder *rptr1, *rptr2;
  990. int i,j;
  991. *newnum = 0;
  992. *newattrs = NULL;
  993. if (newops) *newops = NULL;
  994. if (num_attrs == 0)
  995. return CSA_SUCCESS;
  996. if ((cmsattrs = calloc(1, sizeof(cms_attribute)*num_attrs)) == NULL)
  997. return (CSA_E_INSUFFICIENT_MEMORY);
  998. if (newops && (ops_r = malloc(sizeof(CSA_enum)*num_attrs)) == NULL) {
  999. free(cmsattrs);
  1000. return (CSA_E_INSUFFICIENT_MEMORY);
  1001. }
  1002. for (i = 0, j = 0; i < num_attrs && stat == CSA_SUCCESS; i++) {
  1003. if (csaattrs[i].name == NULL)
  1004. continue;
  1005. if (newops)
  1006. ops_r[j] = (ops ? ops[i] : CSA_MATCH_EQUAL_TO);
  1007. cmsattrs[j].name.name = csaattrs[i].name;
  1008. if (csaattrs[i].value == NULL) {
  1009. j++;
  1010. continue;
  1011. }
  1012. if ((cmsattrs[j].value = (cms_attribute_value *)malloc(
  1013. sizeof(cms_attribute_value))) == NULL) {
  1014. stat = CSA_E_INSUFFICIENT_MEMORY;
  1015. break;
  1016. }
  1017. cmsattrs[j].value->type = csaattrs[i].value->type;
  1018. switch (csaattrs[i].value->type) {
  1019. case CSA_VALUE_ACCESS_LIST:
  1020. stat = _DtCm_csa2cms_access_list(
  1021. csaattrs[i].value->item.access_list_value,
  1022. &cmsattrs[j].value->item.access_list_value);
  1023. break;
  1024. case CSA_VALUE_CALENDAR_USER:
  1025. if (csaattrs[i].value->item.calendar_user_value &&
  1026. csaattrs[i].value->item.calendar_user_value->\
  1027. user_name)
  1028. {
  1029. cmsattrs[j].value->item.calendar_user_value =
  1030. csaattrs[i].value->item.\
  1031. calendar_user_value->user_name;
  1032. } else {
  1033. cmsattrs[j].value->item.calendar_user_value =
  1034. nullstr;
  1035. }
  1036. break;
  1037. case CSA_VALUE_STRING:
  1038. case CSA_VALUE_DATE_TIME:
  1039. case CSA_VALUE_DATE_TIME_RANGE:
  1040. case CSA_VALUE_TIME_DURATION:
  1041. if (csaattrs[i].value->item.string_value) {
  1042. cmsattrs[j].value->item.string_value =
  1043. csaattrs[i].value->item.string_value;
  1044. } else {
  1045. cmsattrs[j].value->item.string_value = nullstr;
  1046. }
  1047. break;
  1048. case CSA_VALUE_REMINDER:
  1049. if ((rptr1 = csaattrs[i].value->item.reminder_value) &&
  1050. (rptr2 = (CSA_reminder *)malloc(sizeof(CSA_reminder))))
  1051. {
  1052. rptr2->lead_time = rptr1->lead_time ?
  1053. rptr1->lead_time : nullstr;
  1054. rptr2->snooze_time = rptr1->snooze_time ?
  1055. rptr1->snooze_time:nullstr;
  1056. rptr2->repeat_count = rptr1->repeat_count;
  1057. rptr2->reminder_data = rptr1->reminder_data;
  1058. cmsattrs[j].value->item.reminder_value = rptr2;
  1059. } else if (rptr1 && rptr2 == NULL)
  1060. stat = CSA_E_INSUFFICIENT_MEMORY;
  1061. break;
  1062. default:
  1063. /* all other value types uses the same type
  1064. * of data, so we just copy the value/address of
  1065. * of the data
  1066. */
  1067. cmsattrs[j].value->item.sint32_value =
  1068. csaattrs[i].value->item.sint32_value;
  1069. }
  1070. j++;
  1071. }
  1072. if (stat != CSA_SUCCESS) {
  1073. free_cmsattrs(num_attrs, cmsattrs);
  1074. if (newops) free(ops_r);
  1075. } else if (j > 0) {
  1076. *newnum = j;
  1077. *newattrs = cmsattrs;
  1078. if (newops) *newops = ops_r;
  1079. } else {
  1080. free(cmsattrs);
  1081. if (newops) free(ops_r);
  1082. }
  1083. return (stat);
  1084. }
  1085. static void
  1086. free_cmsattrs(CSA_uint32 num_attrs, cms_attribute *attrs)
  1087. {
  1088. int i;
  1089. for (i = 0; i < num_attrs; i++) {
  1090. if (attrs[i].value == NULL)
  1091. continue;
  1092. switch (attrs[i].value->type) {
  1093. case CSA_VALUE_ACCESS_LIST:
  1094. _DtCm_free_cms_access_entry(
  1095. attrs[i].value->item.access_list_value);
  1096. break;
  1097. case CSA_VALUE_REMINDER:
  1098. if (attrs[i].value->item.reminder_value)
  1099. free(attrs[i].value->item.reminder_value);
  1100. break;
  1101. }
  1102. free(attrs[i].value);
  1103. }
  1104. free (attrs);
  1105. }
  1106. /*
  1107. * Newnum is initialized to 0 and newattrs to NULL when num_attrs == 0
  1108. */
  1109. static CSA_return_code
  1110. csa2cmsnames(
  1111. CSA_uint32 num_names,
  1112. char **reminder_names,
  1113. CSA_uint32 *newnum,
  1114. cms_attr_name **newnames)
  1115. {
  1116. cms_attr_name *cmsnames;
  1117. int i,j;
  1118. *newnum = 0;
  1119. *newnames = NULL;
  1120. if (num_names == 0)
  1121. return (CSA_SUCCESS);
  1122. if ((cmsnames = calloc(1, sizeof(cms_attr_name)*num_names)) == NULL)
  1123. return (CSA_E_INSUFFICIENT_MEMORY);
  1124. for (i = 0, j = 0; i < num_names; i++) {
  1125. if (reminder_names[i] == NULL)
  1126. continue;
  1127. else {
  1128. cmsnames[j].name = reminder_names[i];
  1129. j++;
  1130. }
  1131. }
  1132. if (j > 0) {
  1133. *newnum = j;
  1134. *newnames = cmsnames;
  1135. } else
  1136. free(cmsnames);
  1137. return (CSA_SUCCESS);
  1138. }
  1139. /*
  1140. * It is an old server and so we need to determine whether the user
  1141. * is the calendar owner ourselves.
  1142. * If the calendar name is the same as a user name, then that user
  1143. * is the owner, and we just need to make sure the calendar is located
  1144. * in the same domain as ours. If the calendar is located in another
  1145. * domain and since we can't do cross domain authentication yet, to be save
  1146. * we assume that the user is not the owner.
  1147. * If the calendar name is not a user name, we need to make an rpc call
  1148. * (table_set_access) to test whether the user is the owner.
  1149. */
  1150. static CSA_return_code
  1151. _GetV4UserAccess(Calendar *cal, cms_access_entry *alist)
  1152. {
  1153. CSA_return_code stat = CSA_SUCCESS;
  1154. char *user = _DtCmGetUserName();
  1155. char *localhost = _DtCmGetHostAtDomain();
  1156. char buf[BUFSIZ];
  1157. char *ptr, *dom;
  1158. int worldaccess = 0, useraccess = 0;
  1159. boolean_t isowner = B_FALSE;
  1160. /* first check if user is owner */
  1161. if (ptr = strchr(cal->name, '@')) *ptr = '\0';
  1162. if (_DtCmIsUserName(cal->name) == B_TRUE) {
  1163. if (strcmp(user, cal->name) == 0) {
  1164. /* check whether calendar location is in
  1165. * the same domain
  1166. */
  1167. if (dom = strchr(cal->location, '.')) dom++;
  1168. if (dom == NULL || _DtCmIsSamePath(
  1169. _DtCmGetLocalDomain(NULL), dom) == B_TRUE)
  1170. isowner = B_TRUE;
  1171. }
  1172. } else {
  1173. CSA_access_rights *csalist;
  1174. /* need to test whether the user is the owner */
  1175. if ((stat = _DtCm_cms2csa_access_list(alist, &csalist))
  1176. == CSA_SUCCESS) {
  1177. stat = _DtCm_table_set_access(cal, csalist);
  1178. _DtCm_free_csa_access_list(csalist);
  1179. if (stat == CSA_SUCCESS)
  1180. isowner = B_TRUE;
  1181. else if (stat == CSA_E_NO_AUTHORITY) {
  1182. isowner = B_FALSE;
  1183. stat = CSA_SUCCESS;
  1184. }
  1185. }
  1186. }
  1187. if (ptr) *ptr = '@';
  1188. if (stat != CSA_SUCCESS)
  1189. return (stat);
  1190. if (isowner) {
  1191. cal->access = CSA_OWNER_RIGHTS;
  1192. return (CSA_SUCCESS);
  1193. }
  1194. snprintf(buf, sizeof buf, "%s@%s", user, localhost);
  1195. for (; alist != NULL; alist = alist->next) {
  1196. if (strcasecmp(alist->user, "world") == 0)
  1197. worldaccess = alist->rights;
  1198. else if (_DtCmIsSameUser(buf, alist->user)) {
  1199. useraccess = alist->rights;
  1200. break;
  1201. }
  1202. }
  1203. cal->access = useraccess | worldaccess;
  1204. return (CSA_SUCCESS);
  1205. }