]> arthur.barton.de Git - netatalk.git/commitdiff
handle extended characters in NBP and zone names.
authorbfernhomberg <bfernhomberg>
Wed, 9 Jun 2004 01:07:16 +0000 (01:07 +0000)
committerbfernhomberg <bfernhomberg>
Wed, 9 Jun 2004 01:07:16 +0000 (01:07 +0000)
bin/getzones/getzones.c
bin/nbp/nbplkup.c
bin/nbp/nbprgstr.c
bin/nbp/nbpunrgstr.c
etc/afpd/afp_config.c
etc/atalkd/config.c

index db44f2b96de8a0a15f4d9125c3eb20ffcb5db59b..1c21498cadeb791743fd9153a91355bb4a6d6094 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: getzones.c,v 1.6 2001-08-11 11:47:22 srittau Exp $
+ * $Id: getzones.c,v 1.6.14.1 2004-06-09 01:07:17 bfernhomberg Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -24,6 +24,7 @@
 #include <netatalk/at.h>
 #include <atalk/atp.h>
 #include <atalk/util.h>
+#include <atalk/unicode.h>
 #include <atalk/zip.h>
 
 void print_zones(short n, char *buf);
@@ -151,7 +152,22 @@ int main( argc, argv )
  */
 void print_zones( short n, char *buf )
 {
+    size_t zone_len;
+    char *zone;
+
     for ( ; n--; buf += (*buf) + 1 ) {
-       printf( "%.*s\n", *buf, buf+1 );
+
+        if ((size_t)(-1) == (zone_len = convert_string_allocate( CH_MAC,
+                       CH_UNIX, buf+1, *buf, &zone)) ) {
+            zone_len = *buf;
+            if (( zone = strdup(buf+1)) == NULL ) {
+               perror( "strdup" );
+               exit( 1 );
+            }
+        }
+
+       printf( "%.*s\n", zone_len, zone );
+
+       free(zone);
     }
 }
index b677e4600234e692c4572d559c9e2d0ad2c932f7..e4bf45a7d3e2be649679c139f16ad4693f657263 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: nbplkup.c,v 1.4 2001-06-29 14:14:46 rufustfirefly Exp $
+ * $Id: nbplkup.c,v 1.4.14.1 2004-06-09 01:07:17 bfernhomberg Exp $
  *
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
@@ -38,6 +38,8 @@
 #include <stdlib.h>
 #endif /* ! sun || ! i386 */
 
+#include <atalk/unicode.h>
+
 char *Obj = "=";
 char *Type = "=";
 char *Zone = "*";
@@ -53,7 +55,7 @@ void Usage( av0 )
        p++;
     }
 
-    printf( "Usage:\t%s [ -A address ] [ -r responses] [ obj:type@zone ]\n", p );
+    printf( "Usage:\t%s [ -A address ] [ -r responses] [-m Mac charset] [ obj:type@zone ]\n", p );
     exit( 1 );
 }
 
@@ -65,12 +67,16 @@ int main( ac, av )
     char               *name;
     int                        i, c, nresp = 1000;
     struct at_addr      addr;
+    char               *obj = NULL;
+    size_t             obj_len;
+    charset_t          chMac = CH_MAC;
+    char *             convname;
 
     extern char                *optarg;
     extern int         optind;
 
     memset(&addr, 0, sizeof(addr));
