]> arthur.barton.de Git - netatalk.git/blob - bin/nbp/nbpunrgstr.c
- merge branch-netatalk-afp-3x-dev, HEAD was tagged before
[netatalk.git] / bin / nbp / nbpunrgstr.c
1 /*
2  * $Id: nbpunrgstr.c,v 1.6 2005-04-28 20:49:20 bfernhomberg Exp $
3  *
4  * Copyright (c) 1990,1991 Regents of The University of Michigan.
5  * All Rights Reserved.
6  *
7  * Permission to use, copy, modify, and distribute this software and
8  * its documentation for any purpose and without fee is hereby granted,
9  * provided that the above copyright notice appears in all copies and
10  * that both that copyright notice and this permission notice appear
11  * in supporting documentation, and that the name of The University
12  * of Michigan not be used in advertising or publicity pertaining to
13  * distribution of the software without specific, written prior
14  * permission. This software is supplied as is without expressed or
15  * implied warranties of any kind.
16  *
17  *      Research Systems Unix Group
18  *      The University of Michigan
19  *      c/o Mike Clark
20  *      535 W. William Street
21  *      Ann Arbor, Michigan
22  *      +1-313-763-0525
23  *      netatalk@itd.umich.edu
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif /* HAVE_CONFIG_H */
29
30 #include <sys/types.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
34 #ifdef HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif /* HAVE_UNISTD_H */
37 #include <netatalk/endian.h>
38 #include <netatalk/at.h>
39 #include <atalk/util.h>
40 #include <atalk/nbp.h>
41
42 #include <atalk/unicode.h>
43
44 void Usage( av0 )
45     char        *av0;
46 {
47     char        *p;
48
49     if (( p = strrchr( av0, '/' )) == 0 ) {
50         p = av0;
51     } else {
52         p++;
53     }
54
55     fprintf( stderr, "Usage: %s [ -A address ] [ -m Mac charset] obj:type@zone\n", p );
56     exit( 1 );
57 }
58
59 int main( ac, av )
60     int         ac;
61     char        **av;
62 {
63     char                *Obj = 0, *Type = 0, *Zone = 0;
64     char                *convname = 0;
65     struct at_addr      addr;
66     int                 c;
67     charset_t           chMac = CH_MAC;
68
69     extern char         *optarg;
70     extern int          optind;
71     
72     memset(&addr, 0, sizeof(addr));
73     while ((c = getopt(ac, av, "A:m:")) != EOF) {
74       switch (c) {
75       case 'A':
76         if (!atalk_aton(optarg, &addr)) {
77           fprintf(stderr, "Bad address.\n");
78           exit(1);
79         }
80         break;
81       case 'm':
82         if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
83           fprintf(stderr, "Invalid Mac charset.\n");
84           exit(1);
85         }
86         break;
87
88       default:
89         Usage(av[0]);
90         break;
91       }
92     }
93
94     if (ac - optind != 1) {
95         Usage( av[ 0 ] );
96     }
97
98     /* Convert the name */
99     if ((size_t)(-1) == convert_string_allocate(CH_UNIX, chMac, 
100                         av[optind], strlen(av[optind]), &convname))
101         convname = av[optind]; 
102
103     /*
104      * Get the name. If Type or Obj aren't specified, error.
105      */
106     if ( nbp_name( convname, &Obj, &Type, &Zone ) || !Obj || !Type ) {
107         Usage( av[ 0 ] );
108     }
109
110     if ( nbp_unrgstr( Obj, Type, Zone, &addr ) < 0 ) {
111         fprintf( stderr, "Can't unregister %s:%s@%s\n", Obj, Type,
112                 Zone ? Zone : "*" );
113         exit( 1 );
114     }
115
116     return 0;
117 }