Changeset 131 for trunk/src/slib.c
- Timestamp:
- Oct 22, 2007, 11:19:15 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/slib.c
r76 r131 1425 1425 int sl_policy_get_real(char * user) 1426 1426 { 1427 struct passwd * tempres;1428 1429 1427 SL_ENTER(_("sl_policy_get_real")); 1430 1428 SL_REQUIRE(uids_are_stored == SL_FALSE, _("uids_are_stored == SL_FALSE")); … … 1433 1431 if (euid == 0 || ruid == 0) 1434 1432 { 1435 tempres = sh_getpwnam(user); 1433 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 1434 struct passwd pwd; 1435 char buffer[SH_PWBUF_SIZE]; 1436 struct passwd * tempres; 1437 sh_getpwnam_r(user, &pwd, buffer, sizeof(buffer), &tempres); 1438 #else 1439 struct passwd * tempres = sh_getpwnam(user); 1440 #endif 1436 1441 1437 1442 SL_REQUIRE (NULL != tempres, _("tempres != NULL")); … … 1471 1476 if (euid != ruid || egid != rgid) 1472 1477 { 1473 tempres = sh_getpwnam(user); 1478 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 1479 struct passwd pwd; 1480 char buffer[SH_PWBUF_SIZE]; 1481 struct passwd * tempres; 1482 sh_getpwnam_r(user, &pwd, buffer, sizeof(buffer), &tempres); 1483 #else 1484 struct passwd * tempres = sh_getpwnam(user); 1485 #endif 1474 1486 1475 1487 SL_REQUIRE (NULL != tempres, _("tempres != NULL")); 1476 1488 1477 #if 01478 rgid = tempres->pw_gid;1479 ruid = tempres->pw_uid;1480 SL_REQUIRE(sl_unset_suid() == SL_ENONE,1481 _("sl_unset_suid() == SL_ENONE"));1482 #endif1483 1489 SL_REQUIRE (sl_drop_privileges() == SL_ENONE, 1484 1490 _("sl_drop_privileges() == SL_ENONE")); … … 2115 2121 SL_IRETURN(SL_ENONE, _("sl_read_timeout_prep")); 2116 2122 } 2117 2118 2119 int sl_read_timeout (SL_TICKET ticket, void * buf_in, size_t count, 2120 int timeout) 2121 { 2123 2124 2125 int sl_read_timeout_fd (int fd, void * buf_in, size_t count, 2126 int timeout, int is_nonblocking) 2127 { 2128 int sflags; 2122 2129 fd_set readfds; 2123 2130 struct timeval tv; … … 2135 2142 extern volatile int sig_termfast; 2136 2143 2137 if (buf_in == NULL || SL_ISERROR(fd = get_the_fd(ticket))) 2138 { 2139 if (buf_in == NULL) 2140 { 2141 TPT(( 0, FIL__, __LINE__, _("msg=<null buffer>"))); 2142 return (SL_ENULL); 2143 } 2144 if (SL_ISERROR(fd = get_the_fd(ticket))) 2145 { 2146 TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd)); 2147 return (fd); 2148 } 2144 if (is_nonblocking == SL_FALSE) 2145 { 2146 /* set to non-blocking mode 2147 */ 2148 sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0); 2149 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags | O_NONBLOCK); 2149 2150 } 2150 2151 … … 2190 2191 else 2191 2192 { 2193 if (is_nonblocking == SL_FALSE) 2194 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags); 2192 2195 return (SL_EREAD); 2193 2196 } … … 2203 2206 else if (retval == 0) 2204 2207 { 2208 if (is_nonblocking == SL_FALSE) 2209 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags); 2205 2210 return (SL_TIMEOUT); 2206 2211 } 2207 2212 else 2208 2213 { 2214 if (is_nonblocking == SL_FALSE) 2215 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags); 2209 2216 return (SL_EREAD); 2210 2217 } … … 2212 2219 if (sig_termfast == 1) 2213 2220 { 2221 if (is_nonblocking == SL_FALSE) 2222 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags); 2214 2223 return (SL_EREAD); 2215 2224 } … … 2220 2229 if (tdiff > timeout) 2221 2230 { 2231 if (is_nonblocking == SL_FALSE) 2232 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags); 2222 2233 return (SL_TIMEOUT); 2223 2234 } 2224 2235 } 2225 2236 2237 if (is_nonblocking == SL_FALSE) 2238 retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags); 2226 2239 return ((int) bytes); 2240 } 2241 2242 int sl_read_timeout (SL_TICKET ticket, void * buf_in, size_t count, 2243 int timeout, int is_nonblocking) 2244 { 2245 int fd; 2246 2247 if (buf_in == NULL || SL_ISERROR(fd = get_the_fd(ticket))) 2248 { 2249 if (buf_in == NULL) 2250 { 2251 TPT(( 0, FIL__, __LINE__, _("msg=<null buffer>"))); 2252 return (SL_ENULL); 2253 } 2254 if (SL_ISERROR(fd = get_the_fd(ticket))) 2255 { 2256 TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd)); 2257 return (fd); 2258 } 2259 } 2260 2261 return sl_read_timeout_fd (fd, buf_in, count, timeout, is_nonblocking); 2227 2262 } 2228 2263
Note:
See TracChangeset
for help on using the changeset viewer.