1 | diff -r ../../../postfix-2.4.6/src/bounce/bounce_notify_util.c ./bounce_notify_util.c |
---|
2 | 204a205 |
---|
3 | > #include "search_ldap.c" |
---|
4 | 545,547c546,551 |
---|
5 | < if (NON_NULL_EMPTY(rcpt->orig_addr)) { |
---|
6 | < bounce_print_wrap(bounce, bounce_info, "<%s> (expanded from <%s>): %s", |
---|
7 | < rcpt->address, rcpt->orig_addr, dsn->reason); |
---|
8 | --- |
---|
9 | > char *user_email=malloc(sizeof(char)*70); // 70 chars is limit for email, fix it whatever possible |
---|
10 | > int ret=search_ldap(user_email,rcpt->address); |
---|
11 | > |
---|
12 | > if ((NON_NULL_EMPTY(rcpt->orig_addr)) && ret != NULL) { |
---|
13 | > bounce_print_wrap(bounce, bounce_info, "%s (expanded from <%s>): %s", |
---|
14 | > user_email, rcpt->orig_addr, dsn->reason); |
---|
15 | 550c554 |
---|
16 | < rcpt->address, dsn->reason); |
---|
17 | --- |
---|
18 | > user_email, dsn->reason); |
---|
19 | 551a556,557 |
---|
20 | > |
---|
21 | > free(user_email); |
---|
22 | 641d646 |
---|
23 | < post_mail_fprintf(bounce, "Final-Recipient: rfc822; %s", rcpt->address); |
---|
24 | diff -r ../../../postfix-2.4.6/src/bounce/search_ldap.c ./search_ldap.c |
---|
25 | 0a1,138 |
---|
26 | > #include <stdio.h> |
---|
27 | > #include <ldap.h> |
---|
28 | > #include <sys/time.h> |
---|
29 | > #include <string.h> |
---|
30 | > |
---|
31 | > static void do_other_work(); |
---|
32 | > unsigned long global_counter = 0; |
---|
33 | > |
---|
34 | > |
---|
35 | > |
---|
36 | > int search_ldap (char *ret, char *email) |
---|
37 | > { |
---|
38 | > LDAPMessage *result, *e; |
---|
39 | > BerElement *ber; |
---|
40 | > char *a; |
---|
41 | > char **vals; |
---|
42 | > int i, rc, finished, msgid; |
---|
43 | > int num_entries = 0; |
---|
44 | > struct timeval zerotime; |
---|
45 | > zerotime.tv_sec = zerotime.tv_usec = 0L; |
---|
46 | > LDAP *ld; |
---|
47 | > if ((ld=ldap_init("localhost",389)) == NULL) |
---|
48 | > { |
---|
49 | > perror("ldap_init"); |
---|
50 | > return(0); |
---|
51 | > } |
---|
52 | > |
---|
53 | > if ( ldap_simple_bind_s( ld, NULL, NULL ) != LDAP_SUCCESS ) |
---|
54 | > { |
---|
55 | > ldap_perror( ld, "ldap_simple_bind_s" ); |
---|
56 | > return(0); |
---|
57 | > } |
---|
58 | > |
---|
59 | > char *cpf=(char *)strtok(email,"@"); |
---|
60 | > char *filter=malloc(sizeof(char)*15); |
---|
61 | > strcpy(filter,"uid="); |
---|
62 | > strcat(filter,cpf); |
---|
63 | > char **attr=malloc(sizeof(char *)*2); |
---|
64 | > attr[0]="mail"; |
---|
65 | > attr[1]=NULL; |
---|
66 | > if ((msgid = ldap_search( ld, "dc=ecelepar10612,dc=pr,dc=gov,dc=br", LDAP_SCOPE_SUBTREE,filter,attr , 0 )) == -1 ) { |
---|
67 | > ldap_perror( ld, "ldap_search" ); |
---|
68 | > free(filter); |
---|
69 | > return(0); |
---|
70 | > } |
---|
71 | > free(filter); |
---|
72 | > finished = 0; |
---|
73 | > while ( !finished ) { |
---|
74 | > |
---|
75 | > /* |
---|
76 | > * |
---|
77 | > * * Poll for results. We call ldap_result with the "all" parameter |
---|
78 | > * |
---|
79 | > * * set to zero. This causes ldap_result() to return exactly one |
---|
80 | > * |
---|
81 | > * * entry if at least one entry is available. This allows us to |
---|
82 | > * |
---|
83 | > * * display the entries as they are received. |
---|
84 | > * |
---|
85 | > * */ |
---|
86 | > |
---|
87 | > result = NULL; |
---|
88 | > |
---|
89 | > rc = ldap_result( ld, msgid, 0, &zerotime, &result ); |
---|
90 | > |
---|
91 | > switch (rc) { |
---|
92 | > |
---|
93 | > case -1: |
---|
94 | > |
---|
95 | > /* some error occurred */ |
---|
96 | > ldap_perror( ld, "ldap_result" ); |
---|
97 | > return(0); |
---|
98 | > |
---|
99 | > case 0: |
---|
100 | > /* Timeout was exceeded. No entries are ready for retrieval. */ |
---|
101 | > if (result != NULL) { |
---|
102 | > ldap_msgfree(result); |
---|
103 | > } |
---|
104 | > break; |
---|
105 | > |
---|
106 | > default: |
---|
107 | > |
---|
108 | > /* |
---|
109 | > * |
---|
110 | > * * Either an entry is ready for retrieval, or all entries have |
---|
111 | > * |
---|
112 | > * * been retrieved. |
---|
113 | > * |
---|
114 | > * */ |
---|
115 | > |
---|
116 | > if (( e = ldap_first_entry( ld, result )) == NULL ) { |
---|
117 | > /* All done */ |
---|
118 | > finished = 1; |
---|
119 | > if ( result != NULL ) { |
---|
120 | > ldap_msgfree( result ); |
---|
121 | > } |
---|
122 | > continue; |
---|
123 | > |
---|
124 | > } |
---|
125 | > |
---|
126 | > /* for each entry print out name + all attrs and values */ |
---|
127 | > |
---|
128 | > num_entries++; |
---|
129 | > for ( a = ldap_first_attribute( ld, e, &ber ); |
---|
130 | > a != NULL; a = ldap_next_attribute( ld, e, ber ) ) { |
---|
131 | > if (( vals = ldap_get_values( ld, e, a )) != NULL ) { |
---|
132 | > for ( i = 0; vals[ i ] != NULL; i++ ) |
---|
133 | > strcpy(ret,vals[i]); |
---|
134 | > ldap_value_free( vals ); |
---|
135 | > } |
---|
136 | > ldap_memfree( a ); |
---|
137 | > } |
---|
138 | > |
---|
139 | > ldap_msgfree( result ); |
---|
140 | > |
---|
141 | > } |
---|
142 | > |
---|
143 | > /* Do other work here while you are waiting... */ |
---|
144 | > |
---|
145 | > do_other_work(); |
---|
146 | > |
---|
147 | > } |
---|
148 | > |
---|
149 | > ldap_unbind( ld ); |
---|
150 | > return(1); |
---|
151 | > |
---|
152 | > } |
---|
153 | > |
---|
154 | > |
---|
155 | > |
---|
156 | > |
---|
157 | > |
---|
158 | > static void do_other_work() |
---|
159 | > |
---|
160 | > { |
---|
161 | > global_counter++; |
---|
162 | > } |
---|
163 | > |
---|
164 | |
---|