|
Lines 64-69
Link Here
|
| 64 |
#include <time.h> |
64 |
#include <time.h> |
| 65 |
#include <string.h> |
65 |
#include <string.h> |
| 66 |
#include <unistd.h> |
66 |
#include <unistd.h> |
|
|
67 |
#ifdef __APPLE_LAUNCHD__ |
| 68 |
#include <launch.h> |
| 69 |
#endif |
| 67 |
|
70 |
|
| 68 |
#include "xmalloc.h" |
71 |
#include "xmalloc.h" |
| 69 |
#include "ssh.h" |
72 |
#include "ssh.h" |
|
Lines 1031-1037
Link Here
|
| 1031 |
int |
1034 |
int |
| 1032 |
main(int ac, char **av) |
1035 |
main(int ac, char **av) |
| 1033 |
{ |
1036 |
{ |
|
|
1037 |
#ifdef __APPLE_LAUNCHD__ |
| 1038 |
int c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0, l_flag = 0; |
| 1039 |
#else |
| 1034 |
int c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0; |
1040 |
int c_flag = 0, d_flag = 0, k_flag = 0, s_flag = 0; |
|
|
1041 |
#endif |
| 1035 |
int sock, fd, ch, result, saved_errno; |
1042 |
int sock, fd, ch, result, saved_errno; |
| 1036 |
u_int nalloc; |
1043 |
u_int nalloc; |
| 1037 |
char *shell, *format, *pidstr, *agentsocket = NULL; |
1044 |
char *shell, *format, *pidstr, *agentsocket = NULL; |
|
Lines 1065-1071
Link Here
|
| 1065 |
init_rng(); |
1072 |
init_rng(); |
| 1066 |
seed_rng(); |
1073 |
seed_rng(); |
| 1067 |
|
1074 |
|
|
|
1075 |
#ifdef __APPLE_LAUNCHD__ |
| 1076 |
while ((ch = getopt(ac, av, "cdklsa:t:")) != -1) { |
| 1077 |
#else |
| 1068 |
while ((ch = getopt(ac, av, "cdksa:t:")) != -1) { |
1078 |
while ((ch = getopt(ac, av, "cdksa:t:")) != -1) { |
|
|
1079 |
#endif |
| 1069 |
switch (ch) { |
1080 |
switch (ch) { |
| 1070 |
case 'c': |
1081 |
case 'c': |
| 1071 |
if (s_flag) |
1082 |
if (s_flag) |
|
Lines 1075-1080
Link Here
|
| 1075 |
case 'k': |
1086 |
case 'k': |
| 1076 |
k_flag++; |
1087 |
k_flag++; |
| 1077 |
break; |
1088 |
break; |
|
|
1089 |
#ifdef __APPLE_LAUNCHD__ |
| 1090 |
case 'l': |
| 1091 |
l_flag++; |
| 1092 |
break; |
| 1093 |
#endif |
| 1078 |
case 's': |
1094 |
case 's': |
| 1079 |
if (c_flag) |
1095 |
if (c_flag) |
| 1080 |
usage(); |
1096 |
usage(); |
|
Lines 1101-1107
Link Here
|
| 1101 |
ac -= optind; |
1117 |
ac -= optind; |
| 1102 |
av += optind; |
1118 |
av += optind; |
| 1103 |
|
1119 |
|
|
|
1120 |
#ifdef __APPPLE_LAUNCHD__ |
| 1121 |
if (ac > 0 && (c_flag || k_flag || s_flag || d_flag || l_flag)) |
| 1122 |
#else |
| 1104 |
if (ac > 0 && (c_flag || k_flag || s_flag || d_flag)) |
1123 |
if (ac > 0 && (c_flag || k_flag || s_flag || d_flag)) |
|
|
1124 |
#endif |
| 1105 |
usage(); |
1125 |
usage(); |
| 1106 |
|
1126 |
|
| 1107 |
if (ac == 0 && !c_flag && !s_flag) { |
1127 |
if (ac == 0 && !c_flag && !s_flag) { |
|
Lines 1157-1162
Link Here
|
| 1157 |
* Create socket early so it will exist before command gets run from |
1177 |
* Create socket early so it will exist before command gets run from |
| 1158 |
* the parent. |
1178 |
* the parent. |
| 1159 |
*/ |
1179 |
*/ |
|
|
1180 |
#ifdef __APPLE_LAUNCHD__ |
| 1181 |
if (l_flag) { |
| 1182 |
launch_data_t resp, msg, tmp; |
| 1183 |
size_t listeners_i; |
| 1184 |
|
| 1185 |
msg = launch_data_new_string(LAUNCH_KEY_CHECKIN); |
| 1186 |
|
| 1187 |
resp = launch_msg(msg); |
| 1188 |
|
| 1189 |
if (NULL == resp) { |
| 1190 |
perror("launch_msg"); |
| 1191 |
exit(1); |
| 1192 |
} |
| 1193 |
launch_data_free(msg); |
| 1194 |
switch (launch_data_get_type(resp)) { |
| 1195 |
case LAUNCH_DATA_ERRNO: |
| 1196 |
errno = launch_data_get_errno(resp); |
| 1197 |
perror("launch_msg response"); |
| 1198 |
exit(1); |
| 1199 |
case LAUNCH_DATA_DICTIONARY: |
| 1200 |
break; |
| 1201 |
default: |
| 1202 |
fprintf(stderr, "launch_msg unknown response"); |
| 1203 |
exit(1); |
| 1204 |
} |
| 1205 |
tmp = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_SOCKETS); |
| 1206 |
|
| 1207 |
if (NULL == tmp) { |
| 1208 |
fprintf(stderr, "no sockets\n"); |
| 1209 |
exit(1); |
| 1210 |
} |
| 1211 |
|
| 1212 |
tmp = launch_data_dict_lookup(tmp, "Listeners"); |
| 1213 |
|
| 1214 |
if (NULL == tmp) { |
| 1215 |
fprintf(stderr, "no known listeners\n"); |
| 1216 |
exit(1); |
| 1217 |
} |
| 1218 |
|
| 1219 |
for (listeners_i = 0; listeners_i < launch_data_array_get_count(tmp); listeners_i++) { |
| 1220 |
launch_data_t obj_at_ind = launch_data_array_get_index(tmp, listeners_i); |
| 1221 |
new_socket(AUTH_SOCKET, launch_data_get_fd(obj_at_ind)); |
| 1222 |
} |
| 1223 |
|
| 1224 |
launch_data_free(resp); |
| 1225 |
} else { |
| 1226 |
#endif |
| 1160 |
sock = socket(AF_UNIX, SOCK_STREAM, 0); |
1227 |
sock = socket(AF_UNIX, SOCK_STREAM, 0); |
| 1161 |
if (sock < 0) { |
1228 |
if (sock < 0) { |
| 1162 |
perror("socket"); |
1229 |
perror("socket"); |
|
Lines 1178-1183
Link Here
|
| 1178 |
perror("listen"); |
1245 |
perror("listen"); |
| 1179 |
cleanup_exit(1); |
1246 |
cleanup_exit(1); |
| 1180 |
} |
1247 |
} |
|
|
1248 |
#ifdef __APPLE_LAUNCHD__ |
| 1249 |
} |
| 1250 |
#endif |
| 1181 |
|
1251 |
|
| 1182 |
/* |
1252 |
/* |
| 1183 |
* Fork, and have the parent execute the command, if any, or present |
1253 |
* Fork, and have the parent execute the command, if any, or present |
|
Lines 1191-1196
Link Here
|
| 1191 |
printf("echo Agent pid %ld;\n", (long)parent_pid); |
1261 |
printf("echo Agent pid %ld;\n", (long)parent_pid); |
| 1192 |
goto skip; |
1262 |
goto skip; |
| 1193 |
} |
1263 |
} |
|
|
1264 |
|
| 1265 |
#ifdef __APPLE_LAUNCHD__ |
| 1266 |
if (l_flag) |
| 1267 |
goto skip2; |
| 1268 |
#endif |
| 1269 |
|
| 1194 |
pid = fork(); |
1270 |
pid = fork(); |
| 1195 |
if (pid == -1) { |
1271 |
if (pid == -1) { |
| 1196 |
perror("fork"); |
1272 |
perror("fork"); |
|
Lines 1246-1251
Link Here
|
| 1246 |
|
1322 |
|
| 1247 |
skip: |
1323 |
skip: |
| 1248 |
new_socket(AUTH_SOCKET, sock); |
1324 |
new_socket(AUTH_SOCKET, sock); |
|
|
1325 |
skip2: |
| 1249 |
if (ac > 0) |
1326 |
if (ac > 0) |
| 1250 |
parent_alive_interval = 10; |
1327 |
parent_alive_interval = 10; |
| 1251 |
idtab_init(); |
1328 |
idtab_init(); |