root/source3/lib/netapi/examples/user/user_setinfo.c

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  *  Unix SMB/CIFS implementation.
   3  *  NetUserSetInfo 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 *username = NULL;
  36         uint32_t level = 0;
  37         uint32_t parm_err = 0;
  38         uint8_t *buffer = NULL;
  39         const char *val = NULL;
  40 
  41         struct USER_INFO_0 u0;
  42         struct USER_INFO_1 u1;
  43         struct USER_INFO_2 u2;
  44         struct USER_INFO_3 u3;
  45         struct USER_INFO_4 u4;
  46         struct USER_INFO_21 u21;
  47         struct USER_INFO_22 u22;
  48         struct USER_INFO_1003 u1003;
  49         struct USER_INFO_1005 u1005;
  50         struct USER_INFO_1006 u1006;
  51         struct USER_INFO_1007 u1007;
  52         struct USER_INFO_1008 u1008;
  53         struct USER_INFO_1009 u1009;
  54         struct USER_INFO_1010 u1010;
  55         struct USER_INFO_1011 u1011;
  56         struct USER_INFO_1012 u1012;
  57         struct USER_INFO_1014 u1014;
  58         struct USER_INFO_1017 u1017;
  59         struct USER_INFO_1020 u1020;
  60         struct USER_INFO_1024 u1024;
  61         struct USER_INFO_1051 u1051;
  62         struct USER_INFO_1052 u1052;
  63         struct USER_INFO_1053 u1053;
  64 
  65         poptContext pc;
  66         int opt;
  67 
  68         struct poptOption long_options[] = {
  69                 POPT_AUTOHELP
  70                 POPT_COMMON_LIBNETAPI_EXAMPLES
  71                 POPT_TABLEEND
  72         };
  73 
  74         status = libnetapi_init(&ctx);
  75         if (status != 0) {
  76                 return status;
  77         }
  78 
  79         pc = poptGetContext("user_setinfo", argc, argv, long_options, 0);
  80 
  81         poptSetOtherOptionHelp(pc, "hostname username level");
  82         while((opt = poptGetNextOpt(pc)) != -1) {
  83         }
  84 
  85         if (!poptPeekArg(pc)) {
  86                 poptPrintHelp(pc, stderr, 0);
  87                 goto out;
  88         }
  89         hostname = poptGetArg(pc);
  90 
  91         if (!poptPeekArg(pc)) {
  92                 poptPrintHelp(pc, stderr, 0);
  93                 goto out;
  94         }
  95         username = poptGetArg(pc);
  96 
  97         if (!poptPeekArg(pc)) {
  98                 poptPrintHelp(pc, stderr, 0);
  99                 goto out;
 100         }
 101         level = atoi(poptGetArg(pc));
 102 
 103         if (!poptPeekArg(pc)) {
 104                 poptPrintHelp(pc, stderr, 0);
 105                 goto out;
 106         }
 107         val = poptGetArg(pc);
 108 
 109         /* NetUserSetInfo */
 110 
 111         switch (level) {
 112                 case 0:
 113                         u0.usri0_name = val;
 114                         buffer = (uint8_t *)&u0;
 115                         break;
 116                 case 1:
 117                 case 2:
 118                 case 3:
 119                 case 4:
 120                         break;
 121                 case 21:
 122                         break;
 123                 case 22:
 124                         break;
 125                 case 1003:
 126                         u1003.usri1003_password = val;
 127                         buffer = (uint8_t *)&u1003;
 128                         break;
 129                 case 1005:
 130                         u1005.usri1005_priv = atoi(val);
 131                         buffer = (uint8_t *)&u1005;
 132                         break;
 133                 case 1006:
 134                         u1006.usri1006_home_dir = val;
 135                         buffer = (uint8_t *)&u1006;
 136                         break;
 137                 case 1007:
 138                         u1007.usri1007_comment = val;
 139                         buffer = (uint8_t *)&u1007;
 140                         break;
 141                 case 1008:
 142                         u1008.usri1008_flags = atoi(val);
 143                         buffer = (uint8_t *)&u1008;
 144                         break;
 145                 case 1009:
 146                         u1009.usri1009_script_path = val;
 147                         buffer = (uint8_t *)&u1009;
 148                         break;
 149                 case 1010:
 150                         u1010.usri1010_auth_flags = atoi(val);
 151                         buffer = (uint8_t *)&u1010;
 152                         break;
 153                 case 1011:
 154                         u1011.usri1011_full_name = val;
 155                         buffer = (uint8_t *)&u1011;
 156                         break;
 157                 case 1012:
 158                         u1012.usri1012_usr_comment = val;
 159                         buffer = (uint8_t *)&u1012;
 160                         break;
 161                 case 1014:
 162                         u1014.usri1014_workstations = val;
 163                         buffer = (uint8_t *)&u1014;
 164                         break;
 165                 case 1017:
 166                         u1017.usri1017_acct_expires = atoi(val);
 167                         buffer = (uint8_t *)&u1017;
 168                         break;
 169                 case 1020:
 170                         break;
 171                 case 1024:
 172                         u1024.usri1024_country_code = atoi(val);
 173                         buffer = (uint8_t *)&u1024;
 174                         break;
 175                 case 1051:
 176                         u1051.usri1051_primary_group_id = atoi(val);
 177                         buffer = (uint8_t *)&u1051;
 178                         break;
 179                 case 1052:
 180                         u1052.usri1052_profile = val;
 181                         buffer = (uint8_t *)&u1052;
 182                         break;
 183                 case 1053:
 184                         u1053.usri1053_home_dir_drive = val;
 185                         buffer = (uint8_t *)&u1053;
 186                         break;
 187                 default:
 188                         break;
 189         }
 190 
 191         status = NetUserSetInfo(hostname,
 192                                 username,
 193                                 level,
 194                                 buffer,
 195                                 &parm_err);
 196         if (status != 0) {
 197                 printf("NetUserSetInfo failed with: %s\n",
 198                         libnetapi_get_error_string(ctx, status));
 199                 goto out;
 200         }
 201 
 202  out:
 203         libnetapi_free(ctx);
 204         poptFreeContext(pc);
 205 
 206         return status;
 207 }

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