Exemple #1
0
static void
passwd_verify_plain(struct auth_request *request, const char *password,
		    verify_plain_callback_t *callback)
{
	struct passwd pw;
	enum passdb_result res;
	int ret;

	res = passwd_lookup(request, &pw);
	if (res != PASSDB_RESULT_OK) {
		callback(res, request);
		return;
	}
	/* check if the password is valid */
	ret = auth_request_password_verify(request, password, pw.pw_passwd,
					   PASSWD_PASS_SCHEME, AUTH_SUBSYS_DB);

	/* clear the passwords from memory */
	safe_memset(pw.pw_passwd, 0, strlen(pw.pw_passwd));

	if (ret <= 0) {
		callback(PASSDB_RESULT_PASSWORD_MISMATCH, request);
		return;
	}

	/* make sure we're using the username exactly as it's in the database */
        auth_request_set_field(request, "user", pw.pw_name, NULL);

	callback(PASSDB_RESULT_OK, request);
}
Exemple #2
0
/*
 * Return FILE for output packet
 */
FILE *outpkt_open(Node *from, Node *to,
		   int grade, int type, int flav, int bad)
{
    Packet pkt;
    OutPkt *p;
    Passwd *pwd;

    /*
     * Search for existing packet
     */
    for(p=outpkt_first; p; p=p->next)
	if(node_eq(from, &p->from) && node_eq(to, &p->to) &&
	   flav==p->flav && type==p->type && grade==p->grade && bad==p->bad)
	{
	    p->n++;
	    /* If file exists, but isn't currently opened, reopen it */
	    if(!p->fp)
		p->fp = outpkt_fopen(p->tmpname, A_MODE);
	    return p->fp;
	}

    /*
     * Doesn't exist, create a new one
     */
    p = outpkt_new(from, to);
    outpkt_names(p, grade, type, flav, bad);

    /* Open file and write header */
    p->fp = outpkt_fopen(p->tmpname, W_MODE);
    if(p->fp == NULL)
    {
	fglog("$failed to open packet %s", p->tmpname);
	return NULL;
    }
    
    debug(2, "New packet %s (%s): %s -> %s",
	  p->outname, p->tmpname,
	  znfp1(&p->from), znfp2(&p->to)    );
    
    pkt.from = p->from;
    pkt.to   = p->to;
    pkt.time = time(NULL);
    /* Password */
    pwd = passwd_lookup("packet", to);
    BUF_COPY(pkt.passwd, pwd ? pwd->passwd : "");

    /* Rest is filled in by pkt_put_hdr() */
    if(pkt_put_hdr(p->fp, &pkt) == ERROR)
    {
	fglog("$Can't write to packet file %s", p->tmpname);
	fclose(p->fp);
	p->fp = NULL;
	return NULL;
    }

    /* o.k., return the FILE */
    return p->fp;
}
Exemple #3
0
static void
passwd_lookup_credentials(struct auth_request *request,
			  lookup_credentials_callback_t *callback)
{
	struct passwd pw;
	enum passdb_result res;

	res = passwd_lookup(request, &pw);
	if (res != PASSDB_RESULT_OK) {
		callback(res, NULL, 0, request);
		return;
	}
	/* make sure we're using the username exactly as it's in the database */
        auth_request_set_field(request, "user", pw.pw_name, NULL);
	passdb_handle_credentials(PASSDB_RESULT_OK, pw.pw_passwd,
				  PASSWD_PASS_SCHEME, callback, request);
}
Exemple #4
0
/*
 * Create new packet
 */
