| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifdef HAVE_CONFIG_H |
| 25 |
#include <config.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
RCSID("$Id$"); |
| 29 |
|
| 30 |
#include <krb5.h> |
| 31 |
|
| 32 |
#ifdef DCE |
| 33 |
|
| 34 |
#include <stdio.h> |
| 35 |
#include <sys/stat.h> |
| 36 |
#include <sys/wait.h> |
| 37 |
#include <fcntl.h> |
| 38 |
#include <sys/param.h> |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#define POSIX_SETJMP |
| 49 |
#define POSIX_SIGNALS |
| 50 |
#define HAVE_WAITPID |
| 51 |
|
| 52 |
#include <signal.h> |
| 53 |
#include <setjmp.h> |
| 54 |
#ifndef POSIX_SETJMP |
| 55 |
#undef sigjmp_buf |
| 56 |
#undef sigsetjmp |
| 57 |
#undef siglongjmp |
| 58 |
#define sigjmp_buf jmp_buf |
| 59 |
#define sigsetjmp(j,s) setjmp(j) |
| 60 |
#define siglongjmp longjmp |
| 61 |
#endif |
| 62 |
|
| 63 |
#ifdef POSIX_SIGNALS |
| 64 |
typedef struct sigaction handler; |
| 65 |
#define handler_init(H,F) (sigemptyset(&(H).sa_mask), \ |
| 66 |
(H).sa_flags=0, \ |
| 67 |
(H).sa_handler=(F)) |
| 68 |
#define handler_swap(S,NEW,OLD) sigaction(S, &NEW, &OLD) |
| 69 |
#define handler_set(S,OLD) sigaction(S, &OLD, NULL) |
| 70 |
#else |
| 71 |
typedef sigtype (*handler)(); |
| 72 |
#define handler_init(H,F) ((H) = (F)) |
| 73 |
#define handler_swap(S,NEW,OLD) ((OLD) = signal ((S), (NEW))) |
| 74 |
#define handler_set(S,OLD) (signal ((S), (OLD))) |
| 75 |
#endif |
| 76 |
|
| 77 |
#define krb5_sigtype void |
| 78 |
#define WAIT_USES_INT |
| 79 |
typedef krb5_sigtype sigtype; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
#define AFSCALL_SETPAG 2 |
| 96 |
#define AFSCALL_GETPAG 11 |
| 97 |
|
| 98 |
#if defined(sun) |
| 99 |
#define AFS_SYSCALL 72 |
| 100 |
|
| 101 |
#elif defined(hpux) |
| 102 |
|
| 103 |
#define AFS_SYSCALL 326 |
| 104 |
|
| 105 |
#elif defined(_AIX) |
| 106 |
#ifndef DPAGAIX |
| 107 |
#define DPAGAIX LIBEXECDIR "/dpagaix" |
| 108 |
#endif |
| 109 |
int *load(); |
| 110 |
static int (*dpagaix)(int, int, int, int, int, int) = 0; |
| 111 |
|
| 112 |
#elif defined(sgi) || defined(_sgi) |
| 113 |
#define AFS_SYSCALL 206+1000 |
| 114 |
|
| 115 |
#else |
| 116 |
#define AFS_SYSCALL (Unknown_DFS_AFS_SYSCALL) |
| 117 |
#endif |
| 118 |
|
| 119 |
|
| 120 |
#ifdef WAIT_USES_INT |
| 121 |
int wait_status; |
| 122 |
#else |
| 123 |
union wait wait_status; |
| 124 |
#endif |
| 125 |
|
| 126 |
#ifndef K5DCECON |
| 127 |
#define K5DCECON LIBEXECDIR "/k5dcecon" |
| 128 |
#endif |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
static sigjmp_buf setpag_buf; |
| 138 |
|
| 139 |
static sigtype mysig() |
| 140 |
{ |
| 141 |
siglongjmp(setpag_buf, 1); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
static int krb5_dfs_pag_syscall(opt1,opt2) |
| 152 |
int opt1; |
| 153 |
int opt2; |
| 154 |
{ |
| 155 |
handler sa1, osa1; |
| 156 |
handler sa2, osa2; |
| 157 |
int pag = -2; |
| 158 |
|
| 159 |
handler_init (sa1, mysig); |
| 160 |
handler_init (sa2, mysig); |
| 161 |
handler_swap (SIGSYS, sa1, osa1); |
| 162 |
handler_swap (SIGSEGV, sa2, osa2); |
| 163 |
|
| 164 |
if (sigsetjmp(setpag_buf, 1) == 0) { |
| 165 |
|
| 166 |
#if defined(_AIX) |
| 167 |
if (!dpagaix) |
| 168 |
dpagaix = load(DPAGAIX, 0, 0); |
| 169 |
if (dpagaix) |
| 170 |
pag = (*dpagaix)(opt1, opt2, 0, 0, 0, 0); |
| 171 |
#else |
| 172 |
pag = syscall(AFS_SYSCALL, opt1, opt2, 0, 0, 0, 0); |
| 173 |
#endif |
| 174 |
|
| 175 |
handler_set (SIGSYS, osa1); |
| 176 |
handler_set (SIGSEGV, osa2); |
| 177 |
return(pag); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
handler_set (SIGSYS, osa1); |
| 182 |
handler_set (SIGSEGV, osa2); |
| 183 |
return(-2); |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
int krb5_dfs_newpag(new_pag) |
| 200 |
int new_pag; |
| 201 |
{ |
| 202 |
return(krb5_dfs_pag_syscall(AFSCALL_SETPAG, new_pag)); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
int krb5_dfs_getpag() |
| 212 |
{ |
| 213 |
return(krb5_dfs_pag_syscall(AFSCALL_GETPAG, 0)); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
int krb5_dfs_pag(context, flag, principal, luser) |
| 248 |
krb5_context context; |
| 249 |
int flag; |
| 250 |
krb5_principal principal; |
| 251 |
const char *luser; |
| 252 |
|
| 253 |
{ |
| 254 |
|
| 255 |
struct stat stx; |
| 256 |
int fd[2]; |
| 257 |
int i,j; |
| 258 |
int pid; |
| 259 |
int new_pag; |
| 260 |
int pag; |
| 261 |
char newccname[MAXPATHLEN] = ""; |
| 262 |
char *princ; |
| 263 |
int err; |
| 264 |
struct sigaction newsig, oldsig; |
| 265 |
|
| 266 |
#ifdef WAIT_USES_INT |
| 267 |
int wait_status; |
| 268 |
#else |
| 269 |
union wait wait_status; |
| 270 |
#endif |
| 271 |
|
| 272 |
if (krb5_unparse_name(context, principal, &princ)) |
| 273 |
return(0); |
| 274 |
|
| 275 |
|
| 276 |
if (krb5_dfs_getpag() == -2) |
| 277 |
return(0); |
| 278 |
|
| 279 |
if (pipe(fd) == -1) |
| 280 |
return(0); |
| 281 |
|
| 282 |
|
| 283 |
memset((char *)&newsig, 0, sizeof(newsig)); |
| 284 |
newsig.sa_handler = SIG_DFL; |
| 285 |
sigaction(SIGCHLD, &newsig, &oldsig); |
| 286 |
|
| 287 |
pid = fork(); |
| 288 |
if (pid <0) |
| 289 |
return(0); |
| 290 |
|
| 291 |
if (pid == 0) { |
| 292 |
|
| 293 |
close(1); |
| 294 |
dup(fd[1]); |
| 295 |
close(fd[0]); |
| 296 |
close(fd[1]); |
| 297 |
|
| 298 |
execl(K5DCECON, "k5dcecon", |
| 299 |
(flag) ? "-f" : "-s" , |
| 300 |
"-l", luser, |
| 301 |
"-p", princ, (char *)0); |
| 302 |
|
| 303 |
exit(127); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
close(fd[1]); |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
wait_status = 0; |
| 317 |
#ifdef HAVE_WAITPID |
| 318 |
err = waitpid((pid_t) pid, &wait_status, 0); |
| 319 |
#else |
| 320 |
err = wait4(pid, &wait_status, 0, (struct rusage *) NULL); |
| 321 |
#endif |
| 322 |
|
| 323 |
|
| 324 |
sigaction(SIGCHLD, &oldsig, 0); |
| 325 |
if (WIFEXITED(wait_status)){ |
| 326 |
if (WEXITSTATUS(wait_status) == 0) { |
| 327 |
i = 1; |
| 328 |
j = 0; |
| 329 |
while (i != 0) { |
| 330 |
i = read(fd[0], &newccname[j], sizeof(newccname)-1-j); |
| 331 |
if ( i > 0) |
| 332 |
j += i; |
| 333 |
if (j >= sizeof(newccname)-1) |
| 334 |
i = 0; |
| 335 |
} |
| 336 |
close(fd[0]); |
| 337 |
if (j > 0) { |
| 338 |
newccname[j] = '\0'; |
| 339 |
esetenv("KRB5CCNAME",newccname,1); |
| 340 |
sscanf(&newccname[j-8],"%8x",&new_pag); |
| 341 |
if (new_pag && strncmp("FILE:/opt/dcelocal/var/security/creds/dcecred_", newccname, 46) == 0) { |
| 342 |
if((pag = krb5_dfs_newpag(new_pag)) != -2) { |
| 343 |
return(pag); |
| 344 |
} |
| 345 |
} |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
return(0); |
| 350 |
} |
| 351 |
|
| 352 |
#else |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
krb5_boolean |
| 360 |
krb5_dfs_pag(context, principal, luser) |
| 361 |
krb5_context context; |
| 362 |
krb5_principal principal; |
| 363 |
const char *luser; |
| 364 |
{ |
| 365 |
return(0); |
| 366 |
} |
| 367 |
|
| 368 |
#endif |