-    while (( c = getopt( ac, av, "r:A:" )) != EOF ) {
+    while (( c = getopt( ac, av, "r:A:m:" )) != EOF ) {
        switch ( c ) {
        case 'A':
            if (!atalk_aton(optarg, &addr)) {
@@ -81,6 +87,12 @@ int main( ac, av )
        case 'r' :
            nresp = atoi( optarg );
            break;
+        case 'm':
+            if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
+               fprintf(stderr, "Invalid Mac charset.\n");
+               exit(1);
+           }
+            break;
 
        default :
            Usage( av[ 0 ] );
@@ -137,7 +149,11 @@ int main( ac, av )
     }
 
     if ( ac - optind == 1 ) {
-       if ( nbp_name( av[ optind ], &Obj, &Type, &Zone )) {
+       if ((size_t)(-1) == convert_string_allocate( CH_UNIX, chMac,
+                           av[ optind ], strlen(av[optind]), &convname))
+            convname = av[ optind ];
+
+       if ( nbp_name( convname, &Obj, &Type, &Zone )) {
            Usage( av[ 0 ] );
            exit( 1 );
        }
@@ -148,13 +164,26 @@ int main( ac, av )
        exit( -1 );
     }
     for ( i = 0; i < c; i++ ) {
+       
+       if ((size_t)(-1) == (obj_len = convert_string_allocate( chMac, 
+                       CH_UNIX, nn[ i ].nn_obj, nn[ i ].nn_objlen, &obj)) ) {
+            obj_len = nn[ i ].nn_objlen;
+            if (( obj = strdup(nn[ i ].nn_obj)) == NULL ) {
+               perror( "strdup" );
+               exit( 1 );
+           }
+        }
+
        printf( "%31.*s:%-34.*s %u.%u:%u\n",
-               nn[ i ].nn_objlen, nn[ i ].nn_obj,
+               obj_len, obj,
                nn[ i ].nn_typelen, nn[ i ].nn_type,
                ntohs( nn[ i ].nn_sat.sat_addr.s_net ),
                nn[ i ].nn_sat.sat_addr.s_node,
                nn[ i ].nn_sat.sat_port );
+
+       free(obj);
     }
 
+    free(nn);
     return 0;
 }
index b12039603b6b37c3995b1b4b528eef74853e0351..a80a1943289c62e99d6aba19f59b3a9df57d3038 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: nbprgstr.c,v 1.4 2001-06-29 14:14:46 rufustfirefly Exp $
+ * $Id: nbprgstr.c,v 1.4.14.1 2004-06-09 01:07:17 bfernhomberg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -20,6 +20,7 @@
 #include <atalk/netddp.h>
 #include <atalk/nbp.h>
 #include <atalk/util.h>
+#include <atalk/unicode.h>
 
 void Usage( av0 )
     char       *av0;
@@ -32,7 +33,7 @@ void Usage( av0 )
        p++;
     }
 
-    fprintf( stderr, "Usage: %s [ -A address ] obj:type@zone\n", p );
+    fprintf( stderr, "Usage: %s [ -A address ] [-m Mac charset] [ -p port] obj:type@zone\n", p );
     exit( 1 );
 }
 
@@ -43,13 +44,15 @@ int main( ac, av )
     struct sockaddr_at addr;
     struct at_addr      ataddr;
     char               *Obj = 0, *Type = 0, *Zone = 0;
+    char               *convname = 0;
     int                        s, c, port = 0;
+    charset_t          chMac = CH_MAC;
     
     extern char                *optarg;
     extern int         optind;
 
     memset(&ataddr, 0, sizeof(ataddr));
