~ubuntu-branches/ubuntu/natty/freeradius/natty-updates

« back to all changes in this revision

Viewing changes to src/lib/print.c

  • Committer: Bazaar Package Importer
  • Author(s): Josip Rodin
  • Date: 2009-11-23 03:57:37 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20091123035737-zsgtzhfych8hir68
Tags: 2.1.7+dfsg-1
* Adopting the package, closes: #536623.
* New upstream version, closes: #513484.
  + Fixes the blooper in unlang evaluation logic, closes: #526175.
* Used quilt (and added README.source), and moved upstream file patching
  into debian/patches/. The source is no longer in collab-maint git
  (to make it simpler for me to finally get this out the door), but
  kept the .gitignore should we need that again.
* Dropped the dialup_admin/bin/backup_radacct patch (integrated upstream).
* Dropped the raddb/Makefile patch (problem no longer exists upstream).
* Dropped the lib/packet.c lib/radius.c main/listen.c patches (was from
  upstream 2.0.5 anyway).
* Dropped references to otp.conf, it no longer exists upstream.
  Keep removing the conffile statoverride in prerm.
* Dropped references to snmp.conf, it no longer exists upstream.
  Keep removing the conffile statoverride in prerm.
* Ship /etc/freeradius/modules/* in the freeradius package.
* Stop shipping sites-enabled symlinks in the package and instead create
  them only on initial install, thanks to Matej Vela, closes: #533396.
* Add export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" to the init script
  at the request of John Morrissey, closes: #550143.
* Stop installing /var/run/freeradius in the package to silence Lintian.
  The init script already recreates it at will.
* Remove executable bit from example.pl to silence Lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * print.c      Routines to print stuff.
3
3
 *
4
 
 * Version:     $Id: print.c,v 1.56 2008/03/28 10:10:12 aland Exp $
 
4
 * Version:     $Id$
5
5
 *
6
6
 *   This library is free software; you can redistribute it and/or
7
7
 *   modify it under the terms of the GNU Lesser General Public
21
21
 */
22
22
 
23
23
#include        <freeradius-devel/ident.h>
24
 
RCSID("$Id: print.c,v 1.56 2008/03/28 10:10:12 aland Exp $")
 
24
RCSID("$Id$")
25
25
 
26
26
#include        <freeradius-devel/libradius.h>
27
27
 
35
35
 *      Note that we don't care about the length of the input string,
36
36
 *      because '\0' is an invalid UTF-8 character.
37
37
 */
38
 
static int utf8_char(uint8_t *str)
 
38
int fr_utf8_char(const uint8_t *str)
39
39
{
40
40
        if (*str < 0x20) return 0;
41
41
 
127
127
 *      has to be larger than the input string by at least 5 bytes.
128
128
 *      If not, the output is silently truncated...
129
129
 */
130
 
void librad_safeprint(char *in, size_t inlen, char *out, size_t outlen)
 
130
void fr_print_string(const char *in, size_t inlen, char *out, size_t outlen)
131
131
{
132
 
        uint8_t         *str = (uint8_t *)in;
 
132
        const uint8_t   *str = (const uint8_t *) in;
133
133
        int             sp = 0;
134
134
        int             utf8 = 0;
135
135
 
144
144
                 *      Some clients send strings with an off-by-one
145
145
                 *      length (confused with strings in C).
146
146
                 */
147
 
                if ((inlen == 0) && (*str == 0)) break;
 
147
                if ((inlen == 1) && (*str == 0)) break;
148
148
 
149
149
                switch (*str) {
150
150
                        case '\\':
176
176
                        continue;
177
177
                }
178
178
 
179
 
                utf8 = utf8_char((uint8_t *)str);
 
179
                utf8 = fr_utf8_char(str);
180
180
                if (!utf8) {
181
181
                        snprintf(out, outlen, "\\%03o", *str);
182
182
                        out  += 4;
217
217
                        if ((delimitst == 1) && vp->flags.has_tag) {
218
218
                                /* Tagged attribute: print delimter and ignore tag */
219
219
                                buf[0] = '"';
220
 
                                librad_safeprint(vp->vp_strvalue,
 
220
                                fr_print_string(vp->vp_strvalue,
221
221
                                                 vp->length, buf + 1, sizeof(buf) - 2);
222
222
                                strcat(buf, "\"");
223
223
                        } else if (delimitst == 1) {
224
224
                                /* Non-tagged attribute: print delimter */
225
225
                                buf[0] = '"';
226
 
                                librad_safeprint(vp->vp_strvalue,
 
226
                                fr_print_string(vp->vp_strvalue,
227
227
                                                 vp->length, buf + 1, sizeof(buf) - 2);
228
228
                                strcat(buf, "\"");
229
229
 
233
233
 
234
234
                        } else {
235
235
                                /* Non-tagged attribute: no delimiter */
236
 
                                librad_safeprint(vp->vp_strvalue,
 
236
                                fr_print_string(vp->vp_strvalue,
237
237
                                                 vp->length, buf, sizeof(buf));
238
238
                        }
239
239
                        a = buf;
272
272
                        }
273
273
                        if (len > 0) a = buf;
274
274
                        break;
 
275
                case PW_TYPE_SIGNED: /* Damned code for 1 WiMAX attribute */
 
276
                        snprintf(buf, sizeof(buf), "%d", vp->vp_signed);
 
277
                        a = buf;
 
278
                        break;
275
279
                case PW_TYPE_IPADDR:
276
280
                        a = inet_ntop(AF_INET, &(vp->vp_ipaddr),
277
281
                                      buf, sizeof(buf));
329
333
                        a = buf;
330
334
                        break;
331
335
 
 
336
                case PW_TYPE_TLV:
 
337
                        if (outlen <= (2 * (vp->length + 1))) return 0;
 
338
 
 
339
                        strcpy(buf, "0x");
 
340
 
 
341
                        fr_bin2hex(vp->vp_tlv, buf + 2, vp->length);
 
342
                        a = buf;
 
343
                  break;
 
344
 
332
345
                default:
333
346
                        a = "UNKNOWN-TYPE";
334
347
                        break;