Debian Codegraph @

src/OVAL/probes/unix/password_probe.c

raw symbols SCIP
1 /**
2 * @file password_probe.c
3 * @brief password probe
4 * @author "Steve Grubb" <[email protected]>
5 *
6 * 2010/06/13 [email protected]
7 * This probe is able to process a password_object as defined in OVAL 5.4 and 5.5.
8 *
9 */
10
11 /*
12 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
13 * All Rights Reserved.
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 *
29 * Authors:
30 * Steve Grubb <[email protected]>
31 */
32
33 /*
34 * password probe:
35 *
36 * username
37 * password
38 * user_id
39 * group_id
40 * gcos
41 * home_dir
42 * login_shell
43 */
44 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
45 #include <config.h>cxx . . $ `<file>/build/config.h`/
46 #endif
47
48 #include <stdlib.h>
49 #include <string.h>
50 #include <stdio.h>
51 #include <errno.h>
52 #include <pwd.h>
53 #include <paths.h>
54 #if defined(OS_APPLE)
55 #include <utmp.h>
56 #elif defined(OS_FREEBSD)
57 #include <utmpx.h>
58 #else
59 #include <lastlog.h>
60 #endif
61
62 #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/
63 #include "probe-api.h"cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
64 #include "probe/entcmp.h"cxx . . $ `<file>/src/OVAL/probes/probe/entcmp.h`/
65 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
66 #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
67 #include <probe/option.h>cxx . . $ `<file>/src/OVAL/probes/probe/option.h`/
68 #include "password_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/password_probe.h`/
69
70 /* Convenience structure for the results being reported */
71 struct result_infocxx . . $ result_info# {
72 const char *usernamecxx . . $ result_info#username.;
73 const char *passwordcxx . . $ result_info#password.;
74 uid_tcxx . . $ uid_t# user_idcxx . . $ result_info#user_id.;
75 gid_tcxx . . $ gid_t# group_idcxx . . $ result_info#group_id.;
76 const char *gcoscxx . . $ result_info#gcos.;
77 const char *home_dircxx . . $ result_info#home_dir.;
78 const char *login_shellcxx . . $ result_info#login_shell.;
79 int64_tcxx . . $ int64_t# last_logincxx . . $ result_info#last_login.;
80 };
81
82 static void report_findingcxx . . $ report_finding(9589c62511f80a85).(struct result_infocxx . . $ result_info# *res, probe_ctxcxx . . $ probe_ctx# *ctx, oval_schema_version_tcxx . . $ oval_schema_version_t# over)
83 {
84 SEXP_tcxx . . $ SEXP_t# *item;
85
86 item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_UNIX_PASSWORDcxx . . $ OVAL_UNIX_PASSWORD., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
87 "username", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->usernamecxx . . $ result_info#username.,
88 "password", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->passwordcxx . . $ result_info#password.,
89 "user_id", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#)res->user_idcxx . . $ result_info#user_id.,
90 "group_id", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#)res->group_idcxx . . $ result_info#group_id.,
91 "gcos", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->gcoscxx . . $ result_info#gcos.,
92 "home_dir", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->home_dircxx . . $ result_info#home_dir.,
93 "login_shell", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->login_shellcxx . . $ result_info#login_shell.,
94 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
95
96 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(over, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.10)) >= 0) {
97 SEXP_tcxx . . $ SEXP_t# last_login;
98 SEXP_number_newi_64_rcxx . . $ SEXP_number_newi_64_r(9cdf56af611bb354).(&last_login, res->last_logincxx . . $ result_info#last_login.);
99 probe_item_ent_addcxx . . $ probe_item_ent_add(9f488d3b029fc9d1).(item, "last_login", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &last_login);
100 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&last_login);
101 }
102
103 probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item);
104 }
105
106 #if defined(OS_FREEBSD)
107 static time_t get_last_login(char *username) {
108 struct utmpx *ut;
109 time_t t = 0;
110
111 /* Iterate over the entries of the utx.log file */
112 while ((ut = getutxent()) != NULL) {
113 if (strcmp(username,ut->ut_user) == 0) {
114 t = ut->ut_tv.tv_sec;
115 break;
116 }
117 }
118
119 endutxent();
120
121 return t;
122 }
123
124 static void _freebsd_process_struct_passwd(struct passwd *pw, SEXP_t *un_ent, probe_ctx *ctx, oval_schema_version_t over)
125 {
126 SEXP_t *un;
127 struct result_info r;
128
129 dI("Have user: %s", pw->pw_name);
130 un = SEXP_string_newf("%s", pw->pw_name);
131 if (probe_entobj_cmp(un_ent, un) != OVAL_RESULT_TRUE) {
132 SEXP_free(un);
133 return;
134 }
135
136 r.username = pw->pw_name;
137 r.password = pw->pw_passwd;
138 r.user_id = pw->pw_uid;
139 r.group_id = pw->pw_gid;
140 r.gcos = pw->pw_gecos;
141 r.home_dir = pw->pw_dir;
142 r.login_shell = pw->pw_shell;
143 r.last_login = -1;
144
145 if (oval_schema_version_cmp(over, OVAL_SCHEMA_VERSION(5.10)) >= 0) {
146 r.last_login = get_last_login(pw->pw_name);
147 }
148
149 report_finding(&r, ctx, over);
150 SEXP_free(un);
151 }
152
153 static int read_password(SEXP_t *un_ent, probe_ctx *ctx, oval_schema_version_t over)
154 {
155 struct passwd *pw;
156
157 while ((pw = getpwent())) {
158 _freebsd_process_struct_passwd(pw, un_ent, ctx, over);
159 }
160
161 endpwent();
162 return 0;
163 }
164
165 int password_probe_offline_mode_supported()
166 {
167 return PROBE_OFFLINE_NONE;
168 }
169
170 #else
171 static void _process_struct_passwdcxx . . $ _process_struct_passwd(e56f23f3dafa0a57).(struct passwdcxx . . $ passwd# *pw, const char *lastlog, SEXP_tcxx . . $ SEXP_t# *un_ent, probe_ctxcxx . . $ probe_ctx# *ctx, oval_schema_version_tcxx . . $ oval_schema_version_t# over)
172 {
173 SEXP_tcxx . . $ SEXP_t# *un;
174 struct result_infocxx . . $ result_info# r;
175
176 dIcxx . . $ `src/common/debug_priv.h:61:9`!("Have user: %s", pw->pw_name);
177 un = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", pw->pw_namecxx . . $ passwd#pw_name.);
178 if (probe_entobj_cmpcxx . . $ probe_entobj_cmp(e245451a1311e799).(un_ent, un) != OVAL_RESULT_TRUEcxx . . $ OVAL_RESULT_TRUE.) {
179 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(un);
180 return;
181 }
182
183 r.usernamecxx . . $ result_info#username. = pw->pw_namecxx . . $ passwd#pw_name.;
184 r.passwordcxx . . $ result_info#password. = pw->pw_passwdcxx . . $ passwd#pw_passwd.;
185 r.user_idcxx . . $ result_info#user_id. = pw->pw_uidcxx . . $ passwd#pw_uid.;
186 r.group_idcxx . . $ result_info#group_id. = pw->pw_gidcxx . . $ passwd#pw_gid.;
187 r.gcoscxx . . $ result_info#gcos. = pw->pw_gecoscxx . . $ passwd#pw_gecos.;
188 r.home_dircxx . . $ result_info#home_dir. = pw->pw_dircxx . . $ passwd#pw_dir.;
189 r.login_shellcxx . . $ result_info#login_shell. = pw->pw_shellcxx . . $ passwd#pw_shell.;
190 r.last_logincxx . . $ result_info#last_login. = -1;
191
192 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(over, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.10)) >= 0) {
193 FILEcxx . . $ FILE# *ll_fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(lastlog, "r");
194
195 if (ll_fp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
196 struct lastlogcxx . . $ lastlog# ll;
197
198 if (fseekocxx . . $ fseeko(543fae30d249f6b1).(ll_fp, (off_tcxx . . $ off_t#)pw->pw_uidcxx . . $ passwd#pw_uid. * sizeof(ll), SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!) == 0)
199 if (freadcxx . . $ fread(738fc8ac1d711e58).((char *)&ll, sizeof(ll), 1, ll_fp) == 1)
200 r.last_logincxx . . $ result_info#last_login. = (int64_tcxx . . $ int64_t#)ll.ll_timecxx . . $ lastlog#ll_time.;
201 fclosecxx . . $ fclose(89bc1efcdac0ca22).(ll_fp);
202 }
203 }
204
205 report_findingcxx . . $ report_finding(9589c62511f80a85).(&r, ctx, over);
206 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(un);
207 }
208
209 static int read_passwordcxx . . $ read_password(cb78ed6edd5c6722).(SEXP_tcxx . . $ SEXP_t# *un_ent, probe_ctxcxx . . $ probe_ctx# *ctx, oval_schema_version_tcxx . . $ oval_schema_version_t# over)
210 {
211 struct passwdcxx . . $ passwd# *pw;
212
213 if (ctx->offline_modecxx . . $ probe_ctx#offline_mode. & PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.) {
214 const char *root = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT");
215 if (root == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
216 return 1;
217 char *passwd_file_path = oscap_path_joincxx . . $ oscap_path_join(a713fe7b9a57cf96).(root, "/etc/passwd");
218 char *lastlog_file_path = oscap_path_joincxx . . $ oscap_path_join(a713fe7b9a57cf96).(root, _PATH_LASTLOGcxx . . $ `<external>/11492533085529128233/paths.h:50:9`!);
219 FILEcxx . . $ FILE# *fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(passwd_file_path, "r");
220 if (fp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
221 freecxx . . $ free(5d22bdacc48458e8).(passwd_file_path);
222 freecxx . . $ free(5d22bdacc48458e8).(lastlog_file_path);
223 return 1;
224 }
225 while ((pw = fgetpwentcxx . . $ fgetpwent(f08b270e2f637c5e).(fp))) {
226 _process_struct_passwdcxx . . $ _process_struct_passwd(e56f23f3dafa0a57).(pw, lastlog_file_path, un_ent, ctx, over);
227 }
228 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
229 freecxx . . $ free(5d22bdacc48458e8).(passwd_file_path);
230 freecxx . . $ free(5d22bdacc48458e8).(lastlog_file_path);
231 } else {
232 while ((pw = getpwentcxx . . $ getpwent(83f8b62001d65846).())) {
233 _process_struct_passwdcxx . . $ _process_struct_passwd(e56f23f3dafa0a57).(pw, _PATH_LASTLOGcxx . . $ `<external>/11492533085529128233/paths.h:50:9`!, un_ent, ctx, over);
234 }
235 endpwentcxx . . $ endpwent(49f6e7a06ebc5aa8).();
236 }
237
238 return 0;
239 }
240
241 int password_probe_offline_mode_supportedcxx . . $ password_probe_offline_mode_supported(b126dc7c1de90089).()
242 {
243 return PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.;
244 }
245 #endif
246
247 int password_probe_maincxx . . $ password_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *arg)
248 {
249 SEXP_tcxx . . $ SEXP_t# *ent, *obj;
250 oval_schema_version_tcxx . . $ oval_schema_version_t# over;
251
252 obj = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx);
253
254 if (obj == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
255 return PROBE_ENOOBJcxx . . $ `src/OVAL/probes/public/probe-common.h:21:9`!;
256
257 over = probe_obj_get_platform_schema_versioncxx . . $ probe_obj_get_platform_schema_version(5bacca80194debea).(obj);
258 ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(obj, "username", 1);
259
260 if (ent == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
261 return PROBE_ENOVALcxx . . $ `src/OVAL/probes/public/probe-common.h:10:9`!;
262 }
263
264 // Now we check the file...
265 if (read_passwordcxx . . $ read_password(cb78ed6edd5c6722).(ent, ctx, over) != 0) {
266 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(ent);
267 return PROBE_EINVALcxx . . $ `src/OVAL/probes/public/probe-common.h:8:9`!;
268 }
269 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(ent);
270
271 return 0;
272 }