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 /*******************************************************************************
27 ** $XConsortium: cmfns.c /main/3 1995/11/03 10:37:19 rswiston $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
52 static char sccsid[] = "@(#)cmfns.c 1.3 94/11/07 Copyr 1993 Sun Microsystems, Inc.";
56 * Copyright 1993 Sun Microsystems, Inc. All rights reserved
61 #include <EUSCompat.h>
76 extern char *strdup(const char *);
77 extern FILE *fdopen(int, const char *);
80 * Returns 1 if we can use FNS, else 0
82 * The first call to this routine can be a little costly. Subsequent calls
83 * are very cheap. So avoid calling this routine at startup.
86 cmfns_use_fns(Props *p)
90 static int fns_available;
91 static boolean_t use_fns;
94 use_fns = convert_boolean_str(get_char_prop(p, CP_USEFNS));
95 if ((fns_available = dtfns_available()) == -1) {
101 if (use_fns && fns_available) {
109 * Takes an absolute FNS name and attempts to generate an English
110 * description for it. I.e:
112 * org:ssi.eng:user:dipol -> dipol (in ssi.eng)
113 * org:ssi.eng:site:b21 -> b21 (a Site in ssi.eng)
114 * org:ssi.eng -> ssi.eng (Organization)
115 * host:sidewinder -> sidewinder (Host)
117 * dipol@sidewinder -> dipol@sidewinder
118 * org:ssi.eng:host:sidewinder -> sideiwnder (a Host in ssi.eng)
121 * -1 buf not big enough
122 * 0 name is not an FNS name. No description generated
123 * 1 Success. Description is paced in buf
129 int size) /* FNS name to generate description for */
138 char *a_user_in = " (in %s)";
139 char *a_site_in = " (a Site in %s)";
140 char *a_host_in = " (a Host in %s)";
141 char *an_org = " (Organization)";
142 char *a_host = " (Host)";
143 char *a_site = " (Site)";
144 char *thisuser = "Me";
145 char *myorg = "My Organization";
146 char *hostorg = "This Host's Organization";
149 buf[size - 1] = '\0';
150 tmp_buf = strdup(name);
152 if ((tail = strchr(head, DTFNS_SEPARATOR)) == NULL) {
154 * No colon. Either one of the special FNS names or
155 * it is not an FNS name
157 if (strcmp(head, DTFNS_MYORG_NAME) == 0) {
158 strncpy(buf, myorg, size);
159 } else if (strcmp(head, DTFNS_HOSTORG_NAME) == 0) {
160 strncpy(buf, hostorg, size);
161 } else if (strcmp(head, DTFNS_THISUSER_NAME) == 0) {
162 strncpy(buf, thisuser, size);
164 /* Not an FNS name */
174 if (strcmp(head, DTFNS_ORG_NAME) == 0) {
175 /* Starts with org:. Get org */
177 if ((tail = strchr(head, DTFNS_SEPARATOR)) == NULL) {
178 /* just org:orgname */
179 strncpy(buf, head, size);
181 strncat(buf, an_org, size);
189 if ((tail = strchr(head, DTFNS_SEPARATOR)) == NULL) {
191 * Hmmm... We have "org:orgname:something"
192 * Just return the description for an organization
194 strncpy(buf, org, size);
196 strncat(buf, an_org, size);
204 if (strcmp(head, DTFNS_USER_NAME) == 0) {
205 s = org ? a_user_in : "";
206 } else if (strcmp(head, DTFNS_HOST_NAME) == 0) {
207 s = org ? a_host_in : a_host;
208 } else if (strcmp(head, DTFNS_SITE_NAME) == 0) {
209 s = org ? a_site_in : a_site;
214 strncpy(buf, tail, size);
219 if (size > (int)(strlen(org) + strlen(s) + 2)) {
220 sprintf(buf + len, s, org);
222 /* Buffer too small */
226 strncat(buf, s, size);
242 * Get a calendar address from FNS
244 * 'name' may be an absolute Helix name:
246 * org:ssi.eng:user:smith
249 * 'name' may be an FNS shorthand name:
253 * 'name' may be a calendar address:
255 * In which case it is copied unmodified into addr_buf.
257 * 'buf' is a buffer provided by the caller in which the calendar address
260 * 'size' is the size of 'buf'
265 * -1 Name not found / Error
266 * 0 FNS not available
271 cmfns_lookup_calendar(
284 DP(("cmfns_lookup_calendar: Looking up %s\n", name));
286 name_buf = strdup(name);
288 strncpy(addr_buf, name, addr_size);
290 addr_buf[addr_size - 1] = '\0';
291 if ((org = strchr(name_buf, '@')) != NULL) {
292 /* Either a calendar address or FNS shorthand */
295 if (gethostbyname(org) != NULL) {
296 /* Old style address. Just return it */
302 /* Expand name to point at a calendar service */
303 rcode = dtfns_service_name(name_buf, "user", CMFNS_CALENDAR_SERVICE,
304 CMFNS_CALENDAR_TYPE, org, fns_name, sizeof(fns_name));
310 /* Specify the address types we support */
311 types[0] = CMFNS_CALENDAR_ADDR_TYPE;
312 types[1] = "SUNW_calendar";
313 types[2] = "SUNW_cal_deskset";
316 /* Get string bound to calendar service name */
317 rcode = dtfns_lookup_str(fns_name, types, addr_buf, addr_size,
324 if (strchr(addr_buf, '@') == NULL) {
326 * Just the location (host) is bound in FNS. Pull
327 * the name of the object (user) out of the FNS
330 tmp = strdup(addr_buf);
331 if ((p = strstr(fns_name, ":service:")) == NULL) {
338 sprintf(addr_buf, "%s@%s", p + 1, tmp);
343 * Crossing organizations. Is host qualified
346 p = strchr(addr_buf, '@');
348 if (strchr(p, '.') == NULL) {
350 * Host does not appear to have domain
353 strcat(addr_buf, ".");
354 strcat(addr_buf, org);
358 DP(("cmfns_lookup_calendar: FNS Lookup complete. address=%s",
364 * Register a calendar location in FNS.
367 cmfns_register_calendar(const char *username, const char *location)
376 user = strdup(username);
378 if ((p = strchr(user, '@')) != NULL) {
382 DP(("register_calendar: Generating service name for %s\n", user));
383 /* Expand name to point at a calendar service */
384 rcode = dtfns_service_name(user, DTFNS_USER_NAME,
385 CMFNS_CALENDAR_SERVICE, CMFNS_CALENDAR_TYPE, NULL,
393 types[0] = CMFNS_CALENDAR_ADDR_TYPE;
394 types[1] = "SUNW_calendar";
395 types[2] = "SUNW_cal_deskset";
398 DP(("register_calendar: Binding %s to %s\n", location, buf));
399 return dtfns_bind_str(buf, CMFNS_CALENDAR_TYPE, types, location);