1/* 2 * $Id: nbpunrgstr.c,v 1.10 2009-10-29 11:35:58 didg 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 44static void Usage(char *av0) 45{ 46 char *p; 47 48 if (( p = strrchr( av0, '/' )) == NULL ) { 49 p = av0; 50 } else { 51 p++; 52 } 53 54 fprintf( stderr, "Usage: %s [ -A address ] [ -m Mac charset] obj:type@zone\n", p ); 55 exit( 1 ); 56} 57 58int main(int ac, char **av) 59{ 60 char *Obj = NULL, *Type = NULL, *Zone = NULL; 61 char *convname = NULL; 62 struct at_addr addr; 63 int c; 64 charset_t chMac = CH_MAC; 65 66 extern char *optarg; 67 extern int optind; 68 69 memset(&addr, 0, sizeof(addr)); 70 while ((c = getopt(ac, av, "A:m:")) != EOF) { 71 switch (c) { 72 case 'A': 73 if (!atalk_aton(optarg, &addr)) { 74 fprintf(stderr, "Bad address.\n"); 75 exit(1); 76 } 77 break; 78 case 'm': 79 if ((charset_t)-1 == (chMac = add_charset(optarg)) ) { 80 fprintf(stderr, "Invalid Mac charset.\n"); 81 exit(1); 82 } 83 break; 84 85 default: 86 Usage(av[0]); 87 break; 88 } 89 } 90 91 if (ac - optind != 1) { 92 Usage( av[ 0 ] ); 93 } 94 95 /* Convert the name */ 96 if ((size_t)(-1) == convert_string_allocate(CH_UNIX, chMac, 97 av[optind], -1, &convname)) 98 convname = av[optind]; 99 100 /* 101 * Get the name. If Type or Obj aren't specified, error. 102 */ 103 if ( nbp_name( convname, &Obj, &Type, &Zone ) || !Obj || !Type ) { 104 Usage( av[ 0 ] ); 105 } 106 107 if ( nbp_unrgstr( Obj, Type, Zone, &addr ) < 0 ) { 108 fprintf( stderr, "Can't unregister %s:%s@%s\n", Obj, Type, 109 Zone ? Zone : "*" ); 110 exit( 1 ); 111 } 112 113 return 0; 114} 115