Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 145839 | Differences between
and this patch

Collapse All | Expand All

(-)../3/poppassd.c (+68 lines)
Lines 66-71 Link Here
66
#include <shadow.h>
66
#include <shadow.h>
67
#include <signal.h>
67
#include <signal.h>
68
#include <sys/time.h>
68
#include <sys/time.h>
69
#include <getopt.h>
69
#if !__GLIBC__ >= 2
70
#if !__GLIBC__ >= 2
70
#include <ulimit.h>
71
#include <ulimit.h>
71
#endif
72
#endif
Lines 89-94 Link Here
89
#define POP_NEWPASS 1
90
#define POP_NEWPASS 1
90
#define POP_SKIPASS 2
91
#define POP_SKIPASS 2
91
92
93
char **pamstrings[2]; // 0 - oldpass, 1 - newpass
94
92
void WriteToClient (char *fmt, ...)
95
void WriteToClient (char *fmt, ...)
93
{
96
{
94
	va_list ap;
97
	va_list ap;
Lines 115-128 Link Here
115
	line[BUFSIZE-1] = '\0';
118
	line[BUFSIZE-1] = '\0';
116
}
119
}
117
120
121
void showusage(int ret)
122
{
123
	if(ret != 0)
124
		WriteToClient ("500 Invalid option given. Use -h option to get more help.");
125
	else
126
		WriteToClient ( 
127
"Usage: poppassd [OPTION]...\n\
128
\n\
129
-o OLDPASS        Add OLDPASS to the list of PAM messages for old password\n\
130
-n NEWPASS        Add NEWPASS to the list of PAM messages for new password\n\
131
\n\
132
-h                Show this help message and exit\n\
133
");
134
	exit(ret);
135
}
136
137
void setstrings(int argc, char **argv)
138
{
139
     int old=0, new=0, c;
140
     extern int opterr;
141
142
     opterr = 0;
143
     while(1)
144
     {
145
	     c = getopt(argc, argv, "n:o:h");
146
	     if(c==-1) break;
147
	     else if (c=='o') old++;
148
	     else if (c=='n') new++;
149
	     else if (c=='h') showusage(0);
150
	     else showusage(1);
151
     }
152
153
     if(argv[optind] != NULL)
154
	     showusage(1);
155
156
     pamstrings[POP_OLDPASS] = calloc(sizeof(*pamstrings[POP_OLDPASS]), old + 1);
157
     pamstrings[POP_NEWPASS] = calloc(sizeof(*pamstrings[POP_NEWPASS]), new + 1);
158
     if((pamstrings[POP_OLDPASS] == NULL) || (pamstrings[POP_NEWPASS] == NULL))
159
     {
160
	     WriteToClient("500 Could not allocate enough memory");
161
	     exit(1);
162
     }
163
     optind = 1;
164
165
     while(1)
166
     {
167
	     c = getopt(argc, argv, "n:o:");
168
	     if(c==-1) break;
169
	     else if(c=='o') pamstrings[POP_OLDPASS][--old] = optarg;
170
	     else if(c=='n') pamstrings[POP_NEWPASS][--new] = optarg;
171
     }
172
}
173
118
static inline int getstate(const char *msg)
174
static inline int getstate(const char *msg)
119
{
175
{
176
	char **pammsg;
177
120
       /* Interpret possible PAM messages (not including errors) */
178
       /* Interpret possible PAM messages (not including errors) */
179
	for(pammsg = pamstrings[POP_OLDPASS] ; *pammsg ; pammsg++)
180
		if(!strcmp(msg, *pammsg))
181
			return POP_OLDPASS;
182
121
       if(!strcmp(msg, "Password: "))
183
       if(!strcmp(msg, "Password: "))
122
               return POP_OLDPASS;
184
               return POP_OLDPASS;
123
       if(!strcmp(msg, "Enter login(LDAP) password: "))
185
       if(!strcmp(msg, "Enter login(LDAP) password: "))
124
               return POP_OLDPASS;
186
               return POP_OLDPASS;
125
187
188
	for(pammsg = pamstrings[POP_NEWPASS] ; *pammsg ; pammsg++)
189
		if(!strcmp(msg, *pammsg))
190
			return POP_NEWPASS;
191
126
       if(!strcmp(msg, "New password: "))
192
       if(!strcmp(msg, "New password: "))
127
               return POP_NEWPASS;
193
               return POP_NEWPASS;
128
       if(!strcmp(msg, "Re-enter new password: "))
194
       if(!strcmp(msg, "Re-enter new password: "))
Lines 204-209 Link Here
204
     char user[BUFSIZE];
270
     char user[BUFSIZE];
205
     struct passwd *pw, *getpwnam();
271
     struct passwd *pw, *getpwnam();
206
     pam_handle_t *pamh=NULL;
272
     pam_handle_t *pamh=NULL;
273
274
     setstrings(argc, argv);
207
     
275
     
208
     *user = *oldpass = *newpass = 0;
276
     *user = *oldpass = *newpass = 0;
209
277

Return to bug 145839