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 librararies 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;
226 /* check to make sure user is not creating a calendar
227 * using another user's name
229 if (ptr = strchr(cal->name, '@')) *ptr = NULL;
230 if (_DtCmIsUserName(cal->name) == B_TRUE) {
232 if ((owner = _DtCmGetUserName()) == NULL)
233 stat = CSA_E_FAILURE;
235 if (strcmp(cal->name, owner))
236 stat = CSA_E_NO_AUTHORITY;
238 stat = CSA_E_INVALID_PARAMETER;
242 * for v2 and v3 servers, calling a lookup routine has
243 * the side effect of having a calendar created
246 if (stat == CSA_SUCCESS &&
247 (stat = _DtCm_table_lookup_range(cal, 0, 0, B_TRUE, 0, 0,
248 0, 0, NULL, NULL, &entries)) == CSA_SUCCESS) {
249 if (entries) _DtCm_free_libentries(entries);
255 extern CSA_return_code
256 _DtCm_rpc_delete_calendar(Calendar *cal)
258 CSA_return_code stat;
259 _DtCm_Client_Info *ci;
261 DP(("rpccalls.c: _DtCm_rpc_delete_calendar\n"));
264 return (CSA_E_INVALID_PARAMETER);
266 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
267 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
272 cal->conn.retry = B_FALSE;
274 if (ci->vers_out == TABLEVERS) {
276 CSA_return_code *res;
281 res = cms_remove_calendar_5(&arg, &cal->conn);
286 stat = (cal->conn.stat == RPC_SUCCESS) ?
287 CSA_E_SERVICE_UNAVAILABLE :
288 _DtCm_clntstat_to_csastat(cal->conn.stat);
291 stat = CSA_E_NOT_SUPPORTED;
296 extern CSA_return_code
297 _DtCm_rpc_register_client(Calendar *cal, unsigned long update_type)
299 CSA_return_code stat;
300 _DtCm_Client_Info *ci = NULL;
302 DP(("rpccalls.c: _DtCm_rpc_register_client\n"));
305 return (CSA_E_INVALID_PARAMETER);
307 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
308 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
313 cal->conn.retry = B_TRUE;
315 return (_DtCm_do_registration(&cal->conn, cal->name, update_type));
318 extern CSA_return_code
319 _DtCm_rpc_unregister_client(Calendar *cal, unsigned long update_type)
321 CSA_return_code stat;
322 _DtCm_Client_Info *ci = NULL;
324 DP(("rpccalls.c: _DtCm_rpc_unregister_client\n"));
327 return (CSA_E_INVALID_PARAMETER);
329 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
330 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
335 cal->conn.retry = B_TRUE;
337 return (_DtCm_do_unregistration(&cal->conn, cal->name, update_type));
340 extern CSA_return_code
341 _DtCm_rpc_lookup_reminder(
344 CSA_uint32 num_names,
345 char **reminder_names,
346 CSA_uint32 *num_rems,
347 CSA_reminder_reference **rems)
349 _DtCm_Client_Info *ci=NULL;
350 CSA_return_code stat = CSA_SUCCESS;
352 DP(("rpccalls.c: _DtCm_rpc_lookup_reminder\n"));
354 if (cal == NULL || num_rems == 0 || rems == NULL)
355 return (CSA_E_INVALID_PARAMETER);
357 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
358 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
362 cal->conn.retry = B_TRUE;
364 if (ci->vers_out == TABLEVERS) {
365 cms_reminder_args args;
366 cms_reminder_res *res;
367 CSA_uint32 num_cmsnames;
368 cms_attr_name *cmsnames;
370 if ((stat = csa2cmsnames(num_names, reminder_names,
371 &num_cmsnames, &cmsnames)) != CSA_SUCCESS)
374 args.cal = cal->name;
376 args.num_names = num_cmsnames;
377 args.names = cmsnames;
379 res = cms_lookup_reminder_5(&args, &cal->conn);
385 if ((stat = res->stat) == CSA_SUCCESS)
386 stat = _DtCm_cms2csa_reminder_ref(res->rems,
389 stat = (cal->conn.stat == RPC_SUCCESS) ?
390 CSA_E_SERVICE_UNAVAILABLE :
391 _DtCm_clntstat_to_csastat(cal->conn.stat);
395 stat = _DtCm_table_lookup_reminder(cal, num_names,
396 reminder_names, num_rems, rems);
403 * Lookup calendar entries.
404 * If it's an old server, will try to match the attributes in the library;
405 * but if attrlist contains attributes not supported by the old backend,
406 * will just return CSA_E_UNSUPPORTED_ATTRIBUTE.
408 extern CSA_return_code
409 _DtCm_rpc_lookup_entries(
411 CSA_uint32 num_attrs,
412 CSA_attribute * attrs,
414 _DtCm_libentry **elist_r)
416 _DtCm_Client_Info *ci=NULL;
417 CSA_return_code stat = CSA_SUCCESS;
419 DP(("rpccalls.c: _DtCm_rpc_lookup_entries\n"));
422 return (CSA_E_INVALID_PARAMETER);
424 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
425 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
429 cal->conn.retry = B_TRUE;
433 if (ci->vers_out == TABLEVERS) {
434 cms_lookup_entries_args args;
435 cms_entries_res *res;
436 CSA_uint32 num_cmsattrs;
437 cms_attribute *cmsattrs;
440 if ((stat = csa2cmsattrs(num_attrs, attrs, ops, &num_cmsattrs,
441 &cmsattrs, &newops)) != CSA_SUCCESS)
444 args.cal = cal->name;
445 args.char_set = nullstr;
446 args.num_attrs = num_cmsattrs;
447 args.attrs = cmsattrs;
450 res = cms_lookup_entries_5(&args, &cal->conn);
452 free_cmsattrs(num_cmsattrs, cmsattrs);
453 if (newops) free(newops);
456 if ((stat = res->stat) == CSA_SUCCESS) {
457 stat = _DtCmCmsentriesToLibentries(
458 &cal->entry_tbl, res->entries, elist_r);
461 xdr_free((xdrproc_t)xdr_cms_entries_res, (char *)res);
463 stat = (cal->conn.stat == RPC_SUCCESS) ?
464 CSA_E_SERVICE_UNAVAILABLE :
465 _DtCm_clntstat_to_csastat(cal->conn.stat);
468 time_t start1, start2, end1, end2;
470 boolean_t no_start_time_range;
471 boolean_t no_end_time_range;
474 cms_attribute *hattrs;
477 _DtCm_libentry *entry;
479 /* hash the matching criteria */
480 if ((stat = _DtCmHashCriteria(cal->entry_tbl, num_attrs, attrs,
481 NULL, ops, &no_match, &no_start_time_range,
482 &no_end_time_range, &start1, &start2, &end1, &end2, &id,
483 &hnum, &hattrs, &hops)) == CSA_E_INVALID_ATTRIBUTE)
485 return (CSA_SUCCESS);
486 } else if (stat != CSA_SUCCESS || no_match == B_TRUE) {
490 if (id > 0 && no_start_time_range && no_end_time_range) {
491 /* get the key for the first event */
493 if ((stat = _DtCm_table_lookup_key_range(cal, NULL, id,
494 _DtCM_BOT, _DtCM_EOT, &key, NULL)) == CSA_SUCCESS &&
498 if ((stat = _DtCm_make_libentry(NULL, &entry))
502 if ((stat = _DtCm_table_lookup(cal,
503 entry)) == CSA_SUCCESS)
506 _DtCm_free_libentries(entry);
510 stat = _DtCm_table_lookup_range(cal, start1, start2,
511 no_end_time_range, end1, end2,
512 id, hnum, hattrs, hops, elist_r);
515 _DtCmFreeHashedArrays(hnum, hattrs, hops);
521 extern CSA_return_code
522 _DtCm_rpc_enumerate_sequence(
524 _DtCm_libentry *entry,
527 _DtCm_libentry **elist_r)
529 _DtCm_Client_Info *ci=NULL;
530 CSA_return_code stat = CSA_SUCCESS;
533 DP(("rpccalls.c: _DtCm_rpc_enumerate_sequence\n"));
536 return (CSA_E_INVALID_PARAMETER);
538 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
539 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
543 cal->conn.retry = B_TRUE;
547 if (ci->vers_out == TABLEVERS) {
548 cms_enumerate_args args;
549 cms_entries_res *res;
551 args.cal = cal->name;
552 args.id = entry->e->key.id;
556 res = cms_enumerate_sequence_5(&args, &cal->conn);
559 if ((stat = res->stat) == CSA_SUCCESS) {
560 stat = _DtCmCmsentriesToLibentries(
561 &cal->entry_tbl, res->entries, elist_r);
564 xdr_free((xdrproc_t)xdr_cms_entries_res, (char *)res);
566 stat = (cal->conn.stat == RPC_SUCCESS) ?
567 CSA_E_SERVICE_UNAVAILABLE :
568 _DtCm_clntstat_to_csastat(cal->conn.stat);
573 stat = _DtCm_table_lookup_key_range(cal, entry, 0, start, end,
580 extern CSA_return_code
581 _DtCm_rpc_lookup_entry_by_id(Calendar *cal, _DtCm_libentry *entry)
583 _DtCm_Client_Info *ci=NULL;
584 CSA_return_code stat = CSA_SUCCESS;
587 DP(("rpccalls.c: _DtCm_rpc_lookup_entry_by_id\n"));
590 return (CSA_E_INVALID_PARAMETER);
592 if ((stat = _DtCm_create_tcp_client(cal->location,
593 (cal->file_version < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
594 TABLEVERS_4 : TABLEVERS), _DtCM_LONG_TIMEOUT, &ci))
599 cal->conn.retry = B_TRUE;
601 if (ci->vers_out == TABLEVERS) {
602 cms_get_entry_attr_args args;
603 cms_get_entry_attr_res *res;
606 * the entry reference id is filled in already
607 * otherwise, we would not be in this routine
609 args.cal = cal->name;
611 args.keys = &entry->e->key;
615 res = cms_get_entry_attr_5(&args, &cal->conn);
619 if ((stat = res->entries->stat) == CSA_SUCCESS)
621 if ((stat = _DtCmUpdateAttributes(
622 res->entries->num_attrs,
624 &entry->e->num_attrs,
626 &cal->entry_tbl, B_FALSE,
627 NULL, B_TRUE)) == CSA_SUCCESS)
629 entry->filled = B_TRUE;
635 stat = (cal->conn.stat == RPC_SUCCESS) ?
636 CSA_E_SERVICE_UNAVAILABLE :
637 _DtCm_clntstat_to_csastat(cal->conn.stat);
640 if (res) xdr_free((xdrproc_t)xdr_cms_get_entry_attr_res, (char *)res);
643 stat = _DtCm_table_lookup(cal, entry);
649 extern CSA_return_code
650 _DtCm_rpc_get_cal_attrs(Calendar *cal, int index, CSA_uint32 num_names, char **names)
652 _DtCm_Client_Info *ci;
653 CSA_return_code stat = CSA_SUCCESS;
654 cms_attribute_value val;
656 DP(("rpccalls.c: _DtCm_rpc_get_cal_attrs\n"));
659 return (CSA_E_INVALID_PARAMETER);
661 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
662 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
667 cal->conn.retry = B_TRUE;
669 if (ci->vers_out == TABLEVERS) {
670 cms_get_cal_attr_args arg;
671 cms_get_cal_attr_res *res;
672 CSA_uint32 num_cmsnames;
673 cms_attr_name *cmsnames;
675 if ((stat = csa2cmsnames(num_names, names,
676 &num_cmsnames, &cmsnames)) != CSA_SUCCESS)
680 arg.num_names = num_cmsnames;
681 arg.names = cmsnames;
683 res = cms_get_calendar_attr_5(&arg, &cal->conn);
686 if ((stat = res->stat) == CSA_SUCCESS) {
687 if ((stat = _DtCmUpdateAttributes(
688 res->num_attrs, res->attrs, &cal->num_attrs,
689 &cal->attrs, &cal->cal_tbl, B_TRUE, NULL,
690 B_TRUE)) == CSA_SUCCESS)
691 cal->got_attrs = B_TRUE;
694 xdr_free((xdrproc_t)xdr_cms_get_cal_attr_res, (char *)res);
696 stat = (cal->conn.stat == RPC_SUCCESS) ?
697 CSA_E_SERVICE_UNAVAILABLE :
698 _DtCm_clntstat_to_csastat(cal->conn.stat);
703 case CSA_CAL_ATTR_ACCESS_LIST_I:
704 if ((stat = _DtCm_table_get_access(cal,
705 &val.item.access_list_value)) == CSA_SUCCESS) {
706 val.type = CSA_VALUE_ACCESS_LIST;
707 stat = _DtCmUpdateAccessListAttrVal(&val,
709 [CSA_CAL_ATTR_ACCESS_LIST_I].value);
710 _DtCm_free_cms_access_entry(val.item.\
715 case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
716 if ((stat = _DtCm_table_size(cal,
717 (int*)&val.item.uint32_value)) == CSA_SUCCESS) {
718 val.type = CSA_VALUE_UINT32;
719 stat = _DtCmUpdateSint32AttrVal(&val,
721 [CSA_CAL_ATTR_NUMBER_ENTRIES_I].value);
730 extern CSA_return_code
731 _DtCm_rpc_set_cal_attrs(Calendar *cal, CSA_uint32 num_attrs, CSA_attribute * attrs)
733 _DtCm_Client_Info *ci;
734 CSA_return_code stat = CSA_SUCCESS;
737 DP(("rpccalls.c: _DtCm_rpc_set_cal_attrs\n"));
739 if (cal == NULL || attrs == NULL)
740 return (CSA_E_INVALID_PARAMETER);
742 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
743 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
749 cal->conn.retry = B_FALSE;
751 if (ci->vers_out == TABLEVERS) {
752 CSA_return_code *res;
753 cms_set_cal_attr_args args;
754 CSA_uint32 num_cmsattrs;
755 cms_attribute *cmsattrs;
757 if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
758 &cmsattrs, NULL)) != CSA_SUCCESS)
761 if (num_cmsattrs == 0)
762 return (CSA_E_INVALID_PARAMETER);
764 args.cal = cal->name;
766 args.num_attrs = num_cmsattrs;
767 args.attrs = cmsattrs;
769 res = cms_set_calendar_attr_5(&args, &cal->conn);
771 free_cmsattrs(num_cmsattrs, cmsattrs);
775 if (stat == CSA_SUCCESS) {
776 _DtCm_free_cms_attribute_values(cal->num_attrs,
780 stat = (cal->conn.stat == RPC_SUCCESS) ?
781 CSA_E_SERVICE_UNAVAILABLE :
782 _DtCm_clntstat_to_csastat(cal->conn.stat);
789 * CSA_CAL_ATTR_ACCESS_LIST is the only settable attribute
791 for (i = num_attrs - 1; i >= 0; i--) {
795 if (attrs[i].value == NULL)
796 stat = _DtCm_table_set_access(cal, NULL);
798 stat = _DtCm_table_set_access(cal,
799 attrs[i].value->item.access_list_value);
805 extern CSA_return_code
806 _DtCm_rpc_insert_entry(
808 CSA_uint32 num_attrs,
809 CSA_attribute * attrs,
810 _DtCm_libentry **entry_r)
812 _DtCm_Client_Info *ci = NULL;
813 CSA_return_code stat = CSA_SUCCESS;
815 DP(("rpccalls.c: _DtCm_rpc_insert_entry;\n"));
817 if (cal == NULL || num_attrs == 0 || attrs == NULL || entry_r == NULL)
818 return (CSA_E_INVALID_PARAMETER);
820 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
821 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
826 cal->conn.retry = B_FALSE;
828 if (ci->vers_out == TABLEVERS) {
830 cms_insert_args args;
831 CSA_uint32 num_cmsattrs;
832 cms_attribute *cmsattrs;
834 if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
835 &cmsattrs, NULL)) != CSA_SUCCESS)
838 if (num_cmsattrs == 0)
839 return (CSA_E_INVALID_PARAMETER);
841 args.cal = cal->name;
843 args.num_attrs = num_cmsattrs;
844 args.attrs = cmsattrs;
846 res = cms_insert_entry_5(&args, &cal->conn);
848 free_cmsattrs(num_cmsattrs, cmsattrs);
851 if ((stat = res->stat) == CSA_SUCCESS) {
852 stat = _DtCmCmsentriesToLibentries(
853 &cal->entry_tbl, res->entry, entry_r);
856 xdr_free((xdrproc_t)xdr_cms_entry_res, (char *)res);
858 stat = (cal->conn.stat == RPC_SUCCESS) ?
859 CSA_E_SERVICE_UNAVAILABLE :
860 _DtCm_clntstat_to_csastat(cal->conn.stat);
865 stat = _DtCm_table_insert(cal, num_attrs, attrs, entry_r);
871 extern CSA_return_code
872 _DtCm_rpc_update_entry(
874 _DtCm_libentry *oentry,
875 CSA_uint32 num_attrs,
876 CSA_attribute * attrs,
878 _DtCm_libentry **nentry)
880 _DtCm_Client_Info *ci = NULL;
881 CSA_return_code stat = CSA_SUCCESS;
882 _DtCm_libentry *hptr = NULL, *tptr, *cptr;
885 DP(("rpccalls.c: _DtCm_rpc_update_entry\n"));
887 if (cal == NULL || oentry == NULL)
888 return (CSA_E_INVALID_PARAMETER);
890 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
891 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
896 cal->conn.retry = B_FALSE;
898 if (ci->vers_out == TABLEVERS) {
900 cms_update_args args;
901 CSA_uint32 num_cmsattrs;
902 cms_attribute *cmsattrs;
904 if ((stat = csa2cmsattrs(num_attrs, attrs, NULL, &num_cmsattrs,
905 &cmsattrs, NULL)) != CSA_SUCCESS)
908 if (num_cmsattrs == 0)
909 return (CSA_E_INVALID_PARAMETER);
911 args.cal = cal->name;
913 args.entry = oentry->e->key;
915 args.num_attrs = num_cmsattrs;
916 args.attrs = cmsattrs;
918 res = cms_update_entry_5(&args, &cal->conn);
920 free_cmsattrs(num_cmsattrs, cmsattrs);
923 if ((stat = res->stat) == CSA_SUCCESS) {
924 stat = _DtCmCmsentriesToLibentries(
925 &cal->entry_tbl, res->entry, nentry);
928 xdr_free((xdrproc_t)xdr_cms_entry_res, (char *)res);
930 stat = (cal->conn.stat == RPC_SUCCESS) ?
931 CSA_E_SERVICE_UNAVAILABLE :
932 _DtCm_clntstat_to_csastat(cal->conn.stat);
937 stat = _DtCm_table_update(cal, oentry, num_attrs, attrs,
945 extern CSA_return_code
946 _DtCm_rpc_delete_entry(
948 _DtCm_libentry *entry,
951 _DtCm_Client_Info *ci = NULL;
952 CSA_return_code stat = CSA_SUCCESS;
954 DP(("rpccalls.c: _DtCm_rpc_delete_entry\n"));
956 if (cal == NULL || entry == NULL)
957 return (CSA_E_INVALID_PARAMETER);
959 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
960 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS)
965 cal->conn.retry = B_FALSE;
967 if (ci->vers_out == TABLEVERS) {
968 CSA_return_code *res;
969 cms_delete_args args;
971 args.cal = cal->name;
973 args.entry = entry->e->key;
976 res = cms_delete_entry_5(&args, &cal->conn);
981 stat = (cal->conn.stat == RPC_SUCCESS) ?
982 CSA_E_SERVICE_UNAVAILABLE :
983 _DtCm_clntstat_to_csastat(cal->conn.stat);
988 stat = _DtCm_table_delete(cal, entry, scope);
994 extern CSA_return_code
995 _DtCm_rpc_list_calendar_attributes(
997 CSA_uint32 *number_names,
1000 _DtCm_Client_Info *ci = NULL;
1001 CSA_return_code stat = CSA_SUCCESS;
1003 DP(("rpccalls.c: _DtCm_rpc_list_calendar_attributes\n"));
1006 return (CSA_E_INVALID_PARAMETER);
1008 if ((stat = _DtCm_create_tcp_client(cal->location, TABLEVERS,
1009 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
1013 cal->conn.retry = B_TRUE;
1015 if (ci->vers_out == TABLEVERS) {
1016 cms_enumerate_calendar_attr_res *res;
1023 res = cms_enumerate_calendar_attr_5(&cal->name, &cal->conn);
1026 if ((stat = res->stat) == CSA_SUCCESS && res->num_names)
1028 if (names = _DtCm_alloc_character_pointers(
1030 for (i = 0; i < res->num_names; i++) {
1031 if ((names[i] = strdup(
1032 res->names[i].name))
1035 return (CSA_E_INSUFFICIENT_MEMORY);
1038 *number_names = res->num_names;
1043 stat = (cal->conn.stat == RPC_SUCCESS) ?
1044 CSA_E_SERVICE_UNAVAILABLE :
1045 _DtCm_clntstat_to_csastat(cal->conn.stat);
1050 stat = CSA_E_NOT_SUPPORTED;
1056 extern CSA_return_code
1057 _DtCm_rpc_list_calendars(
1059 CSA_uint32 *number_names,
1060 CSA_calendar_user **names_r)
1062 _DtCm_Client_Info *ci = NULL;
1063 CSA_return_code stat = CSA_SUCCESS;
1064 _DtCm_Connection conn;
1066 DP(("rpccalls.c: _DtCm_rpc_list_calendars\n"));
1068 if ((stat = _DtCm_create_tcp_client(location, TABLEVERS,
1069 _DtCM_LONG_TIMEOUT, &ci)) != CSA_SUCCESS) {
1073 conn.retry = B_TRUE;
1075 if (ci->vers_out == TABLEVERS) {
1076 cms_list_calendars_res *res;
1077 CSA_calendar_user *names;
1083 res = cms_list_calendars_5(NULL, &conn);
1086 if ((stat = res->stat) == CSA_SUCCESS && res->num_names)
1088 if (names = _DtCm_alloc_calendar_users(
1090 for (i = 0; i < res->num_names; i++) {
1091 if ((names[i].calendar_address =
1092 strdup(res->names[i]))
1095 return (CSA_E_INSUFFICIENT_MEMORY);
1098 *number_names = res->num_names;
1103 stat = (conn.stat == RPC_SUCCESS) ?
1104 CSA_E_SERVICE_UNAVAILABLE :
1105 _DtCm_clntstat_to_csastat(conn.stat);
1110 stat = CSA_E_NOT_SUPPORTED;
1116 extern CSA_return_code
1117 _DtCm_do_unregistration(
1118 _DtCm_Connection *conn,
1120 unsigned long update_type)
1122 CSA_return_code stat;
1124 if (conn->ci->vers_out == TABLEVERS) {
1125 cms_register_args args;
1126 CSA_return_code *res;
1129 args.update_type = update_type;
1130 args.prognum = _DtCm_transient;
1131 args.versnum = AGENTVERS_2;
1132 args.procnum = update_callback;
1133 args.pid = getpid();
1135 res = cms_unregister_5(&args, conn);
1140 stat = (conn->stat == RPC_SUCCESS) ?
1141 CSA_E_SERVICE_UNAVAILABLE :
1142 _DtCm_clntstat_to_csastat(conn->stat);
1145 stat = _DtCm_table_unregister_target(conn, cal);
1148 if (stat == CSA_SUCCESS)
1149 _DtCm_remove_registration(conn->ci, cal);
1154 extern CSA_return_code
1155 _DtCm_do_registration(
1156 _DtCm_Connection *conn,
1158 unsigned long update_type)
1160 CSA_return_code stat;
1162 if (conn->ci->vers_out == TABLEVERS) {
1163 cms_register_args args;
1164 CSA_return_code *res;
1167 args.update_type = update_type;
1168 args.prognum = _DtCm_transient;
1169 args.versnum = AGENTVERS_2;
1170 args.procnum = update_callback;
1171 args.pid = getpid();
1173 res = cms_register_5(&args, conn);
1178 stat = (conn->stat == RPC_SUCCESS) ?
1179 CSA_E_SERVICE_UNAVAILABLE :
1180 _DtCm_clntstat_to_csastat(conn->stat);
1184 stat = _DtCm_table_register_target(conn, cal);
1187 if (stat == CSA_SUCCESS) {
1188 if ((stat = _DtCm_add_registration(conn->ci, cal, update_type))
1190 (void) _DtCm_do_unregistration(conn, cal, update_type);
1197 /*****************************************************************************
1198 * static functions used within the file
1199 *****************************************************************************/
1202 * Newnum is initialized to 0 and newattrs to NULL when num_attrs == 0
1204 static CSA_return_code
1206 CSA_uint32 num_attrs,
1207 CSA_attribute *csaattrs,
1210 cms_attribute **newattrs,
1213 CSA_return_code stat = CSA_SUCCESS;
1214 cms_attribute *cmsattrs;
1216 CSA_reminder *rptr1, *rptr2;
1221 if (newops) *newops = NULL;
1226 if ((cmsattrs = calloc(1, sizeof(cms_attribute)*num_attrs)) == NULL)
1227 return (CSA_E_INSUFFICIENT_MEMORY);
1229 if (newops && (ops_r = malloc(sizeof(CSA_enum)*num_attrs)) == NULL) {
1231 return (CSA_E_INSUFFICIENT_MEMORY);
1234 for (i = 0, j = 0; i < num_attrs && stat == CSA_SUCCESS; i++) {
1235 if (csaattrs[i].name == NULL)
1239 ops_r[j] = (ops ? ops[i] : CSA_MATCH_EQUAL_TO);
1241 cmsattrs[j].name.name = csaattrs[i].name;
1242 if (csaattrs[i].value == NULL) {
1247 if ((cmsattrs[j].value = (cms_attribute_value *)malloc(
1248 sizeof(cms_attribute_value))) == NULL) {
1249 stat = CSA_E_INSUFFICIENT_MEMORY;
1253 cmsattrs[j].value->type = csaattrs[i].value->type;
1255 switch (csaattrs[i].value->type) {
1256 case CSA_VALUE_ACCESS_LIST:
1257 stat = _DtCm_csa2cms_access_list(
1258 csaattrs[i].value->item.access_list_value,
1259 &cmsattrs[j].value->item.access_list_value);
1261 case CSA_VALUE_CALENDAR_USER:
1262 if (csaattrs[i].value->item.calendar_user_value &&
1263 csaattrs[i].value->item.calendar_user_value->\
1266 cmsattrs[j].value->item.calendar_user_value =
1267 csaattrs[i].value->item.\
1268 calendar_user_value->user_name;
1270 cmsattrs[j].value->item.calendar_user_value =
1274 case CSA_VALUE_STRING:
1275 case CSA_VALUE_DATE_TIME:
1276 case CSA_VALUE_DATE_TIME_RANGE:
1277 case CSA_VALUE_TIME_DURATION:
1278 if (csaattrs[i].value->item.string_value) {
1279 cmsattrs[j].value->item.string_value =
1280 csaattrs[i].value->item.string_value;
1282 cmsattrs[j].value->item.string_value = nullstr;
1285 case CSA_VALUE_REMINDER:
1286 if ((rptr1 = csaattrs[i].value->item.reminder_value) &&
1287 (rptr2 = (CSA_reminder *)malloc(sizeof(CSA_reminder))))
1289 rptr2->lead_time = rptr1->lead_time ?
1290 rptr1->lead_time : nullstr;
1291 rptr2->snooze_time = rptr1->snooze_time ?
1292 rptr1->snooze_time:nullstr;
1293 rptr2->repeat_count = rptr1->repeat_count;
1294 rptr2->reminder_data = rptr1->reminder_data;
1295 cmsattrs[j].value->item.reminder_value = rptr2;
1296 } else if (rptr1 && rptr2 == NULL)
1297 stat = CSA_E_INSUFFICIENT_MEMORY;
1300 /* all other value types uses the same type
1301 * of data, so we just copy the value/address of
1304 cmsattrs[j].value->item.sint32_value =
1305 csaattrs[i].value->item.sint32_value;
1310 if (stat != CSA_SUCCESS) {
1312 free_cmsattrs(num_attrs, cmsattrs);
1313 if (newops) free(ops_r);
1317 *newattrs = cmsattrs;
1318 if (newops) *newops = ops_r;
1321 if (newops) free(ops_r);
1328 free_cmsattrs(CSA_uint32 num_attrs, cms_attribute *attrs)
1332 for (i = 0; i < num_attrs; i++) {
1333 if (attrs[i].value == NULL)
1336 switch (attrs[i].value->type) {
1337 case CSA_VALUE_ACCESS_LIST:
1338 _DtCm_free_cms_access_entry(
1339 attrs[i].value->item.access_list_value);
1341 case CSA_VALUE_REMINDER:
1342 if (attrs[i].value->item.reminder_value)
1343 free(attrs[i].value->item.reminder_value);
1347 free(attrs[i].value);
1353 * Newnum is initialized to 0 and newattrs to NULL when num_attrs == 0
1355 static CSA_return_code
1357 CSA_uint32 num_names,
1358 char **reminder_names,
1360 cms_attr_name **newnames)
1362 cms_attr_name *cmsnames;
1369 return (CSA_SUCCESS);
1371 if ((cmsnames = calloc(1, sizeof(cms_attr_name)*num_names)) == NULL)
1372 return (CSA_E_INSUFFICIENT_MEMORY);
1374 for (i = 0, j = 0; i < num_names; i++) {
1375 if (reminder_names[i] == NULL)
1378 cmsnames[j].name = reminder_names[i];
1385 *newnames = cmsnames;
1389 return (CSA_SUCCESS);
1393 * It is an old server and so we need to determine whether the user
1394 * is the calendar owner ourselves.
1395 * If the calendar name is the same as a user name, then that user
1396 * is the owner, and we just need to make sure the calendar is located
1397 * in the same domain as ours. If the calendar is located in another
1398 * domain and since we can't do cross domain authentication yet, to be save
1399 * we assume that the user is not the owner.
1400 * If the calendar name is not a user name, we need to make an rpc call
1401 * (table_set_access) to test whether the user is the owner.
1403 static CSA_return_code
1404 _GetV4UserAccess(Calendar *cal, cms_access_entry *alist)
1406 CSA_return_code stat = CSA_SUCCESS;
1407 char *user = _DtCmGetUserName();
1408 char *localhost = _DtCmGetHostAtDomain();
1411 int worldaccess = 0, useraccess = 0;
1412 boolean_t isowner = B_FALSE;
1414 /* first check if user is owner */
1415 if (ptr = strchr(cal->name, '@')) *ptr = NULL;
1417 if (_DtCmIsUserName(cal->name) == B_TRUE) {
1418 if (strcmp(user, cal->name) == 0) {
1419 /* check whether calendar location is in
1422 if (dom = strchr(cal->location, '.')) dom++;
1423 if (dom == NULL || _DtCmIsSamePath(
1424 _DtCmGetLocalDomain(NULL), dom) == B_TRUE)
1428 CSA_access_rights *csalist;
1430 /* need to test whether the user is the owner */
1431 if ((stat = _DtCm_cms2csa_access_list(alist, &csalist))
1434 stat = _DtCm_table_set_access(cal, csalist);
1435 _DtCm_free_csa_access_list(csalist);
1437 if (stat == CSA_SUCCESS)
1439 else if (stat == CSA_E_NO_AUTHORITY) {
1445 if (ptr) *ptr = '@';
1446 if (stat != CSA_SUCCESS)
1450 cal->access = CSA_OWNER_RIGHTS;
1451 return (CSA_SUCCESS);
1454 sprintf(buf, "%s@%s", user, localhost);
1455 for (; alist != NULL; alist = alist->next) {
1456 if (strcasecmp(alist->user, "world") == 0)
1457 worldaccess = alist->rights;
1458 else if (_DtCmIsSameUser(buf, alist->user)) {
1459 useraccess = alist->rights;
1464 cal->access = useraccess | worldaccess;
1465 return (CSA_SUCCESS);