INN commit: trunk/nnrpd (commands.c nnrpd.h perl.c perm.c python.c)
INN Commit
Russ_Allbery at isc.org
Sat Dec 27 13:39:23 UTC 2008
Date: Saturday, December 27, 2008 @ 05:39:23
Author: iulius
Revision: 8266
Remove useless intermediate variables to handle the response
code of Perl and Python authentication filters. We now have
a pointer to the response code that we can use in several
functions.
#see 107
Modified:
trunk/nnrpd/commands.c
trunk/nnrpd/nnrpd.h
trunk/nnrpd/perl.c
trunk/nnrpd/perm.c
trunk/nnrpd/python.c
------------+
commands.c | 17 +++++++----------
nnrpd.h | 6 +++---
perl.c | 12 ++++--------
perm.c | 20 +++++++++-----------
python.c | 20 ++++++++------------
5 files changed, 31 insertions(+), 44 deletions(-)
Modified: commands.c
===================================================================
--- commands.c 2008-12-27 09:40:24 UTC (rev 8265)
+++ commands.c 2008-12-27 13:39:23 UTC (rev 8266)
@@ -246,8 +246,7 @@
static char Password[SMBUF];
char accesslist[BIG_BUFFER];
char errorstr[BIG_BUFFER];
- char code[BIG_BUFFER];
- int codenum;
+ int code;
if (strcasecmp(av[1], "GENERIC") == 0) {
char *logrec = Glom(av);
@@ -358,9 +357,9 @@
strlcpy(Password, av[2], sizeof(Password));
errorstr[0] = '\0';
- snprintf(code, sizeof(code), "%d", NNTP_FAIL_AUTHINFO_BAD);
+ code = NNTP_FAIL_AUTHINFO_BAD;
- PERMlogin(User, Password, code, errorstr);
+ PERMlogin(User, Password, &code, errorstr);
PERMgetpermissions();
/* If authentication is successful. */
@@ -378,12 +377,10 @@
return;
}
- codenum = atoi(code);
-
/* For backwards compatibility, we return 481 instead of 502 (which had
* the same meaning as 481 in RFC 2980). */
- if (codenum == NNTP_ERR_ACCESS) {
- codenum = NNTP_FAIL_AUTHINFO_BAD;
+ if (code == NNTP_ERR_ACCESS) {
+ code = NNTP_FAIL_AUTHINFO_BAD;
}
syslog(L_NOTICE, "%s bad_auth", Client.host);
@@ -391,11 +388,11 @@
if (errorstr[0] != '\0') {
syslog(L_NOTICE, "%s script error str: %s", Client.host, errorstr);
Reply("%d %s\r\n",
- codenum != NNTP_FAIL_AUTHINFO_BAD ? NNTP_FAIL_ACTION : codenum,
+ code != NNTP_FAIL_AUTHINFO_BAD ? NNTP_FAIL_ACTION : code,
errorstr);
} else {
Reply("%d Authentication failed\r\n",
- codenum != NNTP_FAIL_AUTHINFO_BAD ? NNTP_FAIL_ACTION : codenum);
+ code != NNTP_FAIL_AUTHINFO_BAD ? NNTP_FAIL_ACTION : code);
}
}
}
Modified: nnrpd.h
===================================================================
--- nnrpd.h 2008-12-27 09:40:24 UTC (rev 8265)
+++ nnrpd.h 2008-12-27 13:39:23 UTC (rev 8266)
@@ -227,7 +227,7 @@
extern bool PERMartok(void);
extern void PERMgetaccess(char *nnrpaccess);
extern void PERMgetpermissions(void);
-extern void PERMlogin(char *uname, char *pass, char* code, char *errorstr);
+extern void PERMlogin(char *uname, char *pass, int* code, char *errorstr);
extern bool PERMmatch(char **Pats, char **list);
extern bool ParseDistlist(char ***argvp, char *list);
extern void SetDefaultAccess(ACCESSGROUP*);
@@ -276,14 +276,14 @@
#ifdef DO_PERL
extern void loadPerl(void);
extern void perlAccess(char *user, struct vector *access_vec);
-extern int perlAuthenticate(char *user, char *passwd, char *code, char *errorstring, char*newUser);
+extern void perlAuthenticate(char *user, char *passwd, int *code, char *errorstring, char*newUser);
extern void perlAuthInit(void);
#endif /* DO_PERL */
#ifdef DO_PYTHON
extern bool PY_use_dynamic;
-int PY_authenticate(char *path, char *Username, char *Password, char *code, char *errorstring, char *newUser);
+void PY_authenticate(char *path, char *Username, char *Password, int *code, char *errorstring, char *newUser);
void PY_access(char* path, struct vector *access_vec, char *Username);
void PY_close_python(void);
int PY_dynamic(char *Username, char *NewsGroup, int PostFlag, char **reply_message);
Modified: perl.c
===================================================================
--- perl.c 2008-12-27 09:40:24 UTC (rev 8265)
+++ perl.c 2008-12-27 13:39:23 UTC (rev 8266)
@@ -326,17 +326,16 @@
}
-int
-perlAuthenticate(char *user, char *passwd, char *code, char *errorstring, char *newUser)
+void
+perlAuthenticate(char *user, char *passwd, int *code, char *errorstring, char *newUser)
{
dSP;
HV *attribs;
int rc;
char *p;
- int codenum;
if (!PerlFilterActive)
- return NNTP_ERR_ACCESS;
+ *code = NNTP_FAIL_AUTHINFO_BAD;
if (perl_get_cv("authenticate", 0) == NULL) {
syslog(L_ERROR, "Perl function authenticate not defined");
@@ -385,16 +384,13 @@
p = POPp;
strlcpy(errorstring, p, BIG_BUFFER);
- codenum = POPi;
- snprintf(code, sizeof(code), "%d", codenum);
+ *code = POPi;
hv_undef(attribs);
PUTBACK;
FREETMPS;
LEAVE;
-
- return codenum;
}
Modified: perm.c
===================================================================
--- perm.c 2008-12-27 09:40:24 UTC (rev 8265)
+++ perm.c 2008-12-27 13:39:23 UTC (rev 8266)
@@ -85,7 +85,7 @@
static bool MatchHost(char*, char*, char*);
static int MatchUser(char*, char*);
static char *ResolveUser(AUTHGROUP*);
-static char *AuthenticateUser(AUTHGROUP*, char*, char*, char*, char*);
+static char *AuthenticateUser(AUTHGROUP*, char*, char*, int*, char*);
static void GrowArray(void*, void*);
static void PERMvectortoaccess(ACCESSGROUP *acc, const char *name, struct vector *acccess_vec) UNUSED;
@@ -1481,7 +1481,7 @@
}
void
-PERMlogin(char *uname, char *pass, char *code, char *errorstr)
+PERMlogin(char *uname, char *pass, int *code, char *errorstr)
{
int i = 0;
char *runame;
@@ -1959,7 +1959,7 @@
*/
static char *
AuthenticateUser(AUTHGROUP *auth, char *username, char *password,
- char *code UNUSED, char *errorstr UNUSED)
+ int *code UNUSED, char *errorstr UNUSED)
{
int i, j;
char *command;
@@ -1983,7 +1983,6 @@
for (i = 0; auth->auth_methods[i]; i++) {
if (auth->auth_methods[i]->type == PERMperl_auth) {
#ifdef DO_PERL
- int codenum;
char *script_path, *cp;
char **args;
char newUser[BIG_BUFFER];
@@ -2000,8 +1999,8 @@
perlAuthInit();
newUser[0] = '\0';
- codenum = perlAuthenticate(username, password, code, errorstr, newUser);
- if (codenum == NNTP_OK_AUTHINFO) {
+ perlAuthenticate(username, password, code, errorstr, newUser);
+ if (*code == NNTP_OK_AUTHINFO) {
if (newUser[0] != '\0')
user = xstrdup(newUser);
else
@@ -2021,7 +2020,6 @@
#endif /* DO_PERL */
} else if (auth->auth_methods[i]->type == PERMpython_auth) {
#ifdef DO_PYTHON
- int codenum;
char *script_path, *cp;
char **args;
char newUser[BIG_BUFFER];
@@ -2032,10 +2030,10 @@
script_path = concat(args[0], (char *) 0);
if ((script_path != NULL) && (strlen(script_path) > 0)) {
newUser[0] = '\0';
- codenum = PY_authenticate(script_path, username, password,
- code, errorstr, newUser);
+ PY_authenticate(script_path, username, password,
+ code, errorstr, newUser);
free(script_path);
- if (codenum == NNTP_OK_AUTHINFO) {
+ if (*code == NNTP_OK_AUTHINFO) {
if (newUser[0] != '\0')
user = xstrdup(newUser);
else
@@ -2046,7 +2044,7 @@
fflush(locallog);
}
break;
- } else if (codenum < 0) {
+ } else if (*code < 0) {
syslog(L_NOTICE, "PY_authenticate(): authentication skipped due to no Python authentication method defined.");
} else {
syslog(L_NOTICE, "%s bad_auth", Client.host);
Modified: python.c
===================================================================
--- python.c 2008-12-27 09:40:24 UTC (rev 8265)
+++ python.c 2008-12-27 13:39:23 UTC (rev 8266)
@@ -99,16 +99,16 @@
/*
** Authenticate connecting host by username&password.
**
-** Return NNTP reply code as returned by Python method or -1 if method
-** is not defined.
+** code contains the NNTP reply code as returned by Python method
+** or -1 if method is not defined.
*/
-int
-PY_authenticate(char* file, char *Username, char *Password, char *code,
+void
+PY_authenticate(char* file, char *Username, char *Password, int *code,
char *errorstring, char *newUser)
{
PyObject *result, *item, *proc;
int authnum;
- int codenum, i;
+ int i;
char *temp;
PY_load_python();
@@ -116,7 +116,7 @@
/* Return if authentication method is not defined. */
if (proc == NULL)
- return -1;
+ *code = -1;
/* Initialize PythonAuthObject with connect method specific items. */
authnum = 0;
@@ -187,8 +187,7 @@
}
/* Store the code. */
- codenum = PyInt_AS_LONG(item);
- snprintf(code, sizeof(code), "%d", codenum);
+ *code = PyInt_AS_LONG(item);
/* Get the error string. */
item = PyTuple_GetItem(result, 1);
@@ -233,10 +232,7 @@
}
/* Log auth result. */
- syslog(L_NOTICE, "python authenticate method succeeded, return code %d, error string %s", codenum, errorstring);
-
- /* Return response code. */
- return codenum;
+ syslog(L_NOTICE, "python authenticate method succeeded, return code %d, error string %s", *code, errorstring);
}
More information about the inn-committers
mailing list