The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
base.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 
17 /**
18  * $Id: ca66b3b60cd49ac9f8018242acf907e48bf043cc $
19  * @file src/protocols/tftp/base.c
20  * @brief TFTP protocol.
21  * @author Jorge Pereira <jpereira@freeradius.org>
22  *
23  * @copyright 2021 The FreeRADIUS server project.
24  * @copyright 2021 Network RADIUS SAS (legal@networkradius.com)
25  */
26 
27 RCSID("$Id: ca66b3b60cd49ac9f8018242acf907e48bf043cc $")
28 
29 #include <freeradius-devel/util/pair.h>
30 
31 #include "tftp.h"
32 #include "attrs.h"
33 
35 
37 
40  { .out = &dict_tftp, .proto = "tftp" },
41  { NULL }
42 };
43 
52 
54 
57  { .out = &attr_tftp_block, .name = "Block", .type = FR_TYPE_UINT16, .dict = &dict_tftp },
58  { .out = &attr_tftp_block_size, .name = "Block-Size", .type = FR_TYPE_UINT16, .dict = &dict_tftp },
59  { .out = &attr_tftp_data, .name = "Data", .type = FR_TYPE_OCTETS, .dict = &dict_tftp },
60  { .out = &attr_tftp_error_code, .name = "Error-Code", .type = FR_TYPE_UINT16, .dict = &dict_tftp },
61  { .out = &attr_tftp_error_message, .name = "Error-Message", .type = FR_TYPE_STRING, .dict = &dict_tftp },
62  { .out = &attr_tftp_filename, .name = "Filename", .type = FR_TYPE_STRING, .dict = &dict_tftp },
63  { .out = &attr_tftp_opcode, .name = "Opcode", .type = FR_TYPE_UINT16, .dict = &dict_tftp },
64  { .out = &attr_tftp_mode, .name = "Mode", .type = FR_TYPE_UINT8, .dict = &dict_tftp },
65 
66  { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_tftp },
67 
68  { NULL }
69 };
70 
72  [FR_PACKET_TYPE_VALUE_READ_REQUEST] = "Read-Request",
73  [FR_PACKET_TYPE_VALUE_WRITE_REQUEST] = "Write-Request",
74  [FR_PACKET_TYPE_VALUE_DATA] = "Data",
75  [FR_PACKET_TYPE_VALUE_ACKNOWLEDGEMENT] = "Acknowledgement",
76  [FR_PACKET_TYPE_VALUE_ERROR] = "Error",
77  [FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND] = "Do-Not-Respond"
78 };
79 
81  [FR_ERROR_CODE_VALUE_FILE_NOT_FOUND] = "File not found",
82  [FR_ERROR_CODE_VALUE_ACCESS_VIOLATION] = "Access violation",
83  [FR_ERROR_CODE_VALUE_DISK_FULL] = "Disk Full",
84  [FR_ERROR_CODE_VALUE_ILLEGAL_OPERATION] = "Illegal TFTP operation",
85  [FR_ERROR_CODE_VALUE_UNKNOWN_TRANSFER_ID] = "Unknown transfer ID",
86  [FR_ERROR_CODE_VALUE_FILE_ALREADY_EXISTS] = "File already exists",
87  [FR_ERROR_CODE_VALUE_NO_SUCH_USER] = "No such user"
88 };
89 
91 {
92  if (instance_count > 0) {
94  return 0;
95  }
96 
98 
100  fail:
101  instance_count--;
102  return -1;
103  }
104 
107  goto fail;
108  }
109 
110 
111  return 0;
112 }
113 
115 {
117 
118  if (--instance_count > 0) return;
119 
121 }
#define RCSID(id)
Definition: build.h:481
#define fr_dict_autofree(_to_free)
Definition: dict.h:850
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition: dict.h:267
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition: dict.h:280
int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load)
Process a dict_attr_autoload element to load/verify a dictionary attribute.
Definition: dict_util.c:4090
#define fr_dict_autoload(_to_load)
Definition: dict.h:847
Specifies an attribute which must be present for the module to function.
Definition: dict.h:266
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition: dict.h:279
fr_dict_attr_t const * attr_packet_type
Definition: base.c:91
@ FR_TYPE_STRING
String of printable characters.
Definition: merged_model.c:83
@ FR_TYPE_UINT16
16 Bit unsigned integer.
Definition: merged_model.c:98
@ FR_TYPE_UINT8
8 Bit unsigned integer.
Definition: merged_model.c:97
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
@ FR_TYPE_OCTETS
Raw octets.
Definition: merged_model.c:84
unsigned int uint32_t
Definition: merged_model.c:33
fr_dict_autoload_t libfreeradius_tftp[]
Definition: base.c:39
fr_dict_attr_t const * attr_tftp_mode
Definition: base.c:51
char const * fr_tftp_error_codes[FR_TFTP_MAX_ERROR_CODE]
Definition: base.c:80
static uint32_t instance_count
Definition: base.c:34
fr_dict_attr_t const * attr_tftp_opcode
Definition: base.c:50
fr_dict_attr_t const * attr_tftp_error_message
Definition: base.c:48
char const * fr_tftp_codes[FR_TFTP_MAX_CODE]
Definition: base.c:71
int fr_tftp_global_init(void)
Definition: base.c:90
fr_dict_attr_t const * attr_tftp_filename
Definition: base.c:49
fr_dict_attr_t const * attr_tftp_block
Definition: base.c:44
fr_dict_attr_t const * attr_tftp_data
Definition: base.c:46
fr_dict_t const * dict_tftp
Definition: base.c:36
fr_dict_attr_autoload_t libfreeradius_tftp_dict_attr[]
Definition: base.c:56
fr_dict_attr_t const * attr_tftp_block_size
Definition: base.c:45
void fr_tftp_global_free(void)
Definition: base.c:114
fr_dict_attr_t const * attr_tftp_error_code
Definition: base.c:47
VQP attributes.
fr_assert(0)
Functions to encode/decode TFTP packets.
#define FR_TFTP_MAX_CODE
Definition: tftp.h:39
#define FR_TFTP_MAX_ERROR_CODE
Definition: tftp.h:40