Pessoal,
algu�m tem id�ia de como poderia obter o ip do usu�rio do squid que est�
sendo autenticado pelo ncsa_auth.
Abaixo est� um fragmento do c�digo do ncsa_auth.
Precido de algo mais ou menos assim:
char ipaddr[20];
ipaddr = ip_do_usuario_sendo_autenticado;
S� isso :-)
Algu�m tem id�ia ??
Desculpe pelo c�digo extenso....
Obrigado.
/* ********************************************* */
/* INICIO DO ncsa_auth.c */
/*
* ncsa_auth.c
*/
#include "config.h"
corta ...
#include "util.h"
#include "hash.h"
static hash_table *hash = NULL;
static HASHFREE my_free;
typedef struct _user_data {
/* first two items must be same as hash_link */
char *user;
struct _user_data *next;
char *passwd;
} user_data;
static void
my_free(void *p)
{
user_data *u = p;
xfree(u->user);
xfree(u->passwd);
xfree(u);
}
static void
read_passwd_file(const char *passwdfile)
{
FILE *f;
char buf[8192];
user_data *u;
char *user;
char *passwd;
if (hash != NULL) {
hashFreeItems(hash, my_free);
}
/* initial setup */
hash = hash_create((HASHCMP *) strcmp, 7921, hash_string);
if (NULL == hash) {
fprintf(stderr, "ncsa_auth: cannot create hash table\n");
exit(1);
}
f = fopen(passwdfile, "r");
corta..
}
fclose(f);
}
int
main(int argc, char **argv)
{
struct stat sb;
time_t change_time = 0;
char buf[256];
char *user, *passwd, *p;
user_data *u;
setbuf(stdout, NULL);
if (argc != 2) {
fprintf(stderr, "Usage: ncsa_auth <passwordfile>\n");
exit(1);
}
if (stat(argv[1], &sb) != 0) {
fprintf(stderr, "cannot stat %s\n", argv[1]);
exit(1);
}
while (fgets(buf, 256, stdin) != NULL) {
if ((p = strchr(buf, '\n')) != NULL)
*p = '\0'; /* strip \n */
if (stat(argv[1], &sb) == 0) {
if (sb.st_mtime != change_time) {
read_passwd_file(argv[1]);
change_time = sb.st_mtime;
}
}
if ((user = strtok(buf, " ")) == NULL) {
printf("ERR\n");
continue;
}
if ((passwd = strtok(NULL, "")) == NULL) {
printf("ERR\n");
continue;
}
u = hash_lookup(hash, user);
if (u == NULL) {
printf("ERR\n");
} else if (strcmp(u->passwd, (char *) crypt(passwd, u->passwd))) {
printf("ERR\n");
} else {
printf("OK\n");
}
}
exit(0);
}
/* FIM DO ncsa_auth */
Assinantes em 18/06/2002: 2237
Mensagens recebidas desde 07/01/1999: 171629
Historico e [des]cadastramento: http://linux-br.conectiva.com.br
Assuntos administrativos e problemas com a lista:
mailto:[EMAIL PROTECTED]