* clear out some warnings by gcc 9.3.1.
[alpine.git] / web / src / alpined.d / alpineldap.c
blob4438d8874a3f2018b9e9315a5deee42c97657562
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: alpineldap.c 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $";
3 #endif
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 * ========================================================================
17 #include <system.h>
18 #include <general.h>
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"
65 #include "alpined.h"
66 #include "ldap.h"
68 struct pine *wps_global; /* THE global variable! */
69 //char wtmp_20k_buf[20480];
71 char *peSocketName;
73 #ifdef ENABLE_LDAP
74 WPLDAP_S *wpldap_global;
75 #endif
77 int peNoPassword, peCredentialError;
78 int peCertQuery, peCertFailure;
79 char peCredentialRequestor[CRED_REQ_SIZE];
80 STRLIST_S *peCertHosts;
82 void
83 sml_addmsg(priority, text)
84 int priority;
85 char *text;
89 void
90 peDestroyUserContext(pps)
91 struct pine **pps;
95 int
96 main(argc, argv)
97 int argc;
98 char *argv[];
100 #ifdef ENABLE_LDAP
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;
109 #ifdef DEBUG
110 debug = 0;
111 #endif /* DEBUG */
113 for(i = 1 ; i < argc; i++){
114 if(*argv[i] == '-'){
115 switch (argv[i++][1]) {
116 case 'p':
117 p = argv[i];
118 break;
119 case 'u':
120 userid = argv[i];
121 break;
122 case 'd':
123 domain = argv[i];
124 break;
125 default:
126 usage = rv = 1;
127 break;
130 else
131 usage = rv = 1;
132 if(usage == 1) break;
134 if(argc == 1) usage = rv = 1;
135 if (usage == 1 || !p || !userid){
136 usage = rv = 1;
137 goto done;
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);
146 else {
147 fprintf(stderr, "Failed to read pineconf\n");
148 rv = 1;
149 goto done;
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");
155 usage = 1;
156 goto done;
158 if((pname = peLdapPname(userid, domain ? domain : wps_global->VAR_USER_DOMAIN)) != NULL){
159 fprintf(stdout, "%s\n", pname);
160 fs_give((void **)&pname);
162 else
163 fprintf(stdout, "\n");
165 done:
166 if(usage)
167 fprintf(stderr, "usage: pineldap -u userid -p pineconf [-d domain]\n");
168 if(wpldap_global){
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);
177 exit(rv);
178 #else
179 fprintf(stderr, "%s: Not built with LDAP support\n", argv[0]);
180 exit(-1);
181 #endif