static FILE *pkt_create(Node *to)
{
    Packet pkt;
    Passwd *pwd;
    
    if((packet_file = fopen(packet_tmp, W_MODE)) == NULL)
    {
	fglog("$ERROR: pkt_open(): can't create packet %s", packet_tmp);
	return NULL;
    }
    
    /*
     * Change mode to PACKET_MODE
     */
    chmod(packet_tmp, PACKET_MODE);
    
    debug(4, "New packet file %s (tmp %s)", packet_name, packet_tmp);

#ifndef BEST_AKA
    cf_set_zone(to->zone);
#else
    cf_set_best(to->zone, to->net, to->node);
#endif /* !BEST_AKA */
    
    /*
     * Write packet header
     */
    pkt.from = cf_n_addr();
    pkt.to   = *to;
    pkt.time = time(NULL);
    /* Password */
    pwd = passwd_lookup("packet", to);
    BUF_COPY(pkt.passwd, pwd ? pwd->passwd : "");

    /* Rest is filled in by pkt_put_hdr() */
    if(pkt_put_hdr(packet_file, &pkt) == ERROR)
    {
	fglog("$ERROR: can't write to packet file %s", packet_tmp);
	return NULL;
    }

    return packet_file;
}
Exemple #5
0
static FILE *pkt_open_node(Node *node, char *flav, int bsy)
{
    char *out;
    FILE *fp;
    long pos;
    Packet pkt;
    int count;
    
    /* Name of .OUT file */
    out = bink_find_out(node, flav);
    if(!out)
	return NULL;
    /* Create directory if necessary */
    if(bink_mkdir(node) == ERROR)
	return NULL;

    packet_bsy = bsy;
    if(bsy)
	if(bink_bsy_create(node, WAIT) == ERROR)
	    return NULL;

    pkt_newname(out);

    /*
     * Open and lock OUT packet
     */
    count = 0;
    do
    {
	count++;
	/*
	 * Check count and give up, if too many retries
	 */
	if(count >= MAX_COUNT)
	{
	    fp = NULL;
	    break;
	}
	
	/* Open OUT file for append, creating empty one if necessary */
	debug(4, "Open OUT file in append mode");
	fp = fopen(out, A_MODE);
	if(fp == NULL)
	{
	    /* If this failed we're out of luck ... */
	    fglog("$ERROR: can't open OUT file %s", out);
	    break;
	}

	/* Reopen in read/write mode */
	debug(4, "Reopen OUT file in read/write mode");
	fclose(fp);
	fp = fopen(out, RP_MODE);
	if(fp == NULL)
	{
	    /* OUT file deleted in the meantime - retry */
	    debug(4, "OUT file deleted, retrying");
	    continue;
	}
	chmod(out, PACKET_MODE);

	/* Lock it, waiting for lock to be granted */
	debug(4, "Locking OUT file");
	if(lock_file(fp))
	{
	    /* Lock error ... */
	    fglog("$ERROR: can't lock OUT file %s", out);
	    fclose(fp);
	    fp = NULL;
	    break;
	}

	/* Lock succeeded, but the OUT file may have been deleted */
	if(access(out, F_OK) == -1)
	{
	    debug(4, "OUT file deleted, retrying");
	    fclose(fp);
	    fp = NULL;
	}
    }
    while(fp == NULL);

    /*
     * fp==NULL is an error in the do ... while loop
     */
    if(fp == NULL)
    {
	if(bsy)
	    bink_bsy_delete(node);
	return NULL;
    }

    /*
     * Test, whether this is a new empty packet, or an already existing one.
     */
    /* Seek to EOF */
    if(fseek(fp, 0L, SEEK_END) == -1)
    {
	/* fseek() error ... */
	fglog("$ERROR: fseek EOF OUT file %s failed", out);
	if(bsy)
	    bink_bsy_delete(node);
	fclose(fp);
	return NULL;
    }
    if( (pos = ftell(fp)) == -1L )
    {
	/* ftell() error ... */
	fglog("$ERROR: ftell OUT file %s failed", out);
	if(bsy)
	    bink_bsy_delete(node);
	fclose(fp);
	return NULL;
    }

    if(pos == 0L)
    {
	Passwd *pwd;
	
	/*
	 * This is a new packet file
	 */
	debug(4, "%s is a new packet, writing header", out);
	
#ifndef BEST_AKA
        cf_set_zone(node->zone);
#else
	cf_set_best(node->zone, node->net, node->node);
#endif /* !BEST_AKA */

	pkt.from = cf_n_addr();
	pkt.to   = *node;
	pkt.time = time(NULL);
	/* Password */
	pwd = passwd_lookup("packet", node);
	BUF_COPY(pkt.passwd, pwd ? pwd->passwd : "");

	/* Rest is filled in by pkt_put_hdr() */
	if(pkt_put_hdr(fp, &pkt) == ERROR)
	{
	    fglog("$ERROR: can't write to packet file %s", out);
	    if(bsy)
		bink_bsy_delete(node);
	    fclose(fp);
	    return NULL;
	}
    }
    else
    {
	/*
	 * This is an already existing packet file: seek to end of file
	 * - 2, there must be a terminating 0-word. Start writing new data
	 * at the EOF - 2 position.
	 */
	debug(4, "%s already exists, seek to EOF-2", out);

	if(fseek(fp, -2L, SEEK_END) == -1)
	{
	    /* fseek() error ... */
	    fglog("$ERROR: fseek EOF-2 OUT file %s failed", out);
	    if(bsy)
		bink_bsy_delete(node);
	    fclose(fp);
	    return NULL;
	}
	if( pkt_get_int16(fp) != 0L )
	{
	    fglog("$ERROR: malformed packet %s, no terminating 0-word", out);
	    if(bsy)
		bink_bsy_delete(node);
	    fclose(fp);
	    return NULL;
	}
	if(fseek(fp, -2L, SEEK_END) == -1)
	{
	    /* fseek() error ... */
	    fglog("$ERROR: fseek EOF-2 OUT file %s failed", out);
	    if(bsy)
		bink_bsy_delete(node);
	    fclose(fp);
	    return NULL;
	}
    }

    packet_file = fp;
    packet_node = *node;
    
    return fp;
}