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: laccess.c /main/1 1996/04/21 19:23:33 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 #include <EUSCompat.h>
38 /******************************************************************************
39 * forward declaration of static functions used within the file
40 ******************************************************************************/
41 static void get_component(char **str, char *comp, char token);
42 static void get_last_component(char *head, char **tail, char *comp, char token);
43 static boolean_t match_forward(char *str1, char *str2);
44 static boolean_t match_backward(char *str1, char *str2);
46 /*****************************************************************************
47 * extern functions used in the library
48 *****************************************************************************/
51 * Correct format assumed, i.e. str = label1[.label2 ...]
52 * Compare str2 against str1 which should be more fully qualified than str2
55 _DtCmIsSamePath(char *str1, char *str2)
57 if (str1 == NULL || str2 == NULL)
61 if (*str1 == '.' || *str2 == '.')
62 return (B_FALSE); /* bad format */
64 if (match_forward(str1, str2) == B_TRUE)
67 return (match_backward(str1, str2));
71 * compare user1 and user2
72 * user1 = user@host[.domain]
73 * user2 = any format in (user, user@host[.domain], user@domain)
76 _DtCmIsSameUser(char *user1, char *user2)
79 char buf[BUFSIZ], *domain;
81 if (user1 == NULL || user2 == NULL)
84 /* compare user name */
85 str1 = _DtCmGetPrefix(user1, '@');
86 str2 = _DtCmGetPrefix(user2, '@');
88 if (str1 == NULL || str2 == NULL) {
94 if (strcmp(str1, str2)) {
102 /* if only user name is specified, don't need to check domain */
103 str2 = strchr(user2, '@');
107 domain = _DtCmGetLocalDomain(NULL);
109 /* first assume user2=user@domain */
110 str1 = strchr(user1, '.');
112 if (_DtCmIsSamePath(domain, ++str2)) {
117 if (_DtCmIsSamePath(++str1, ++str2)) {
122 /* assume user2=user@host[.domain] */
124 str1 = strchr(user1, '@');
125 snprintf(buf, sizeof buf, "%s.%s", ++str1, domain);
128 str1 = strchr(user1, '@');
132 if (_DtCmIsSamePath(str1, str2))
138 /*****************************************************************************
139 * static functions used within the file
140 *****************************************************************************/
143 * str consists of components separated by token
144 * get and copy the first component into comp and
145 * strip it out of str, so str would point to the first
146 * token or the null terminator.
149 get_component(char **str, char *comp, char token)
160 while (ptr && *ptr != 0 && *ptr != token)
169 * head and tail points to the first and last character
170 * of a string which consists of components separated by token.
171 * get and copy the last component into comp and
172 * strip it out of the string, so tail would point to the last
173 * token or the head of the string.
176 get_last_component(char *head, char **tail, char *comp, char token)
187 while (cptr != head && *cptr != token)
195 while (ptr != (*tail + 1))
204 match_forward(char *str1, char *str2)
206 char com1[BUFSIZ], com2[BUFSIZ];
208 if (str1 == NULL || str2 == NULL)
212 get_component(&str1, com1, '.');
213 get_component(&str2, com2, '.');
225 if (strcasecmp(com1, com2) != 0)
228 /* take care of case: a.b a. */
229 if (strcmp(str2, ".") == 0
230 && (strcmp(str1, ".") != 0 || *str1 != '\0'))
241 } else if (strcmp(str2, ".") == 0 || *str2 == '\0')
249 match_backward(char *str1, char *str2)
253 char com1[BUFSIZ], com2[BUFSIZ];
255 if (str1 == NULL || str2 == NULL)
265 ptr1 = (len1 ? (str1 + len1 - 1) : str1);
266 ptr2 = (len2 ? (str2 + len2 - 1) : str2);
268 if (*ptr1 == '.' && ptr1 != str1)
271 if (*ptr2 == '.' && ptr2 != str2)
275 get_last_component(str1, &ptr1, com1, '.');
276 get_last_component(str2, &ptr2, com2, '.');
288 if (strcasecmp(com1, com2) != 0)
296 return (B_FALSE); /* bad format */
298 return (B_TRUE); /* done */
304 return (B_FALSE); /* bad format */
306 return (B_TRUE); /* done */