1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
* Unix SMB/CIFS implementation.
* NetUserSetInfo query
* Copyright (C) Guenther Deschner 2008
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netapi.h>
#include "common.h"
int main(int argc, const char **argv)
{
NET_API_STATUS status;
struct libnetapi_ctx *ctx = NULL;
const char *hostname = NULL;
const char *username = NULL;
uint32_t level = 0;
uint32_t parm_err = 0;
uint8_t *buffer = NULL;
const char *val = NULL;
struct USER_INFO_0 u0;
struct USER_INFO_1 u1;
struct USER_INFO_2 u2;
struct USER_INFO_3 u3;
struct USER_INFO_4 u4;
struct USER_INFO_21 u21;
struct USER_INFO_22 u22;
struct USER_INFO_1003 u1003;
struct USER_INFO_1005 u1005;
struct USER_INFO_1006 u1006;
struct USER_INFO_1007 u1007;
struct USER_INFO_1008 u1008;
struct USER_INFO_1009 u1009;
struct USER_INFO_1010 u1010;
struct USER_INFO_1011 u1011;
struct USER_INFO_1012 u1012;
struct USER_INFO_1014 u1014;
struct USER_INFO_1017 u1017;
struct USER_INFO_1020 u1020;
struct USER_INFO_1024 u1024;
struct USER_INFO_1051 u1051;
struct USER_INFO_1052 u1052;
struct USER_INFO_1053 u1053;
poptContext pc;
int opt;
struct poptOption long_options[] = {
POPT_AUTOHELP
POPT_COMMON_LIBNETAPI_EXAMPLES
POPT_TABLEEND
};
status = libnetapi_init(&ctx);
if (status != 0) {
return status;
}
pc = poptGetContext("user_setinfo", argc, argv, long_options, 0);
poptSetOtherOptionHelp(pc, "hostname username level");
while((opt = poptGetNextOpt(pc)) != -1) {
}
if (!poptPeekArg(pc)) {
poptPrintHelp(pc, stderr, 0);
goto out;
}
hostname = poptGetArg(pc);
if (!poptPeekArg(pc)) {
poptPrintHelp(pc, stderr, 0);
goto out;
}
username = poptGetArg(pc);
if (!poptPeekArg(pc)) {
poptPrintHelp(pc, stderr, 0);
goto out;
}
level = atoi(poptGetArg(pc));
if (!poptPeekArg(pc)) {
poptPrintHelp(pc, stderr, 0);
goto out;
}
val = poptGetArg(pc);
/* NetUserSetInfo */
switch (level) {
case 0:
u0.usri0_name = val;
buffer = (uint8_t *)&u0;
break;
case 1:
case 2:
case 3:
case 4:
break;
case 21:
break;
case 22:
break;
case 1003:
u1003.usri1003_password = val;
buffer = (uint8_t *)&u1003;
break;
case 1005:
u1005.usri1005_priv = atoi(val);
buffer = (uint8_t *)&u1005;
break;
case 1006:
u1006.usri1006_home_dir = val;
buffer = (uint8_t *)&u1006;
break;
case 1007:
u1007.usri1007_comment = val;
buffer = (uint8_t *)&u1007;
break;
case 1008:
u1008.usri1008_flags = atoi(val);
buffer = (uint8_t *)&u1008;
break;
case 1009:
u1009.usri1009_script_path = val;
buffer = (uint8_t *)&u1009;
break;
case 1010:
u1010.usri1010_auth_flags = atoi(val);
buffer = (uint8_t *)&u1010;
break;
case 1011:
u1011.usri1011_full_name = val;
buffer = (uint8_t *)&u1011;
break;
case 1012:
u1012.usri1012_usr_comment = val;
buffer = (uint8_t *)&u1012;
break;
case 1014:
u1014.usri1014_workstations = val;
buffer = (uint8_t *)&u1014;
break;
case 1017:
u1017.usri1017_acct_expires = atoi(val);
buffer = (uint8_t *)&u1017;
break;
case 1020:
break;
case 1024:
u1024.usri1024_country_code = atoi(val);
buffer = (uint8_t *)&u1024;
break;
case 1051:
u1051.usri1051_primary_group_id = atoi(val);
buffer = (uint8_t *)&u1051;
break;
case 1052:
u1052.usri1052_profile = val;
buffer = (uint8_t *)&u1052;
break;
case 1053:
u1053.usri1053_home_dir_drive = val;
buffer = (uint8_t *)&u1053;
break;
default:
break;
}
status = NetUserSetInfo(hostname,
username,
level,
buffer,
&parm_err);
if (status != 0) {
printf("NetUserSetInfo failed with: %s\n",
libnetapi_get_error_string(ctx, status));
goto out;
}
out:
libnetapi_free(ctx);
poptFreeContext(pc);
return status;
}
|