2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2008
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.
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.
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/>.
20 #include <sys/types.h>
30 int main(int argc, const char **argv)
32 NET_API_STATUS status;
33 struct libnetapi_ctx *ctx = NULL;
34 const char *hostname = NULL;
35 const char *username = NULL;
36 uint8_t *buffer = NULL;
40 struct USER_INFO_0 *u0;
41 struct USER_INFO_1 *u1;
42 struct USER_INFO_10 *u10;
43 struct USER_INFO_20 *u20;
44 struct USER_INFO_23 *u23;
49 struct poptOption long_options[] = {
51 POPT_COMMON_LIBNETAPI_EXAMPLES
55 status = libnetapi_init(&ctx);
60 pc = poptGetContext("user_getinfo", argc, argv, long_options, 0);
62 poptSetOtherOptionHelp(pc, "hostname username level");
63 while((opt = poptGetNextOpt(pc)) != -1) {
66 if (!poptPeekArg(pc)) {
67 poptPrintHelp(pc, stderr, 0);
70 hostname = poptGetArg(pc);
72 if (!poptPeekArg(pc)) {
73 poptPrintHelp(pc, stderr, 0);
76 username = poptGetArg(pc);
78 if (poptPeekArg(pc)) {
79 level = atoi(poptGetArg(pc));
84 status = NetUserGetInfo(hostname,
89 printf("NetUserGetInfo failed with: %s\n",
90 libnetapi_get_error_string(ctx, status));
96 u0 = (struct USER_INFO_0 *)buffer;
97 printf("name: %s\n", u0->usri0_name);
100 u1 = (struct USER_INFO_1 *)buffer;
101 printf("name: %s\n", u1->usri1_name);
102 printf("password: %s\n", u1->usri1_password);
103 printf("password_age: %d\n", u1->usri1_password_age);
104 printf("priv: %d\n", u1->usri1_priv);
105 printf("homedir: %s\n", u1->usri1_home_dir);
106 printf("comment: %s\n", u1->usri1_comment);
107 printf("flags: 0x%08x\n", u1->usri1_flags);
108 printf("script: %s\n", u1->usri1_script_path);
111 u10 = (struct USER_INFO_10 *)buffer;
112 printf("name: %s\n", u10->usri10_name);
113 printf("comment: %s\n", u10->usri10_comment);
114 printf("usr_comment: %s\n", u10->usri10_usr_comment);
115 printf("full_name: %s\n", u10->usri10_full_name);
118 u20 = (struct USER_INFO_20 *)buffer;
119 printf("name: %s\n", u20->usri20_name);
120 printf("comment: %s\n", u20->usri20_comment);
121 printf("flags: 0x%08x\n", u20->usri20_flags);
122 printf("rid: %d\n", u20->usri20_user_id);
125 u23 = (struct USER_INFO_23 *)buffer;
126 printf("name: %s\n", u23->usri23_name);
127 printf("comment: %s\n", u23->usri23_comment);
128 printf("flags: 0x%08x\n", u23->usri23_flags);
129 if (ConvertSidToStringSid(u23->usri23_user_sid,
131 printf("user_sid: %s\n", sid_str);