1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * check_domain_dl.c
  29  *    This program takes domain string from command line and calls
  30  *    mapid_stdchk_domain() to check it, and output the checking result
  31  *    on stdout. The program differs from check_domain.c in that it
  32  *    uses dlopen().
  33  *
  34  * Return value:
  35  *    On success, returns 0; on error, returns 1.
  36  *
  37  * Usage:
  38  *    ./check_domain_dl <domain> <expected_result>
  39  */
  40 
  41 #include <stdio.h>
  42 #include <dlfcn.h>
  43 #include <link.h>
  44 #include <nfs/mapid.h>
  45 
  46 #define LIB     "/usr/lib/nfs/libmapid.so"
  47 typedef int (*CheckDomain)(const char *);
  48 
  49 int
  50 main(int argc, char **argv)
  51 {
  52         void * dlh;
  53         CheckDomain stdchk_domain;
  54         int valid;
  55 
  56         if (argc != 3) {
  57                 fprintf(stderr,
  58                     "Usage: %s <domain> <expected_result>\n", argv[0]);
  59                 exit(1);
  60         }
  61 
  62         dlh = dlopen(LIB, RTLD_LAZY);
  63         if (dlh == (void *)0) {
  64                 fprintf(stderr, LIB" not found\n%s\n", dlerror());
  65                 exit(1);
  66         }
  67 
  68         stdchk_domain = (CheckDomain)dlsym(dlh, "mapid_stdchk_domain");
  69         if (stdchk_domain == (CheckDomain)0) {
  70                 fprintf(stderr,
  71                     "mapid_stdchk_domain() not found\n%s\n", dlerror());
  72                 exit(1);
  73         }
  74 
  75         valid = stdchk_domain(argv[1]);
  76         printf("%d\n", valid);
  77 
  78         if (valid != atoi(argv[2])) exit(1);
  79 
  80         exit(0);
  81 }