2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: rpccalls.c /main/1 1996/04/21 19:24:20 drk $ */
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.
31 /*****************************************************************************
32 * interface to cm rpc calls
33 * - this files make calls to v5 backend
34 * - calls to v4 and before are implemented in table.c
35 *****************************************************************************/
37 #include <EUSCompat.h>
41 #include <netdb.h> /* define MAXHOSTNAMELEN */
42 #include <sys/utsname.h> /* SYS_NMLN */
45 #include <sys/systeminfo.h>
51 #include "connection.h"
52 #include "convert5-4.h"
53 #include "convert4-5.h"
61 #include "updateattrs.h"
67 extern u_long _DtCm_transient;
69 static char *nullstr = "";
71 /*****************************************************************************
72 * forward declaration of static functions
73 *****************************************************************************/
74 static CSA_return_code csa2cmsattrs(CSA_uint32 num_attrs, CSA_attribute *csaattrs,
75 CSA_enum *ops, CSA_uint32 *newnum,
76 cms_attribute **newattrs, CSA_enum **newops);
77 static void free_cmsattrs(CSA_uint32 num_attrs, cms_attribute *attrs);
78 static CSA_return_code csa2cmsnames(CSA_uint32 num_names, char **reminder_names,
79 CSA_uint32 *newnum, cms_attr_name **newnames);
80 static CSA_return_code _GetV4UserAccess(Calendar *cal, cms_access_entry *alist);
82 /*****************************************************************************
83 * extern functions used in the library
84 *****************************************************************************/
86 extern CSA_return_code
87 _DtCm_rpc_open_calendar(Calendar *cal)
89 _DtCm_Client_Info *ci=NULL;
92 DP(("rpccalls.c: _DtCm_rpc_open_calendar\n"));
95 return (CSA_E_INVALID_PARAMETER);
97 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
98 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
102 cal->conn.retry = B_TRUE;
104 if (ci->vers_out == TABLEVERS) {
111 res = cms_open_calendar_5(&arg, &cal->conn);
114 if ((stat = res->stat) == CSA_SUCCESS) {
115 cal->rpc_version = res->svr_vers;
116 cal->file_version = res->file_vers;
117 cal->access = res->user_access;
120 xdr_free((xdrproc_t)xdr_cms_open_res, (char *)res);
122 stat = (cal->conn.stat == RPC_SUCCESS) ?
123 CSA_E_SERVICE_UNAVAILABLE :
124 _DtCm_clntstat_to_csastat(cal->conn.stat);
127 _DtCm_libentry *entries;
128 cms_access_entry *alist;
130 cal->rpc_version = ci->vers_out;
131 cal->file_version = ci->vers_out - 1;
134 * call lookup_range to check the existence of
137 if ((stat = _DtCm_table_lookup_range(cal, 0, 0, B_TRUE, 0, 0,
138 0, 0, NULL, NULL, &entries)) == CSA_SUCCESS) {
139 if (entries) _DtCm_free_libentries(entries);
141 if ((stat = _DtCm_table_get_access(cal, &alist))
143 stat = _GetV4UserAccess(cal, alist);
144 _DtCm_free_cms_access_entry(alist);
151 extern CSA_return_code
152 _DtCm_rpc_create_calendar(
154 CSA_uint32 num_attrs,
155 CSA_attribute * attrs)
157 _DtCm_Client_Info *ci=NULL;
158 CSA_return_code stat = CSA_SUCCESS;
160 DP(("rpccalls.c: _DtCm_rpc_create_calendar\n"));
163 return (CSA_E_INVALID_PARAMETER);
165 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
166 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
170 cal->conn.retry = B_FALSE;
172 if (ci->vers_out == TABLEVERS) {
173 cms_create_args args;
174 CSA_return_code *res;
175 CSA_uint32 num_cmsattrs;
176 cms_attribute *cmsattrs;
178 if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
179 &cmsattrs, NULL)) != CSA_SUCCESS)
182 args.cal = cal->name;
183 args.char_set = nullstr;
185 args.num_attrs = num_cmsattrs;
186 args.attrs = cmsattrs;
188 res = cms_create_calendar_5(&args, &cal->conn);
190 if (num_cmsattrs) free_cmsattrs(num_cmsattrs, cmsattrs);
195 stat = (cal->conn.stat == RPC_SUCCESS) ?
196 CSA_E_SERVICE_UNAVAILABLE :
197 _DtCm_clntstat_to_csastat(cal->conn.stat);
199 } else if (ci->vers_out == TABLEVERS_4) {
201 if ((stat = _DtCm_table_create(cal))
202 == CSA_SUCCESS && num_attrs > 0) {
207 * for old backends, the only settable
208 * calendar attribute is access list
210 for (i = num_attrs - 1; i >= 0; i--) {
214 if (attrs[i].value == NULL)
215 stat = _DtCm_table_set_access(cal, NULL);
217 stat = _DtCm_table_set_access(cal,
218 attrs[i].value->item.access_list_value);
221 } else if (ci->vers_out < TABLEVERS_4) {
222 _DtCm_libentry *entries;
225 /* check to make sure user is not creating a calendar
226 * using another user's name
228 if (ptr = strchr(cal->name, '@')) *ptr = '\0';
229 if (_DtCmIsUserName(cal->name) == B_TRUE) {
231 if ((owner = _DtCmGetUserName()) == NULL)
232 stat = CSA_E_FAILURE;
234 if (strcmp(cal->name, owner))
235 stat = CSA_E_NO_AUTHORITY;
237 stat = CSA_E_INVALID_PARAMETER;
241 * for v2 and v3 servers, calling a lookup routine has
242 * the side effect of having a calendar created
245 if (stat == CSA_SUCCESS &&
246 (stat = _DtCm_table_lookup_range(cal, 0, 0, B_TRUE, 0, 0,
247 0, 0, NULL, NULL, &entries)) == CSA_SUCCESS) {
248 if (entries) _DtCm_free_libentries(entries);
254 extern CSA_return_code
255 _DtCm_rpc_delete_calendar(Calendar *cal)
257 CSA_return_code stat;
258 _DtCm_Client_Info *ci;
260 DP(("rpccalls.c: _DtCm_rpc_delete_calendar\n"));
263 return (CSA_E_INVALID_PARAMETER);
265 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
266 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
271 cal->conn.retry = B_FALSE;
273 if (ci->vers_out == TABLEVERS) {
275 CSA_return_code *res;
280 res = cms_remove_calendar_5(&arg, &cal->conn);
285 stat = (cal->conn.stat == RPC_SUCCESS) ?
286 CSA_E_SERVICE_UNAVAILABLE :
287 _DtCm_clntstat_to_csastat(cal->conn.stat);
290 stat = CSA_E_NOT_SUPPORTED;
295 extern CSA_return_code
296 _DtCm_rpc_register_client(Calendar *cal, unsigned long update_type)
298 CSA_return_code stat;
299 _DtCm_Client_Info *ci = NULL;
301 DP(("rpccalls.c: _DtCm_rpc_register_client\n"));
304 return (CSA_E_INVALID_PARAMETER);
306 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
307 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
312 cal->conn.retry = B_TRUE;
314 return (_DtCm_do_registration(&cal->conn, cal->name, update_type));
317 extern CSA_return_code
318 _DtCm_rpc_unregister_client(Calendar *cal, unsigned long update_type)
320 CSA_return_code stat;
321 _DtCm_Client_Info *ci = NULL;
323 DP(("rpccalls.c: _DtCm_rpc_unregister_client\n"));
326 return (CSA_E_INVALID_PARAMETER);
328 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
329 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
334 cal->conn.retry = B_TRUE;
336 return (_DtCm_do_unregistration(&cal->conn, cal->name, update_type));
339 extern CSA_return_code
340 _DtCm_rpc_lookup_reminder(
343 CSA_uint32 num_names,
344 char **reminder_names,
345 CSA_uint32 *num_rems,
346 CSA_reminder_reference **rems)
348 _DtCm_Client_Info *ci=NULL;
349 CSA_return_code stat = CSA_SUCCESS;
351 DP(("rpccalls.c: _DtCm_rpc_lookup_reminder\n"));
353 if (cal == NULL || num_rems == 0 || rems == NULL)
354 return (CSA_E_INVALID_PARAMETER);
356 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
357 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
361 cal->conn.retry = B_TRUE;
363 if (ci->vers_out == TABLEVERS) {
364 cms_reminder_args args;
365 cms_reminder_res *res;
366 CSA_uint32 num_cmsnames;
367 cms_attr_name *cmsnames;
369 if ((stat = csa2cmsnames(num_names, reminder_names,
370 &num_cmsnames, &cmsnames)) != CSA_SUCCESS)
373 args.cal = cal->name;
375 args.num_names = num_cmsnames;
376 args.names = cmsnames;
378 res = cms_lookup_reminder_5(&args, &cal->conn);
384 if ((stat = res->stat) == CSA_SUCCESS)
385 stat = _DtCm_cms2csa_reminder_ref(res->rems,
388 stat = (cal->conn.stat == RPC_SUCCESS) ?
389 CSA_E_SERVICE_UNAVAILABLE :
390 _DtCm_clntstat_to_csastat(cal->conn.stat);
394 stat = _DtCm_table_lookup_reminder(cal, num_names,
395 reminder_names, num_rems, rems);
402 * Lookup calendar entries.
403 * If it's an old server, will try to match the attributes in the library;
404 * but if attrlist contains attributes not supported by the old backend,
405 * will just return CSA_E_UNSUPPORTED_ATTRIBUTE.
407 extern CSA_return_code
408 _DtCm_rpc_lookup_entries(
410 CSA_uint32 num_attrs,
411 CSA_attribute * attrs,
413 _DtCm_libentry **elist_r)
415 _DtCm_Client_Info *ci=NULL;
416 CSA_return_code stat = CSA_SUCCESS;
418 DP(("rpccalls.c: _DtCm_rpc_lookup_entries\n"));
421 return (CSA_E_INVALID_PARAMETER);
423 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
424 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
428 cal->conn.retry = B_TRUE;
432 if (ci->vers_out == TABLEVERS) {
433 cms_lookup_entries_args args;
434 cms_entries_res *res;
435 CSA_uint32 num_cmsattrs;
436 cms_attribute *cmsattrs;
439 if ((stat = csa2cmsattrs(num_attrs, attrs, ops, &num_cmsattrs,
440 &cmsattrs, &newops)) != CSA_SUCCESS)
443 args.cal = cal->name;
444 args.char_set = nullstr;
445 args.num_attrs = num_cmsattrs;
446 args.attrs = cmsattrs;
449 res = cms_lookup_entries_5(&args, &cal->conn);
451 free_cmsattrs(num_cmsattrs, cmsattrs);
452 if (newops) free(newops);
455 if ((stat = res->stat) == CSA_SUCCESS) {
456 stat = _DtCmCmsentriesToLibentries(
457 &cal->entry_tbl, res->entries, elist_r);
460 xdr_free((xdrproc_t)xdr_cms_entries_res, (char *)res);
462 stat = (cal->conn.stat == RPC_SUCCESS) ?
463 CSA_E_SERVICE_UNAVAILABLE :
464 _DtCm_clntstat_to_csastat(cal->conn.stat);
467 time_t start1, start2, end1, end2;
469 boolean_t no_start_time_range;
470 boolean_t no_end_time_range;
473 cms_attribute *hattrs;
476 _DtCm_libentry *entry;
478 /* hash the matching criteria */
479 if ((stat = _DtCmHashCriteria(cal->entry_tbl, num_attrs, attrs,
480 NULL, ops, &no_match, &no_start_time_range,
481 &no_end_time_range, &start1, &start2, &end1, &end2, &id,
482 &hnum, &hattrs, &hops)) == CSA_E_INVALID_ATTRIBUTE)
484 return (CSA_SUCCESS);
485 } else if (stat != CSA_SUCCESS || no_match == B_TRUE) {
489 if (id > 0 && no_start_time_range && no_end_time_range) {
490 /* get the key for the first event */
492 if ((stat = _DtCm_table_lookup_key_range(cal, NULL, id,
493 _DtCM_BOT, _DtCM_EOT, &key, NULL)) == CSA_SUCCESS &&
497 if ((stat = _DtCm_make_libentry(NULL, &entry))
501 if ((stat = _DtCm_table_lookup(cal,
502 entry)) == CSA_SUCCESS)
505 _DtCm_free_libentries(entry);
509 stat = _DtCm_table_lookup_range(cal, start1, start2,
510 no_end_time_range, end1, end2,
511 id, hnum, hattrs, hops, elist_r);
514 _DtCmFreeHashedArrays(hnum, hattrs, hops);
520 extern CSA_return_code
521 _DtCm_rpc_enumerate_sequence(
523 _DtCm_libentry *entry,
526 _DtCm_libentry **elist_r)
528 _DtCm_Client_Info *ci=NULL;
529 CSA_return_code stat = CSA_SUCCESS;
531 DP(("rpccalls.c: _DtCm_rpc_enumerate_sequence\n"));
534 return (CSA_E_INVALID_PARAMETER);
536 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
537 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
541 cal->conn.retry = B_TRUE;
545 if (ci->vers_out == TABLEVERS) {
546 cms_enumerate_args args;
547 cms_entries_res *res;
549 args.cal = cal->name;
550 args.id = entry->e->key.id;
554 res = cms_enumerate_sequence_5(&args, &cal->conn);
557 if ((stat = res->stat) == CSA_SUCCESS) {
558 stat = _DtCmCmsentriesToLibentries(
559 &cal->entry_tbl, res->entries, elist_r);
562 xdr_free((xdrproc_t)xdr_cms_entries_res, (char *)res);
564 stat = (cal->conn.stat == RPC_SUCCESS) ?
565 CSA_E_SERVICE_UNAVAILABLE :
566 _DtCm_clntstat_to_csastat(cal->conn.stat);
571 stat = _DtCm_table_lookup_key_range(cal, entry, 0, start, end,
578 extern CSA_return_code
579 _DtCm_rpc_lookup_entry_by_id(Calendar *cal, _DtCm_libentry *entry)
581 _DtCm_Client_Info *ci=NULL;
582 CSA_return_code stat = CSA_SUCCESS;
584 DP(("rpccalls.c: _DtCm_rpc_lookup_entry_by_id\n"));
587 return (CSA_E_INVALID_PARAMETER);
589 if ((stat = _DtCm_create_tcp_client(cal->location,
590 (cal->file_version < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
591 TABLEVERS_4 : TABLEVERS), _DtCM_LONG_TIMEOUT, &ci))
596 cal->conn.retry = B_TRUE;
598 if (ci->vers_out == TABLEVERS) {
599 cms_get_entry_attr_args args;
600 cms_get_entry_attr_res *res;
603 * the entry reference id is filled in already
604 * otherwise, we would not be in this routine
606 args.cal = cal->name;
608 args.keys = &entry->e->key;
612 res = cms_get_entry_attr_5(&args, &cal->conn);
616 if ((stat = res->entries->stat) == CSA_SUCCESS)
618 if ((stat = _DtCmUpdateAttributes(
619 res->entries->num_attrs,
621 &entry->e->num_attrs,
623 &cal->entry_tbl, B_FALSE,
624 NULL, B_TRUE)) == CSA_SUCCESS)
626 entry->filled = B_TRUE;
632 stat = (cal->conn.stat == RPC_SUCCESS) ?
633 CSA_E_SERVICE_UNAVAILABLE :
634 _DtCm_clntstat_to_csastat(cal->conn.stat);
637 if (res) xdr_free((xdrproc_t)xdr_cms_get_entry_attr_res, (char *)res);
640 stat = _DtCm_table_lookup(cal, entry);
646 extern CSA_return_code
647 _DtCm_rpc_get_cal_attrs(Calendar *cal, int index, CSA_uint32 num_names, char **names)
649 _DtCm_Client_Info *ci;
650 CSA_return_code stat = CSA_SUCCESS;
651 cms_attribute_value val;
653 DP(("rpccalls.c: _DtCm_rpc_get_cal_attrs\n"));
656 return (CSA_E_INVALID_PARAMETER);
658 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
659 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
664 cal->conn.retry = B_TRUE;
666 if (ci->vers_out == TABLEVERS) {
667 cms_get_cal_attr_args arg;
668 cms_get_cal_attr_res *res;
669 CSA_uint32 num_cmsnames;
670 cms_attr_name *cmsnames;
672 if ((stat = csa2cmsnames(num_names, names,
673 &num_cmsnames, &cmsnames)) != CSA_SUCCESS)
677 arg.num_names = num_cmsnames;
678 arg.names = cmsnames;
680 res = cms_get_calendar_attr_5(&arg, &cal->conn);
683 if ((stat = res->stat) == CSA_SUCCESS) {
684 if ((stat = _DtCmUpdateAttributes(
685 res->num_attrs, res->attrs, &cal->num_attrs,
686 &cal->attrs, &cal->cal_tbl, B_TRUE, NULL,
687 B_TRUE)) == CSA_SUCCESS)
688 cal->got_attrs = B_TRUE;
691 xdr_free((xdrproc_t)xdr_cms_get_cal_attr_res, (char *)res);
693 stat = (cal->conn.stat == RPC_SUCCESS) ?
694 CSA_E_SERVICE_UNAVAILABLE :
695 _DtCm_clntstat_to_csastat(cal->conn.stat);
700 case CSA_CAL_ATTR_ACCESS_LIST_I:
701 if ((stat = _DtCm_table_get_access(cal,
702 &val.item.access_list_value)) == CSA_SUCCESS) {
703 val.type = CSA_VALUE_ACCESS_LIST;
704 stat = _DtCmUpdateAccessListAttrVal(&val,
706 [CSA_CAL_ATTR_ACCESS_LIST_I].value);
707 _DtCm_free_cms_access_entry(val.item.\
712 case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
713 if ((stat = _DtCm_table_size(cal,
714 (int*)&val.item.uint32_value)) == CSA_SUCCESS) {
715 val.type = CSA_VALUE_UINT32;
716 stat = _DtCmUpdateSint32AttrVal(&val,
718 [CSA_CAL_ATTR_NUMBER_ENTRIES_I].value);
727 extern CSA_return_code
728 _DtCm_rpc_set_cal_attrs(Calendar *cal, CSA_uint32 num_attrs, CSA_attribute * attrs)
730 _DtCm_Client_Info *ci;
731 CSA_return_code stat = CSA_SUCCESS;
733 DP(("rpccalls.c: _DtCm_rpc_set_cal_attrs\n"));
735 if (cal == NULL || attrs == NULL)
736 return (CSA_E_INVALID_PARAMETER);
738 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
739 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
745 cal->conn.retry = B_FALSE;
747 if (ci->vers_out == TABLEVERS) {
748 CSA_return_code *res;
749 cms_set_cal_attr_args args;
750 CSA_uint32 num_cmsattrs;
751 cms_attribute *cmsattrs;
753 if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
754 &cmsattrs, NULL)) != CSA_SUCCESS)
757 if (num_cmsattrs == 0)
758 return (CSA_E_INVALID_PARAMETER);
760 args.cal = cal->name;
762 args.num_attrs = num_cmsattrs;
763 args.attrs = cmsattrs;
765 res = cms_set_calendar_attr_5(&args, &cal->conn);
767 free_cmsattrs(num_cmsattrs, cmsattrs);
771 if (stat == CSA_SUCCESS) {
772 _DtCm_free_cms_attribute_values(cal->num_attrs,
776 stat = (cal->conn.stat == RPC_SUCCESS) ?
777 CSA_E_SERVICE_UNAVAILABLE :
778 _DtCm_clntstat_to_csastat(cal->conn.stat);
785 * CSA_CAL_ATTR_ACCESS_LIST is the only settable attribute
787 for (i = num_attrs - 1; i >= 0; i--) {
791 if (attrs[i].value == NULL)
792 stat = _DtCm_table_set_access(cal, NULL);
794 stat = _DtCm_table_set_access(cal,
795 attrs[i].value->item.access_list_value);
801 extern CSA_return_code
802 _DtCm_rpc_insert_entry(
804 CSA_uint32 num_attrs,
805 CSA_attribute * attrs,
806 _DtCm_libentry **entry_r)
808 _DtCm_Client_Info *ci = NULL;
809 CSA_return_code stat = CSA_SUCCESS;
811 DP(("rpccalls.c: _DtCm_rpc_insert_entry;\n"));
813 if (cal == NULL || num_attrs == 0 || attrs == NULL || entry_r == NULL)
814 return (CSA_E_INVALID_PARAMETER);
816 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
817 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
822 cal->conn.retry = B_FALSE;
824 if (ci->vers_out == TABLEVERS) {
826 cms_insert_args args;
827 CSA_uint32 num_cmsattrs;
828 cms_attribute *cmsattrs;
830 if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
831 &cmsattrs, NULL)) != CSA_SUCCESS)
834 if (num_cmsattrs == 0)
835 return (CSA_E_INVALID_PARAMETER);
837 args.cal = cal->name;
839 args.num_attrs = num_cmsattrs;
840 args.attrs = cmsattrs;
842 res = cms_insert_entry_5(&args, &cal->conn);
844 free_cmsattrs(num_cmsattrs, cmsattrs);
847 if ((stat = res->stat) == CSA_SUCCESS) {
848 stat = _DtCmCmsentriesToLibentries(
849 &cal->entry_tbl, res->entry, entry_r);
852 xdr_free((xdrproc_t)xdr_cms_entry_res, (char *)res);
854 stat = (cal->conn.stat == RPC_SUCCESS) ?
855 CSA_E_SERVICE_UNAVAILABLE :
856 _DtCm_clntstat_to_csastat(cal->conn.stat);
861 stat = _DtCm_table_insert(cal, num_attrs, attrs, entry_r);
867 extern CSA_return_code
868 _DtCm_rpc_update_entry(
870 _DtCm_libentry *oentry,
871 CSA_uint32 num_attrs,
872 CSA_attribute * attrs,
874 _DtCm_libentry **nentry)
876 _DtCm_Client_Info *ci = NULL;
877 CSA_return_code stat = CSA_SUCCESS;
879 DP(("rpccalls.c: _DtCm_rpc_update_entry\n"));
881 if (cal == NULL || oentry == NULL)
882 return (CSA_E_INVALID_PARAMETER);
884 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
885 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
890 cal->conn.retry = B_FALSE;
892 if (ci->vers_out == TABLEVERS) {
894 cms_update_args args;
895 CSA_uint32 num_cmsattrs;
896 cms_attribute *cmsattrs;
898 if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
899 &cmsattrs, NULL)) != CSA_SUCCESS)
902 if (num_cmsattrs == 0)
903 return (CSA_E_INVALID_PARAMETER);
905 args.cal = cal->name;
907 args.entry = oentry->e->key;
909 args.num_attrs = num_cmsattrs;
910 args.attrs = cmsattrs;
912 res = cms_update_entry_5(&args, &cal->conn);
914 free_cmsattrs(num_cmsattrs, cmsattrs);
917 if ((stat = res->stat) == CSA_SUCCESS) {
918 stat = _DtCmCmsentriesToLibentries(
919 &cal->entry_tbl, res->entry, nentry);
922 xdr_free((xdrproc_t)xdr_cms_entry_res, (char *)res);
924 stat = (cal->conn.stat == RPC_SUCCESS) ?
925 CSA_E_SERVICE_UNAVAILABLE :
926 _DtCm_clntstat_to_csastat(cal->conn.stat);
931 stat = _DtCm_table_update(cal, oentry, num_attrs, attrs,
939 extern CSA_return_code
940 _DtCm_rpc_delete_entry(
942 _DtCm_libentry *entry,
945 _DtCm_Client_Info *ci = NULL;
946 CSA_return_code stat = CSA_SUCCESS;
948 DP(("rpccalls.c: _DtCm_rpc_delete_entry\n"));
950 if (cal == NULL || entry == NULL)
951 return (CSA_E_INVALID_PARAMETER);
953 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
954 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
959 cal->conn.retry = B_FALSE;
961 if (ci->vers_out == TABLEVERS) {
962 CSA_return_code *res;
963 cms_delete_args args;
965 args.cal = cal->name;
967 args.entry = entry->e->key;
970 res = cms_delete_entry_5(&args, &cal->conn);
975 stat = (cal->conn.stat == RPC_SUCCESS) ?
976 CSA_E_SERVICE_UNAVAILABLE :
977 _DtCm_clntstat_to_csastat(cal->conn.stat);
982 stat = _DtCm_table_delete(cal, entry, scope);
988 extern CSA_return_code
989 _DtCm_rpc_list_calendar_attributes(
991 CSA_uint32 *number_names,
994 _DtCm_Client_Info *ci = NULL;
995 CSA_return_code stat = CSA_SUCCESS;
997 DP(("rpccalls.c: _DtCm_rpc_list_calendar_attributes\n"));
1000 return (CSA_E_INVALID_PARAMETER);
1002 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
1003 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
1007 cal->conn.retry = B_TRUE;
1009 if (ci->vers_out == TABLEVERS) {
1010 cms_enumerate_calendar_attr_res *res;
1017 res = cms_enumerate_calendar_attr_5(&cal->name, &cal->conn);
1020 if ((stat = res->stat) == CSA_SUCCESS && res->num_names)
1022 if (names = _DtCm_alloc_character_pointers(
1024 for (i = 0; i < res->num_names; i++) {
1025 if ((names[i] = strdup(
1026 res->names[i].name))
1029 return (CSA_E_INSUFFICIENT_MEMORY);
1032 *number_names = res->num_names;
1037 stat = (cal->conn.stat == RPC_SUCCESS) ?
1038 CSA_E_SERVICE_UNAVAILABLE :
1039 _DtCm_clntstat_to_csastat(cal->conn.stat);
1044 stat = CSA_E_NOT_SUPPORTED;
1050 extern CSA_return_code
1051 _DtCm_rpc_list_calendars(
1053 CSA_uint32 *number_names,
1054 CSA_calendar_user **names_r)
1056 _DtCm_Client_Info *ci = NULL;
1057 CSA_return_code stat = CSA_SUCCESS;
1058 _DtCm_Connection conn;
1060 DP(("rpccalls.c: _DtCm_rpc_list_calendars\n"));
1062 if ((stat = _DtCm_create_tcp_client(location, TABLEVERS,
1063 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
1067 conn.retry = B_TRUE;
1069 if (ci->vers_out == TABLEVERS) {
1070 cms_list_calendars_res *res;
1071 CSA_calendar_user *names;
1077 res = cms_list_calendars_5(NULL, &conn);
1080 if ((stat = res->stat) == CSA_SUCCESS && res->num_names)
1082 if (names = _DtCm_alloc_calendar_users(
1084 for (i = 0; i < res->num_names; i++) {
1085 if ((names[i].calendar_address =
1086 strdup(res->names[i]))
1089 return (CSA_E_INSUFFICIENT_MEMORY);
1092 *number_names = res->num_names;
1097 stat = (conn.stat == RPC_SUCCESS) ?
1098 CSA_E_SERVICE_UNAVAILABLE :
1099 _DtCm_clntstat_to_csastat(conn.stat);
1104 stat = CSA_E_NOT_SUPPORTED;
1110 extern CSA_return_code
1111 _DtCm_do_unregistration(
1112 _DtCm_Connection *conn,
1114 unsigned long update_type)
1116 CSA_return_code stat;
1118 if (conn->ci->vers_out == TABLEVERS) {
1119 cms_register_args args;
1120 CSA_return_code *res;
1123 args.update_type = update_type;
1124 args.prognum = _DtCm_transient;
1125 args.versnum = AGENTVERS_2;
1126 args.procnum = update_callback;
1127 args.pid = getpid();
1129 res = cms_unregister_5(&args, conn);
1134 stat = (conn->stat == RPC_SUCCESS) ?
1135 CSA_E_SERVICE_UNAVAILABLE :
1136 _DtCm_clntstat_to_csastat(conn->stat);
1139 stat = _DtCm_table_unregister_target(conn, cal);
1142 if (stat == CSA_SUCCESS)
1143 _DtCm_remove_registration(conn->ci, cal);
1148 extern CSA_return_code
1149 _DtCm_do_registration(
1150 _DtCm_Connection *conn,
1152 unsigned long update_type)
1154 CSA_return_code stat;
1156 if (conn->ci->vers_out == TABLEVERS) {
1157 cms_register_args args;
1158 CSA_return_code *res;
1161 args.update_type = update_type;
1162 args.prognum = _DtCm_transient;
1163 args.versnum = AGENTVERS_2;
1164 args.procnum = update_callback;
1165 args.pid = getpid();
1167 res = cms_register_5(&args, conn);
1172 stat = (conn->stat == RPC_SUCCESS) ?
1173 CSA_E_SERVICE_UNAVAILABLE :
1174 _DtCm_clntstat_to_csastat(conn->stat);
1178 stat = _DtCm_table_register_target(conn, cal);
1181 if (stat == CSA_SUCCESS) {
1182 if ((stat = _DtCm_add_registration(conn->ci, cal, update_type))
1184 (void) _DtCm_do_unregistration(conn, cal, update_type);
1191 /*****************************************************************************
1192 * static functions used within the file
1193 *****************************************************************************/
1196 * Newnum is initialized to 0 and newattrs to NULL when num_attrs == 0
1198 static CSA_return_code
1200 CSA_uint32 num_attrs,
1201 CSA_attribute *csaattrs,
1204 cms_attribute **newattrs,
1207 CSA_return_code stat = CSA_SUCCESS;
1208 cms_attribute *cmsattrs;
1210 CSA_reminder *rptr1, *rptr2;
1215 if (newops) *newops = NULL;
1220 if ((cmsattrs = calloc(1, sizeof(cms_attribute)*num_attrs)) == NULL)
1221 return (CSA_E_INSUFFICIENT_MEMORY);
1223 if (newops && (ops_r = malloc(sizeof(CSA_enum)*num_attrs)) == NULL) {
1225 return (CSA_E_INSUFFICIENT_MEMORY);
1228 for (i = 0, j = 0; i < num_attrs && stat == CSA_SUCCESS; i++) {
1229 if (csaattrs[i].name == NULL)
1233 ops_r[j] = (ops ? ops[i] : CSA_MATCH_EQUAL_TO);
1235 cmsattrs[j].name.name = csaattrs[i].name;
1236 if (csaattrs[i].value == NULL) {
1241 if ((cmsattrs[j].value = (cms_attribute_value *)malloc(
1242 sizeof(cms_attribute_value))) == NULL) {
1243 stat = CSA_E_INSUFFICIENT_MEMORY;
1247 cmsattrs[j].value->type = csaattrs[i].value->type;
1249 switch (csaattrs[i].value->type) {
1250 case CSA_VALUE_ACCESS_LIST:
1251 stat = _DtCm_csa2cms_access_list(
1252 csaattrs[i].value->item.access_list_value,
1253 &cmsattrs[j].value->item.access_list_value);
1255 case CSA_VALUE_CALENDAR_USER:
1256 if (csaattrs[i].value->item.calendar_user_value &&
1257 csaattrs[i].value->item.calendar_user_value->\
1260 cmsattrs[j].value->item.calendar_user_value =
1261 csaattrs[i].value->item.\
1262 calendar_user_value->user_name;
1264 cmsattrs[j].value->item.calendar_user_value =
1268 case CSA_VALUE_STRING:
1269 case CSA_VALUE_DATE_TIME:
1270 case CSA_VALUE_DATE_TIME_RANGE:
1271 case CSA_VALUE_TIME_DURATION:
1272 if (csaattrs[i].value->item.string_value) {
1273 cmsattrs[j].value->item.string_value =
1274 csaattrs[i].value->item.string_value;
1276 cmsattrs[j].value->item.string_value = nullstr;
1279 case CSA_VALUE_REMINDER:
1280 if ((rptr1 = csaattrs[i].value->item.reminder_value) &&
1281 (rptr2 = (CSA_reminder *)malloc(sizeof(CSA_reminder))))
1283 rptr2->lead_time = rptr1->lead_time ?
1284 rptr1->lead_time : nullstr;
1285 rptr2->snooze_time = rptr1->snooze_time ?
1286 rptr1->snooze_time:nullstr;
1287 rptr2->repeat_count = rptr1->repeat_count;
1288 rptr2->reminder_data = rptr1->reminder_data;
1289 cmsattrs[j].value->item.reminder_value = rptr2;
1290 } else if (rptr1 && rptr2 == NULL)
1291 stat = CSA_E_INSUFFICIENT_MEMORY;
1294 /* all other value types uses the same type
1295 * of data, so we just copy the value/address of
1298 cmsattrs[j].value->item.sint32_value =
1299 csaattrs[i].value->item.sint32_value;
1304 if (stat != CSA_SUCCESS) {
1306 free_cmsattrs(num_attrs, cmsattrs);
1307 if (newops) free(ops_r);
1311 *newattrs = cmsattrs;
1312 if (newops) *newops = ops_r;
1315 if (newops) free(ops_r);
1322 free_cmsattrs(CSA_uint32 num_attrs, cms_attribute *attrs)
1326 for (i = 0; i < num_attrs; i++) {
1327 if (attrs[i].value == NULL)
1330 switch (attrs[i].value->type) {
1331 case CSA_VALUE_ACCESS_LIST:
1332 _DtCm_free_cms_access_entry(
1333 attrs[i].value->item.access_list_value);
1335 case CSA_VALUE_REMINDER:
1336 if (attrs[i].value->item.reminder_value)
1337 free(attrs[i].value->item.reminder_value);
1341 free(attrs[i].value);
1347 * Newnum is initialized to 0 and newattrs to NULL when num_attrs == 0
1349 static CSA_return_code
1351 CSA_uint32 num_names,
1352 char **reminder_names,
1354 cms_attr_name **newnames)
1356 cms_attr_name *cmsnames;
1363 return (CSA_SUCCESS);
1365 if ((cmsnames = calloc(1, sizeof(cms_attr_name)*num_names)) == NULL)
1366 return (CSA_E_INSUFFICIENT_MEMORY);
1368 for (i = 0, j = 0; i < num_names; i++) {
1369 if (reminder_names[i] == NULL)
1372 cmsnames[j].name = reminder_names[i];
1379 *newnames = cmsnames;
1383 return (CSA_SUCCESS);
1387 * It is an old server and so we need to determine whether the user
1388 * is the calendar owner ourselves.
1389 * If the calendar name is the same as a user name, then that user
1390 * is the owner, and we just need to make sure the calendar is located
1391 * in the same domain as ours. If the calendar is located in another
1392 * domain and since we can't do cross domain authentication yet, to be save
1393 * we assume that the user is not the owner.
1394 * If the calendar name is not a user name, we need to make an rpc call
1395 * (table_set_access) to test whether the user is the owner.
1397 static CSA_return_code
1398 _GetV4UserAccess(Calendar *cal, cms_access_entry *alist)
1400 CSA_return_code stat = CSA_SUCCESS;
1401 char *user = _DtCmGetUserName();
1402 char *localhost = _DtCmGetHostAtDomain();
1405 int worldaccess = 0, useraccess = 0;
1406 boolean_t isowner = B_FALSE;
1408 /* first check if user is owner */
1409 if (ptr = strchr(cal->name, '@')) *ptr = '\0';
1411 if (_DtCmIsUserName(cal->name) == B_TRUE) {
1412 if (strcmp(user, cal->name) == 0) {
1413 /* check whether calendar location is in
1416 if (dom = strchr(cal->location, '.')) dom++;
1417 if (dom == NULL || _DtCmIsSamePath(
1418 _DtCmGetLocalDomain(NULL), dom) == B_TRUE)
1422 CSA_access_rights *csalist;
1424 /* need to test whether the user is the owner */
1425 if ((stat = _DtCm_cms2csa_access_list(alist, &csalist))
1428 stat = _DtCm_table_set_access(cal, csalist);
1429 _DtCm_free_csa_access_list(csalist);
1431 if (stat == CSA_SUCCESS)
1433 else if (stat == CSA_E_NO_AUTHORITY) {
1439 if (ptr) *ptr = '@';
1440 if (stat != CSA_SUCCESS)
1444 cal->access = CSA_OWNER_RIGHTS;
1445 return (CSA_SUCCESS);
1448 snprintf(buf, sizeof buf, "%s@%s", user, localhost);
1449 for (; alist != NULL; alist = alist->next) {
1450 if (strcasecmp(alist->user, "world") == 0)
1451 worldaccess = alist->rights;
1452 else if (_DtCmIsSameUser(buf, alist->user)) {
1453 useraccess = alist->rights;
1458 cal->access = useraccess | worldaccess;
1459 return (CSA_SUCCESS);