1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: alpineldap.c 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $";
5 /* ========================================================================
6 * Copyright 2006-2007 University of Washington
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * ========================================================================
20 #include "../../../c-client/c-client.h"
21 #include "../../../c-client/imap4r1.h"
23 #include "../../../pith/osdep/color.h" /* color support library */
24 #include "../../../pith/osdep/canaccess.h"
25 #include "../../../pith/osdep/temp_nam.h"
27 #include "../../../pith/stream.h"
28 #include "../../../pith/context.h"
29 #include "../../../pith/state.h"
30 #include "../../../pith/msgno.h"
31 #include "../../../pith/debug.h"
32 #include "../../../pith/init.h"
33 #include "../../../pith/conf.h"
34 #include "../../../pith/conftype.h"
35 #include "../../../pith/detoken.h"
36 #include "../../../pith/flag.h"
37 #include "../../../pith/help.h"
38 #include "../../../pith/remote.h"
39 #include "../../../pith/status.h"
40 #include "../../../pith/mailcmd.h"
41 #include "../../../pith/savetype.h"
42 #include "../../../pith/save.h"
43 #include "../../../pith/reply.h"
44 #include "../../../pith/sort.h"
45 #include "../../../pith/ldap.h"
46 #include "../../../pith/addrbook.h"
47 #include "../../../pith/takeaddr.h"
48 #include "../../../pith/bldaddr.h"
49 #include "../../../pith/copyaddr.h"
50 #include "../../../pith/thread.h"
51 #include "../../../pith/folder.h"
52 #include "../../../pith/mailview.h"
53 #include "../../../pith/indxtype.h"
54 #include "../../../pith/mailindx.h"
55 #include "../../../pith/mailpart.h"
56 #include "../../../pith/mimedesc.h"
57 #include "../../../pith/detach.h"
58 #include "../../../pith/newmail.h"
59 #include "../../../pith/charset.h"
60 #include "../../../pith/util.h"
61 #include "../../../pith/rfc2231.h"
62 #include "../../../pith/string.h"
63 #include "../../../pith/send.h"
68 struct pine
*wps_global
; /* THE global variable! */
69 //char wtmp_20k_buf[20480];
74 WPLDAP_S
*wpldap_global
;
77 int peNoPassword
, peCredentialError
;
78 int peCertQuery
, peCertFailure
;
79 char peCredentialRequestor
[CRED_REQ_SIZE
];
80 STRLIST_S
*peCertHosts
;
83 sml_addmsg(priority
, text
)
90 peDestroyUserContext(pps
)
101 struct pine
*pine_state
;
102 char *p
= NULL
, *userid
= NULL
, *domain
= NULL
, *pname
;
103 struct variable
*vars
;
104 int i
, usage
= 0, rv
= 0;
106 pine_state
= new_pine_struct();
107 wps_global
= pine_state
;
108 vars
= wps_global
->vars
;
113 for(i
= 1 ; i
< argc
; i
++){
115 switch (argv
[i
++][1]) {
132 if(usage
== 1) break;
134 if(argc
== 1) usage
= rv
= 1;
135 if (usage
== 1 || !p
|| !userid
){
139 wpldap_global
= (WPLDAP_S
*)fs_get(sizeof(WPLDAP_S
));
140 wpldap_global
->query_no
= 0;
141 wpldap_global
->ldap_search_list
= NULL
;
143 wps_global
->pconf
= new_pinerc_s(p
);
144 if(wps_global
->pconf
)
145 read_pinerc(wps_global
->pconf
, vars
, ParseGlobal
);
147 fprintf(stderr
, "Failed to read pineconf\n");
151 set_current_val(&wps_global
->vars
[V_LDAP_SERVERS
], FALSE
, FALSE
);
152 set_current_val(&wps_global
->vars
[V_USER_DOMAIN
], FALSE
, FALSE
);
153 if(!wps_global
->VAR_USER_DOMAIN
&& !domain
){
154 fprintf(stderr
, "No domain set in pineconf\n");
158 if((pname
= peLdapPname(userid
, domain
? domain
: wps_global
->VAR_USER_DOMAIN
)) != NULL
){
159 fprintf(stdout
, "%s\n", pname
);
160 fs_give((void **)&pname
);
163 fprintf(stdout
, "\n");
167 fprintf(stderr
, "usage: pineldap -u userid -p pineconf [-d domain]\n");
169 if(wpldap_global
->ldap_search_list
)
170 free_wpldapres(wpldap_global
->ldap_search_list
);
171 fs_give((void **)&wpldap_global
);
173 if(wps_global
->pconf
)
174 free_pinerc_s(&wps_global
->pconf
);
175 free_pine_struct(&pine_state
);
179 fprintf(stderr
, "%s: Not built with LDAP support\n", argv
[0]);