~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to dttools/src/auth_hostname.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the file COPYING for details.
 
6
*/
 
7
 
 
8
#include "auth.h"
 
9
#include "debug.h"
 
10
#include "domain_name_cache.h"
 
11
 
 
12
#include <stdlib.h>
 
13
#include <stdio.h>
 
14
#include <string.h>
 
15
#include <unistd.h>
 
16
#include <errno.h>
 
17
 
 
18
static int auth_hostname_assert( struct link *link, struct hash_table *t, time_t stoptime )
 
19
{
 
20
        char line[AUTH_LINE_MAX];
 
21
 
 
22
        if(!link_readline(link,line,sizeof(line),stoptime)) {
 
23
                debug(D_AUTH,"hostname: lost connection");
 
24
                return 0;
 
25
        }
 
26
 
 
27
        if(!strcmp(line,"yes")) {
 
28
                debug(D_AUTH,"hostname: accepted");
 
29
                return 1;
 
30
        }
 
31
 
 
32
        return 0;
 
33
}
 
34
 
 
35
static int auth_hostname_accept( struct link *link, char **subject, struct hash_table *t, time_t stoptime )
 
36
{
 
37
        char addr[LINK_ADDRESS_MAX];
 
38
        char name[DOMAIN_NAME_MAX];
 
39
        int port;
 
40
 
 
41
        if(!link_address_remote(link,addr,&port)) {
 
42
                debug(D_AUTH,"hostname: couldn't get address of link");
 
43
                goto reject;
 
44
        }
 
45
 
 
46
        if(!domain_name_cache_lookup_reverse(addr,name)) {
 
47
                debug(D_AUTH,"hostname: couldn't look up name of %s",name);
 
48
                goto reject;
 
49
        }
 
50
 
 
51
        *subject = strdup(name);
 
52
        if(!*subject) {
 
53
                debug(D_AUTH,"hostname: out of memory");
 
54
                goto reject;
 
55
        }
 
56
 
 
57
        link_putliteral(link,"yes\n",stoptime);
 
58
        return 1;
 
59
 
 
60
        reject:
 
61
        link_putliteral(link,"no\n",stoptime);
 
62
        return 0;
 
63
}
 
64
 
 
65
int auth_hostname_register()
 
66
{
 
67
        debug(D_AUTH,"hostname: registered");
 
68
        return auth_register( "hostname", auth_hostname_assert, auth_hostname_accept );
 
69
}
 
70