Changeset 410
- Timestamp:
- Aug 28, 2012, 7:06:46 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/sh_error.h
r405 r410 191 191 void sh_efile_report(); 192 192 int sh_efile_path(const char * str); 193 int sh_efile_group(const char * str); 193 194 194 195 /* (re)set the console device(s) -
trunk/include/sh_static.h
r145 r410 15 15 void sh_setpwent(void); 16 16 struct group * sh_getgrnam(const char *name); 17 int sh_getgrnam_r(const char *name, struct group *gbuf, 18 char *buf, size_t buflen, struct group **gbufp); 17 19 18 20 struct passwd * sh_getpwnam(const char *name); … … 38 40 39 41 #define sh_initgroups initgroups 42 #define sh_getgrnam getgrnam 43 #define sh_getgrnam_r getgrnam_r 40 44 #define sh_getgrgid getgrgid 41 45 #define sh_getgrgid_r getgrgid_r -
trunk/include/sh_unix.h
r409 r410 340 340 char * sh_unix_getUIDdir (int level, uid_t uid, char * out, size_t len); 341 341 342 /* get a group GID 343 */ 344 long sh_group_to_gid (const char * g, int * fail); 342 345 343 346 #ifdef HAVE_GETTIMEOFDAY -
trunk/src/sh_err_log.c
r405 r410 1058 1058 static char * gEfile = NULL; 1059 1059 static int gFail = 0; 1060 static long gGid = 0; 1061 1062 int sh_efile_group(const char * str) 1063 { 1064 int fail; 1065 long gid = sh_group_to_gid(str, &fail); 1066 1067 if (fail < 0) 1068 { 1069 return -1; 1070 } 1071 gGid = gid; 1072 return 0; 1073 } 1074 1060 1075 1061 1076 int sh_efile_path(const char * str) … … 1148 1163 fchmod (filed, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); 1149 1164 sl_close (fd); 1165 } 1166 else 1167 { 1168 static int nFail = 0; 1169 1170 if (nFail == 0) 1171 { 1172 char errmsg[1024]; 1173 char * tmp = sh_util_safe_name (lockfile); 1174 1175 sl_snprintf(errmsg, sizeof(errmsg), 1176 _("Error creating lockfile %s"), 1177 tmp); 1178 1179 sh_error_handle (SH_ERR_ERR, FIL__, __LINE__, 1180 0, MSG_E_SUBGEN, 1181 errmsg, _("sh_efile_lock")); 1182 ++nFail; 1183 SH_FREE(tmp); 1184 } 1150 1185 } 1151 1186 } … … 1191 1226 void sh_efile_report() 1192 1227 { 1228 extern int get_the_fd (SL_TICKET ticket); 1193 1229 SL_TICKET fd; 1194 1230 char *efile; … … 1226 1262 1227 1263 time_t now = time(NULL); 1264 int filed = get_the_fd(fd); 1228 1265 1229 1266 (void) sh_unix_time (now, tstamp, sizeof(tstamp)); … … 1233 1270 tstamp, 1234 1271 (long long) now, 1235 tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]); 1272 (long) tmp[0], (long) tmp[1], (long) tmp[2], 1273 (long) tmp[3], (long) tmp[4], (long) tmp[5]); 1236 1274 #else 1237 1275 sl_snprintf(report, sizeof(report), … … 1239 1277 tstamp, 1240 1278 (long) now, 1241 tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]); 1279 (long) tmp[0], (long) tmp[1], (long) tmp[2], 1280 (long) tmp[3], (long) tmp[4], (long) tmp[5]); 1242 1281 #endif 1243 1282 … … 1246 1285 status = sl_write (fd, report, strlen(report)); 1247 1286 (void) sl_sync(fd); 1287 1288 /* make group writeable, such that nagios can truncate */ 1289 fchmod (filed, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); 1290 status = fchown (filed, -1, gGid); 1291 if (status < 0) 1292 { 1293 int errnum = errno; 1294 static int nFail = 0; 1295 if (nFail == 0) 1296 { 1297 char errmsg[1024]; 1298 char buf[256]; 1299 char * tmp = sh_util_safe_name (efile); 1300 1301 sl_snprintf(errmsg, sizeof(errmsg), 1302 _("Error changing group of %s to %ld: %s"), 1303 tmp, gGid, 1304 sh_error_message (errnum, buf, sizeof(buf))); 1305 sh_error_handle (SH_ERR_ERR, FIL__, __LINE__, 1306 errnum, MSG_E_SUBGEN, 1307 errmsg, _("sh_efile_report")); 1308 ++nFail; 1309 SH_FREE(tmp); 1310 } 1311 } 1312 1248 1313 (void) sl_close(fd); 1249 1314 } -
trunk/src/sh_readconf.c
r405 r410 1218 1218 { N_("setreportfile"), SH_SECTION_MISC, SH_SECTION_NONE, 1219 1219 sh_efile_path }, 1220 { N_("setreportgroup"), SH_SECTION_MISC, SH_SECTION_NONE, 1221 sh_efile_group }, 1220 1222 1221 1223 #ifdef WITH_MESSAGE_QUEUE -
trunk/src/sh_unix.c
r409 r410 1000 1000 } 1001 1001 1002 1003 /* ---------------------------------------------------------------- */ 1004 1005 long sh_group_to_gid (const char * g, int * fail) 1006 { 1007 struct group * w; 1008 gid_t gid = 0; 1009 1010 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 1011 struct group grp; 1012 char * buffer; 1013 #endif 1014 1015 *fail = -1; 1016 1017 if (g) 1018 { 1019 size_t i; 1020 size_t len = strlen(g); 1021 1022 *fail = 0; 1023 1024 for (i = 0; i < len; ++i) 1025 { 1026 char c = g[i]; 1027 1028 if (!isdigit((int) c)) 1029 goto is_a_name; 1030 } 1031 return atol(g); 1032 1033 is_a_name: 1034 1035 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 1036 buffer = SH_ALLOC(SH_GRBUF_SIZE); 1037 sh_getgrnam_r(g, &grp, buffer, SH_GRBUF_SIZE, &w); 1038 #else 1039 w = sh_getgrnam(g); 1040 #endif 1041 1042 if (w == NULL) 1043 { 1044 char * tmp = sh_util_strdup(g); 1045 sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_EINVALS, 1046 _("sh_group_to_gid"), tmp); 1047 SH_FREE(tmp); 1048 *fail = -1; 1049 } 1050 else 1051 { 1052 gid = w->gr_gid; 1053 } 1054 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 1055 SH_FREE(buffer); 1056 #endif 1057 } 1058 1059 return gid; 1060 } 1002 1061 1003 1062 /* ---------------------------------------------------------------- */
Note:
See TracChangeset
for help on using the changeset viewer.