2 static char copyright[] = "Copyright 1992 The University of Adelaide";
8 * Author: Mark R. Prior
9 * Communications and Systems Branch
10 * Information Technology Division
11 * The University of Adelaide
12 * E-mail: mrp@itd.adelaide.edu.au
16 * A module implementing the describe whois++ command.
18 * Redistribution and use in source and binary forms are permitted
19 * provided that the above copyright notice and this paragraph are
20 * duplicated in all such forms and that any documentation,
21 * advertising materials, and other materials related to such
22 * distribution and use acknowledge that the software was developed
23 * by the University of Adelaide. The name of the University may not
24 * be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
28 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33 int displayDescribe( ld, organisation )
39 LDAPMessage *result, *entry;
42 static char *masterDSA[] = { "masterDSA", NULL };
43 static char *manager[] = { "manager", NULL };
44 static char *roleOccupant[] = { "roleOccupant", NULL };
45 static char *attributes[] = { "postalAddress", "telephoneNumber",
46 "facsimileTelephoneNumber", "mail", "lastModifiedBy",
53 if ( !EQ( language, "english" ) )
54 printFormatted( lineLength, TRUE, stdout,
55 "The output of the DESCRIBE command must be in english \
56 according to the IAFA services template." );
58 printFormatted( lineLength, FALSE, stdout,
59 "%-19s Whois++", "Service-Name:" );
60 if ( hostname != NULL )
61 printFormatted( lineLength, FALSE, stdout, "%-19s %s",
62 "Primary-Name:", hostname );
64 printFormatted( lineLength, FALSE, stdout,
65 "%-19s <unknown>", "Primary-Name:" );
66 printFormatted( lineLength, FALSE, stdout,
67 "%-19s Whois++ service using LDAP to access a Quipu based",
69 printFormatted( lineLength, FALSE, stdout,
70 "%-19s X.500 Directory Service.", "" );
71 printFormatted( lineLength, FALSE, stdout,
72 "%-19s whois++ protocol on tcp port 43", "Access-Protocol:" );
73 printFormatted( lineLength, FALSE, stdout,
74 "%-19s whois, x.500, ldap", "Keywords:" );
75 printFormatted( lineLength, FALSE, stdout,
76 "%-19s 24 hours a day, 7 days a week", "Access-Times:" );
77 printFormatted( lineLength, FALSE, stdout,
78 "%-19s Open Access", "Policy:" );
79 printFormatted( lineLength, FALSE, stdout,
81 if ( contact == NULL ) {
83 * The contact hasn't identified themselves in the tailor file
84 * so lets try to work it out by finding out who manages the
85 * DSA that masters the organisation's entry!
88 printFormatted( lineLength, TRUE, stdout,
89 "No contact info provided, searching ..." );
90 ldap_search_s( ld, organisation, LDAP_SCOPE_BASE,
91 "objectclass=*", masterDSA, 0, &result );
92 if ( ld->ld_errno != LDAP_SUCCESS ) {
93 printFormatted( lineLength, FALSE, stdout,
94 "%-19s <Unknown>", "Contact:" );
98 printFormatted( lineLength, TRUE, stdout,
99 "Looking for the master DSA ..." );
100 if ( (values = ldap_get_values( ld, result, "masterDSA" )) == NULL
101 || values[0] == NULL ) {
102 printFormatted( lineLength, FALSE, stdout,
103 "%-19s <Unknown>", "Contact:" );
107 printFormatted( lineLength, TRUE, stdout,
108 "Searching for the DSA manager ..." );
109 ldap_search_s( ld, values[0], LDAP_SCOPE_BASE, "objectclass=*",
110 manager, 0, &result );
111 if ( ld->ld_errno != LDAP_SUCCESS ) {
112 printFormatted( lineLength, FALSE, stdout,
113 "%-19s <Unknown>", "Contact:" );
114 printFormatted( lineLength, TRUE, stdout,
116 ldap_err2string( ld->ld_errno ) );
119 if ( (values = ldap_get_values( ld, result, "manager" )) == NULL ) {
120 printFormatted( lineLength, FALSE, stdout,
121 "%-19s <Unknown>", "Contact:" );
125 printFormatted( lineLength, TRUE, stdout,
126 "Retrieving the DSA manager's entry ..." );
128 * we have at least one manager for this DSA but which one is
129 * the "correct" one to list?
131 len1 = strlen( organisation );
132 for ( i = 0; values[i] != NULL; i++ )
133 if ( strlen( values[i] ) >= len1 ) {
134 len2 = strlen( values[i] );
135 if ( EQ( organisation, &values[i][len2-len1] ) )
136 contact = strdup( values[i] );
138 ldap_value_free( values );
139 if ( contact == NULL ) {
140 printFormatted( lineLength, FALSE, stdout,
141 "%-19s <Unknown>", "Contact:" );
143 printFormatted( lineLength, TRUE, stdout,
144 "Cannot find a suitable manager" );
147 ldap_search_s( ld, contact, LDAP_SCOPE_BASE, "objectclass=*",
148 roleOccupant, 0, &result );
149 if ( ld->ld_errno != LDAP_SUCCESS ) {
150 printFormatted( lineLength, FALSE, stdout,
151 "%-19s <Unknown>", "Contact:" );
152 printFormatted( lineLength, TRUE, stdout,
154 ldap_err2string( ld->ld_errno ) );
157 if ( (values = ldap_get_values( ld, result, "roleOccupant" )) != NULL
158 || values[0] == NULL ) {
161 contact = strdup( values[0] );
162 ldap_value_free( values );
165 printFormatted( lineLength, TRUE, stdout,
166 "The contact is %s", contact );
168 ldap_search_s( ld, contact, LDAP_SCOPE_BASE, "objectclass=*",
169 attributes, 0, &result );
170 if ( ld->ld_errno != LDAP_SUCCESS ) {
171 printFormatted( lineLength, FALSE, stdout, "%-19s <Unknown>",
173 printFormatted( lineLength, TRUE, stdout,
174 "Read for \"%s\" returned error, %s", contact,
175 ldap_err2string( ld->ld_errno ) );
178 if ( (values = ldap_get_values( ld, result, "preferredName" )) != NULL
179 && values[0] != NULL ) {
180 printFormatted( lineLength, FALSE, stdout, "%-19s %s",
181 "Contact:", values[0] );
182 ldap_value_free( values );
185 value = ldap_dn2ufn( ptr = ldap_get_dn( ld, result ) );
187 if ( (ptr = index( value, ',' )) != NULL )
189 printFormatted( lineLength, FALSE, stdout, "%-19s %s",
191 ldap_memfree( value );
195 if ( ( values = ldap_get_values( ld, result, "postalAddress" )) != NULL ) {
196 for ( i = 0; values[i] != NULL; i++ ) {
197 printFormatted( lineLength, FALSE, stdout, "%-19s %s",
199 strtok( values[i], "$" ) );
200 while ( ( ptr = strtok( NULL, "$" ) ) != NULL )
201 printFormatted( lineLength, FALSE, stdout,
202 "%-19s%s", "", ptr );
204 ldap_value_free( values );
206 if ( ( values = ldap_get_values( ld, result, "telephoneNumber" )) != NULL ) {
207 for ( i = 0; values[i] != NULL; i++ )
208 printFormatted( lineLength, FALSE, stdout, "%-19s %s",
209 "Telephone:", values[i] );
210 ldap_value_free( values );
212 if ( ( values = ldap_get_values( ld, result, "facsimileTelephoneNumber" )) != NULL ) {
213 for ( i = 0; values[i] != NULL; i++ )
214 printFormatted( lineLength, FALSE, stdout, "%-19s %s",
216 ldap_value_free( values );
218 if ( ( values = ldap_get_values( ld, result, "mail" )) != NULL ) {
219 for ( i = 0; values[i] != NULL; i++ )
220 printFormatted( lineLength, FALSE, stdout, "%-19s %s",
221 "Electronic-Address:", values[i] );
222 ldap_value_free( values );
224 if ( ( values = ldap_get_values( ld, result, "lastModifiedBy" )) != NULL ) {
225 for ( i = 0; values[i] != NULL; i++ )
226 printFormatted( lineLength, FALSE, stdout,
227 "%-19s \"%s\"", "Modified-By:", values[i] );
228 ldap_value_free( values );