1/* 2 * Unix SMB/CIFS implementation. 3 * NetGroupAdd 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 30int main(int argc, const char **argv) 31{ 32 NET_API_STATUS status; 33 struct libnetapi_ctx *ctx = NULL; 34 const char *hostname = NULL; 35 const char *groupname = NULL; 36 struct GROUP_INFO_1 g1; 37 uint32_t parm_error = 0; 38 39 poptContext pc; 40 int opt; 41 42 struct poptOption long_options[] = { 43 POPT_AUTOHELP 44 POPT_COMMON_LIBNETAPI_EXAMPLES 45 POPT_TABLEEND 46 }; 47 48 status = libnetapi_init(&ctx); 49 if (status != 0) { 50 return status; 51 } 52 53 pc = poptGetContext("group_add", argc, argv, long_options, 0); 54 55 poptSetOtherOptionHelp(pc, "hostname groupname"); 56 while((opt = poptGetNextOpt(pc)) != -1) { 57 } 58 59 if (!poptPeekArg(pc)) { 60 poptPrintHelp(pc, stderr, 0); 61 goto out; 62 } 63 hostname = poptGetArg(pc); 64 65 if (!poptPeekArg(pc)) { 66 poptPrintHelp(pc, stderr, 0); 67 goto out; 68 } 69 groupname = poptGetArg(pc); 70 71 /* NetGroupAdd */ 72 73 g1.grpi1_name = groupname; 74 g1.grpi1_comment = "Domain Group created using NetApi example code"; 75 76 status = NetGroupAdd(hostname, 77 1, 78 (uint8_t *)&g1, 79 &parm_error); 80 if (status != 0) { 81 printf("NetGroupAdd failed with: %s\n", 82 libnetapi_get_error_string(ctx, status)); 83 } 84 85 out: 86 libnetapi_free(ctx); 87 poptFreeContext(pc); 88 89 return status; 90} 91