* Clean up some function definitions to comply with strict
[alpine.git] / web / src / alpined.d / alpineldap.c
blob3165572955a4f18ebd12d1e15ed34126c01973a9
1 /* ========================================================================
2 * Copyright 2006-2007 University of Washington
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * ========================================================================
13 #include <system.h>
14 #include <general.h>
16 #include "../../../c-client/c-client.h"
17 #include "../../../c-client/imap4r1.h"
19 #include "../../../pith/osdep/color.h" /* color support library */
20 #include "../../../pith/osdep/canaccess.h"
21 #include "../../../pith/osdep/temp_nam.h"
23 #include "../../../pith/stream.h"
24 #include "../../../pith/context.h"
25 #include "../../../pith/state.h"
26 #include "../../../pith/msgno.h"
27 #include "../../../pith/debug.h"
28 #include "../../../pith/init.h"
29 #include "../../../pith/conf.h"
30 #include "../../../pith/conftype.h"
31 #include "../../../pith/detoken.h"
32 #include "../../../pith/flag.h"
33 #include "../../../pith/help.h"
34 #include "../../../pith/remote.h"
35 #include "../../../pith/status.h"
36 #include "../../../pith/mailcmd.h"
37 #include "../../../pith/savetype.h"
38 #include "../../../pith/save.h"
39 #include "../../../pith/reply.h"
40 #include "../../../pith/sort.h"
41 #include "../../../pith/ldap.h"
42 #include "../../../pith/addrbook.h"
43 #include "../../../pith/takeaddr.h"
44 #include "../../../pith/bldaddr.h"
45 #include "../../../pith/copyaddr.h"
46 #include "../../../pith/thread.h"
47 #include "../../../pith/folder.h"
48 #include "../../../pith/mailview.h"
49 #include "../../../pith/indxtype.h"
50 #include "../../../pith/mailindx.h"
51 #include "../../../pith/mailpart.h"
52 #include "../../../pith/mimedesc.h"
53 #include "../../../pith/detach.h"
54 #include "../../../pith/newmail.h"
55 #include "../../../pith/charset.h"
56 #include "../../../pith/util.h"
57 #include "../../../pith/rfc2231.h"
58 #include "../../../pith/string.h"
59 #include "../../../pith/send.h"
61 #include "alpined.h"
62 #include "ldap.h"
64 struct pine *wps_global; /* THE global variable! */
65 //char wtmp_20k_buf[20480];
67 char *peSocketName;
69 #ifdef ENABLE_LDAP
70 WPLDAP_S *wpldap_global;
71 #endif
73 int peNoPassword, peCredentialError;
74 int peCertQuery, peCertFailure;
75 char peCredentialRequestor[CRED_REQ_SIZE];
76 STRLIST_S *peCertHosts;
78 void
79 sml_addmsg(int priority, char *text)
83 void
84 peDestroyUserContext(struct pine **pps)
88 int
89 main(int argc, char *argv[])
91 #ifdef ENABLE_LDAP
92 struct pine *pine_state;
93 char *p = NULL, *userid = NULL, *domain = NULL, *pname;
94 struct variable *vars;
95 int i, usage = 0, rv = 0;
97 pine_state = new_pine_struct();
98 wps_global = pine_state;
99 vars = wps_global->vars;
100 #ifdef DEBUG
101 debug = 0;
102 #endif /* DEBUG */
104 for(i = 1 ; i < argc; i++){
105 if(*argv[i] == '-'){
106 switch (argv[i++][1]) {
107 case 'p':
108 p = argv[i];
109 break;
110 case 'u':
111 userid = argv[i];
112 break;
113 case 'd':
114 domain = argv[i];
115 break;
116 default:
117 usage = rv = 1;
118 break;
121 else
122 usage = rv = 1;
123 if(usage == 1) break;
125 if(argc == 1) usage = rv = 1;
126 if (usage == 1 || !p || !userid){
127 usage = rv = 1;
128 goto done;
130 wpldap_global = (WPLDAP_S *)fs_get(sizeof(WPLDAP_S));
131 wpldap_global->query_no = 0;
132 wpldap_global->ldap_search_list = NULL;
134 wps_global->pconf = new_pinerc_s(p);
135 if(wps_global->pconf)
136 read_pinerc(wps_global->pconf, vars, ParseGlobal);
137 else {
138 fprintf(stderr, "Failed to read pineconf\n");
139 rv = 1;
140 goto done;
142 set_current_val(&wps_global->vars[V_LDAP_SERVERS], FALSE, FALSE);
143 set_current_val(&wps_global->vars[V_USER_DOMAIN], FALSE, FALSE);
144 if(!wps_global->VAR_USER_DOMAIN && !domain){
145 fprintf(stderr, "No domain set in pineconf\n");
146 usage = 1;
147 goto done;
149 if((pname = peLdapPname(userid, domain ? domain : wps_global->VAR_USER_DOMAIN)) != NULL){
150 fprintf(stdout, "%s\n", pname);
151 fs_give((void **)&pname);
153 else
154 fprintf(stdout, "\n");
156 done:
157 if(usage)
158 fprintf(stderr, "usage: pineldap -u userid -p pineconf [-d domain]\n");
159 if(wpldap_global){
160 if(wpldap_global->ldap_search_list)
161 free_wpldapres(wpldap_global->ldap_search_list);
162 fs_give((void **)&wpldap_global);
164 if(wps_global->pconf)
165 free_pinerc_s(&wps_global->pconf);
166 free_pine_struct(&pine_state);
168 exit(rv);
169 #else
170 fprintf(stderr, "%s: Not built with LDAP support\n", argv[0]);
171 exit(-1);
172 #endif