Cross Reference: friendly.c
xref
: /
osnet-11
/
usr
/
src
/
lib
/
libldap4
/
common
/
friendly.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
friendly.c revision 1
3649
N/A
/*
5564
N/A
*
5564
N/A
* Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved.
3649
N/A
* Use is subject to license terms.
3649
N/A
*
3649
N/A
*/
3649
N/A
3649
N/A
#
pragma
ident
"%Z%%M% %I% %E% SMI"
3649
N/A
3649
N/A
/*
3649
N/A
* Copyright (c) 1990 Regents of the University of Michigan.
3649
N/A
* All rights reserved.
3649
N/A
*
3649
N/A
*
friendly.c
3649
N/A
*/
5564
N/A
3649
N/A
#
ifndef
lint
3649
N/A
static
char
copyright
[] =
"@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n"
;
5564
N/A
#
endif
3649
N/A
3649
N/A
#
include
<
stdio.h
>
3649
N/A
#
include
<
ctype.h
>
3649
N/A
#
include
<
string.h
>
3649
N/A
#
include
<
stdlib.h
>
/* malloc(), free() for Solaris */
3649
N/A
#
ifdef
MACOS
3649
N/A
#
include
<
stdlib.h
>
3649
N/A
#
include
"
macos.h
"
3649
N/A
#
endif
/* MACOS */
3649
N/A
3649
N/A
#
if
defined
(
DOS
) ||
defined
(
_WIN32
)
3649
N/A
#
include
<
malloc.h
>
3649
N/A
#
include
"
msdos.h
"
3649
N/A
#
endif
/* DOS */
3649
N/A
3649
N/A
#
if
!
defined
(
MACOS
) && !
defined
(
DOS
)
3649
N/A
#
include
<
errno.h
>
3649
N/A
#
include
<
sys
/
types.h
>
3649
N/A
#
include
<
sys
/
socket.h
>
3649
N/A
#
endif
3649
N/A
3649
N/A
#
include
"
lber.h
"
3649
N/A
#
include
"
ldap.h
"
3649
N/A
#
include
"
ldap-private.h
"
3649
N/A
#
include
"
ldap-int.h
"
3649
N/A
3649
N/A
char
*
3649
N/A
ldap_friendly_name
(
char
*
filename
,
char
*
uname
,
FriendlyMap
**
map
)
3649
N/A
{
3649
N/A
int
i,
entries
;
3649
N/A
FILE
*
fp
;
3649
N/A
char
*s;
3649
N/A
char
buf
[
BUFSIZ
];
3649
N/A
3649
N/A
if
(
map
==
NULL
) {
3649
N/A
#
if
!
defined
(
MACOS
) && !
defined
(
DOS
)
3649
N/A
errno
=
EINVAL
;
3649
N/A
#
endif
3649
N/A
return
(
uname
);
3649
N/A
}
3649
N/A
3649
N/A
if
( *
map
==
NULL
) {
3649
N/A
if
( (
fp
=
fopen
(
filename
,
"r"
)) ==
NULL
)
3649
N/A
return
(
uname
);
3649
N/A
3649
N/A
entries
= 0;
3649
N/A
while
(
fgets
(
buf
,
sizeof
(
buf
),
fp
) !=
NULL
) {
3649
N/A
if
(
buf
[0] !=
'#'
)
3649
N/A
entries
++;
3649
N/A
}
3649
N/A
rewind
(
fp
);
3649
N/A
3649
N/A
if
( (*
map
= (
FriendlyMap
*)
malloc
( (
entries
+
1
) *
3649
N/A
sizeof
(
FriendlyMap
) )) ==
NULL
) {
3649
N/A
(
void
)
fclose
(
fp
);
3649
N/A
return
(
uname
);
3649
N/A
}
3649
N/A
3649
N/A
i = 0;
3649
N/A
while
(
fgets
(
buf
,
sizeof
(
buf
),
fp
) !=
NULL
&& i <
entries
) {
3649
N/A
if
(
buf
[0] ==
'#'
)
3649
N/A
continue
;
3649
N/A
3649
N/A
if
( (s =
strchr
(
buf
,
'\n'
)) !=
NULL
)
3649
N/A
*s =
'\0'
;
3649
N/A
3649
N/A
if
( (s =
strchr
(
buf
,
'\t'
)) ==
NULL
)
3649
N/A
continue
;
3649
N/A
*s++ =
'\0'
;
3649
N/A
3649
N/A
if
( *s ==
'"'
) {
3649
N/A
int
esc
= 0,
found
= 0;
3649
N/A
3649
N/A
for
( ++s; *s && !
found
; s++ ) {
3649
N/A
switch
( *s ) {
3649
N/A
case
'\\'
:
3649
N/A
esc
=
1
;
3649
N/A
break
;
3649
N/A
case
'"'
:
3649
N/A
if
( !
esc
)
3649
N/A
found
=
1
;
3649
N/A
/* FALL */
3649
N/A
default
:
3649
N/A
esc
= 0;
3649
N/A
break
;
3649
N/A
}
3649
N/A
}
3649
N/A
}
3649
N/A
3649
N/A
(*
map
)[i].
f_unfriendly
=
strdup
(
buf
);
3649
N/A
(*
map
)[i].
f_friendly
=
strdup
( s );
3649
N/A
i++;
3649
N/A
}
3649
N/A
3649
N/A
(
void
)
fclose
(
fp
);
3649
N/A
(*
map
)[i].
f_unfriendly
=
NULL
;
3649
N/A
}
3649
N/A
3649
N/A
for
( i = 0; (*
map
)[i].
f_unfriendly
!=
NULL
; i++ ) {
3649
N/A
if
(
strcasecmp
(
uname
, (*
map
)[i].
f_unfriendly
) == 0 )
3649
N/A
return
( (*
map
)[i].
f_friendly
);
3649
N/A
}
3649
N/A
return
(
uname
);
3649
N/A
}
3649
N/A
3649
N/A
3649
N/A
void
3649
N/A
ldap_free_friendlymap
(
FriendlyMap
**
map
)
3649
N/A
{
3649
N/A
struct
friendly
*
pF
= *
map
;
3649
N/A
3649
N/A
if
(
pF
==
NULL
)
3649
N/A
return
;
3649
N/A
3649
N/A
while
(
pF
->
f_unfriendly
)
3649
N/A
{
3649
N/A
free
(
pF
->
f_unfriendly
);
3649
N/A
free
(
pF
->
f_friendly
);
3649
N/A
pF
++;
3649
N/A
}
3649
N/A
free
( *
map
);
3649
N/A
*
map
=
NULL
;
3649
N/A
}
3649
N/A