root/source3/lib/netapi/examples/group/group_adduser.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  *  Unix SMB/CIFS implementation.
   3  *  NetGroupAddUser query
   4  *  Copyright (C) Guenther Deschner 2008
   5  *
   6  *  This program is free software; you can redistribute it and/or modify
   7  *  it under the terms of the GNU General Public License as published by
   8  *  the Free Software Foundation; either version 3 of the License, or
   9  *  (at your option) any later version.
  10  *
  11  *  This program is distributed in the hope that it will be useful,
  12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  *  GNU General Public License for more details.
  15  *
  16  *  You should have received a copy of the GNU General Public License
  17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  18  */
  19 
  20 #include <sys/types.h>
  21 #include <inttypes.h>
  22 #include <stdio.h>
  23 #include <stdlib.h>
  24 #include <string.h>
  25 
  26 #include <netapi.h>
  27 
  28 #include "common.h"
  29 
  30 int main(int argc, const char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
  31 {
  32         NET_API_STATUS status;
  33         struct libnetapi_ctx *ctx = NULL;
  34         const char *hostname = NULL;
  35         const char *groupname = NULL;
  36         const char *username = NULL;
  37 
  38         poptContext pc;
  39         int opt;
  40 
  41         struct poptOption long_options[] = {
  42                 POPT_AUTOHELP
  43                 POPT_COMMON_LIBNETAPI_EXAMPLES
  44                 POPT_TABLEEND
  45         };
  46 
  47         status = libnetapi_init(&ctx);
  48         if (status != 0) {
  49                 return status;
  50         }
  51 
  52         pc = poptGetContext("group_adduser", argc, argv, long_options, 0);
  53 
  54         poptSetOtherOptionHelp(pc, "hostname groupname username");
  55         while((opt = poptGetNextOpt(pc)) != -1) {
  56         }
  57 
  58         if (!poptPeekArg(pc)) {
  59                 poptPrintHelp(pc, stderr, 0);
  60                 goto out;
  61         }
  62         hostname = poptGetArg(pc);
  63 
  64         if (!poptPeekArg(pc)) {
  65                 poptPrintHelp(pc, stderr, 0);
  66                 goto out;
  67         }
  68         groupname = poptGetArg(pc);
  69 
  70         if (!poptPeekArg(pc)) {
  71                 poptPrintHelp(pc, stderr, 0);
  72                 goto out;
  73         }
  74         username = poptGetArg(pc);
  75 
  76         /* NetGroupAddUser */
  77 
  78         status = NetGroupAddUser(hostname,
  79                                  groupname,
  80                                  username);
  81         if (status != 0) {
  82                 printf("NetGroupAddUser failed with: %s\n",
  83                         libnetapi_get_error_string(ctx, status));
  84         }
  85 
  86  out:
  87         libnetapi_free(ctx);
  88         poptFreeContext(pc);
  89 
  90         return status;
  91 }

/* [<][>][^][v][top][bottom][index][help] */