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

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  *  Unix SMB/CIFS implementation.
   3  *  NetGroupSetInfo 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 *option = NULL;
  37         uint8_t *buffer = NULL;
  38         uint32_t level = 0;
  39         uint32_t parm_err = 0;
  40         struct GROUP_INFO_0 g0;
  41         struct GROUP_INFO_1 g1;
  42         struct GROUP_INFO_2 g2;
  43         struct GROUP_INFO_3 g3;
  44         struct GROUP_INFO_1002 g1002;
  45         struct GROUP_INFO_1005 g1005;
  46 
  47         poptContext pc;
  48         int opt;
  49 
  50         struct poptOption long_options[] = {
  51                 POPT_AUTOHELP
  52                 POPT_COMMON_LIBNETAPI_EXAMPLES
  53                 POPT_TABLEEND
  54         };
  55 
  56         status = libnetapi_init(&ctx);
  57         if (status != 0) {
  58                 return status;
  59         }
  60 
  61         pc = poptGetContext("group_setinfo", argc, argv, long_options, 0);
  62 
  63         poptSetOtherOptionHelp(pc, "hostname groupname level option");
  64         while((opt = poptGetNextOpt(pc)) != -1) {
  65         }
  66 
  67         if (!poptPeekArg(pc)) {
  68                 poptPrintHelp(pc, stderr, 0);
  69                 goto out;
  70         }
  71         hostname = poptGetArg(pc);
  72 
  73         if (!poptPeekArg(pc)) {
  74                 poptPrintHelp(pc, stderr, 0);
  75                 goto out;
  76         }
  77         groupname = poptGetArg(pc);
  78 
  79         if (!poptPeekArg(pc)) {
  80                 poptPrintHelp(pc, stderr, 0);
  81                 goto out;
  82         }
  83         level = atoi(poptGetArg(pc));
  84 
  85         if (!poptPeekArg(pc)) {
  86                 poptPrintHelp(pc, stderr, 0);
  87                 goto out;
  88         }
  89         option = poptGetArg(pc);
  90 
  91         /* NetGroupSetInfo */
  92 
  93         switch (level) {
  94                 case 0:
  95                         g0.grpi0_name = option;
  96                         buffer = (uint8_t *)&g0;
  97                         break;
  98                 case 1:
  99                         g1.grpi1_name = option; /* this one will be ignored */
 100                         g1.grpi1_comment = option;
 101                         buffer = (uint8_t *)&g1;
 102                         break;
 103                 case 2:
 104                         g2.grpi2_name = option; /* this one will be ignored */
 105                         g2.grpi2_comment = option;
 106                         g2.grpi2_group_id = 4711; /* this one will be ignored */
 107                         g2.grpi2_attributes = 7;
 108                         buffer = (uint8_t *)&g2;
 109                         break;
 110                 case 3:
 111                         g3.grpi3_name = option; /* this one will be ignored */
 112                         g3.grpi3_comment = option;
 113                         g2.grpi2_attributes = 7;
 114                         buffer = (uint8_t *)&g3;
 115                         break;
 116                 case 1002:
 117                         g1002.grpi1002_comment = option;
 118                         buffer = (uint8_t *)&g1002;
 119                         break;
 120                 case 1005:
 121                         g1005.grpi1005_attributes = atoi(option);
 122                         buffer = (uint8_t *)&g1005;
 123                         break;
 124         }
 125 
 126         status = NetGroupSetInfo(hostname,
 127                                  groupname,
 128                                  level,
 129                                  buffer,
 130                                  &parm_err);
 131         if (status != 0) {
 132                 printf("NetGroupSetInfo failed with: %s\n",
 133                         libnetapi_get_error_string(ctx, status));
 134                 goto out;
 135         }
 136 
 137  out:
 138         libnetapi_free(ctx);
 139         poptFreeContext(pc);
 140 
 141         return status;
 142 }

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