1 /* $Id: sendpass.c 7145 2005-04-10 03:28:01Z rra $
10 #include "inn/innconf.h"
17 ** Send authentication information to an NNTP server.
19 int NNTPsendpassword(char *server, FILE *FromServer, FILE *ToServer)
31 /* Default to innconf->server. If that's not set either, error out. Fake
32 errno since some of our callers rely on it. */
34 server = innconf->server;
40 /* Open the password file; coarse check on errno, but good enough. */
41 path = concatpath(innconf->pathetc, _PATH_NNTPPASS);
45 return errno == EPERM ? -1 : 0;
47 /* Scan the file, skipping blank and comment lines. */
48 while (fgets(buff, sizeof buff, F) != NULL) {
49 if ((p = strchr(buff, '\n')) != NULL)
51 if (buff[0] == '\0' || buff[0] == '#')
55 if ((user = strchr(buff, ':')) == NULL)
58 if ((pass = strchr(user, ':')) == NULL)
61 if ((style = strchr(pass, ':')) != NULL) {
63 if (strcmp(style, "authinfo") != 0) {
69 if (strcasecmp(server, buff) != 0)
73 /* Send the first part of the command, get a reply. */
74 fprintf(ToServer, "authinfo user %s\r\n", user);
75 if (fflush(ToServer) == EOF || ferror(ToServer))
77 if (fgets(input, sizeof input, FromServer) == NULL
78 || atoi(input) != NNTP_AUTH_NEXT_VAL)
83 /* Send the second part of the command, get a reply. */
84 fprintf(ToServer, "authinfo pass %s\r\n", pass);
85 if (fflush(ToServer) == EOF || ferror(ToServer))
87 if (fgets(input, sizeof input, FromServer) == NULL
88 || atoi(input) != NNTP_AUTH_OK_VAL)
97 /* End of file without finding a password, that's okay. */
103 /* Save errno, close the file, fail. */