Debian Codegraph @

src/OVAL/probes/unix/shadow_probe.c

raw symbols SCIP
1 /**
2 * @file shadow_probe.c
3 * @brief shadow probe
4 * @author "Steve Grubb" <[email protected]>
5 *
6 * 2010/06/13 [email protected]
7 * This probe is able to process a shadow_object as defined in OVAL 5.4 and 5.5.
8 *
9 */
10
11 /*
12 * Copyright 2009-2010 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 * shadow probe:
35 *
36 * username
37 * password
38 * chg_lst
39 * chg_allow
40 * chg_req
41 * exp_warn
42 * exp_inact
43 * exp_date
44 * flag
45 */
46
47 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
48 #include <config.h>cxx . . $ `<file>/build/config.h`/
49 #endif
50
51 #include <stdlib.h>
52 #include <string.h>
53 #include <stdio.h>
54 #include <errno.h>
55
56 #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/
57 #include "probe-api.h"cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
58 #include "probe/entcmp.h"cxx . . $ `<file>/src/OVAL/probes/probe/entcmp.h`/
59 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
60 #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
61 #include <probe/option.h>cxx . . $ `<file>/src/OVAL/probes/probe/option.h`/
62 #include "shadow_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/shadow_probe.h`/
63
64 #ifndef HAVE_SHADOW_Hcxx . . $ `build/config.h:75:9`!
65 int shadow_probe_main(probe_ctx *ctx, void *arg)
66 {
67 SEXP_t *item_sexp;
68
69 (void)arg;
70
71 item_sexp = probe_item_create(OVAL_UNIX_SHADOW, NULL, NULL);
72 probe_item_setstatus (item_sexp, SYSCHAR_STATUS_NOT_COLLECTED);
73 probe_item_collect(ctx, item_sexp);
74
75 return 0;
76 }
77 #else
78 /* shadow.h is present */
79 #include <shadow.h>
80
81 static oval_schema_version_tcxx . . $ oval_schema_version_t# overcxx . . $ over.;
82
83 /* Convenience structure for the results being reported */
84 struct result_infocxx . . $ result_info# {
85 const char *usernamecxx . . $ result_info#username.;
86 const char *passwordcxx . . $ result_info#password.;
87 long chg_lstcxx . . $ result_info#chg_lst.;
88 long chg_allowcxx . . $ result_info#chg_allow.;
89 long chg_reqcxx . . $ result_info#chg_req.;
90 long exp_warncxx . . $ result_info#exp_warn.;
91 long exp_inactcxx . . $ result_info#exp_inact.;
92 long exp_datecxx . . $ result_info#exp_date.;
93 unsigned long flagcxx . . $ result_info#flag.;
94 };
95
96 static SEXP_tcxx . . $ SEXP_t# *parse_enc_mthcxx . . $ parse_enc_mth(b11f8c5057ee8d85).(const char *pwd)
97 {
98 char *mth_str;
99
100 switch (*pwd) {
101 case '_':
102 return SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("BSDi");
103 case '$':
104 pwd++;
105 switch (*pwd) {
106 case '1':
107 mth_str = "MD5";
108 pwd++;
109 break;
110 case '2':
111 mth_str = "Blowfish";
112 pwd++;
113 if (*pwd == 'a')
114 pwd++;
115 break;
116 case '5':
117 mth_str = "SHA-256";
118 pwd++;
119 break;
120 case '6':
121 mth_str = "SHA-512";
122 pwd++;
123 break;
124 default:
125 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(pwd, "md5", 3))
126 goto fail;
127 mth_str = "Sun MD5";
128 pwd += 3;
129 }
130
131 if (*pwd != '$')
132 goto fail;
133
134 return SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", mth_str);
135 default:
136 return SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("DES");
137 }
138
139 fail:
140 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
141 }
142
143 static void report_findingcxx . . $ report_finding(a44e8875aacc0cc1).(struct result_infocxx . . $ result_info# *res, probe_ctxcxx . . $ probe_ctx# *ctx)
144 {
145 SEXP_tcxx . . $ SEXP_t# *item, *enc_mth;
146 SEXP_tcxx . . $ SEXP_t# se_chl_mem, se_cha_mem, se_chr_mem;
147 SEXP_tcxx . . $ SEXP_t# se_exw_mem, se_exi_mem, se_exd_mem;
148 SEXP_tcxx . . $ SEXP_t# se_flg_mem;
149
150 item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_UNIX_SHADOWcxx . . $ OVAL_UNIX_SHADOW., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
151 "username", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->usernamecxx . . $ result_info#username.,
152 "password", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->passwordcxx . . $ result_info#password.,
153 "chg_lst", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., SEXP_number_newi_64_rcxx . . $ SEXP_number_newi_64_r(9cdf56af611bb354).(&se_chl_mem, res->chg_lstcxx . . $ result_info#chg_lst.),
154 "chg_allow", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., SEXP_number_newi_64_rcxx . . $ SEXP_number_newi_64_r(9cdf56af611bb354).(&se_cha_mem, res->chg_allowcxx . . $ result_info#chg_allow.),
155 "chg_req", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., SEXP_number_newi_64_rcxx . . $ SEXP_number_newi_64_r(9cdf56af611bb354).(&se_chr_mem, res->chg_reqcxx . . $ result_info#chg_req.),
156 "exp_warn", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., SEXP_number_newi_64_rcxx . . $ SEXP_number_newi_64_r(9cdf56af611bb354).(&se_exw_mem, res->exp_warncxx . . $ result_info#exp_warn.),
157 "exp_inact", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., SEXP_number_newi_64_rcxx . . $ SEXP_number_newi_64_r(9cdf56af611bb354).(&se_exi_mem, res->exp_inactcxx . . $ result_info#exp_inact.),
158 "exp_date", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., SEXP_number_newi_64_rcxx . . $ SEXP_number_newi_64_r(9cdf56af611bb354).(&se_exd_mem, res->exp_datecxx . . $ result_info#exp_date.),
159 "flag", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., SEXP_string_newf_rcxx . . $ SEXP_string_newf_r(f7254ae56fe447d7).(&se_flg_mem, "%lu", res->flagcxx . . $ result_info#flag.),
160 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
161 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(overcxx . . $ over., OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.8)) >= 0) {
162 enc_mth = parse_enc_mthcxx . . $ parse_enc_mth(b11f8c5057ee8d85).(res->passwordcxx . . $ result_info#password.);
163 if (enc_mth) {
164 probe_item_ent_addcxx . . $ probe_item_ent_add(9f488d3b029fc9d1).(item, "encrypt_method", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, enc_mth);
165 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(enc_mth);
166 }
167 }
168
169 probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item);
170
171 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_chl_mem);
172 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_cha_mem);
173 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_chr_mem);
174 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_exw_mem);
175 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_exi_mem);
176 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_exd_mem);
177 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_flg_mem);
178 }
179
180 static void _process_struct_shadowcxx . . $ _process_struct_shadow(31964ddae9cc2d9c).(struct spwdcxx . . $ spwd# *sp, SEXP_tcxx . . $ SEXP_t# *un_ent, probe_ctxcxx . . $ probe_ctx# *ctx)
181 {
182 SEXP_tcxx . . $ SEXP_t# *un;
183 struct result_infocxx . . $ result_info# r;
184
185 dIcxx . . $ `src/common/debug_priv.h:61:9`!("Have user: %s", sp->sp_namp);
186 un = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", sp->sp_nampcxx . . $ spwd#sp_namp.);
187 if (probe_entobj_cmpcxx . . $ probe_entobj_cmp(e245451a1311e799).(un_ent, un) != OVAL_RESULT_TRUEcxx . . $ OVAL_RESULT_TRUE.) {
188 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(un);
189 return;
190 }
191
192 r.usernamecxx . . $ result_info#username. = sp->sp_nampcxx . . $ spwd#sp_namp.;
193 r.passwordcxx . . $ result_info#password. = sp->sp_pwdpcxx . . $ spwd#sp_pwdp.;
194 r.chg_lstcxx . . $ result_info#chg_lst. = sp->sp_lstchgcxx . . $ spwd#sp_lstchg.;
195 r.chg_allowcxx . . $ result_info#chg_allow. = sp->sp_mincxx . . $ spwd#sp_min.;
196 r.chg_reqcxx . . $ result_info#chg_req. = sp->sp_maxcxx . . $ spwd#sp_max.;
197 r.exp_warncxx . . $ result_info#exp_warn. = sp->sp_warncxx . . $ spwd#sp_warn.;
198 r.exp_inactcxx . . $ result_info#exp_inact. = sp->sp_inactcxx . . $ spwd#sp_inact.;
199 r.exp_datecxx . . $ result_info#exp_date. = sp->sp_expirecxx . . $ spwd#sp_expire.;
200 r.flagcxx . . $ result_info#flag. = sp->sp_flagcxx . . $ spwd#sp_flag.;
201
202 report_findingcxx . . $ report_finding(a44e8875aacc0cc1).(&r, ctx);
203 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(un);
204 }
205
206 static int read_shadowcxx . . $ read_shadow(241d6c535218441).(SEXP_tcxx . . $ SEXP_t# *un_ent, probe_ctxcxx . . $ probe_ctx# *ctx)
207 {
208 struct spwdcxx . . $ spwd# *sp;
209
210 if (ctx->offline_modecxx . . $ probe_ctx#offline_mode. & PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.) {
211 const char *root = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT");
212 char *shadow_file_path = oscap_path_joincxx . . $ oscap_path_join(a713fe7b9a57cf96).(root, "/etc/shadow");
213 FILEcxx . . $ FILE# *fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(shadow_file_path, "r");
214 if (fp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
215 freecxx . . $ free(5d22bdacc48458e8).(shadow_file_path);
216 return 1;
217 }
218 while ((sp = fgetspentcxx . . $ fgetspent(995ae8882cd6e620).(fp))) {
219 _process_struct_shadowcxx . . $ _process_struct_shadow(31964ddae9cc2d9c).(sp, un_ent, ctx);
220 }
221 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
222 freecxx . . $ free(5d22bdacc48458e8).(shadow_file_path);
223 } else {
224 while ((sp = getspentcxx . . $ getspent(b2abbb707bc5e58f).())) {
225 _process_struct_shadowcxx . . $ _process_struct_shadow(31964ddae9cc2d9c).(sp, un_ent, ctx);
226 }
227 endspentcxx . . $ endspent(49f6e7a06ebc5aa8).();
228 }
229
230 return 0;
231 }
232
233 int shadow_probe_offline_mode_supportedcxx . . $ shadow_probe_offline_mode_supported(b126dc7c1de90089).()
234 {
235 return PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.;
236 }
237
238 int shadow_probe_maincxx . . $ shadow_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *arg)
239 {
240 SEXP_tcxx . . $ SEXP_t# *ent, *obj;
241
242 obj = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx);
243 overcxx . . $ over. = probe_obj_get_platform_schema_versioncxx . . $ probe_obj_get_platform_schema_version(5bacca80194debea).(obj);
244 ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(obj, "username", 1);
245 if (ent == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
246 return PROBE_ENOVALcxx . . $ `src/OVAL/probes/public/probe-common.h:10:9`!;
247 }
248
249 // Now we check the file...
250 read_shadowcxx . . $ read_shadow(241d6c535218441).(ent, ctx);
251 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(ent);
252
253 return 0;
254 }
255 #endif /* HAVE_SHADOW_H */