• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/samba-3.5.8/source3/lib/netapi/examples/user/
1/*
2 *  Unix SMB/CIFS implementation.
3 *  NetUserModalsGet 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	uint8_t *buffer = NULL;
36	uint32_t level = 0;
37	char *sid_str = NULL;
38
39	struct USER_MODALS_INFO_0 *u0;
40	struct USER_MODALS_INFO_1 *u1;
41	struct USER_MODALS_INFO_2 *u2;
42	struct USER_MODALS_INFO_3 *u3;
43
44	poptContext pc;
45	int opt;
46
47	struct poptOption long_options[] = {
48		POPT_AUTOHELP
49		POPT_COMMON_LIBNETAPI_EXAMPLES
50		POPT_TABLEEND
51	};
52
53	status = libnetapi_init(&ctx);
54	if (status != 0) {
55		return status;
56	}
57
58	pc = poptGetContext("user_modalsget", argc, argv, long_options, 0);
59
60	poptSetOtherOptionHelp(pc, "hostname level");
61	while((opt = poptGetNextOpt(pc)) != -1) {
62	}
63
64	if (!poptPeekArg(pc)) {
65		poptPrintHelp(pc, stderr, 0);
66		goto out;
67	}
68	hostname = poptGetArg(pc);
69
70	if (poptPeekArg(pc)) {
71		level = atoi(poptGetArg(pc));
72	}
73
74	/* NetUserModalsGet */
75
76	status = NetUserModalsGet(hostname,
77				  level,
78				  &buffer);
79	if (status != 0) {
80		printf("NetUserModalsGet failed with: %s\n",
81			libnetapi_get_error_string(ctx, status));
82		goto out;
83	}
84
85	switch (level) {
86		case 0:
87			u0 = (struct USER_MODALS_INFO_0 *)buffer;
88			printf("min passwd len: %d character\n",
89				u0->usrmod0_min_passwd_len);
90			printf("max passwd age: %d (days)\n",
91				u0->usrmod0_max_passwd_age/86400);
92			printf("min passwd age: %d (days)\n",
93				u0->usrmod0_min_passwd_age/86400);
94			printf("force logoff: %d (seconds)\n",
95				u0->usrmod0_force_logoff);
96			printf("password history length: %d entries\n",
97				u0->usrmod0_password_hist_len);
98			break;
99		case 1:
100			u1 = (struct USER_MODALS_INFO_1 *)buffer;
101			printf("role: %d\n", u1->usrmod1_role);
102			printf("primary: %s\n", u1->usrmod1_primary);
103			break;
104		case 2:
105			u2 = (struct USER_MODALS_INFO_2 *)buffer;
106			printf("domain name: %s\n", u2->usrmod2_domain_name);
107			if (ConvertSidToStringSid(u2->usrmod2_domain_id,
108						  &sid_str)) {
109				printf("domain sid: %s\n", sid_str);
110				free(sid_str);
111			}
112			break;
113		case 3:
114			u3 = (struct USER_MODALS_INFO_3 *)buffer;
115			printf("lockout duration: %d (seconds)\n",
116				u3->usrmod3_lockout_duration);
117			printf("lockout observation window: %d (seconds)\n",
118				u3->usrmod3_lockout_observation_window);
119			printf("lockout threshold: %d entries\n",
120				u3->usrmod3_lockout_threshold);
121			break;
122		default:
123			break;
124	}
125
126 out:
127	libnetapi_free(ctx);
128	poptFreeContext(pc);
129
130	return status;
131}
132