2366 | | exec $dscl . -create /Users/${name} UniqueID ${uid} |
| 2366 | set failed? 0 |
| 2367 | try { |
| 2368 | exec $dscl . -create /Users/${name} UniqueID ${uid} 2>@stderr |
| 2369 | |
| 2370 | # These are implicitly added on Mac OSX Lion. AuthenticationAuthority |
| 2371 | # causes the user to be visible in the Users & Groups Preference Pane, |
| 2372 | # and the others are just noise, so delete them. |
| 2373 | # https://trac.macports.org/ticket/30168 |
| 2374 | exec $dscl . -delete /Users/${name} AuthenticationAuthority 2>@stderr |
| 2375 | exec $dscl . -delete /Users/${name} PasswordPolicyOptions 2>@stderr |
| 2376 | exec $dscl . -delete /Users/${name} dsAttrTypeNative:KerberosKeys 2>@stderr |
| 2377 | exec $dscl . -delete /Users/${name} dsAttrTypeNative:ShadowHashData 2>@stderr |
| 2378 | |
| 2379 | exec $dscl . -create /Users/${name} RealName ${realname} 2>@stderr |
| 2380 | exec $dscl . -create /Users/${name} Password ${passwd} 2>@stderr |
| 2381 | exec $dscl . -create /Users/${name} PrimaryGroupID ${gid} 2>@stderr |
| 2382 | exec $dscl . -create /Users/${name} NFSHomeDirectory ${home} 2>@stderr |
| 2383 | exec $dscl . -create /Users/${name} UserShell ${shell} 2>@stderr |
| 2384 | } catch {{CHILDKILLED *} eCode eMessage} { |
| 2385 | # the foreachs are a simple workaround for Tcl 8.4, which doesn't |
| 2386 | # seem to have lassign |
| 2387 | foreach {- pid sigName msg} $eCode { |
| 2388 | ui_error "dscl($pid) was killed by $sigName: $msg" |
| 2389 | ui_debug "dscl printed: $eMessage" |
| 2390 | } |
| 2391 | |
| 2392 | set failed? 1 |
| 2393 | } catch {{CHILDSTATUS *} eCode eMessage} { |
| 2394 | foreach {- pid code} $eCode { |
| 2395 | ui_error "dscl($pid) termined with an exit status of $code" |
| 2396 | ui_debug "dscl printed: $eMessage" |
| 2397 | } |
| 2398 | |
| 2399 | set failed? 1 |
| 2400 | } catch {{POSIX *} eCode eMessage} { |
| 2401 | foreach {- errName msg} { |
| 2402 | ui_error "failed to execute $dscl: $errName: $msg" |
| 2403 | ui_debug "dscl printed: $eMessage" |
| 2404 | } |
| 2405 | |
| 2406 | set failed? 1 |
| 2407 | } finally { |
| 2408 | if {${failed?}} { |
| 2409 | # creating the user properly failed and we're bailing out |
| 2410 | # anyway, try to delete the half-created user to revert to the |
| 2411 | # state before the error |
| 2412 | ui_debug "Attempting to clean up failed creation of user $name" |
| 2413 | try { |
| 2414 | exec $dscl . -delete /Users/${name} 2>@stderr |
| 2415 | } catch {{CHILDKILLED *} eCode eMessage} { |
| 2416 | foreach {- pid sigName msg} { |
| 2417 | ui_warn "dscl($pid) was killed by $sigName: $msg while trying to clean up failed creation of user $name." |
| 2418 | ui_debug "dscl printed: $eMessage" |
| 2419 | } |
| 2420 | } catch {{CHILDSTATUS *} eCode eMessage} { |
| 2421 | # ignoring childstatus failure, because that probably means |
| 2422 | # the first call failed and the user wasn't even created |
| 2423 | } catch {{POSIX *} eCode eMessage} { |
| 2424 | foreach {- errName msg} { |
| 2425 | ui_warn "failed to execute $dscl: $errName: $msg while trying to clean up failed creation of user $name." |
| 2426 | ui_debug "dscl printed: $eMessage" |
| 2427 | } |
| 2428 | } |
2368 | | # These are implicitly added on Mac OSX Lion. AuthenticationAuthority |
2369 | | # causes the user to be visible in the Users & Groups Preference Pane, |
2370 | | # and the others are just noise, so delete them. |
2371 | | # https://trac.macports.org/ticket/30168 |
2372 | | exec $dscl . -delete /Users/${name} AuthenticationAuthority |
2373 | | exec $dscl . -delete /Users/${name} PasswordPolicyOptions |
2374 | | exec $dscl . -delete /Users/${name} dsAttrTypeNative:KerberosKeys |
2375 | | exec $dscl . -delete /Users/${name} dsAttrTypeNative:ShadowHashData |
2376 | | |
2377 | | exec $dscl . -create /Users/${name} RealName ${realname} |
2378 | | exec $dscl . -create /Users/${name} Password ${passwd} |
2379 | | exec $dscl . -create /Users/${name} PrimaryGroupID ${gid} |
2380 | | exec $dscl . -create /Users/${name} NFSHomeDirectory ${home} |
2381 | | exec $dscl . -create /Users/${name} UserShell ${shell} |
| 2430 | # and raise an error to abort |
| 2431 | error "dscl failed to create required user $name." |
| 2432 | } |
| 2433 | } |
2422 | | exec $dscl . -create /Groups/${name} Password ${passwd} |
2423 | | exec $dscl . -create /Groups/${name} RealName ${realname} |
2424 | | exec $dscl . -create /Groups/${name} PrimaryGroupID ${gid} |
2425 | | if {${users} ne ""} { |
2426 | | exec $dscl . -create /Groups/${name} GroupMembership ${users} |
| 2474 | set failed? 0 |
| 2475 | try { |
| 2476 | exec $dscl . -create /Groups/${name} Password ${passwd} |
| 2477 | exec $dscl . -create /Groups/${name} RealName ${realname} |
| 2478 | exec $dscl . -create /Groups/${name} PrimaryGroupID ${gid} |
| 2479 | if {${users} ne ""} { |
| 2480 | exec $dscl . -create /Groups/${name} GroupMembership ${users} |
| 2481 | } |
| 2482 | } catch {{CHILDKILLED *} eCode eMessage} { |
| 2483 | # the foreachs are a simple workaround for Tcl 8.4, which doesn't |
| 2484 | # seem to have lassign |
| 2485 | foreach {- pid sigName msg} $eCode { |
| 2486 | ui_error "dscl($pid) was killed by $sigName: $msg" |
| 2487 | ui_debug "dscl printed: $eMessage" |
| 2488 | } |
| 2489 | |
| 2490 | set failed? 1 |
| 2491 | } catch {{CHILDSTATUS *} eCode eMessage} { |
| 2492 | foreach {- pid code} $eCode { |
| 2493 | ui_error "dscl($pid) termined with an exit status of $code" |
| 2494 | ui_debug "dscl printed: $eMessage" |
| 2495 | } |
| 2496 | |
| 2497 | set failed? 1 |
| 2498 | } catch {{POSIX *} eCode eMessage} { |
| 2499 | foreach {- errName msg} { |
| 2500 | ui_error "failed to execute $dscl: $errName: $msg" |
| 2501 | ui_debug "dscl printed: $eMessage" |
| 2502 | } |
| 2503 | |
| 2504 | set failed? 1 |
| 2505 | } finally { |
| 2506 | if {${failed?}} { |
| 2507 | # creating the user properly failed and we're bailing out |
| 2508 | # anyway, try to delete the half-created user to revert to the |
| 2509 | # state before the error |
| 2510 | ui_debug "Attempting to clean up failed creation of group $name" |
| 2511 | try { |
| 2512 | exec $dscl . -delete /Groups/${name} 2>@stderr |
| 2513 | } catch {{CHILDKILLED *} eCode eMessage} { |
| 2514 | foreach {- pid sigName msg} { |
| 2515 | ui_warn "dscl($pid) was killed by $sigName: $msg while trying to clean up failed creation of group $name." |
| 2516 | ui_debug "dscl printed: $eMessage" |
| 2517 | } |
| 2518 | } catch {{CHILDSTATUS *} eCode eMessage} { |
| 2519 | # ignoring childstatus failure, because that probably means |
| 2520 | # the first call failed and the user wasn't even created |
| 2521 | } catch {{POSIX *} eCode eMessage} { |
| 2522 | foreach {- errName msg} { |
| 2523 | ui_warn "failed to execute $dscl: $errName: $msg while trying to clean up failed creation of group $name." |
| 2524 | ui_debug "dscl printed: $eMessage" |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | # and raise an error to abort |
| 2529 | error "dscl failed to create required group $name." |
| 2530 | } |