File: auth.c

package info (click to toggle)
dns2tcp 0.5.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,268 kB
  • sloc: ansic: 5,320; sh: 3,553; makefile: 63
file content (105 lines) | stat: -rw-r--r-- 3,220 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
** Copyright (C) 2006 Olivier DEMBOUR
** $Id: auth.c,v 1.19.4.3 2010/01/06 12:50:40 dembour Exp $
**
** 
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with This program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <string.h>
#include <stdio.h>       

#include "client.h"
#include "dns.h"
#include "myerror.h"
#include "list.h"
#include "requests.h"
#include "socket.h"
#include "base64.h"
#include "myrand.h"
#include "session.h"
#include "myerror.h"
#include "debug.h"
#include "rr.h"

/**
 * @brief ask and list remote resource available
 * @param[in] conf configuration
 * @retval 0 on success
 * @retval -1 on error
 **/

int			list_resources(t_conf *conf)
{
  char			domain[MAX_DNS_LEN + 1];
  char			buffer[MAX_DNS_LEN + 1];
  int			len;
  uint16_t		id, session_id;
  t_request		request;
  uint32_t		count = 0;
  uint8_t		compress;

  if (!((session_id = create_session(conf))))
    return (-1);
  if (create_simple_req(conf, &request, RESOURCE, (char *)&domain, session_id))
    return (-1);
  DPRINTF(1, "Requesting resource\n");
  if ((id = send_query(conf, &request)) == 0)
    return (-1);
  if (!(request.len = get_simple_reply(conf, (char *)&request.req_data, id)))
    return (-1);
  printf("Available connection(s) : \n");
  while ((len = request.request_functions->rr_decode_next_reply(&request, (char *)&buffer, MAX_DNS_LEN , count++)))
    {
      buffer[len] = 0;
      printf("\t%s\n", &buffer[PACKET_LEN]);
    }
  compress = query_is_compressed((char *)&(request.req_data), request.len);
  printf("\nNote : Compression %s available !\n", compress ? "SEEMS" : "NOT");
  return (0);
}

/**
 * @brief connect to a specific ressource
 * @param[in] conf configuration
 * @param[in] session_id session identifier
 * @retval 0 on success
 * @retval 1 on error
 **/

uint16_t		connect_resource(t_conf *conf, uint16_t session_id)
{
  char			domain[MAX_DNS_LEN + 1];
  char			*resource;
  char			buffer[MAX_DNS_LEN + 1];
  int			len;
  t_request		request;
  t_packet		*packet;

  if (create_simple_req(conf, &request, CONNECT, (char *)&domain, session_id))
    return(-1);
  resource = &request.req_data[PACKET_LEN];
  DPRINTF(1, "Connect to resource \"%s\"\n", conf->resource);
  strncpy(resource, conf->resource, sizeof(request.req_data) - PACKET_LEN - 1);
  request.len = PACKET_LEN + strlen(conf->resource);
  if ((len = transceive_query(conf, &request, (char *)&buffer, sizeof(buffer)-1 )) == -1)
    return (1);
  buffer[len] = 0;
  packet = (t_packet *)&buffer;
  if (packet->type != OK)
    fprintf(stderr, "Error : %s\n", (char *) (packet+1));
  return (packet->type != OK);
}