-    while (( c = getopt( ac, av, "p:A:" )) != EOF ) {
+    while (( c = getopt( ac, av, "p:A:m:" )) != EOF ) {
        switch ( c ) {
        case 'A':
            if (!atalk_aton(optarg, &ataddr)) {
@@ -58,6 +61,13 @@ int main( ac, av )
            }
            break;
 
+        case 'm':
+            if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
+                fprintf(stderr, "Invalid Mac charset.\n");
+                exit(1);
+            }
+            break;
+
        case 'p' :
            port = atoi( optarg );
            break;
@@ -71,10 +81,15 @@ int main( ac, av )
        Usage( av[ 0 ] );
     }
 
+    /* Convert the name */
+    if ((size_t)(-1) == convert_string_allocate(CH_UNIX, chMac,
+                        av[optind], strlen(av[optind]), &convname))
+        convname = av[optind];
+
     /*
      * Get the name. If Type or Obj aren't specified, error.
      */
-    if ( nbp_name( av[ optind ], &Obj, &Type, &Zone ) || !Obj || !Type ) {
+    if ( nbp_name( convname, &Obj, &Type, &Zone ) || !Obj || !Type ) {
        Usage( av[ 0 ] );
     }
 
index 4cd68039596e14f5a15a1ca6484a33467d61c34b..df7f9c858918fb549066cc6adeb493e061b54d73 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: nbpunrgstr.c,v 1.5 2001-07-31 19:49:02 srittau Exp $
+ * $Id: nbpunrgstr.c,v 1.5.14.1 2004-06-09 01:07:17 bfernhomberg Exp $
  *
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
@@ -39,6 +39,8 @@
 #include <atalk/util.h>
 #include <atalk/nbp.h>
 
+#include <atalk/unicode.h>
+
 void Usage( av0 )
     char       *av0;
 {
@@ -50,7 +52,7 @@ void Usage( av0 )
        p++;
     }
 
-    fprintf( stderr, "Usage: %s [ -A address ] obj:type@zone\n", p );
+    fprintf( stderr, "Usage: %s [ -A address ] [ -m Mac charset] obj:type@zone\n", p );
     exit( 1 );
 }
 
@@ -59,14 +61,16 @@ int main( ac, av )
     char       **av;
 {
     char               *Obj = 0, *Type = 0, *Zone = 0;
+    char               *convname = 0;
     struct at_addr      addr;
     int                 c;
+    charset_t          chMac = CH_MAC;
 
     extern char                *optarg;
     extern int         optind;
     
     memset(&addr, 0, sizeof(addr));
-    while ((c = getopt(ac, av, "A:")) != EOF) {
+    while ((c = getopt(ac, av, "A:m:")) != EOF) {
       switch (c) {
       case 'A':
        if (!atalk_aton(optarg, &addr)) {
@@ -74,6 +78,13 @@ int main( ac, av )
          exit(1);
        }
        break;
+      case 'm':
+        if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
+          fprintf(stderr, "Invalid Mac charset.\n");
+          exit(1);
+        }
+        break;
+
       default:
        Usage(av[0]);
        break;
@@ -84,10 +95,15 @@ int main( ac, av )
        Usage( av[ 0 ] );
     }
 
+    /* Convert the name */
+    if ((size_t)(-1) == convert_string_allocate(CH_UNIX, chMac, 
+                        av[optind], strlen(av[optind]), &convname))
+        convname = av[optind]; 
+
     /*
      * Get the name. If Type or Obj aren't specified, error.
      */
-    if ( nbp_name( av[optind], &Obj, &Type, &Zone ) || !Obj || !Type ) {
+    if ( nbp_name( convname, &Obj, &Type, &Zone ) || !Obj || !Type ) {
        Usage( av[ 0 ] );
     }
 
index db28e06b5792cf58561107ee6e28976305913b7b..3d702c6db58a868ae4884c0110ef15e6d2ccc650 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_config.c,v 1.22.6.6 2004-05-04 15:38:24 didg Exp $
+ * $Id: afp_config.c,v 1.22.6.7 2004-06-09 01:07:17 bfernhomberg Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved.  See COPYRIGHT.
@@ -253,6 +253,7 @@ static AFPConfig *ASPConfigInit(const struct afp_options *options,
     ATP atp;
     ASP asp;
     char *Obj, *Type = "AFPServer", *Zone = "*";
+    char *convname;
 
     if ((config = (AFPConfig *) calloc(1, sizeof(AFPConfig))) == NULL)
         return NULL;
@@ -272,10 +273,19 @@ static AFPConfig *ASPConfigInit(const struct afp_options *options,
 
     /* register asp server */
     Obj = (char *) options->hostname;
-    if (nbp_name(options->server, &Obj, &Type, &Zone )) {
+    if ((size_t)-1 ==(convert_string_allocate( options->unixcharset, options->maccharset,
+                         options->server, strlen(options->server), &convname)) ) {
+        if ((convname = strdup(options->server)) == NULL ) {
+            LOG(log_error, logtype_afpd, "malloc: %m" );
+            goto serv_free_return;
+        }
+    }
+
+    if (nbp_name(convname, &Obj, &Type, &Zone )) {
         LOG(log_error, logtype_afpd, "main: can't parse %s", options->server );
         goto serv_free_return;
     }
+    free (convname);
 
     /* dup Obj, Type and Zone as they get assigned to a single internal
      * buffer by nbp_name */
index ed034d6131b3e0a7f47cb8fc3fce7f4a77a420be..b29f350e30c76376bccba8683cdf1e542180eb07 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: config.c,v 1.13.6.3 2004-02-14 00:30:51 didg Exp $
+ * $Id: config.c,v 1.13.6.4 2004-06-09 01:07:16 bfernhomberg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved. See COPYRIGHT.
@@ -55,6 +55,7 @@ char *strchr (), *strrchr ();
 #include <sys/stropts.h>
 #endif /* __svr4__ */
 
+#include <atalk/unicode.h>
 #include "interface.h"
 #include "multicast.h"
 #include "rtmp.h"
@@ -187,6 +188,8 @@ int writeconf( cf )
     struct interface   *iface;
     struct list                *l;
     int                        mode = 0644, fd;
+    size_t             len;
+    char               *zonename;
 
     if ( cf == NULL ) {
        path = _PATH_ATALKDCONF;
@@ -259,9 +262,20 @@ int writeconf( cf )
                    ntohs( iface->i_addr.sat_addr.s_net ),
                    iface->i_addr.sat_addr.s_node );
            for ( l = iface->i_rt->rt_zt; l; l = l->l_next ) {
-               fprintf( newconf, " -zone \"%.*s\"",
-                       ((struct ziptab *)l->l_data)->zt_len,
-                       ((struct ziptab *)l->l_data)->zt_name );
+                /* codepage conversion */
+                if ((size_t)(-1) == (len = convert_string_allocate(CH_MAC, CH_UNIX, 
+                                      ((struct ziptab *)l->l_data)->zt_name,
+                                      ((struct ziptab *)l->l_data)->zt_len,
+                                      &zonename)) ) {
+                    if ( NULL == 
+                      (zonename = strdup(((struct ziptab *)l->l_data)->zt_name))) {
+                       LOG(log_error, logtype_atalkd, "malloc: %m" );
+                       return( -1 );
+                    }
+                    len = ((struct ziptab *)l->l_data)->zt_len;
+                } 
+               fprintf( newconf, " -zone \"%.*s\"", len, zonename);
+                free(zonename);
            }
            fprintf( newconf, "\n" );
 
@@ -667,11 +681,16 @@ int zone( iface, av )
     struct ziptab      *zt;
     char               *zname;
 
-    if (( zname = av[ 0 ] ) == NULL ) {
+    if ( av[ 0 ]  == NULL ) {
        fprintf( stderr, "No zone.\n" );
        return -1;
     }
 
+    /* codepage conversion */
+    if ((size_t)(-1) == convert_string_allocate(CH_UNIX, CH_MAC, av[0], strlen(av[0]), &zname)) {
+       zname = strdup(av[0]);
+    }
+
     /*
      * Only process "-zone" if this interface has "-seed".  We keep our
      * list of configured zones in the interface structure.  Then we can
@@ -682,6 +701,7 @@ int zone( iface, av )
            fprintf( stderr, "Must specify net-range before zones.\n" );
            return -1;
         }
+
        if (( zt = newzt( strlen( zname ), zname )) == NULL ) {
            perror( "newzt" );
            return -1;
@@ -693,6 +713,8 @@ int zone( iface, av )
            iface->i_czt->zt_next = zt;
        }
     }
+    free(zname);
+
     return( 2 );
 }