mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-05 04:40:31 +09:00
Compare commits
985 Commits
v0-2
...
release-0-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
254a166c02 | ||
|
|
3e938cb901 | ||
|
|
452b16ede2 | ||
|
|
bd47ff75ba | ||
|
|
0016ded7f9 | ||
|
|
d725b31752 | ||
|
|
c2e86c876c | ||
|
|
028516ba6a | ||
|
|
344b27ac6c | ||
|
|
a700259b01 | ||
|
|
14da14db05 | ||
|
|
474d63f24e | ||
|
|
b3589fbf6c | ||
|
|
dd68bae776 | ||
|
|
4768cf3e85 | ||
|
|
5a95681f01 | ||
|
|
13a3619102 | ||
|
|
c7636edf84 | ||
|
|
27e332b623 | ||
|
|
ebc8544c56 | ||
|
|
0f8e9b839c | ||
|
|
0c02d6effe | ||
|
|
7199b196b0 | ||
|
|
ca83b66066 | ||
|
|
d978f9b58a | ||
|
|
e539eaf9e0 | ||
|
|
b728f44ce9 | ||
|
|
2f0b671a61 | ||
|
|
1fadec37d6 | ||
|
|
2aabbd6245 | ||
|
|
fd6823691b | ||
|
|
b174ad8ae4 | ||
|
|
176778bb1c | ||
|
|
e5bf645010 | ||
|
|
d1c6fa9261 | ||
|
|
b00e2ad40e | ||
|
|
ca9f42a20f | ||
|
|
e939786836 | ||
|
|
11cc5f5815 | ||
|
|
d60b1ec1a2 | ||
|
|
ae11589205 | ||
|
|
70b9475449 | ||
|
|
02aecc1278 | ||
|
|
3e90a11599 | ||
|
|
b4095189d7 | ||
|
|
c0b4c4d60c | ||
|
|
12da24c056 | ||
|
|
d821117033 | ||
|
|
30266f7627 | ||
|
|
10b625e180 | ||
|
|
10f27457d3 | ||
|
|
af1f431364 | ||
|
|
272a4d1e45 | ||
|
|
3a95ecfe74 | ||
|
|
14ae9a7f0c | ||
|
|
51f1918109 | ||
|
|
fa27956daf | ||
|
|
ab0d8a3828 | ||
|
|
efded18724 | ||
|
|
f52bc064e9 | ||
|
|
75f066dfcd | ||
|
|
535ff07f0f | ||
|
|
5e002635fc | ||
|
|
e71c28f6a0 | ||
|
|
c0e091a52f | ||
|
|
8ab0f8e51f | ||
|
|
cce34a6176 | ||
|
|
89f0311927 | ||
|
|
e455f6f756 | ||
|
|
17f2645a32 | ||
|
|
9f034aca9c | ||
|
|
22bdfa3886 | ||
|
|
ef8246a592 | ||
|
|
110d201e02 | ||
|
|
be4f695c5c | ||
|
|
792def7a65 | ||
|
|
840cecbe0e | ||
|
|
27d25752e9 | ||
|
|
a479b30298 | ||
|
|
86620fc991 | ||
|
|
b3dfd5cffc | ||
|
|
f0858ff6b2 | ||
|
|
7b7280e728 | ||
|
|
2523ed0779 | ||
|
|
e736b1a40e | ||
|
|
cbf012c337 | ||
|
|
c360ed1d9a | ||
|
|
22e74e3bab | ||
|
|
02b3104215 | ||
|
|
26a5294116 | ||
|
|
5e4c78e114 | ||
|
|
e74305c5eb | ||
|
|
499f9aa707 | ||
|
|
4dee9a3e68 | ||
|
|
399041180f | ||
|
|
3f55fb5b22 | ||
|
|
37a4a65d60 | ||
|
|
ccd886feb4 | ||
|
|
b1bc283e9a | ||
|
|
be75fac7ff | ||
|
|
6ec65c6f9d | ||
|
|
71ab0cf6cc | ||
|
|
1e0e8a5493 | ||
|
|
4b65aea401 | ||
|
|
98ff6fbbce | ||
|
|
43e0d73b63 | ||
|
|
58294442d3 | ||
|
|
2e9c13dad0 | ||
|
|
9c667ebc26 | ||
|
|
d1b772f1bc | ||
|
|
876f843f23 | ||
|
|
0e2e0983f3 | ||
|
|
6063a8d09c | ||
|
|
40778d4ba9 | ||
|
|
60d6954b75 | ||
|
|
bf376b6d4f | ||
|
|
ff52e3630f | ||
|
|
f1f17f18dc | ||
|
|
7c759b9615 | ||
|
|
d54e9550da | ||
|
|
d7c0270c89 | ||
|
|
7a37f9faf7 | ||
|
|
149a2b4a18 | ||
|
|
ab5b4c7cfe | ||
|
|
e78334688f | ||
|
|
566fda70a5 | ||
|
|
62cebe23d9 | ||
|
|
42aacc7106 | ||
|
|
8ed9cdce80 | ||
|
|
a3a7f17d0f | ||
|
|
571dd56eca | ||
|
|
f6f0988d10 | ||
|
|
f9d1542542 | ||
|
|
d32fe11da3 | ||
|
|
cd7f6bea57 | ||
|
|
c3dc60103f | ||
|
|
2a2616f65c | ||
|
|
f643c34ee8 | ||
|
|
0f77578ee2 | ||
|
|
3e314e863c | ||
|
|
adbb087221 | ||
|
|
3a8d839e86 | ||
|
|
358647f5d9 | ||
|
|
5e76118512 | ||
|
|
e3bdc393cb | ||
|
|
04b49d46c1 | ||
|
|
74b7fb7bba | ||
|
|
c70694c594 | ||
|
|
fef87793a0 | ||
|
|
79c475c917 | ||
|
|
3dd03fec21 | ||
|
|
e8e07f7376 | ||
|
|
1c5ae7dd97 | ||
|
|
f65e3566a2 | ||
|
|
6b0a89a288 | ||
|
|
f84ebc2e27 | ||
|
|
b359229a2e | ||
|
|
496a8e12d9 | ||
|
|
0e8e124d20 | ||
|
|
9a8d4cd0fd | ||
|
|
ffed8b03bb | ||
|
|
5bd38a5f37 | ||
|
|
ab60d1d678 | ||
|
|
5223fa5740 | ||
|
|
95558d54b0 | ||
|
|
068a7dfc49 | ||
|
|
abd8b17a04 | ||
|
|
343e6e482a | ||
|
|
aae1df0589 | ||
|
|
0a57ebb3a9 | ||
|
|
9afad28255 | ||
|
|
8b21b51a78 | ||
|
|
2003a81b44 | ||
|
|
abe6c7c728 | ||
|
|
f78045dfd3 | ||
|
|
39729bd3de | ||
|
|
f6d2a66de2 | ||
|
|
7de3122b42 | ||
|
|
88f4e9ea24 | ||
|
|
4133f484ae | ||
|
|
041aff8060 | ||
|
|
7c7096d8f8 | ||
|
|
fd7b7bc3b5 | ||
|
|
bb034e8e1d | ||
|
|
d37a475816 | ||
|
|
4845642611 | ||
|
|
de8808cb47 | ||
|
|
ca978a9e81 | ||
|
|
ffca268bee | ||
|
|
6a3d31acb7 | ||
|
|
f28352707a | ||
|
|
4b363928f6 | ||
|
|
929f5ca25b | ||
|
|
7ff80a2666 | ||
|
|
480dfd9050 | ||
|
|
bdb32afa20 | ||
|
|
f90ae73b6d | ||
|
|
7fed54b1e5 | ||
|
|
d5840aa1f0 | ||
|
|
6f2225e8fb | ||
|
|
07a9e6b7c6 | ||
|
|
86e6444656 | ||
|
|
8ef62cf784 | ||
|
|
8051ab044c | ||
|
|
18bce13617 | ||
|
|
2a10019f82 | ||
|
|
df4c62212c | ||
|
|
97b6036cbf | ||
|
|
df4f7ed5b8 | ||
|
|
0792c015d6 | ||
|
|
8344598910 | ||
|
|
16870abed7 | ||
|
|
65850a1bad | ||
|
|
1137f0d48c | ||
|
|
d9a50f04e7 | ||
|
|
4aa7d73b43 | ||
|
|
3804e72e24 | ||
|
|
b8508020e5 | ||
|
|
324be0eabd | ||
|
|
cfe5f83cf8 | ||
|
|
a1ad0deb32 | ||
|
|
7c575a2418 | ||
|
|
47cac13c0a | ||
|
|
16d1ef8933 | ||
|
|
b500d76929 | ||
|
|
aef9471217 | ||
|
|
f3454d571e | ||
|
|
1df1f86f7e | ||
|
|
f9db9c5a9c | ||
|
|
96bafeca4c | ||
|
|
626d8ec637 | ||
|
|
f3b36af50e | ||
|
|
385b640d1d | ||
|
|
d4bc6fa954 | ||
|
|
8bae43876f | ||
|
|
fbfea94559 | ||
|
|
6a04b43a45 | ||
|
|
049c62098c | ||
|
|
6801959989 | ||
|
|
8463d9d7c6 | ||
|
|
c497f057a0 | ||
|
|
fc0af0f0d8 | ||
|
|
330c2004a1 | ||
|
|
0b10493e90 | ||
|
|
d23e64fc52 | ||
|
|
fd83d69440 | ||
|
|
461e46b814 | ||
|
|
4f95146151 | ||
|
|
3eb21053d0 | ||
|
|
92db6f8c6d | ||
|
|
0fd0c6d293 | ||
|
|
b49973f17b | ||
|
|
978d265da8 | ||
|
|
cf6dddce34 | ||
|
|
2c4bbe51dd | ||
|
|
756d441f8c | ||
|
|
db6aa88bc4 | ||
|
|
e707af1cd7 | ||
|
|
380a70d650 | ||
|
|
2dc3b5c675 | ||
|
|
63011c29a0 | ||
|
|
e68c3b09a6 | ||
|
|
0793bf5aa6 | ||
|
|
d9b7e4cb7a | ||
|
|
8e6ab1809f | ||
|
|
86418bfbbe | ||
|
|
1e1c13f756 | ||
|
|
8dae851836 | ||
|
|
db284d60b9 | ||
|
|
bfc6c7e606 | ||
|
|
9b13390ad0 | ||
|
|
81fe4299f7 | ||
|
|
5e4bc6ec79 | ||
|
|
f3612879a8 | ||
|
|
57088c4375 | ||
|
|
011ab7c8fe | ||
|
|
e4422d6605 | ||
|
|
14e1d015ee | ||
|
|
3da1c17acb | ||
|
|
7e9f0803c5 | ||
|
|
f989452b3e | ||
|
|
a2780d1dd4 | ||
|
|
ddca45804b | ||
|
|
f92e12c7b0 | ||
|
|
e4da8b99fe | ||
|
|
b993579079 | ||
|
|
807cb635c1 | ||
|
|
3ad559cc23 | ||
|
|
ec02ce0ec2 | ||
|
|
1b9676a0cc | ||
|
|
f4b3ef7604 | ||
|
|
e9974c2053 | ||
|
|
de532ee550 | ||
|
|
67b44e4417 | ||
|
|
83f65031c0 | ||
|
|
63053541e6 | ||
|
|
a040e2e3db | ||
|
|
678d445075 | ||
|
|
3558b9e6b6 | ||
|
|
590c3e2f51 | ||
|
|
28a7343320 | ||
|
|
766bae9d76 | ||
|
|
94a57df0c9 | ||
|
|
5f93742c5e | ||
|
|
9457c770df | ||
|
|
bccb9b16a5 | ||
|
|
1355029ec9 | ||
|
|
5dc8d6069d | ||
|
|
60837b1538 | ||
|
|
debfd1f3a3 | ||
|
|
4f70cc13e2 | ||
|
|
b4111c5c18 | ||
|
|
b9b7174d85 | ||
|
|
69ceaae9a9 | ||
|
|
1abdb28995 | ||
|
|
81dab99afc | ||
|
|
291522772d | ||
|
|
26d1ac325b | ||
|
|
1311d03415 | ||
|
|
549fd32574 | ||
|
|
9f14bbd6ad | ||
|
|
e8f7801540 | ||
|
|
cdde79418a | ||
|
|
9b97da65e6 | ||
|
|
1dcaebe1ce | ||
|
|
28b5d0f875 | ||
|
|
ba217dec1c | ||
|
|
3b8c4dc750 | ||
|
|
5d1fa1be24 | ||
|
|
c8e82528fc | ||
|
|
104e6d39ab | ||
|
|
3f778d9a31 | ||
|
|
a935ad1857 | ||
|
|
7abb3941c8 | ||
|
|
194880b869 | ||
|
|
737f588b3b | ||
|
|
6d5b36fb79 | ||
|
|
8ce6bd3459 | ||
|
|
5b8338d115 | ||
|
|
e73cbbe18c | ||
|
|
69a01b3657 | ||
|
|
e406b81d34 | ||
|
|
fdc2751952 | ||
|
|
fa11083fcb | ||
|
|
2bc8819e8f | ||
|
|
23b6c95e04 | ||
|
|
c041bcc6d9 | ||
|
|
fc5dd23afa | ||
|
|
91d0660cc3 | ||
|
|
fb5769b4be | ||
|
|
56ee212641 | ||
|
|
8f3891e968 | ||
|
|
958a775afa | ||
|
|
e776dc16c9 | ||
|
|
9450a3c987 | ||
|
|
1939a55c3c | ||
|
|
2a116bb291 | ||
|
|
d01c7320f9 | ||
|
|
ea0315ed88 | ||
|
|
85a5eb9499 | ||
|
|
3cd06a1f26 | ||
|
|
19c3d02805 | ||
|
|
b534bfc520 | ||
|
|
ef2c8d66f1 | ||
|
|
1a6038baa5 | ||
|
|
41a8fb5810 | ||
|
|
8843d8b68d | ||
|
|
2aec79ce36 | ||
|
|
bbcbc8425c | ||
|
|
ed8178f3c3 | ||
|
|
933527fc77 | ||
|
|
bf8d139b2d | ||
|
|
093983b804 | ||
|
|
103292dd99 | ||
|
|
76b6b1c694 | ||
|
|
1301864f92 | ||
|
|
d5b6f6cc37 | ||
|
|
052073c36d | ||
|
|
60c778ad7f | ||
|
|
71100dadcd | ||
|
|
5ba33438f3 | ||
|
|
708c0d32a2 | ||
|
|
3659e8c04a | ||
|
|
c4cf349729 | ||
|
|
2c99566697 | ||
|
|
42470857e2 | ||
|
|
8724f97a19 | ||
|
|
8960992267 | ||
|
|
730af24de8 | ||
|
|
a3fa6f3099 | ||
|
|
4dafc25927 | ||
|
|
e671ebcd99 | ||
|
|
bab8508eba | ||
|
|
77cd4795c5 | ||
|
|
dc83f36a00 | ||
|
|
8336c91e9c | ||
|
|
1bea53375b | ||
|
|
3af55a4f49 | ||
|
|
cf482ae3bf | ||
|
|
916958a2bb | ||
|
|
e2af94289f | ||
|
|
fa4c81cfb9 | ||
|
|
7dbc66e4a3 | ||
|
|
3873489688 | ||
|
|
d14a492019 | ||
|
|
848984f25f | ||
|
|
5a755a8219 | ||
|
|
910689126a | ||
|
|
87995db8fe | ||
|
|
70c9da4fb0 | ||
|
|
1ac654ec6c | ||
|
|
fecbdff179 | ||
|
|
894b73abe2 | ||
|
|
da4986e4bc | ||
|
|
08ab186471 | ||
|
|
439d995fed | ||
|
|
2e0b2e2e91 | ||
|
|
80ba62a519 | ||
|
|
a065e35e37 | ||
|
|
2eaf69ee06 | ||
|
|
a15a28e698 | ||
|
|
646a5a2cfc | ||
|
|
9196be1a42 | ||
|
|
1657d0932f | ||
|
|
f0432cc24f | ||
|
|
d008e5aeb8 | ||
|
|
2934765c76 | ||
|
|
f29e119c25 | ||
|
|
126dcd51e5 | ||
|
|
249e11bd2e | ||
|
|
cea0ac4455 | ||
|
|
ae81c4124e | ||
|
|
d75b53805d | ||
|
|
bc0491c098 | ||
|
|
1fd0237ddb | ||
|
|
69af190acb | ||
|
|
c7806a6a16 | ||
|
|
fdc1073e8a | ||
|
|
fb559c6ffd | ||
|
|
f7d2040d5a | ||
|
|
2e5f1c8955 | ||
|
|
184b711a04 | ||
|
|
5708fe1729 | ||
|
|
cc2df5487a | ||
|
|
fc50facaa3 | ||
|
|
8f8e9a2f50 | ||
|
|
ec714ea67d | ||
|
|
de138cd055 | ||
|
|
65331f470a | ||
|
|
d6e23b7628 | ||
|
|
f9baa6552c | ||
|
|
4bf12aaf56 | ||
|
|
7568e42f4e | ||
|
|
83b26b97b5 | ||
|
|
ce1a5d7578 | ||
|
|
57b7e73394 | ||
|
|
33a640e348 | ||
|
|
03c40ac79f | ||
|
|
53a24a4f78 | ||
|
|
8af13665ab | ||
|
|
4838742a8e | ||
|
|
8c45767d34 | ||
|
|
1d78b6d00e | ||
|
|
4c78793961 | ||
|
|
5c934d0970 | ||
|
|
1a280d859d | ||
|
|
dc07d46cca | ||
|
|
6c51183f0e | ||
|
|
61ebfcfa5c | ||
|
|
ff60d8ce22 | ||
|
|
c4169e3c41 | ||
|
|
0b7ae624a3 | ||
|
|
d9a0b90701 | ||
|
|
503bc1b95f | ||
|
|
cd71590fe0 | ||
|
|
1afe6b13c5 | ||
|
|
0d17b6778b | ||
|
|
43d881ba28 | ||
|
|
3d9fbe8eea | ||
|
|
152da07023 | ||
|
|
dda7808851 | ||
|
|
f40ae74f51 | ||
|
|
5b547812eb | ||
|
|
8060f51ec7 | ||
|
|
0e6359c63d | ||
|
|
3e1ed1707c | ||
|
|
2688c1a1d5 | ||
|
|
a08c56baf4 | ||
|
|
137669db3f | ||
|
|
98fbe3020d | ||
|
|
9345ba7030 | ||
|
|
17c146391c | ||
|
|
b27e5b6785 | ||
|
|
9827cac475 | ||
|
|
b23c68264d | ||
|
|
095775ef1b | ||
|
|
c98fce8596 | ||
|
|
e97275c7bc | ||
|
|
783825254a | ||
|
|
e7fc9ab369 | ||
|
|
2b705786c0 | ||
|
|
e46d2d024c | ||
|
|
06eceb3204 | ||
|
|
a7732ebbe5 | ||
|
|
6538121494 | ||
|
|
0534fee674 | ||
|
|
c31893d246 | ||
|
|
f0b14c7b7a | ||
|
|
0b4159d1ec | ||
|
|
015b1649b1 | ||
|
|
5b1c21593c | ||
|
|
2ed97906e3 | ||
|
|
deb9d30f4d | ||
|
|
65d09f3268 | ||
|
|
0881ba13d6 | ||
|
|
83971c0188 | ||
|
|
cc6199d9f0 | ||
|
|
e8f783eb36 | ||
|
|
a1802f1c32 | ||
|
|
d680160500 | ||
|
|
2317a58996 | ||
|
|
567cc5984a | ||
|
|
06a0dea2ad | ||
|
|
982045bb96 | ||
|
|
c3ee07d747 | ||
|
|
fa63c0adee | ||
|
|
78ad279a43 | ||
|
|
e13c2871ff | ||
|
|
f119a27bb6 | ||
|
|
23a55a0a0a | ||
|
|
1cdc7c6e43 | ||
|
|
5c662f6f6b | ||
|
|
afeaea318c | ||
|
|
29035f952c | ||
|
|
3024e3652f | ||
|
|
5fdcd4df7b | ||
|
|
634a2d20b8 | ||
|
|
75fb96f740 | ||
|
|
907b4075c0 | ||
|
|
ddd1d62429 | ||
|
|
84629a394e | ||
|
|
c26fb22122 | ||
|
|
4cc2acda3a | ||
|
|
2c75ad7e19 | ||
|
|
9f7d4d2d60 | ||
|
|
511213872b | ||
|
|
8dbe59efde | ||
|
|
b39fcd6470 | ||
|
|
a19aebba18 | ||
|
|
b1e62ad22b | ||
|
|
9d270f99a7 | ||
|
|
315e5aca84 | ||
|
|
bf312c50a9 | ||
|
|
52d20beb73 | ||
|
|
f11630ab68 | ||
|
|
f32e307899 | ||
|
|
83142315da | ||
|
|
db79fff00d | ||
|
|
5d23142599 | ||
|
|
1f6341f549 | ||
|
|
72aeba410f | ||
|
|
c1c4f299ff | ||
|
|
99946c7bcc | ||
|
|
0eedebd84a | ||
|
|
c1cd3b2974 | ||
|
|
2b4efa171e | ||
|
|
367f4b999a | ||
|
|
75c3996a49 | ||
|
|
320c70a170 | ||
|
|
387f6473f7 | ||
|
|
4d80a1559a | ||
|
|
fd79249df6 | ||
|
|
50616076c7 | ||
|
|
4a383ab3cf | ||
|
|
cefe239958 | ||
|
|
29e6f140fa | ||
|
|
b0778ca169 | ||
|
|
ac724eb3fb | ||
|
|
8ba57619fd | ||
|
|
10ddf310a6 | ||
|
|
5a84af65fa | ||
|
|
5d689c2d29 | ||
|
|
baee8c17b5 | ||
|
|
441929f8b8 | ||
|
|
75da135324 | ||
|
|
7592d9f42c | ||
|
|
62ac83a8ea | ||
|
|
4ad9235805 | ||
|
|
fbc6543c83 | ||
|
|
cedc9d71c3 | ||
|
|
39f8c7faab | ||
|
|
8fecf4d74c | ||
|
|
b5bda67235 | ||
|
|
d62a43ee9d | ||
|
|
56e13b227f | ||
|
|
a0b4b239fb | ||
|
|
4816afc9e8 | ||
|
|
5be3a3c066 | ||
|
|
75eddb1ebb | ||
|
|
45d8248efb | ||
|
|
47ff8d4679 | ||
|
|
0f075f4d95 | ||
|
|
57a5c50a54 | ||
|
|
e99966772e | ||
|
|
8a3c417e14 | ||
|
|
e6c0155567 | ||
|
|
ea59faaec9 | ||
|
|
6402559f28 | ||
|
|
9766b2f8d2 | ||
|
|
b875ce15e8 | ||
|
|
f59630cbbc | ||
|
|
afe0c8b2b5 | ||
|
|
e067061263 | ||
|
|
9001a34cd3 | ||
|
|
2f51befc0f | ||
|
|
03edd0ebb1 | ||
|
|
9704df65e3 | ||
|
|
a3c820cf94 | ||
|
|
e6474a34c3 | ||
|
|
b7f93a4779 | ||
|
|
cc92391034 | ||
|
|
a1e154e9d5 | ||
|
|
bfc428a0da | ||
|
|
44924db3e9 | ||
|
|
ab8523a391 | ||
|
|
460969a9ce | ||
|
|
5ef5841f99 | ||
|
|
163fbfa44d | ||
|
|
479744b146 | ||
|
|
a58b7b93de | ||
|
|
c373e9bb03 | ||
|
|
db2ff03392 | ||
|
|
dc5ef34b54 | ||
|
|
f402e8d113 | ||
|
|
ff73826b45 | ||
|
|
95cd02c000 | ||
|
|
263b8d4f9c | ||
|
|
d20ae18b00 | ||
|
|
fa01372c88 | ||
|
|
9dab7771fa | ||
|
|
038e6411da | ||
|
|
4308bb559c | ||
|
|
3df5a0dabe | ||
|
|
192657d88c | ||
|
|
57a6388b82 | ||
|
|
b9e91ce95a | ||
|
|
e4c521d896 | ||
|
|
70b422d0fb | ||
|
|
91afe0de8a | ||
|
|
e85b16ae49 | ||
|
|
a925c266ca | ||
|
|
c48d04b2c7 | ||
|
|
44ab293f0b | ||
|
|
bf4d29b963 | ||
|
|
25e80032ba | ||
|
|
7e3307cb44 | ||
|
|
cf8e444764 | ||
|
|
109c10bdfd | ||
|
|
3216520b4c | ||
|
|
09fdf0e8e6 | ||
|
|
845615cdd8 | ||
|
|
32fd37d1ad | ||
|
|
42bdb90751 | ||
|
|
2ed09734eb | ||
|
|
b15a04e463 | ||
|
|
2b12ffc820 | ||
|
|
55d42b9c53 | ||
|
|
07506763ff | ||
|
|
55791d1fe6 | ||
|
|
a2cce56134 | ||
|
|
59f04bfddd | ||
|
|
5b2586312a | ||
|
|
ac38bbc138 | ||
|
|
a092a84139 | ||
|
|
c6eb54c39e | ||
|
|
e8a9cb25fe | ||
|
|
08fcbdc97a | ||
|
|
841de3439d | ||
|
|
1a22d18afa | ||
|
|
baf2eaf165 | ||
|
|
ece047171a | ||
|
|
5dc03728ed | ||
|
|
50b701b4e4 | ||
|
|
b246356ab5 | ||
|
|
8f150afeeb | ||
|
|
74a06555f6 | ||
|
|
94021dcdb5 | ||
|
|
1ed7c90890 | ||
|
|
24fc1b2028 | ||
|
|
c608883205 | ||
|
|
c8269682fc | ||
|
|
2bbb005980 | ||
|
|
a565f255f0 | ||
|
|
10dedee3ef | ||
|
|
1ac6f38032 | ||
|
|
ea729492ec | ||
|
|
160f6a08d0 | ||
|
|
1f1e9dc15b | ||
|
|
4ca14e442c | ||
|
|
367fd0cb35 | ||
|
|
c50da458d1 | ||
|
|
576187c686 | ||
|
|
af454c0f34 | ||
|
|
317e90c1c1 | ||
|
|
8e34f0cf0c | ||
|
|
16084e548e | ||
|
|
118d4ee131 | ||
|
|
c847e13c47 | ||
|
|
7f06a999e3 | ||
|
|
cd5588aa75 | ||
|
|
f6e3f1d985 | ||
|
|
7eeb47ffad | ||
|
|
d36a208849 | ||
|
|
fc1cba4407 | ||
|
|
f2788c9866 | ||
|
|
e29ef25cdd | ||
|
|
639e924ef5 | ||
|
|
4174577db3 | ||
|
|
6ec84bfc2e | ||
|
|
13dcfa6bfc | ||
|
|
02ebbfdeca | ||
|
|
749e95cbf1 | ||
|
|
68710f3967 | ||
|
|
22b3122c6c | ||
|
|
640cf4cc93 | ||
|
|
e0ae9635ea | ||
|
|
e4624d6ed7 | ||
|
|
c841e984ba | ||
|
|
234844230c | ||
|
|
a7b70bc9ee | ||
|
|
2a118371fa | ||
|
|
e954d54215 | ||
|
|
3ad76af469 | ||
|
|
926375e8aa | ||
|
|
a8bb3024e8 | ||
|
|
38d8875021 | ||
|
|
e5b7e8fdfc | ||
|
|
3fab89b22f | ||
|
|
61bee4c60c | ||
|
|
04ab5c1b82 | ||
|
|
e9a7d98eac | ||
|
|
1715736f0f | ||
|
|
38176a753e | ||
|
|
89aac630ee | ||
|
|
abf9ccdc5c | ||
|
|
40ddc76e62 | ||
|
|
8333393470 | ||
|
|
89670904c0 | ||
|
|
29c57bab33 | ||
|
|
da1eee8c89 | ||
|
|
8948bf41f1 | ||
|
|
befca1dc8a | ||
|
|
83f481981d | ||
|
|
4f6fd0c451 | ||
|
|
faa83b2380 | ||
|
|
38d86e7e17 | ||
|
|
c4f65cb5dd | ||
|
|
586ed9103f | ||
|
|
d51dc0d80e | ||
|
|
efc3c494cc | ||
|
|
8c05aab03d | ||
|
|
323ee63a1d | ||
|
|
1e52650dbf | ||
|
|
7c6f1be5ea | ||
|
|
f84585ea2f | ||
|
|
aea8587586 | ||
|
|
8d3a43db7a | ||
|
|
7059e05a2a | ||
|
|
fe2bc30984 | ||
|
|
d1fefb4de3 | ||
|
|
cd3dd624b3 | ||
|
|
8d6d96657a | ||
|
|
6c6094538f | ||
|
|
db4ff30f38 | ||
|
|
8253e2170e | ||
|
|
2aeeb5a518 | ||
|
|
c8265940ea | ||
|
|
6492e3e69c | ||
|
|
081e81b813 | ||
|
|
688ac9382f | ||
|
|
1dc12b9cc5 | ||
|
|
01e789184a | ||
|
|
58fd38cd90 | ||
|
|
f8ef75c510 | ||
|
|
b7c65baef3 | ||
|
|
139eb4696c | ||
|
|
ef1a41efcf | ||
|
|
dbab7b5a18 | ||
|
|
b239fda60c | ||
|
|
f286e8c9b0 | ||
|
|
f7959bd5eb | ||
|
|
226e48b4b7 | ||
|
|
a7fbedf8d6 | ||
|
|
b3a0c6d9cb | ||
|
|
1100a22e98 | ||
|
|
18bce1e209 | ||
|
|
30d1bf863e | ||
|
|
0e82ddbd81 | ||
|
|
b5eb33bb69 | ||
|
|
2791ce7e01 | ||
|
|
8485c87cf2 | ||
|
|
5a75c0fd78 | ||
|
|
41dd2a2a3b | ||
|
|
2aa81c0544 | ||
|
|
0856ba3008 | ||
|
|
8d66a455f7 | ||
|
|
a4d98b58fc | ||
|
|
497c31d9a0 | ||
|
|
4db7fc77ff | ||
|
|
3b7940d05e | ||
|
|
2afc8a4f1c | ||
|
|
da65ee4dbb | ||
|
|
0dee533531 | ||
|
|
396db49a41 | ||
|
|
94e91b73f7 | ||
|
|
115450ac9b | ||
|
|
eb461d1dbe | ||
|
|
cfea89fb7c | ||
|
|
5309651849 | ||
|
|
30b02325cb | ||
|
|
1fceffa434 | ||
|
|
3f4c1976fd | ||
|
|
a459a8b4db | ||
|
|
4d203e8420 | ||
|
|
5ba2acde0a | ||
|
|
9ea6ea581d | ||
|
|
4373fc64e3 | ||
|
|
b6fbe97f24 | ||
|
|
d86ac9e04b | ||
|
|
71913c8fea | ||
|
|
8de3dc44ca | ||
|
|
ab54736b5d | ||
|
|
6026de4648 | ||
|
|
a9ef024f10 | ||
|
|
595a5d9ff2 | ||
|
|
356a8a7631 | ||
|
|
9f581a2809 | ||
|
|
d60783eeb7 | ||
|
|
ae4265d304 | ||
|
|
ee3b641fb1 | ||
|
|
c195e0fa7d | ||
|
|
f8d5bb9785 | ||
|
|
3a67aaa428 | ||
|
|
4c84a3e0f2 | ||
|
|
ff0f8b7608 | ||
|
|
9ff4afa523 | ||
|
|
10397d44db | ||
|
|
fc73b0b33f | ||
|
|
7b464d4e15 | ||
|
|
891539af6c | ||
|
|
1b627b3867 | ||
|
|
b06c167775 | ||
|
|
ace6eed6c0 | ||
|
|
cde3151634 | ||
|
|
cd4df00dff | ||
|
|
b2e50e8967 | ||
|
|
2c3e423480 | ||
|
|
8bcd65193c | ||
|
|
54ce86e3b1 | ||
|
|
904a5b2f7c | ||
|
|
ddd10236bd | ||
|
|
b4c65e41f6 | ||
|
|
79e9eb53d4 | ||
|
|
10afd9818c | ||
|
|
186667724a | ||
|
|
f80efcc260 | ||
|
|
2634f45e11 | ||
|
|
98f78e1102 | ||
|
|
8758b1260b | ||
|
|
04d916f3aa | ||
|
|
15d0dc7a4e | ||
|
|
ae4ef84702 | ||
|
|
1fd7a875be | ||
|
|
07d748ef5e | ||
|
|
3441e77ddc | ||
|
|
84430b2277 | ||
|
|
4ab28a049f | ||
|
|
3090d104cf | ||
|
|
75d5bb457f | ||
|
|
6aff00e762 | ||
|
|
2b07dcd1e3 | ||
|
|
affe522b25 | ||
|
|
f16cabc73e | ||
|
|
39a5b53eb5 | ||
|
|
fc8ad69f5c | ||
|
|
78b6e25ede | ||
|
|
e02a6e0225 | ||
|
|
fce4840c77 | ||
|
|
117fc43b69 | ||
|
|
01c0877495 | ||
|
|
33b948cab9 | ||
|
|
d3d7f08d6a | ||
|
|
3b38c66b3d | ||
|
|
390d9e53dc | ||
|
|
fae68cac8a | ||
|
|
cf89b6eb48 | ||
|
|
9249006e64 | ||
|
|
c9818a9948 | ||
|
|
e4d16db116 | ||
|
|
98711e9d0f | ||
|
|
6bda3c7466 | ||
|
|
139f59ec62 | ||
|
|
2ab6894132 | ||
|
|
63cff85b1a | ||
|
|
0151b6e170 | ||
|
|
ee54acb417 | ||
|
|
08e2408896 | ||
|
|
453b91903b | ||
|
|
5681c542f6 | ||
|
|
fe5f283c48 | ||
|
|
05495a263a | ||
|
|
40bce93e97 | ||
|
|
4d889e0af0 | ||
|
|
49c88c2cd7 | ||
|
|
1d3eeda7f9 | ||
|
|
fe98c015e9 | ||
|
|
d347b7e00f | ||
|
|
f99fefc587 | ||
|
|
eced7fb958 | ||
|
|
1486d844e7 | ||
|
|
78273fe5c5 | ||
|
|
3247a7683a | ||
|
|
39a8009e78 | ||
|
|
081adeb3d6 | ||
|
|
1edc164265 | ||
|
|
acb4e37957 | ||
|
|
02f2511985 | ||
|
|
a800db80e4 | ||
|
|
ec0c1ef63b | ||
|
|
b4cebfb03d | ||
|
|
461d9413d3 | ||
|
|
cf1e7fa836 | ||
|
|
14580705d5 | ||
|
|
6ab119d8dc | ||
|
|
f0b2c39d2f | ||
|
|
814cde9069 | ||
|
|
851560426f | ||
|
|
facc434ce4 | ||
|
|
4b8eb38586 | ||
|
|
d3e64a744e | ||
|
|
fad349fecd | ||
|
|
e1a1796783 | ||
|
|
b9e6ce934d | ||
|
|
5ea8088938 | ||
|
|
7ceaf5c43a | ||
|
|
f4bbc45bbe | ||
|
|
ff19095415 | ||
|
|
b8c78bdb5a | ||
|
|
73cde232be | ||
|
|
53226f98f2 | ||
|
|
22b422995f | ||
|
|
ac3d66ac69 | ||
|
|
903e22cd11 | ||
|
|
0679dd4fd8 | ||
|
|
8eaecdc7b8 | ||
|
|
cfbc063dd3 | ||
|
|
81de36e923 | ||
|
|
a80ad5cbd3 | ||
|
|
69a1fac7a1 | ||
|
|
1fd6a2e9e0 | ||
|
|
9414b53bef | ||
|
|
5f58fc773c | ||
|
|
3991b3a3aa | ||
|
|
58404116bc | ||
|
|
8c60d864c7 | ||
|
|
974a160fd3 | ||
|
|
5e03a95a93 | ||
|
|
5db7ec356b | ||
|
|
5d798f6225 | ||
|
|
7250e03f97 | ||
|
|
948c3f1bef | ||
|
|
55c7cc6839 | ||
|
|
ddf4a8e9c9 | ||
|
|
f4d74e285e | ||
|
|
fc0928a572 | ||
|
|
ed53a70854 | ||
|
|
460d0b402b | ||
|
|
2347065481 | ||
|
|
4259c9195c | ||
|
|
70aa33c041 | ||
|
|
944084964a | ||
|
|
f9f8ded7f0 | ||
|
|
6ea3888054 | ||
|
|
b11ddd23b2 | ||
|
|
c3e026c303 |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
.*
|
||||
*.swp
|
||||
*~$
|
||||
build
|
||||
cscope.*
|
||||
tags
|
||||
4
AUTHORS
4
AUTHORS
@@ -1,5 +1,7 @@
|
||||
Author(s):
|
||||
Aris Adamantiadis <aris (at) 0xbadc0de (dot) be> (project initiator)
|
||||
Aris Adamantiadis <aris@0xbadc0de.be> (project initiator)
|
||||
|
||||
Andreas Schneider <mail@cynapses.org> (developer)
|
||||
|
||||
Nick Zitzmann <seiryu (at) comcast (dot) net> (mostly client SFTP stuff)
|
||||
|
||||
|
||||
73
CMakeLists.txt
Normal file
73
CMakeLists.txt
Normal file
@@ -0,0 +1,73 @@
|
||||
project(libssh C)
|
||||
|
||||
# Required cmake version
|
||||
cmake_minimum_required(VERSION 2.6.0)
|
||||
|
||||
# global needed variables
|
||||
set(APPLICATION_NAME ${PROJECT_NAME})
|
||||
|
||||
set(APPLICATION_VERSION "0.4.0")
|
||||
|
||||
set(APPLICATION_VERSION_MAJOR "0")
|
||||
set(APPLICATION_VERSION_MINOR "4")
|
||||
set(APPLICATION_VERSION_PATCH "1")
|
||||
|
||||
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}${APPLICATION_VERSION_MINOR}${APPLICATION_VERSION_PATCH}")
|
||||
|
||||
set(LIBRARY_VERSION "4.0.1")
|
||||
set(LIBRARY_SOVERSION "4")
|
||||
|
||||
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
|
||||
set(CMAKE_MODULE_PATH
|
||||
${CMAKE_SOURCE_DIR}/cmake/Modules
|
||||
)
|
||||
|
||||
# add definitions
|
||||
include(DefineCMakeDefaults)
|
||||
include(DefineCompilerFlags)
|
||||
include(DefineInstallationPaths)
|
||||
include(DefineOptions.cmake)
|
||||
include(CPackConfig.cmake)
|
||||
|
||||
# disallow in-source build
|
||||
include(MacroEnsureOutOfSourceBuild)
|
||||
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")
|
||||
|
||||
# add macros
|
||||
include(MacroAddPlugin)
|
||||
include(MacroCopyFile)
|
||||
|
||||
# search for libraries
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
||||
if (WITH_GCRYPT)
|
||||
find_package(GCrypt REQUIRED)
|
||||
if (NOT GCRYPT_FOUND)
|
||||
message(FATAL_ERROR "Could not find GCrypt")
|
||||
endif (NOT GCRYPT_FOUND)
|
||||
else (WITH_GCRYPT)
|
||||
find_package(OpenSSL)
|
||||
if (NOT CRYPTO_FOUND)
|
||||
find_package(GCrypt)
|
||||
if (NOT GCRYPT_FOUND)
|
||||
message(FATAL_ERROR "Could not find OpenSSL or GCrypt")
|
||||
endif (NOT GCRYPT_FOUND)
|
||||
endif (NOT CRYPTO_FOUND)
|
||||
endif(WITH_GCRYPT)
|
||||
|
||||
# config.h checks
|
||||
include(ConfigureChecks.cmake)
|
||||
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
|
||||
# check subdirectories
|
||||
add_subdirectory(doc)
|
||||
add_subdirectory(include)
|
||||
add_subdirectory(libssh)
|
||||
|
||||
# build samples
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
if (UNIX AND NOT WIN32)
|
||||
add_subdirectory(examples)
|
||||
|
||||
endif (UNIX AND NOT WIN32)
|
||||
48
CPackConfig.cmake
Normal file
48
CPackConfig.cmake
Normal file
@@ -0,0 +1,48 @@
|
||||
# For help take a look at:
|
||||
# http://www.cmake.org/Wiki/CMake:CPackConfiguration
|
||||
|
||||
### general settings
|
||||
set(CPACK_PACKAGE_NAME ${APPLICATION_NAME})
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The SSH library")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
|
||||
set(CPACK_PACKAGE_VENDOR "The SSH Library Development Team")
|
||||
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
|
||||
|
||||
|
||||
### versions
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "0")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "4")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "1")
|
||||
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
||||
|
||||
|
||||
### source generator
|
||||
set(CPACK_SOURCE_GENERATOR "TGZ")
|
||||
set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build/;tags;cscope.*")
|
||||
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
|
||||
|
||||
### nsis generator
|
||||
set(CPACK_GENERATOR "NSIS")
|
||||
|
||||
set(CPACK_PACKAGE_INSTALL_DIRECTORY "libssh")
|
||||
|
||||
set(CPACK_NSIS_DISPLAY_NAME "The SSH Library")
|
||||
set(CPACK_NSIS_COMPRESSOR "/SOLID zlib")
|
||||
set(CPACK_NSIS_MENU_LINKS "http://www.libssh.org/" "libssh homepage")
|
||||
|
||||
set(CPACK_PACKAGE_FILE_NAME ${APPLICATION_NAME}-${CPACK_PACKAGE_VERSION})
|
||||
|
||||
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
|
||||
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers")
|
||||
set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
|
||||
"Libraries used to build programs which use libssh")
|
||||
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
|
||||
"C/C++ header files for use with libssh")
|
||||
set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
|
||||
#set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
|
||||
set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
|
||||
set(CPACK_COMPONENT_HEADERS_GROUP "Development")
|
||||
|
||||
include(CPack)
|
||||
270
ChangeLog
270
ChangeLog
@@ -1,80 +1,198 @@
|
||||
libssh-0.11-dev
|
||||
-server implementation development. I won't document it before it even works.
|
||||
-small bug corrected when connecting to sun ssh servers.
|
||||
-channel wierdness corrected (writing huge data packets)
|
||||
-channel_read_nonblocking added
|
||||
-channel bug where stderr wasn't correctly read fixed.
|
||||
-sftp_file_set_nonblocking added. It's now possible to have nonblocking SFTP IO
|
||||
-connect_status callback.
|
||||
-priv.h contains the internal functions, libssh.h the public interface
|
||||
-options_set_timeout (thx marcelo) really working.
|
||||
-tcp tunneling through channel_open_forward.
|
||||
-channel_request_exec()
|
||||
-channel_request_env()
|
||||
-ssh_get_pubkey_hash()
|
||||
-ssh_is_server_known()
|
||||
-ssh_write_known_host()
|
||||
-options_set_ssh_dir
|
||||
-how could this happen ! there weren't any channel_close !
|
||||
-nasty channel_free bug resolved.
|
||||
-removed the unsigned long all around the code. use only u8,u32 & u64.
|
||||
-it now compiles and runs under amd64 !
|
||||
-channel_request_pty_size
|
||||
-channel_change_pty_size
|
||||
-options_copy()
|
||||
-ported the doc to an HTML file.
|
||||
-small bugfix in packet.c
|
||||
-prefixed error constants with SSH_
|
||||
-sftp_stat, sftp_lstat, sftp_fstat. thanks Michel Bardiaux for the patch.
|
||||
-again channel number mismatch fixed.
|
||||
-fixed a bug in ssh_select making the select fail when a signal has been caught.
|
||||
-keyboard-interactive authentication working.
|
||||
ChangeLog
|
||||
==========
|
||||
|
||||
5th march 2004 : libssh-0.1
|
||||
-Begining of sftp subsystem implementation. It's stable enough to be used :)
|
||||
-some cleanup into channels implementation
|
||||
-Now every channel functions is called by its CHANNEL handler. no any way to play again with numbers.
|
||||
-added channel_poll() and channel_read(). Now, it's possible to manipulate channel streams only with channel_read() and channel_write(),
|
||||
with help of channel_poll().
|
||||
-changed the client so it uses the new channel_poll and channel_read interface
|
||||
-small use-after-free bug with channels resolved, and a noninitialised data of SIGNATURE struct.
|
||||
-changed stupidities in lot of function names.
|
||||
-removed a debug output file opened by default.
|
||||
-Added API.txt, the libssh programmer handbook. (I hate documentation)
|
||||
-Various bug fixes from Nick Zitzmann. Thank to him, libssh now runs under macosX !
|
||||
-Developed a cryptographic structure for handling protocols. Adding a custom-based cipher should be the story of thirty
|
||||
minutes. It now supports aes-256,aes-192,aes-128 and blowfish-128 !
|
||||
-An autoconf script which took me half of a day to set up. Respect it!
|
||||
-A ssh_select wrapper has been written.
|
||||
It all means the API has changed. not a lot but enough to be incompatible with anything which has been written.
|
||||
version 0.4.1 (released 2010-02-13)
|
||||
* Added support for aes128-ctr, aes192-ctr and aes256-ctr encryption.
|
||||
* Added an example for exec.
|
||||
* Added private key type detection feature in privatekey_from_file().
|
||||
* Fixed zlib compression fallback.
|
||||
* Fixed kex bug that client preference should be prioritary
|
||||
* Fixed known_hosts file set by the user.
|
||||
* Fixed a memleak in channel_accept().
|
||||
* Fixed underflow when leave_function() are unbalanced
|
||||
* Fixed memory corruption in handle_channel_request_open().
|
||||
* Fixed closing of a file handle case of errors in privatekey_from_file().
|
||||
* Fixed ssh_get_user_home_dir() to be thread safe.
|
||||
* Fixed the doxygen documentation.
|
||||
|
||||
10th october 2003 : libssh-0.0.4
|
||||
-some terminal code (eof handling) added
|
||||
-channels bugfix (it still needs some tweaking though)
|
||||
-zlib support
|
||||
-added a wrapper.c file. The goal is to provide a similar API to every cryptographic functions. bignums and sha/md5 are wrapped now.
|
||||
-more work than it first looks.
|
||||
-Support for other crypto libs planed (lighter libs)
|
||||
-Fixed stupid select() bug.
|
||||
-libssh now compiles and links with openssl 0.9.6 (but you're advised to upgrade)
|
||||
-RSA pubkey authentication code now works !
|
||||
version 0.4.0 (released 2009-12-10)
|
||||
* Added scp support.
|
||||
* Added support for sending signals (RFC 4254, section 6.9).
|
||||
* Added MSVC support.
|
||||
* Added support for ~/.ssh/config.
|
||||
* Added sftp extension support.
|
||||
* Added X11 forwarding support for client.
|
||||
* Added forward listening.
|
||||
* Added support for openssh extensions (statvfs, fstatvfs).
|
||||
* Added a cleaned up interface for setting options.
|
||||
* Added a generic way to handle sockets asynchronously.
|
||||
* Added logging of the sftp flags used to open a file.
|
||||
* Added full poll() support and poll-emulation for win32.
|
||||
* Added missing 64bit functions in sftp.
|
||||
* Added support for ~/ and SSH_DIR/ in filenames instead of %s/.
|
||||
* Fixed Fix channel_get_exit_status bug.
|
||||
* Fixed calltrace logging to make it optional.
|
||||
* Fixed compilation on Solaris.
|
||||
* Fixed resolving of ip addresses.
|
||||
* Fixed libssh compilation without server support.
|
||||
* Fixed possible memory corruptions (ticket #14).
|
||||
|
||||
15th september 2003 : libssh-0.0.3
|
||||
-added install target in makefile
|
||||
-some cleanup in headers files and source code
|
||||
-change default banner and project name to libssh.
|
||||
-new file auth.c to support more and more authentication ways
|
||||
-bugfix(read offbyone) in send_kex
|
||||
-a base64 parser. don't read the source, it's awful. pure 0xbadc0de.
|
||||
-changed the client filename to "ssh". logic isn't it ?
|
||||
-dss publickey authentication ! still need to wait for the rsa one
|
||||
-bugfix in packet.c : now packet are completely read (and read blocks if waiting the packet)
|
||||
-new misc.c contains misc functions
|
||||
version 0.3.4 (released 2009-09-14)
|
||||
* Added ssh_basename and ssh_dirname.
|
||||
* Added a portable ssh_mkdir function.
|
||||
* Added a sftp_tell64() function.
|
||||
* Added missing NULL pointer checks to crypt_set_algorithms_server.
|
||||
* Fixed ssh_write_knownhost if ~/.ssh doesn't exist.
|
||||
* Fixed a possible integer overflow in buffer_get_data().
|
||||
* Fixed possible security bug in packet_decrypt().
|
||||
* Fixed a possible stack overflow in agent code.
|
||||
|
||||
3rd september 2003: libssh-0.0.2
|
||||
initial release.
|
||||
-client supports both ssh and dss hostkey verification, but doesn't compare
|
||||
them to openssh's files. (~/.ssh/known_hosts)
|
||||
-the only supported authentication method is password.
|
||||
-compiles on linux and openbsd. freebsd and netbsd should work, too
|
||||
-Lot of work which hasn't been discussed here.
|
||||
version 0.3.3 (released 2009-08-18)
|
||||
* Fixed double free pointer crash in dsa_public_to_string.
|
||||
* Fixed channel_get_exit_status bug.
|
||||
* Fixed ssh_finalize which didn't clear the flag.
|
||||
* Fixed memory leak introduced by previous bugfix.
|
||||
* Fixed channel_poll broken when delayed EOF recvd.
|
||||
* Fixed stupid "can't parse known host key" bug.
|
||||
* Fixed possible memory corruption (ticket #14).
|
||||
|
||||
version 0.3.2 (released 2009-08-05)
|
||||
* Added ssh_init() function.
|
||||
* Added sftp_readlink() function.
|
||||
* Added sftp_symlink() function.
|
||||
* Fixed ssh_write_knownhost().
|
||||
* Fixed compilation on Solaris.
|
||||
* Fixed SSHv1 compilation.
|
||||
|
||||
version 0.3.1 (released 2009-07-14)
|
||||
* Added return code SSH_SERVER_FILE_NOT_FOUND.
|
||||
* Fixed compilation of SSHv1.
|
||||
* Fixed several memory leaks.
|
||||
* Fixed possible infinite loops.
|
||||
* Fixed a possible crash bug.
|
||||
* Fixed build warnings.
|
||||
* Fixed cmake on BSD.
|
||||
version 0.3.1 (released 2009-07-14)
|
||||
* Added return code SSH_SERVER_FILE_NOT_FOUND.
|
||||
* Fixed compilation of SSHv1.
|
||||
* Fixed several memory leaks.
|
||||
* Fixed possible infinite loops.
|
||||
* Fixed a possible crash bug.
|
||||
* Fixed build warnings.
|
||||
* Fixed cmake on BSD.
|
||||
|
||||
version 0.3 (released 2009-05-21)
|
||||
* Added support for ssh-agent authentication.
|
||||
* Added POSIX like sftp implementation.
|
||||
* Added error checking to all functions.
|
||||
* Added const to arguments where it was needed.
|
||||
* Added a channel_get_exit_status() function.
|
||||
* Added a channel_read_buffer() function, channel_read() is now
|
||||
a POSIX like function.
|
||||
* Added a more generic auth callback function.
|
||||
* Added printf attribute checking for log and error functions.
|
||||
* Added runtime function tracer support.
|
||||
* Added NSIS build support with CPack.
|
||||
* Added openssh hashed host support.
|
||||
* Added API documentation for all public functions.
|
||||
* Added asynchronous SFTP read function.
|
||||
* Added a ssh_bind_set_fd() function.
|
||||
* Fixed known_hosts parsing.
|
||||
* Fixed a lot of build warnings.
|
||||
* Fixed the Windows build.
|
||||
* Fixed a lot of memory leaks.
|
||||
* Fixed a double free corruption in the server support.
|
||||
* Fixed the "ssh_accept:" bug in server support.
|
||||
* Fixed important channel bugs.
|
||||
* Refactored the socket handling.
|
||||
* Switched to CMake build system.
|
||||
* Improved performance.
|
||||
|
||||
version 0.2 (released 2007-11-29)
|
||||
* General cleanup
|
||||
* More comprehensive API
|
||||
* Up-to-date Doxygen documentation of each public function
|
||||
* Basic server-based support
|
||||
* Libgcrypt support (alternative to openssl and its license)
|
||||
* SSH1 support (disabled by default)
|
||||
* Added 3des-cbc
|
||||
* A lot of bugfixes
|
||||
|
||||
version 0.11-dev
|
||||
* Server implementation development.
|
||||
* Small bug corrected when connecting to sun ssh servers.
|
||||
* Channel wierdness corrected (writing huge data packets)
|
||||
* Channel_read_nonblocking added
|
||||
* Channel bug where stderr wasn't correctly read fixed.
|
||||
* Added sftp_file_set_nonblocking(), which is nonblocking SFTP IO
|
||||
* Connect_status callback.
|
||||
* Priv.h contains the internal functions, libssh.h the public interface
|
||||
* Options_set_timeout (thx marcelo) really working.
|
||||
* Tcp tunneling through channel_open_forward.
|
||||
* Channel_request_exec()
|
||||
* Channel_request_env()
|
||||
* Ssh_get_pubkey_hash()
|
||||
* Ssh_is_server_known()
|
||||
* Ssh_write_known_host()
|
||||
* Options_set_ssh_dir
|
||||
* How could this happen ! there weren't any channel_close !
|
||||
* Nasty channel_free bug resolved.
|
||||
* Removed the unsigned long all around the code. use only u8,u32 & u64.
|
||||
* It now compiles and runs under amd64 !
|
||||
* Channel_request_pty_size
|
||||
* Channel_change_pty_size
|
||||
* Options_copy()
|
||||
* Ported the doc to an HTML file.
|
||||
* Small bugfix in packet.c
|
||||
* Prefixed error constants with SSH_
|
||||
* Sftp_stat, sftp_lstat, sftp_fstat. thanks Michel Bardiaux for the patch.
|
||||
* Again channel number mismatch fixed.
|
||||
* Fixed a bug in ssh_select making the select fail when a signal has been
|
||||
caught.
|
||||
* Keyboard-interactive authentication working.
|
||||
|
||||
version 0.1 (released 2004-03-05)
|
||||
* Begining of sftp subsystem implementation.
|
||||
* Some cleanup into channels implementation
|
||||
* Now every channel functions is called by its CHANNEL handler.
|
||||
* Added channel_poll() and channel_read().
|
||||
* Changed the client so it uses the new channel_poll and channel_read interface
|
||||
* Small use-after-free bug with channels resolved
|
||||
* Changed stupidities in lot of function names.
|
||||
* Removed a debug output file opened by default.
|
||||
* Added API.txt, the libssh programmer handbook.
|
||||
* Various bug fixes from Nick Zitzmann.
|
||||
* Developed a cryptographic structure for handling protocols.
|
||||
* An autoconf script which took me half of a day to set up.
|
||||
* A ssh_select wrapper has been written.
|
||||
|
||||
version 0.0.4 (released 2003-10-10)
|
||||
* Some terminal code (eof handling) added
|
||||
* Channels bugfix (it still needs some tweaking though)
|
||||
* Zlib support
|
||||
* Added a wrapper.c file. The goal is to provide a similar API to every
|
||||
cryptographic functions. bignums and sha/md5 are wrapped now.
|
||||
* More work than it first looks.
|
||||
* Support for other crypto libs planed (lighter libs)
|
||||
* Fixed stupid select() bug.
|
||||
* Libssh now compiles and links with openssl 0.9.6
|
||||
* RSA pubkey authentication code now works !
|
||||
|
||||
version 0.0.3 (released 2003-09-15)
|
||||
* Added install target in makefile
|
||||
* Some cleanup in headers files and source code
|
||||
* Change default banner and project name to libssh.
|
||||
* New file auth.c to support more and more authentication ways
|
||||
* Bugfix(read offbyone) in send_kex
|
||||
* A base64 parser. don't read the source, it's awful. pure 0xbadc0de.
|
||||
* Changed the client filename to "ssh". logic isn't it ?
|
||||
* Dss publickey authentication ! still need to wait for the rsa one
|
||||
* Bugfix in packet.c
|
||||
* New misc.c contains misc functions
|
||||
|
||||
version 0.0.2 (released 2003-09-03)
|
||||
* Initial release.
|
||||
* Client supports both ssh and dss hostkey verification, but doesn't compare them to openssh's files. (~/.ssh/known_hosts)
|
||||
* The only supported authentication method is password.
|
||||
* Compiles on linux and openbsd. freebsd and netbsd should work, too
|
||||
* Lot of work which hasn't been discussed here.
|
||||
|
||||
107
ConfigureChecks.cmake
Normal file
107
ConfigureChecks.cmake
Normal file
@@ -0,0 +1,107 @@
|
||||
include(CheckIncludeFile)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckTypeSize)
|
||||
include(CheckCXXSourceCompiles)
|
||||
include(TestBigEndian)
|
||||
|
||||
set(PACKAGE ${APPLICATION_NAME})
|
||||
set(VERSION ${APPLICATION_VERSION})
|
||||
set(DATADIR ${DATA_INSTALL_DIR})
|
||||
set(LIBDIR ${LIB_INSTALL_DIR})
|
||||
set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
|
||||
set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
|
||||
|
||||
set(BINARYDIR ${CMAKE_BINARY_DIR})
|
||||
set(SOURCEDIR ${CMAKE_SOURCE_DIR})
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUC)
|
||||
check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
|
||||
endif(CMAKE_COMPILER_IS_GNUC)
|
||||
|
||||
# HEADER FILES
|
||||
check_include_file(argp.h HAVE_ARGP_H)
|
||||
check_include_file(pty.h HAVE_PTY_H)
|
||||
check_include_file(terminos.h HAVE_TERMIOS_H)
|
||||
if (WIN32)
|
||||
check_include_file(wspiapi.h HAVE_WSPIAPI_H)
|
||||
if (NOT HAVE_WSPIAPI_H)
|
||||
message(STATUS "WARNING: Without wspiapi.h, this build will only work on Windows XP and newer versions")
|
||||
endif (NOT HAVE_WSPIAPI_H)
|
||||
check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)
|
||||
if (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
|
||||
set(HAVE_GETADDRINFO TRUE)
|
||||
set(HAVE_GETHOSTBYNAME TRUE)
|
||||
endif (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
|
||||
|
||||
set(HAVE_SELECT TRUE)
|
||||
endif (WIN32)
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
||||
check_include_file(openssl/aes.h HAVE_OPENSSL_AES_H)
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
||||
check_include_file(openssl/blowfish.h HAVE_OPENSSL_BLOWFISH_H)
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
||||
check_include_file(openssl/des.h HAVE_OPENSSL_DES_H)
|
||||
|
||||
# FUNCTIONS
|
||||
|
||||
if (UNIX)
|
||||
# libsocket (Solaris)
|
||||
check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET)
|
||||
if (HAVE_LIBSOCKET)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket)
|
||||
endif (HAVE_LIBSOCKET)
|
||||
# libnsl (Solaris)
|
||||
check_library_exists(nsl gethostbyname "" HAVE_LIBNSL)
|
||||
if (HAVE_LIBNSL)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} nsl)
|
||||
endif (HAVE_LIBNSL)
|
||||
# libresolv
|
||||
check_library_exists(resolv hstrerror "" HAVE_LIBRESOLV)
|
||||
if (HAVE_LIBRESOLV)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} resolv)
|
||||
endif (HAVE_LIBRESOLV)
|
||||
check_library_exists(rt nanosleep "" HAVE_LIBRT)
|
||||
# librt
|
||||
if (HAVE_LIBRT)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
|
||||
endif (HAVE_LIBRT)
|
||||
|
||||
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
|
||||
check_function_exists(gethostbyname HAVE_GETHOSTBYNAME)
|
||||
check_function_exists(poll HAVE_POLL)
|
||||
check_function_exists(select HAVE_SELECT)
|
||||
check_function_exists(cfmakeraw HAVE_CFMAKERAW)
|
||||
check_function_exists(regcomp HAVE_REGCOMP)
|
||||
endif (UNIX)
|
||||
|
||||
set(LIBSSH_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "libssh required system libraries")
|
||||
|
||||
# LIBRARIES
|
||||
if (CRYPTO_FOUND)
|
||||
set(HAVE_LIBCRYPTO 1)
|
||||
endif (CRYPTO_FOUND)
|
||||
|
||||
if (GCRYPT_FOUND)
|
||||
set(HAVE_LIBGCRYPT 1)
|
||||
endif (GCRYPT_FOUND)
|
||||
|
||||
if (Z_LIBRARY)
|
||||
set(HAVE_LIBZ 1)
|
||||
endif (Z_LIBRARY)
|
||||
|
||||
# OPTIONS
|
||||
if (WITH_DEBUG_CRYPTO)
|
||||
set(DEBUG_CRYPTO 1)
|
||||
endif (WITH_DEBUG_CRYPTO)
|
||||
|
||||
if (WITH_DEBUG_CALLTRACE)
|
||||
set(DEBUG_CALLTRACE 1)
|
||||
endif (WITH_DEBUG_CALLTRACE)
|
||||
|
||||
# ENDIAN
|
||||
test_big_endian(WORDS_BIGENDIAN)
|
||||
9
DefineOptions.cmake
Normal file
9
DefineOptions.cmake
Normal file
@@ -0,0 +1,9 @@
|
||||
option(WITH_LIBZ "Build with ZLIB support" ON)
|
||||
option(WITH_SSH1 "Build with SSH1 support" OFF)
|
||||
option(WITH_SFTP "Build with SFTP support" ON)
|
||||
option(WITH_SERVER "Build with SSH server support" ON)
|
||||
option(WITH_STATIC_LIB "Build with a static library" OFF)
|
||||
option(WITH_DEBUG_CRYPTO "Build with cryto debug output" OFF)
|
||||
option(WITH_DEBUG_CALLTRACE "Build with calltrace debug output" ON)
|
||||
option(WITH_GCRYPT "Compile against libgcrypt" OFF)
|
||||
option(WITH_PCAP "Compile with Pcap generation support" OFF)
|
||||
2
Doxyfile
2
Doxyfile
@@ -31,7 +31,7 @@ PROJECT_NAME = libssh
|
||||
# This could be handy for archiving the generated documentation or
|
||||
# if some version control system is used.
|
||||
|
||||
PROJECT_NUMBER = 0.2.1-svn
|
||||
PROJECT_NUMBER = 0.3-svn
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
|
||||
# base path where the generated documentation will be put.
|
||||
|
||||
@@ -31,7 +31,7 @@ PROJECT_NAME = libssh
|
||||
# This could be handy for archiving the generated documentation or
|
||||
# if some version control system is used.
|
||||
|
||||
PROJECT_NUMBER = 0.2.1-svn
|
||||
PROJECT_NUMBER = 0.3-svn
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
|
||||
# base path where the generated documentation will be put.
|
||||
|
||||
258
INSTALL
258
INSTALL
@@ -1,236 +1,78 @@
|
||||
Installation Instructions
|
||||
*************************
|
||||
# How to build from source
|
||||
|
||||
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
|
||||
Software Foundation, Inc.
|
||||
## Requirements
|
||||
|
||||
This file is free documentation; the Free Software Foundation gives
|
||||
unlimited permission to copy, distribute and modify it.
|
||||
### Common requirements
|
||||
|
||||
Basic Installation
|
||||
==================
|
||||
In order to build libssh, you need to install several components:
|
||||
|
||||
These are generic installation instructions.
|
||||
- A C compiler
|
||||
- [CMake](http://www.cmake.org) >= 2.6.0.
|
||||
- [openssl](http://www.openssl.org) >= 0.9.8
|
||||
or
|
||||
- [gcrypt](http://www.gnu.org/directory/Security/libgcrypt.html) >= 1.4
|
||||
|
||||
The `configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
those values to create a `Makefile' in each directory of the package.
|
||||
It may also create one or more `.h' files containing system-dependent
|
||||
definitions. Finally, it creates a shell script `config.status' that
|
||||
you can run in the future to recreate the current configuration, and a
|
||||
file `config.log' containing compiler output (useful mainly for
|
||||
debugging `configure').
|
||||
optional:
|
||||
- [libz](http://www.zlib.net) >= 1.2
|
||||
|
||||
It can also use an optional file (typically called `config.cache'
|
||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||
the results of its tests to speed up reconfiguring. (Caching is
|
||||
disabled by default to prevent problems with accidental use of stale
|
||||
cache files.)
|
||||
Note that these version numbers are version we know works correctly. If you
|
||||
build and run libssh successfully with an older version, please let us know.
|
||||
|
||||
If you need to do unusual things to compile the package, please try
|
||||
to figure out how `configure' could check whether to do them, and mail
|
||||
diffs or instructions to the address given in the `README' so they can
|
||||
be considered for the next release. If you are using the cache, and at
|
||||
some point `config.cache' contains results you don't want to keep, you
|
||||
may remove or edit it.
|
||||
|
||||
The file `configure.ac' (or `configure.in') is used to create
|
||||
`configure' by a program called `autoconf'. You only need
|
||||
`configure.ac' if you want to change it or regenerate `configure' using
|
||||
a newer version of `autoconf'.
|
||||
## Building
|
||||
First, you need to configure the compilation, using CMake. Go inside the
|
||||
`build` dir. Create it if it doesn't exist.
|
||||
|
||||
The simplest way to compile this package is:
|
||||
GNU/Linux and MacOS X:
|
||||
|
||||
1. `cd' to the directory containing the package's source code and type
|
||||
`./configure' to configure the package for your system. If you're
|
||||
using `csh' on an old version of System V, you might need to type
|
||||
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||
`configure' itself.
|
||||
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
|
||||
make
|
||||
|
||||
Running `configure' takes awhile. While running, it prints some
|
||||
messages telling which features it is checking for.
|
||||
### CMake standard options
|
||||
Here is a list of the most interesting options provided out of the box by
|
||||
CMake.
|
||||
|
||||
2. Type `make' to compile the package.
|
||||
- CMAKE_BUILD_TYPE: The type of build (can be Debug Release MinSizeRel
|
||||
RelWithDebInfo)
|
||||
- CMAKE_INSTALL_PREFIX: The prefix to use when running make install (Default
|
||||
to /usr/local on GNU/Linux and MacOS X)
|
||||
- CMAKE_C_COMPILER: The path to the C compiler
|
||||
- CMAKE_CXX_COMPILER: The path to the C++ compiler
|
||||
|
||||
3. Optionally, type `make check' to run any self-tests that come with
|
||||
the package.
|
||||
### CMake options defined for libssh
|
||||
|
||||
4. Type `make install' to install the programs and any data files and
|
||||
documentation.
|
||||
Options are defined in the following files:
|
||||
|
||||
5. You can remove the program binaries and object files from the
|
||||
source code directory by typing `make clean'. To also remove the
|
||||
files that `configure' created (so you can compile the package for
|
||||
a different kind of computer), type `make distclean'. There is
|
||||
also a `make maintainer-clean' target, but that is intended mainly
|
||||
for the package's developers. If you use it, you may have to get
|
||||
all sorts of other programs in order to regenerate files that came
|
||||
with the distribution.
|
||||
- DefineOptions.cmake
|
||||
|
||||
Compilers and Options
|
||||
=====================
|
||||
They can be changed with the -D option:
|
||||
|
||||
Some systems require unusual options for compilation or linking that the
|
||||
`configure' script does not know about. Run `./configure --help' for
|
||||
details on some of the pertinent environment variables.
|
||||
`cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_LIBZ=OFF ..`
|
||||
|
||||
You can give `configure' initial values for configuration parameters
|
||||
by setting variables in the command line or in the environment. Here
|
||||
is an example:
|
||||
### Browsing/editing CMake options
|
||||
|
||||
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
||||
In addition to passing options on the command line, you can browse and edit
|
||||
CMake options using `cmakesetup` (Windows), `cmake-gui` or `ccmake` (GNU/Linux
|
||||
and MacOS X).
|
||||
|
||||
*Note Defining Variables::, for more details.
|
||||
- Go to the build dir
|
||||
- On Windows: run `cmakesetup`
|
||||
- On GNU/Linux and MacOS X: run `ccmake ..`
|
||||
|
||||
Compiling For Multiple Architectures
|
||||
====================================
|
||||
## Installing
|
||||
|
||||
You can compile the package for more than one kind of computer at the
|
||||
same time, by placing the object files for each architecture in their
|
||||
own directory. To do this, you must use a version of `make' that
|
||||
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||
directory where you want the object files and executables to go and run
|
||||
the `configure' script. `configure' automatically checks for the
|
||||
source code in the directory that `configure' is in and in `..'.
|
||||
If you want to install libssh after compilation run:
|
||||
|
||||
If you have to use a `make' that does not support the `VPATH'
|
||||
variable, you have to compile the package for one architecture at a
|
||||
time in the source code directory. After you have installed the
|
||||
package for one architecture, use `make distclean' before reconfiguring
|
||||
for another architecture.
|
||||
make install
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
## Running
|
||||
|
||||
By default, `make install' installs the package's commands under
|
||||
`/usr/local/bin', include files under `/usr/local/include', etc. You
|
||||
can specify an installation prefix other than `/usr/local' by giving
|
||||
`configure' the option `--prefix=PREFIX'.
|
||||
The libssh binary can be found in the `build/libssh` directory.
|
||||
|
||||
You can specify separate installation prefixes for
|
||||
architecture-specific files and architecture-independent files. If you
|
||||
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
|
||||
PREFIX as the prefix for installing programs and libraries.
|
||||
Documentation and other data files still use the regular prefix.
|
||||
## About this document
|
||||
|
||||
In addition, if you use an unusual directory layout you can give
|
||||
options like `--bindir=DIR' to specify different values for particular
|
||||
kinds of files. Run `configure --help' for a list of the directories
|
||||
you can set and what kinds of files go in them.
|
||||
|
||||
If the package supports it, you can cause programs to be installed
|
||||
with an extra prefix or suffix on their names by giving `configure' the
|
||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
Some packages pay attention to `--enable-FEATURE' options to
|
||||
`configure', where FEATURE indicates an optional part of the package.
|
||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||
is something like `gnu-as' or `x' (for the X Window System). The
|
||||
`README' should mention any `--enable-' and `--with-' options that the
|
||||
package recognizes.
|
||||
|
||||
For packages that use the X Window System, `configure' can usually
|
||||
find the X include and library files automatically, but if it doesn't,
|
||||
you can use the `configure' options `--x-includes=DIR' and
|
||||
`--x-libraries=DIR' to specify their locations.
|
||||
|
||||
Specifying the System Type
|
||||
==========================
|
||||
|
||||
There may be some features `configure' cannot figure out automatically,
|
||||
but needs to determine by the type of machine the package will run on.
|
||||
Usually, assuming the package is built to be run on the _same_
|
||||
architectures, `configure' can figure that out, but if it prints a
|
||||
message saying it cannot guess the machine type, give it the
|
||||
`--build=TYPE' option. TYPE can either be a short name for the system
|
||||
type, such as `sun4', or a canonical name which has the form:
|
||||
|
||||
CPU-COMPANY-SYSTEM
|
||||
|
||||
where SYSTEM can have one of these forms:
|
||||
|
||||
OS KERNEL-OS
|
||||
|
||||
See the file `config.sub' for the possible values of each field. If
|
||||
`config.sub' isn't included in this package, then this package doesn't
|
||||
need to know the machine type.
|
||||
|
||||
If you are _building_ compiler tools for cross-compiling, you should
|
||||
use the option `--target=TYPE' to select the type of system they will
|
||||
produce code for.
|
||||
|
||||
If you want to _use_ a cross compiler, that generates code for a
|
||||
platform different from the build platform, you should specify the
|
||||
"host" platform (i.e., that on which the generated programs will
|
||||
eventually be run) with `--host=TYPE'.
|
||||
|
||||
Sharing Defaults
|
||||
================
|
||||
|
||||
If you want to set default values for `configure' scripts to share, you
|
||||
can create a site shell script called `config.site' that gives default
|
||||
values for variables like `CC', `cache_file', and `prefix'.
|
||||
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||
`CONFIG_SITE' environment variable to the location of the site script.
|
||||
A warning: not all `configure' scripts look for a site script.
|
||||
|
||||
Defining Variables
|
||||
==================
|
||||
|
||||
Variables not defined in a site shell script can be set in the
|
||||
environment passed to `configure'. However, some packages may run
|
||||
configure again during the build, and the customized values of these
|
||||
variables may be lost. In order to avoid this problem, you should set
|
||||
them in the `configure' command line, using `VAR=value'. For example:
|
||||
|
||||
./configure CC=/usr/local2/bin/gcc
|
||||
|
||||
causes the specified `gcc' to be used as the C compiler (unless it is
|
||||
overridden in the site shell script). Here is a another example:
|
||||
|
||||
/bin/bash ./configure CONFIG_SHELL=/bin/bash
|
||||
|
||||
Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
|
||||
configuration-related scripts to be executed by `/bin/bash'.
|
||||
|
||||
`configure' Invocation
|
||||
======================
|
||||
|
||||
`configure' recognizes the following options to control how it operates.
|
||||
|
||||
`--help'
|
||||
`-h'
|
||||
Print a summary of the options to `configure', and exit.
|
||||
|
||||
`--version'
|
||||
`-V'
|
||||
Print the version of Autoconf used to generate the `configure'
|
||||
script, and exit.
|
||||
|
||||
`--cache-file=FILE'
|
||||
Enable the cache: use and save the results of the tests in FILE,
|
||||
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
||||
disable caching.
|
||||
|
||||
`--config-cache'
|
||||
`-C'
|
||||
Alias for `--cache-file=config.cache'.
|
||||
|
||||
`--quiet'
|
||||
`--silent'
|
||||
`-q'
|
||||
Do not print messages saying which checks are being made. To
|
||||
suppress all normal output, redirect it to `/dev/null' (any error
|
||||
messages will still be shown).
|
||||
|
||||
`--srcdir=DIR'
|
||||
Look for the package's source code in directory DIR. Usually
|
||||
`configure' can determine that directory automatically.
|
||||
|
||||
`configure' also accepts some other, not widely useful, options. Run
|
||||
`configure --help' for more details.
|
||||
This document is written using [Markdown][] syntax, making it possible to
|
||||
provide usable information in both plain text and HTML format. Whenever
|
||||
modifying this document please use [Markdown][] syntax.
|
||||
|
||||
[markdown]: http://www.daringfireball.net/projects/markdown
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
CC= gcc
|
||||
DLLWRAP=dllwrap.exe
|
||||
DEFFILE=libssh.def
|
||||
STATICLIB=libssh.a
|
||||
LIB="c:\Program files\Microsoft Visual Studio .NET 2003\vc7\bin\lib.exe"
|
||||
INCS= -I. -Iinclude -Ic:/openssl/include -I"c:\Program files\gnuwin32\include"
|
||||
CFLAGS= $(INCS)
|
||||
LINK= -L. c:/openssl/lib/MinGW/libeay32.a "c:\program files\gnuwin32\lib\libz.a" c:\Dev-cpp\lib\libws2_32.a #-lws2_32 ##-lgdi32 -lshell32
|
||||
|
||||
libssh_HEADERS= config.h include/libssh/crypto.h include/libssh/libssh.h include/libssh/priv.h include/libssh/server.h include/libssh/sftp.h include/libssh/ssh1.h include/libssh/ssh2.h
|
||||
libssh_OBJS = libssh/auth1.o libssh/auth.o libssh/base64.o libssh/buffer.o \
|
||||
libssh/channels1.o libssh/channels.o libssh/client.o libssh/connect.o \
|
||||
libssh/crc32.o libssh/crypt.o libssh/dh.o libssh/error.o libssh/gcrypt_missing.o \
|
||||
libssh/gzip.o libssh/init.o libssh/kex.o libssh/keyfiles.o \
|
||||
libssh/keys.o libssh/messages.o libssh/misc.o libssh/options.o \
|
||||
libssh/packet.o libssh/server.o libssh/session.o libssh/sftp.o \
|
||||
libssh/sftpserver.o libssh/string.o libssh/wrapper.o libssh/socket.o \
|
||||
libssh/log.o
|
||||
|
||||
|
||||
all: libssh.dll samplesshd.exe libssh.lib
|
||||
|
||||
config.h: config.h.win32-openssl
|
||||
copy config.h.win32-openssl config.h
|
||||
|
||||
%.o: %.c $(libssh_HEADERS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
sample.exe: sample.o $(libssh_OBJS)
|
||||
$(CC) $< -o $@ $(libssh_OBJS) $(LINK)
|
||||
samplesshd.exe: samplesshd.o $(libssh_OBJS)
|
||||
$(CC) $< -o $@ $(libssh_OBJS) $(LINK)
|
||||
|
||||
libssh.dll: $(libssh_OBJS)
|
||||
# $(CC) -shared $(libssh_OBJS) -o libssh.dll $(LINK)
|
||||
$(DLLWRAP) --export-all-symbols --output-def $(DEFFILE) --implib $(STATICLIB) $(libssh_OBJS) $(LINK) -o libssh.dll
|
||||
|
||||
libssh.lib: libssh.dll
|
||||
lib.bat
|
||||
clean:
|
||||
rm -f $(libssh_OBJS) samplesshd.exe sample.exe samplesshd.o sample.o libssh.dll config.h
|
||||
44
Makefile.am
44
Makefile.am
@@ -1,44 +0,0 @@
|
||||
SUBDIRS = libssh include
|
||||
|
||||
AM_CPPFLAGS = -I$(srcdir)/include
|
||||
|
||||
LDADD = $(top_builddir)/libssh/libssh.la
|
||||
|
||||
noinst_PROGRAMS = samplesshd samplessh
|
||||
|
||||
noinst_DATA = samplesftp doxygen
|
||||
|
||||
samplessh_SOURCES = sample.c
|
||||
|
||||
samplesshd_SOURCES = samplesshd.c
|
||||
|
||||
samplesftp: samplessh
|
||||
$(LN_S) -f samplessh samplesftp
|
||||
|
||||
if HAS_DOXYGEN
|
||||
install-doc: doxygen
|
||||
$(INSTALL) -d $(DESTDIR)$(docdir)/html
|
||||
$(INSTALL) --mode=644 doxygen/html/* $(DESTDIR)$(docdir)/html
|
||||
$(INSTALL) -d $(DESTDIR)$(docdir)/examples
|
||||
$(INSTALL) --mode=644 sample.c samplesshd.c $(DESTDIR)$(docdir)/examples
|
||||
$(INSTALL) -d $(DESTDIR)$(mandir)/man3
|
||||
$(INSTALL) --mode=644 doxygen/man/man3/* $(DESTDIR)$(mandir)/man3
|
||||
|
||||
doxygen: clean-local
|
||||
@echo "Running doxygen..."
|
||||
doxygen $(srcdir)/Doxyfile
|
||||
doxygen-dev: clean-local
|
||||
@echo "Running internal doxygen"
|
||||
doxygen $(srcdir)/Doxyfile.internal
|
||||
else
|
||||
doxygen:
|
||||
doxygen-dev:
|
||||
install-doc: doxygen
|
||||
endif
|
||||
|
||||
clean-local:
|
||||
-rm -rf doxygen
|
||||
|
||||
EXTRA_DIST = Doxyfile Doxyfile.internal
|
||||
|
||||
CLEANFILES = samplesftp
|
||||
49
README
49
README
@@ -1,14 +1,14 @@
|
||||
The libSSH and its client
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-Aris Adamantiadis
|
||||
libssh: the SSH library
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
1* Why ?
|
||||
-_-_-_-_-_
|
||||
|
||||
Why not ? :) I've began to work on my own implementation of the ssh protocol
|
||||
because i didn't like the currently public ones.
|
||||
Not any allow you to import and use the functions as a library, and so i
|
||||
worked on a library-based SSH implementation.
|
||||
Not any allowed you to import and use the functions as a powerful library,
|
||||
and so i worked on a library-based SSH implementation which was non-existing
|
||||
in the free and open source software world.
|
||||
|
||||
|
||||
2* How/Who ?
|
||||
@@ -16,24 +16,33 @@ worked on a library-based SSH implementation.
|
||||
|
||||
If you downloaded this file, you must know what it is : a library for
|
||||
accessing ssh client services through C libraries calls in a simple manner.
|
||||
The client is there as a programming example and isn't at all doing its job
|
||||
correctly (doesn't verify public key hashes with the ones in ~/.ssh/
|
||||
and doesn't handle TERM - yet)
|
||||
Everybody can use this software under the terms of the LGPL - see the COPYING
|
||||
file
|
||||
|
||||
3* What ?
|
||||
-_-_-_-_-_
|
||||
If you ask yourself how to compile libssh, please read INSTALL before anything.
|
||||
|
||||
The SSH library features :
|
||||
-Full C library functions for manipulating a client-side SSH connection
|
||||
-Fully configurable sessions
|
||||
-Support for AES-128,AES-192,AES-256,blowfish, in cbc mode
|
||||
-use multiple SSH connections in a same process, at same time.
|
||||
-usable SFTP implementation
|
||||
-Public key and password authentication
|
||||
|
||||
4* Where ?
|
||||
3* Where ?
|
||||
-_-_-_-_-_-_
|
||||
|
||||
http://0xbadc0de.be/?part=libssh
|
||||
http://www.libssh.org
|
||||
|
||||
4* API Changes !
|
||||
-_-_-_-_-_-_-_-_-_
|
||||
|
||||
Changes between 0.3 and 0.4
|
||||
---------------------------
|
||||
|
||||
We changed libssh to be typesafe now:
|
||||
|
||||
SSH_SESSION *session -> ssh_session session
|
||||
SFTP_SESSION *sftp -> sftp_session sftp
|
||||
CHANNEL *channel -> ssh_channel channel
|
||||
STRING *string -> ssh_string string
|
||||
...
|
||||
|
||||
The options structure has been removed and there is a new function. This
|
||||
function can set all available options now. You can find the enum in the
|
||||
header file and it is documented. Example:
|
||||
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
aclocal
|
||||
libtoolize --force --copy
|
||||
autoheader
|
||||
autoconf
|
||||
automake --add-missing --copy --gnu
|
||||
./configure $@
|
||||
195
build/build_make.sh
Executable file
195
build/build_make.sh
Executable file
@@ -0,0 +1,195 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Last Change: 2008-06-18 14:13:46
|
||||
#
|
||||
# Script to build libssh on UNIX.
|
||||
#
|
||||
# Copyright (c) 2006-2007 Andreas Schneider <mail@cynapses.org>
|
||||
#
|
||||
|
||||
SOURCE_DIR=".."
|
||||
|
||||
LANG=C
|
||||
export LANG
|
||||
|
||||
SCRIPT="$0"
|
||||
COUNT=0
|
||||
while [ -L "${SCRIPT}" ]
|
||||
do
|
||||
SCRIPT=$(readlink ${SCRIPT})
|
||||
COUNT=$(expr ${COUNT} + 1)
|
||||
if [ ${COUNT} -gt 100 ]; then
|
||||
echo "Too many symbolic links"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
BUILDDIR=$(dirname ${SCRIPT})
|
||||
|
||||
cleanup_and_exit () {
|
||||
if test "$1" = 0 -o -z "$1" ; then
|
||||
exit 0
|
||||
else
|
||||
exit $1
|
||||
fi
|
||||
}
|
||||
|
||||
function configure() {
|
||||
if [ -n "${CMAKEDIR}" ]; then
|
||||
${CMAKEDIR}/bin/cmake "$@" ${SOURCE_DIR} || cleanup_and_exit $?
|
||||
else
|
||||
cmake "$@" ${SOURCE_DIR} || cleanup_and_exit $?
|
||||
fi
|
||||
}
|
||||
|
||||
function compile() {
|
||||
if [ -f /proc/cpuinfo ]; then
|
||||
CPUCOUNT=$(grep -c processor /proc/cpuinfo)
|
||||
elif test `uname` = "SunOS" ; then
|
||||
CPUCOUNT=$(psrinfo -p)
|
||||
else
|
||||
CPUCOUNT="1"
|
||||
fi
|
||||
|
||||
if [ "${CPUCOUNT}" -gt "1" ]; then
|
||||
${MAKE} -j${CPUCOUNT} $1 || cleanup_and_exit $?
|
||||
else
|
||||
${MAKE} $1 || exit $?
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_build_dir() {
|
||||
find ! -path "*.svn*" ! -name "*.bat" ! -name "*.sh" ! -name "." -print0 | xargs -0 rm -rf
|
||||
}
|
||||
|
||||
function usage () {
|
||||
echo "Usage: `basename $0` [--prefix /install_prefix|--build [debug|final]|--clean|--verbose|--libsuffix (32|64)|--help|--cmakedir /directory|--make
|
||||
(gmake|make)|--ccompiler (gcc|cc)|--withstaticlib|--unittesting|--withss1|--withserver]"
|
||||
cleanup_and_exit
|
||||
}
|
||||
|
||||
cd ${BUILDDIR}
|
||||
|
||||
# the default CMake options:
|
||||
OPTIONS="--graphviz=${BUILDDIR}/libssh.dot"
|
||||
|
||||
# the default 'make' utility:
|
||||
MAKE="make"
|
||||
|
||||
while test -n "$1"; do
|
||||
PARAM="$1"
|
||||
ARG="$2"
|
||||
shift
|
||||
case ${PARAM} in
|
||||
*-*=*)
|
||||
ARG=${PARAM#*=}
|
||||
PARAM=${PARAM%%=*}
|
||||
set -- "----noarg=${PARAM}" "$@"
|
||||
esac
|
||||
case ${PARAM} in
|
||||
*-help|-h)
|
||||
#echo_help
|
||||
usage
|
||||
cleanup_and_exit
|
||||
;;
|
||||
*-build)
|
||||
DOMAKE="1"
|
||||
BUILD_TYPE="${ARG}"
|
||||
test -n "${BUILD_TYPE}" && shift
|
||||
;;
|
||||
*-clean)
|
||||
clean_build_dir
|
||||
cleanup_and_exit
|
||||
;;
|
||||
*-verbose)
|
||||
DOVERBOSE="1"
|
||||
;;
|
||||
*-memtest)
|
||||
OPTIONS="${OPTIONS} -DMEM_NULL_TESTS=ON"
|
||||
;;
|
||||
*-libsuffix)
|
||||
OPTIONS="${OPTIONS} -DLIB_SUFFIX=${ARG}"
|
||||
shift
|
||||
;;
|
||||
*-prefix)
|
||||
OPTIONS="${OPTIONS} -DCMAKE_INSTALL_PREFIX=${ARG}"
|
||||
shift
|
||||
;;
|
||||
*-sysconfdir)
|
||||
OPTIONS="${OPTIONS} -DSYSCONF_INSTALL_DIR=${ARG}"
|
||||
shift
|
||||
;;
|
||||
*-cmakedir)
|
||||
CMAKEDIR="${ARG}"
|
||||
shift
|
||||
;;
|
||||
*-make)
|
||||
MAKE="${ARG}"
|
||||
shift
|
||||
;;
|
||||
*-ccompiler)
|
||||
OPTIONS="${OPTIONS} -DCMAKE_C_COMPILER=${ARG}"
|
||||
shift
|
||||
;;
|
||||
*-withstaticlib)
|
||||
OPTIONS="${OPTIONS} -DWITH_STATIC_LIB=ON"
|
||||
shift
|
||||
;;
|
||||
*-unittesting)
|
||||
OPTIONS="${OPTIONS} -DUNIT_TESTING=ON"
|
||||
shift
|
||||
;;
|
||||
*-withssh1)
|
||||
OPTIONS="${OPTIONS} -DWITH_SSH1=ON"
|
||||
shift
|
||||
;;
|
||||
*-withserver)
|
||||
OPTIONS="${OPTIONS} -DWITH_SERVER=ON"
|
||||
shift
|
||||
;;
|
||||
----noarg)
|
||||
echo "$ARG does not take an argument"
|
||||
cleanup_and_exit
|
||||
;;
|
||||
-*)
|
||||
echo Unknown Option "$PARAM". Exit.
|
||||
cleanup_and_exit 1
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${DOMAKE}" == "1" ]; then
|
||||
OPTIONS="${OPTIONS} -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
|
||||
fi
|
||||
|
||||
if [ -n "${DOVERBOSE}" ]; then
|
||||
OPTIONS="${OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=1"
|
||||
else
|
||||
OPTIONS="${OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=0"
|
||||
fi
|
||||
|
||||
test -f "${BUILDDIR}/.build.log" && rm -f ${BUILDDIR}/.build.log
|
||||
touch ${BUILDDIR}/.build.log
|
||||
# log everything from here to .build.log
|
||||
exec 1> >(exec -a 'build logging tee' tee -a ${BUILDDIR}/.build.log) 2>&1
|
||||
echo "${HOST} started build at $(date)."
|
||||
echo
|
||||
|
||||
configure ${OPTIONS} "$@"
|
||||
|
||||
if [ -n "${DOMAKE}" ]; then
|
||||
test -n "${DOVERBOSE}" && compile VERBOSE=1 || compile
|
||||
fi
|
||||
|
||||
DOT=$(which dot 2>/dev/null)
|
||||
if [ -n "${DOT}" ]; then
|
||||
${DOT} -Tpng -o${BUILDDIR}/libssh.png ${BUILDDIR}/libssh.dot
|
||||
${DOT} -Tsvg -o${BUILDDIR}/libssh.svg ${BUILDDIR}/libssh.dot
|
||||
fi
|
||||
|
||||
exec >&0 2>&0 # so that the logging tee finishes
|
||||
sleep 1 # wait till tee terminates
|
||||
|
||||
cleanup_and_exit 0
|
||||
22
cmake/Modules/COPYING-CMAKE-SCRIPTS
Normal file
22
cmake/Modules/COPYING-CMAKE-SCRIPTS
Normal file
@@ -0,0 +1,22 @@
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
27
cmake/Modules/DefineCMakeDefaults.cmake
Normal file
27
cmake/Modules/DefineCMakeDefaults.cmake
Normal file
@@ -0,0 +1,27 @@
|
||||
# Always include srcdir and builddir in include path
|
||||
# This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in
|
||||
# about every subdir
|
||||
# since cmake 2.4.0
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
# Put the include dirs which are in the source or build tree
|
||||
# before all other include dirs, so the headers in the sources
|
||||
# are prefered over the already installed ones
|
||||
# since cmake 2.4.1
|
||||
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
|
||||
|
||||
# Use colored output
|
||||
# since cmake 2.4.0
|
||||
set(CMAKE_COLOR_MAKEFILE ON)
|
||||
|
||||
# Define the generic version of the libraries here
|
||||
set(GENERIC_LIB_VERSION "0.1.0")
|
||||
set(GENERIC_LIB_SOVERSION "0")
|
||||
|
||||
# Set the default build type to release with debug info
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo
|
||||
CACHE STRING
|
||||
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
|
||||
)
|
||||
endif (NOT CMAKE_BUILD_TYPE)
|
||||
59
cmake/Modules/DefineCompilerFlags.cmake
Normal file
59
cmake/Modules/DefineCompilerFlags.cmake
Normal file
@@ -0,0 +1,59 @@
|
||||
# define system dependent compiler flags
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
|
||||
if (UNIX AND NOT WIN32)
|
||||
if (${CMAKE_C_COMPILER_ID} MATCHES GNU)
|
||||
# add -Wconversion ?
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute")
|
||||
|
||||
# with -fPIC
|
||||
check_c_compiler_flag("-fPIC" WITH_FPIC)
|
||||
if (WITH_FPIC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
endif (WITH_FPIC)
|
||||
|
||||
check_c_compiler_flag("-fstack-protector" WITH_STACK_PROTECTOR)
|
||||
if (WITH_STACK_PROTECTOR)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
|
||||
endif (WITH_STACK_PROTECTOR)
|
||||
|
||||
check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
|
||||
if (WITH_FORTIFY_SOURCE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2")
|
||||
endif (WITH_FORTIFY_SOURCE)
|
||||
|
||||
endif (${CMAKE_C_COMPILER_ID} MATCHES GNU)
|
||||
|
||||
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
# with large file support
|
||||
execute_process(
|
||||
COMMAND
|
||||
getconf LFS64_CFLAGS
|
||||
OUTPUT_VARIABLE
|
||||
_lfs_CFLAGS
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
else (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
# with large file support
|
||||
execute_process(
|
||||
COMMAND
|
||||
getconf LFS_CFLAGS
|
||||
OUTPUT_VARIABLE
|
||||
_lfs_CFLAGS
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
if (_lfs_CFLAGS)
|
||||
string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_lfs_CFLAGS}")
|
||||
endif (_lfs_CFLAGS)
|
||||
|
||||
endif (UNIX AND NOT WIN32)
|
||||
|
||||
# suppress warning about "deprecated" functions
|
||||
if (MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
|
||||
endif (MSVC)
|
||||
107
cmake/Modules/DefineInstallationPaths.cmake
Normal file
107
cmake/Modules/DefineInstallationPaths.cmake
Normal file
@@ -0,0 +1,107 @@
|
||||
if (UNIX)
|
||||
IF (NOT APPLICATION_NAME)
|
||||
MESSAGE(STATUS "${PROJECT_NAME} is used as APPLICATION_NAME")
|
||||
SET(APPLICATION_NAME ${PROJECT_NAME})
|
||||
ENDIF (NOT APPLICATION_NAME)
|
||||
|
||||
# Suffix for Linux
|
||||
SET(LIB_SUFFIX
|
||||
CACHE STRING "Define suffix of directory name (32/64)"
|
||||
)
|
||||
|
||||
SET(EXEC_INSTALL_PREFIX
|
||||
"${CMAKE_INSTALL_PREFIX}"
|
||||
CACHE PATH "Base directory for executables and libraries"
|
||||
)
|
||||
SET(SHARE_INSTALL_PREFIX
|
||||
"${CMAKE_INSTALL_PREFIX}/share"
|
||||
CACHE PATH "Base directory for files which go to share/"
|
||||
)
|
||||
SET(DATA_INSTALL_PREFIX
|
||||
"${SHARE_INSTALL_PREFIX}/${APPLICATION_NAME}"
|
||||
CACHE PATH "The parent directory where applications can install their data")
|
||||
|
||||
# The following are directories where stuff will be installed to
|
||||
SET(BIN_INSTALL_DIR
|
||||
"${EXEC_INSTALL_PREFIX}/bin"
|
||||
CACHE PATH "The ${APPLICATION_NAME} binary install dir (default prefix/bin)"
|
||||
)
|
||||
SET(SBIN_INSTALL_DIR
|
||||
"${EXEC_INSTALL_PREFIX}/sbin"
|
||||
CACHE PATH "The ${APPLICATION_NAME} sbin install dir (default prefix/sbin)"
|
||||
)
|
||||
SET(LIB_INSTALL_DIR
|
||||
"${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}"
|
||||
CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is prefix/lib)"
|
||||
)
|
||||
SET(LIBEXEC_INSTALL_DIR
|
||||
"${EXEC_INSTALL_PREFIX}/libexec"
|
||||
CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is prefix/libexec)"
|
||||
)
|
||||
SET(PLUGIN_INSTALL_DIR
|
||||
"${LIB_INSTALL_DIR}/${APPLICATION_NAME}"
|
||||
CACHE PATH "The subdirectory relative to the install prefix where plugins will be installed (default is prefix/lib/${APPLICATION_NAME})"
|
||||
)
|
||||
SET(INCLUDE_INSTALL_DIR
|
||||
"${CMAKE_INSTALL_PREFIX}/include"
|
||||
CACHE PATH "The subdirectory to the header prefix (default prefix/include)"
|
||||
)
|
||||
|
||||
SET(DATA_INSTALL_DIR
|
||||
"${DATA_INSTALL_PREFIX}"
|
||||
CACHE PATH "The parent directory where applications can install their data (default prefix/share/${APPLICATION_NAME})"
|
||||
)
|
||||
SET(HTML_INSTALL_DIR
|
||||
"${DATA_INSTALL_PREFIX}/doc/HTML"
|
||||
CACHE PATH "The HTML install dir for documentation (default data/doc/html)"
|
||||
)
|
||||
SET(ICON_INSTALL_DIR
|
||||
"${DATA_INSTALL_PREFIX}/icons"
|
||||
CACHE PATH "The icon install dir (default data/icons/)"
|
||||
)
|
||||
SET(SOUND_INSTALL_DIR
|
||||
"${DATA_INSTALL_PREFIX}/sounds"
|
||||
CACHE PATH "The install dir for sound files (default data/sounds)"
|
||||
)
|
||||
|
||||
SET(LOCALE_INSTALL_DIR
|
||||
"${SHARE_INSTALL_PREFIX}/locale"
|
||||
CACHE PATH "The install dir for translations (default prefix/share/locale)"
|
||||
)
|
||||
|
||||
SET(XDG_APPS_DIR
|
||||
"${SHARE_INSTALL_PREFIX}/applications/"
|
||||
CACHE PATH "The XDG apps dir"
|
||||
)
|
||||
SET(XDG_DIRECTORY_DIR
|
||||
"${SHARE_INSTALL_PREFIX}/desktop-directories"
|
||||
CACHE PATH "The XDG directory"
|
||||
)
|
||||
|
||||
SET(SYSCONF_INSTALL_DIR
|
||||
"${EXEC_INSTALL_PREFIX}/etc"
|
||||
CACHE PATH "The ${APPLICATION_NAME} sysconfig install dir (default prefix/etc)"
|
||||
)
|
||||
SET(MAN_INSTALL_DIR
|
||||
"${SHARE_INSTALL_PREFIX}/man"
|
||||
CACHE PATH "The ${APPLICATION_NAME} man install dir (default prefix/man)"
|
||||
)
|
||||
SET(INFO_INSTALL_DIR
|
||||
"${SHARE_INSTALL_PREFIX}/info"
|
||||
CACHE PATH "The ${APPLICATION_NAME} info install dir (default prefix/info)"
|
||||
)
|
||||
endif (UNIX)
|
||||
|
||||
if (WIN32)
|
||||
# Same same
|
||||
set(BIN_INSTALL_DIR "bin" CACHE PATH "-")
|
||||
set(SBIN_INSTALL_DIR "." CACHE PATH "-")
|
||||
set(LIB_INSTALL_DIR "lib" CACHE PATH "-")
|
||||
set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-")
|
||||
set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-")
|
||||
set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-")
|
||||
set(ICON_INSTALL_DIR "." CACHE PATH "-")
|
||||
set(SOUND_INSTALL_DIR "." CACHE PATH "-")
|
||||
set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-")
|
||||
endif (WIN32)
|
||||
|
||||
77
cmake/Modules/FindGCrypt.cmake
Normal file
77
cmake/Modules/FindGCrypt.cmake
Normal file
@@ -0,0 +1,77 @@
|
||||
# - Try to find GCrypt
|
||||
# Once done this will define
|
||||
#
|
||||
# GCRYPT_FOUND - system has GCrypt
|
||||
# GCRYPT_INCLUDE_DIRS - the GCrypt include directory
|
||||
# GCRYPT_LIBRARIES - Link these to use GCrypt
|
||||
# GCRYPT_DEFINITIONS - Compiler switches required for using GCrypt
|
||||
#
|
||||
# Copyright (c) 2009 Andreas Schneider <mail@cynapses.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New
|
||||
# BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
#
|
||||
|
||||
|
||||
if (GCRYPT_LIBRARIES AND GCRYPT_INCLUDE_DIRS)
|
||||
# in cache already
|
||||
set(GCRYPT_FOUND TRUE)
|
||||
else (GCRYPT_LIBRARIES AND GCRYPT_INCLUDE_DIRS)
|
||||
|
||||
find_path(GCRYPT_INCLUDE_DIR
|
||||
NAMES
|
||||
gcrypt.h
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/opt/local/include
|
||||
/sw/include
|
||||
)
|
||||
mark_as_advanced(GCRYPT_INCLUDE_DIR)
|
||||
|
||||
find_library(GCRYPT_LIBRARY
|
||||
NAMES
|
||||
gcrypt
|
||||
PATHS
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/opt/local/lib
|
||||
/sw/lib
|
||||
)
|
||||
mark_as_advanced(GCRYPT_LIBRARY)
|
||||
|
||||
if (GCRYPT_LIBRARY)
|
||||
set(GCRYPT_FOUND TRUE CACHE INTERNAL "Wether the gcrypt library has been found" FORCE)
|
||||
endif (GCRYPT_LIBRARY)
|
||||
|
||||
set(GCRYPT_INCLUDE_DIRS
|
||||
${GCRYPT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
if (GCRYPT_FOUND)
|
||||
set(GCRYPT_LIBRARIES
|
||||
${GCRYPT_LIBRARIES}
|
||||
${GCRYPT_LIBRARY}
|
||||
)
|
||||
endif (GCRYPT_FOUND)
|
||||
|
||||
if (GCRYPT_INCLUDE_DIRS AND GCRYPT_LIBRARIES)
|
||||
set(GCRYPT_FOUND TRUE)
|
||||
endif (GCRYPT_INCLUDE_DIRS AND GCRYPT_LIBRARIES)
|
||||
|
||||
if (GCRYPT_FOUND)
|
||||
if (NOT GCrypt_FIND_QUIETLY)
|
||||
message(STATUS "Found GCrypt: ${GCRYPT_LIBRARIES}")
|
||||
endif (NOT GCrypt_FIND_QUIETLY)
|
||||
else (GCRYPT_FOUND)
|
||||
if (GCrypt_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find GCrypt")
|
||||
endif (GCrypt_FIND_REQUIRED)
|
||||
endif (GCRYPT_FOUND)
|
||||
|
||||
# show the GCRYPT_INCLUDE_DIRS and GCRYPT_LIBRARIES variables only in the advanced view
|
||||
mark_as_advanced(GCRYPT_INCLUDE_DIRS GCRYPT_LIBRARIES)
|
||||
|
||||
endif (GCRYPT_LIBRARIES AND GCRYPT_INCLUDE_DIRS)
|
||||
|
||||
180
cmake/Modules/FindOpenSSL.cmake
Normal file
180
cmake/Modules/FindOpenSSL.cmake
Normal file
@@ -0,0 +1,180 @@
|
||||
# - Try to find OpenSSL
|
||||
# Once done this will define
|
||||
#
|
||||
# OPENSSL_FOUND - system has OpenSSL
|
||||
# OPENSSL_INCLUDE_DIRS - the OpenSSL include directory
|
||||
# OPENSSL_LIBRARIES - Link these to use OpenSSL
|
||||
# OPENSSL_DEFINITIONS - Compiler switches required for using OpenSSL
|
||||
#
|
||||
# Copyright (c) 2009 Andreas Schneider <mail@cynapses.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New
|
||||
# BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
#
|
||||
|
||||
|
||||
if (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)
|
||||
# in cache already
|
||||
set(OPENSSL_FOUND TRUE)
|
||||
else (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)
|
||||
# use pkg-config to get the directories and then use these values
|
||||
# in the FIND_PATH() and FIND_LIBRARY() calls
|
||||
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||
include(UsePkgConfig)
|
||||
pkgconfig(openssl _OPENSSL_INCLUDEDIR _OPENSSL_LIBDIR _OPENSSL_LDFLAGS _OPENSSL_CFLAGS)
|
||||
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||
find_package(PkgConfig)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(_OPENSSL openssl)
|
||||
endif (PKG_CONFIG_FOUND)
|
||||
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||
|
||||
find_path(OPENSSL_INCLUDE_DIR
|
||||
NAMES
|
||||
openssl/ssl.h
|
||||
PATHS
|
||||
${_OPENSSL_INCLUDEDIR}
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/usr/local/ssl/include
|
||||
/opt/local/include
|
||||
/sw/include
|
||||
/usr/lib/sfw/include
|
||||
)
|
||||
mark_as_advanced(OPENSSL_INCLUDE_DIR)
|
||||
|
||||
find_library(SSL_LIBRARY
|
||||
NAMES
|
||||
ssl
|
||||
libssl
|
||||
PATHS
|
||||
${_OPENSSL_LIBDIR}
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/local/ssl/lib
|
||||
/opt/local/lib
|
||||
/sw/lib
|
||||
/usr/sfw/lib/64
|
||||
/usr/sfw/lib
|
||||
)
|
||||
mark_as_advanced(SSL_LIBRARY)
|
||||
|
||||
find_library(SSLEAY32_LIBRARY
|
||||
NAMES
|
||||
ssleay32
|
||||
PATHS
|
||||
${_OPENSSL_LIBDIR}
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/local/ssl/lib
|
||||
/opt/local/lib
|
||||
/sw/lib
|
||||
/usr/sfw/lib/64
|
||||
/usr/sfw/lib
|
||||
)
|
||||
mark_as_advanced(SSLEAY32_LIBRARY)
|
||||
|
||||
find_library(SSLEAY32MD_LIBRARY
|
||||
NAMES
|
||||
ssleay32MD
|
||||
PATHS
|
||||
${_OPENSSL_LIBDIR}
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/local/ssl/lib
|
||||
/opt/local/lib
|
||||
/sw/lib
|
||||
/usr/sfw/lib/64
|
||||
/usr/sfw/lib
|
||||
)
|
||||
mark_as_advanced(SSLEAY32MD_LIBRARY)
|
||||
|
||||
find_library(CRYPTO_LIBRARY
|
||||
NAMES
|
||||
crypto
|
||||
libcrypto
|
||||
eay
|
||||
eay32
|
||||
libeay
|
||||
libeay32
|
||||
PATHS
|
||||
${_OPENSSL_LIBDIR}
|
||||
/lib
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/local/ssl/lib
|
||||
/opt/local/lib
|
||||
/sw/lib
|
||||
/usr/sfw/lib/64
|
||||
/usr/sfw/lib
|
||||
)
|
||||
mark_as_advanced(CRYPTO_LIBRARY)
|
||||
|
||||
if (SSL_LIBRARY)
|
||||
set(SSL_FOUND TRUE CACHE INTERNAL "Wether the ssl library has been found" FORCE)
|
||||
endif (SSL_LIBRARY)
|
||||
|
||||
if (SSLEAY32_LIBRARY)
|
||||
set(SSLEAY32_FOUND TRUE CACHE INTERNAL "Wether the ssleay32 library has been found" FORCE)
|
||||
endif (SSLEAY32_LIBRARY)
|
||||
|
||||
if (SSLEAY32MD_LIBRARY)
|
||||
set(SSLEAY32MD_FOUND TRUE CACHE INTERNAL "Wether the ssleay32MD library has been found" FORCE)
|
||||
endif (SSLEAY32MD_LIBRARY)
|
||||
|
||||
if (CRYPTO_LIBRARY)
|
||||
set(CRYPTO_FOUND TRUE CACHE INTERNAL "Wether the crypto library has been found" FORCE)
|
||||
endif (CRYPTO_LIBRARY)
|
||||
|
||||
set(OPENSSL_INCLUDE_DIRS
|
||||
${OPENSSL_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
if (SSL_FOUND)
|
||||
set(OPENSSL_LIBRARIES
|
||||
${OPENSSL_LIBRARIES}
|
||||
${SSL_LIBRARY}
|
||||
)
|
||||
endif (SSL_FOUND)
|
||||
|
||||
if (SSLEAY32_FOUND)
|
||||
set(OPENSSL_LIBRARIES
|
||||
${OPENSSL_LIBRARIES}
|
||||
${SSLEAY32_LIBRARY}
|
||||
)
|
||||
endif (SSLEAY32_FOUND)
|
||||
|
||||
if (SSLEAY32MD_FOUND)
|
||||
set(OPENSSL_LIBRARIES
|
||||
${OPENSSL_LIBRARIES}
|
||||
${SSLEAY32MD_LIBRARY}
|
||||
)
|
||||
endif (SSLEAY32MD_FOUND)
|
||||
|
||||
if (CRYPTO_FOUND)
|
||||
set(OPENSSL_LIBRARIES
|
||||
${OPENSSL_LIBRARIES}
|
||||
${CRYPTO_LIBRARY}
|
||||
)
|
||||
endif (CRYPTO_FOUND)
|
||||
|
||||
if (OPENSSL_INCLUDE_DIRS AND OPENSSL_LIBRARIES)
|
||||
set(OPENSSL_FOUND TRUE)
|
||||
endif (OPENSSL_INCLUDE_DIRS AND OPENSSL_LIBRARIES)
|
||||
|
||||
if (OPENSSL_FOUND)
|
||||
if (NOT OpenSSL_FIND_QUIETLY)
|
||||
message(STATUS "Found OpenSSL: ${OPENSSL_LIBRARIES}")
|
||||
endif (NOT OpenSSL_FIND_QUIETLY)
|
||||
else (OPENSSL_FOUND)
|
||||
if (OpenSSL_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find OpenSSL")
|
||||
endif (OpenSSL_FIND_REQUIRED)
|
||||
endif (OPENSSL_FOUND)
|
||||
|
||||
# show the OPENSSL_INCLUDE_DIRS and OPENSSL_LIBRARIES variables only in the advanced view
|
||||
mark_as_advanced(OPENSSL_INCLUDE_DIRS OPENSSL_LIBRARIES)
|
||||
|
||||
endif (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)
|
||||
|
||||
79
cmake/Modules/FindZLIB.cmake
Normal file
79
cmake/Modules/FindZLIB.cmake
Normal file
@@ -0,0 +1,79 @@
|
||||
# - Try to find ZLIB
|
||||
# Once done this will define
|
||||
#
|
||||
# ZLIB_FOUND - system has ZLIB
|
||||
# ZLIB_INCLUDE_DIRS - the ZLIB include directory
|
||||
# ZLIB_LIBRARIES - Link these to use ZLIB
|
||||
# ZLIB_DEFINITIONS - Compiler switches required for using ZLIB
|
||||
#
|
||||
# Copyright (c) 2009 Andreas Schneider <mail@cynapses.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New
|
||||
# BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
#
|
||||
|
||||
|
||||
if (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
|
||||
# in cache already
|
||||
set(ZLIB_FOUND TRUE)
|
||||
else (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
|
||||
|
||||
find_path(ZLIB_INCLUDE_DIR
|
||||
NAMES
|
||||
zlib.h
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/opt/local/include
|
||||
/sw/include
|
||||
)
|
||||
mark_as_advanced(ZLIB_INCLUDE_DIR)
|
||||
|
||||
find_library(Z_LIBRARY
|
||||
NAMES
|
||||
z
|
||||
zlib
|
||||
zlib1
|
||||
PATHS
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/opt/local/lib
|
||||
/sw/lib
|
||||
)
|
||||
mark_as_advanced(Z_LIBRARY)
|
||||
|
||||
if (Z_LIBRARY)
|
||||
set(Z_FOUND TRUE)
|
||||
endif (Z_LIBRARY)
|
||||
|
||||
set(ZLIB_INCLUDE_DIRS
|
||||
${ZLIB_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
if (Z_FOUND)
|
||||
set(ZLIB_LIBRARIES
|
||||
${ZLIB_LIBRARIES}
|
||||
${Z_LIBRARY}
|
||||
)
|
||||
endif (Z_FOUND)
|
||||
|
||||
if (ZLIB_INCLUDE_DIRS AND ZLIB_LIBRARIES)
|
||||
set(ZLIB_FOUND TRUE)
|
||||
endif (ZLIB_INCLUDE_DIRS AND ZLIB_LIBRARIES)
|
||||
|
||||
if (ZLIB_FOUND)
|
||||
if (NOT ZLIB_FIND_QUIETLY)
|
||||
message(STATUS "Found ZLIB: ${ZLIB_LIBRARIES}")
|
||||
endif (NOT ZLIB_FIND_QUIETLY)
|
||||
else (ZLIB_FOUND)
|
||||
if (ZLIB_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find ZLIB")
|
||||
endif (ZLIB_FIND_REQUIRED)
|
||||
endif (ZLIB_FOUND)
|
||||
|
||||
# show the ZLIB_INCLUDE_DIRS and ZLIB_LIBRARIES variables only in the advanced view
|
||||
mark_as_advanced(ZLIB_INCLUDE_DIRS ZLIB_LIBRARIES)
|
||||
|
||||
endif (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
|
||||
|
||||
21
cmake/Modules/MacroAddCompileFlags.cmake
Normal file
21
cmake/Modules/MacroAddCompileFlags.cmake
Normal file
@@ -0,0 +1,21 @@
|
||||
# - MACRO_ADD_COMPILE_FLAGS(target_name flag1 ... flagN)
|
||||
|
||||
# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
|
||||
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
|
||||
macro (MACRO_ADD_COMPILE_FLAGS _target)
|
||||
|
||||
get_target_property(_flags ${_target} COMPILE_FLAGS)
|
||||
if (_flags)
|
||||
set(_flags ${_flags} ${ARGN})
|
||||
else (_flags)
|
||||
set(_flags ${ARGN})
|
||||
endif (_flags)
|
||||
|
||||
set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${_flags})
|
||||
|
||||
endmacro (MACRO_ADD_COMPILE_FLAGS)
|
||||
20
cmake/Modules/MacroAddLinkFlags.cmake
Normal file
20
cmake/Modules/MacroAddLinkFlags.cmake
Normal file
@@ -0,0 +1,20 @@
|
||||
# - MACRO_ADD_LINK_FLAGS(target_name flag1 ... flagN)
|
||||
|
||||
# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
|
||||
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
macro (MACRO_ADD_LINK_FLAGS _target)
|
||||
|
||||
get_target_property(_flags ${_target} LINK_FLAGS)
|
||||
if (_flags)
|
||||
set(_flags "${_flags} ${ARGN}")
|
||||
else (_flags)
|
||||
set(_flags "${ARGN}")
|
||||
endif (_flags)
|
||||
|
||||
set_target_properties(${_target} PROPERTIES LINK_FLAGS "${_flags}")
|
||||
|
||||
endmacro (MACRO_ADD_LINK_FLAGS)
|
||||
30
cmake/Modules/MacroAddPlugin.cmake
Normal file
30
cmake/Modules/MacroAddPlugin.cmake
Normal file
@@ -0,0 +1,30 @@
|
||||
# - MACRO_ADD_PLUGIN(name [WITH_PREFIX] file1 .. fileN)
|
||||
#
|
||||
# Create a plugin from the given source files.
|
||||
# If WITH_PREFIX is given, the resulting plugin will have the
|
||||
# prefix "lib", otherwise it won't.
|
||||
#
|
||||
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
|
||||
# Copyright (c) 2006, Laurent Montel, <montel@kde.org>
|
||||
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
|
||||
macro (MACRO_ADD_PLUGIN _target_NAME _with_PREFIX)
|
||||
|
||||
if (${_with_PREFIX} STREQUAL "WITH_PREFIX")
|
||||
set(_first_SRC)
|
||||
else (${_with_PREFIX} STREQUAL "WITH_PREFIX")
|
||||
set(_first_SRC ${_with_PREFIX})
|
||||
endif (${_with_PREFIX} STREQUAL "WITH_PREFIX")
|
||||
|
||||
add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN})
|
||||
|
||||
if (_first_SRC)
|
||||
set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
|
||||
endif (_first_SRC)
|
||||
|
||||
endmacro (MACRO_ADD_PLUGIN _name _sources)
|
||||
|
||||
33
cmake/Modules/MacroCopyFile.cmake
Normal file
33
cmake/Modules/MacroCopyFile.cmake
Normal file
@@ -0,0 +1,33 @@
|
||||
# - macro_copy_file(_src _dst)
|
||||
# Copies a file to ${_dst} only if ${_src} is different (newer) than ${_dst}
|
||||
#
|
||||
# Example:
|
||||
# macro_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/icon.png ${CMAKE_CURRENT_BINARY_DIR}/.)
|
||||
# Copies file icon.png to ${CMAKE_CURRENT_BINARY_DIR} directory
|
||||
#
|
||||
# Copyright (c) 2006-2007 Wengo
|
||||
# Copyright (c) 2006-2008 Andreas Schneider <mail@cynapses.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING file.
|
||||
|
||||
|
||||
macro (macro_copy_file _src _dst)
|
||||
# Removes all path containing .svn or CVS or CMakeLists.txt during the copy
|
||||
if (NOT ${_src} MATCHES ".*\\.svn|CVS|CMakeLists\\.txt.*")
|
||||
|
||||
if (CMAKE_VERBOSE_MAKEFILE)
|
||||
message(STATUS "Copy file from ${_src} to ${_dst}")
|
||||
endif (CMAKE_VERBOSE_MAKEFILE)
|
||||
|
||||
# Creates directory if necessary
|
||||
get_filename_component(_path ${_dst} PATH)
|
||||
file(MAKE_DIRECTORY ${_path})
|
||||
|
||||
execute_process(
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E copy_if_different ${_src} ${_dst}
|
||||
OUTPUT_QUIET
|
||||
)
|
||||
endif (NOT ${_src} MATCHES ".*\\.svn|CVS|CMakeLists\\.txt.*")
|
||||
endmacro (macro_copy_file)
|
||||
17
cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
Normal file
17
cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
Normal file
@@ -0,0 +1,17 @@
|
||||
# - MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
|
||||
# MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
|
||||
|
||||
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
macro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage)
|
||||
|
||||
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource)
|
||||
if (_insource)
|
||||
message(SEND_ERROR "${_errorMessage}")
|
||||
message(FATAL_ERROR "Remove the file CMakeCache.txt in ${CMAKE_SOURCE_DIR} first.")
|
||||
endif (_insource)
|
||||
|
||||
endmacro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
|
||||
127
cmake/Modules/UseDoxygen.cmake
Normal file
127
cmake/Modules/UseDoxygen.cmake
Normal file
@@ -0,0 +1,127 @@
|
||||
# -helper macro to add a "doc" target with CMake build system.
|
||||
# and configure doxy.config.in to doxy.config
|
||||
#
|
||||
# target "doc" allows building the documentation with doxygen/dot on WIN32 and Linux
|
||||
# Creates .chm windows help file if MS HTML help workshop
|
||||
# (available from http://msdn.microsoft.com/workshop/author/htmlhelp)
|
||||
# is installed with its DLLs in PATH.
|
||||
#
|
||||
#
|
||||
# Please note, that the tools, e.g.:
|
||||
# doxygen, dot, latex, dvips, makeindex, gswin32, etc.
|
||||
# must be in path.
|
||||
#
|
||||
# Note about Visual Studio Projects:
|
||||
# MSVS has its own path environment which may differ from the shell.
|
||||
# See "Menu Tools/Options/Projects/VC++ Directories" in VS 7.1
|
||||
#
|
||||
# author Jan Woetzel 2004-2006
|
||||
# www.mip.informatik.uni-kiel.de/~jw
|
||||
|
||||
|
||||
FIND_PACKAGE(Doxygen)
|
||||
|
||||
IF (DOXYGEN_FOUND)
|
||||
|
||||
# click+jump in Emacs and Visual Studio (for doxy.config) (jw)
|
||||
IF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
|
||||
SET(DOXY_WARN_FORMAT "\"$file($line) : $text \"")
|
||||
ELSE (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
|
||||
SET(DOXY_WARN_FORMAT "\"$file:$line: $text \"")
|
||||
ENDIF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
|
||||
|
||||
# we need latex for doxygen because of the formulas
|
||||
FIND_PACKAGE(LATEX)
|
||||
IF (NOT LATEX_COMPILER)
|
||||
MESSAGE(STATUS "latex command LATEX_COMPILER not found but usually required. You will probably get warnings and user inetraction on doxy run.")
|
||||
ENDIF (NOT LATEX_COMPILER)
|
||||
IF (NOT MAKEINDEX_COMPILER)
|
||||
MESSAGE(STATUS "makeindex command MAKEINDEX_COMPILER not found but usually required.")
|
||||
ENDIF (NOT MAKEINDEX_COMPILER)
|
||||
IF (NOT DVIPS_CONVERTER)
|
||||
MESSAGE(STATUS "dvips command DVIPS_CONVERTER not found but usually required.")
|
||||
ENDIF (NOT DVIPS_CONVERTER)
|
||||
FIND_PROGRAM(DOXYGEN_DOT_EXECUTABLE_PATH NAMES dot)
|
||||
IF (DOXYGEN_DOT_EXECUTABLE_PATH)
|
||||
SET(DOXYGEN_DOT_FOUND "YES")
|
||||
ENDIF (DOXYGEN_DOT_EXECUTABLE_PATH)
|
||||
|
||||
IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
|
||||
MESSAGE(STATUS "Generate ${CMAKE_CURRENT_BINARY_DIR}/doxy.config from doxy.config.in")
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/doxy.config
|
||||
@ONLY )
|
||||
# use (configured) doxy.config from (out of place) BUILD tree:
|
||||
SET(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxy.config")
|
||||
ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
|
||||
# use static hand-edited doxy.config from SOURCE tree:
|
||||
SET(DOXY_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
|
||||
IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
|
||||
MESSAGE(STATUS "WARNING: using existing ${CMAKE_CURRENT_SOURCE_DIR}/doxy.config instead of configuring from doxy.config.in file.")
|
||||
ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
|
||||
IF (EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
|
||||
# using template doxy.config.in
|
||||
MESSAGE(STATUS "Generate ${CMAKE_CURRENT_BINARY_DIR}/doxy.config from doxy.config.in")
|
||||
CONFIGURE_FILE(${CMAKE_MODULE_PATH}/doxy.config.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/doxy.config
|
||||
@ONLY )
|
||||
SET(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxy.config")
|
||||
ELSE (EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
|
||||
# failed completely...
|
||||
MESSAGE(SEND_ERROR "Please create ${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in (or doxy.config as fallback)")
|
||||
ENDIF(EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
|
||||
|
||||
ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
|
||||
ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
|
||||
|
||||
ADD_CUSTOM_TARGET(doc ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doxy.config)
|
||||
|
||||
# create a windows help .chm file using hhc.exe
|
||||
# HTMLHelp DLL must be in path!
|
||||
# fallback: use hhw.exe interactively
|
||||
IF (WIN32)
|
||||
FIND_PACKAGE(HTMLHelp)
|
||||
IF (HTML_HELP_COMPILER)
|
||||
SET (TMP "${CMAKE_CURRENT_BINARY_DIR}\\doc\\html\\index.hhp")
|
||||
STRING(REGEX REPLACE "[/]" "\\\\" HHP_FILE ${TMP} )
|
||||
# MESSAGE(SEND_ERROR "DBG HHP_FILE=${HHP_FILE}")
|
||||
ADD_CUSTOM_TARGET(winhelp ${HTML_HELP_COMPILER} ${HHP_FILE})
|
||||
ADD_DEPENDENCIES (winhelp doc)
|
||||
|
||||
IF (NOT TARGET_DOC_SKIP_INSTALL)
|
||||
# install windows help?
|
||||
# determine useful name for output file
|
||||
# should be project and version unique to allow installing
|
||||
# multiple projects into one global directory
|
||||
IF (EXISTS "${PROJECT_BINARY_DIR}/doc/html/index.chm")
|
||||
IF (PROJECT_NAME)
|
||||
SET(OUT "${PROJECT_NAME}")
|
||||
ELSE (PROJECT_NAME)
|
||||
SET(OUT "Documentation") # default
|
||||
ENDIF(PROJECT_NAME)
|
||||
IF (${PROJECT_NAME}_VERSION_MAJOR)
|
||||
SET(OUT "${OUT}-${${PROJECT_NAME}_VERSION_MAJOR}")
|
||||
IF (${PROJECT_NAME}_VERSION_MINOR)
|
||||
SET(OUT "${OUT}.${${PROJECT_NAME}_VERSION_MINOR}")
|
||||
IF (${PROJECT_NAME}_VERSION_PATCH)
|
||||
SET(OUT "${OUT}.${${PROJECT_NAME}_VERSION_PATCH}")
|
||||
ENDIF(${PROJECT_NAME}_VERSION_PATCH)
|
||||
ENDIF(${PROJECT_NAME}_VERSION_MINOR)
|
||||
ENDIF(${PROJECT_NAME}_VERSION_MAJOR)
|
||||
# keep suffix
|
||||
SET(OUT "${OUT}.chm")
|
||||
|
||||
#MESSAGE("DBG ${PROJECT_BINARY_DIR}/doc/html/index.chm \n${OUT}")
|
||||
# create target used by install and package commands
|
||||
INSTALL(FILES "${PROJECT_BINARY_DIR}/doc/html/index.chm"
|
||||
DESTINATION "doc"
|
||||
RENAME "${OUT}"
|
||||
)
|
||||
ENDIF(EXISTS "${PROJECT_BINARY_DIR}/doc/html/index.chm")
|
||||
ENDIF(NOT TARGET_DOC_SKIP_INSTALL)
|
||||
|
||||
ENDIF(HTML_HELP_COMPILER)
|
||||
# MESSAGE(SEND_ERROR "HTML_HELP_COMPILER=${HTML_HELP_COMPILER}")
|
||||
ENDIF (WIN32)
|
||||
ENDIF(DOXYGEN_FOUND)
|
||||
|
||||
110
config.h.cmake
Normal file
110
config.h.cmake
Normal file
@@ -0,0 +1,110 @@
|
||||
/* Name of package */
|
||||
#cmakedefine PACKAGE "${APPLICATION_NAME}"
|
||||
|
||||
/* Version number of package */
|
||||
#cmakedefine VERSION "${APPLICATION_VERSION}"
|
||||
|
||||
#cmakedefine LOCALEDIR "${LOCALE_INSTALL_DIR}"
|
||||
#cmakedefine DATADIR "${DATADIR}"
|
||||
#cmakedefine LIBDIR "${LIBDIR}"
|
||||
#cmakedefine PLUGINDIR "${PLUGINDIR}"
|
||||
#cmakedefine SYSCONFDIR "${SYSCONFDIR}"
|
||||
#cmakedefine BINARYDIR "${BINARYDIR}"
|
||||
#cmakedefine SOURCEDIR "${SOURCEDIR}"
|
||||
|
||||
/************************** HEADER FILES *************************/
|
||||
|
||||
/* Define to 1 if you have the <argp.h> header file. */
|
||||
#cmakedefine HAVE_ARGP_H 1
|
||||
|
||||
/* Define to 1 if you have the <pty.h> header file. */
|
||||
#cmakedefine HAVE_PTY_H 1
|
||||
|
||||
/* Define to 1 if you have the <termios.h> header file. */
|
||||
#cmakedefine HAVE_TERMIOS_H 1
|
||||
|
||||
/* Define to 1 if you have the <openssl/aes.h> header file. */
|
||||
#cmakedefine HAVE_OPENSSL_AES_H 1
|
||||
|
||||
/* Define to 1 if you have the <wspiapi.h> header file. */
|
||||
#cmakedefine HAVE_WSPIAPI_H 1
|
||||
|
||||
/* Define to 1 if you have the <openssl/blowfish.h> header file. */
|
||||
#cmakedefine HAVE_OPENSSL_BLOWFISH_H 1
|
||||
|
||||
/* Define to 1 if you have the <openssl/des.h> header file. */
|
||||
#cmakedefine HAVE_OPENSSL_DES_H 1
|
||||
|
||||
/*************************** FUNCTIONS ***************************/
|
||||
|
||||
/* Define to 1 if you have the `cfmakeraw' function. */
|
||||
#cmakedefine HAVE_CFMAKERAW 1
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#cmakedefine HAVE_GETADDRINFO 1
|
||||
|
||||
/* Define to 1 if you have the `gethostbyname' function. */
|
||||
#cmakedefine HAVE_GETHOSTBYNAME 1
|
||||
|
||||
/* Define to 1 if you have the `poll' function. */
|
||||
#cmakedefine HAVE_POLL 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#cmakedefine HAVE_SELECT 1
|
||||
|
||||
/* Define to 1 if you have the `regcomp' function. */
|
||||
#cmakedefine HAVE_REGCOMP 1
|
||||
|
||||
/*************************** LIBRARIES ***************************/
|
||||
|
||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||
#cmakedefine HAVE_LIBCRYPTO 1
|
||||
|
||||
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
|
||||
#cmakedefine HAVE_LIBGCRYPT 1
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#cmakedefine HAVE_LIBZ 1
|
||||
|
||||
/**************************** OPTIONS ****************************/
|
||||
|
||||
/* Define to 1 if you want to enable ZLIB */
|
||||
#cmakedefine WITH_LIBZ 1
|
||||
|
||||
/* Define to 1 if you want to enable SFTP */
|
||||
#cmakedefine WITH_SFTP 1
|
||||
|
||||
/* Define to 1 if you want to enable SSH1 */
|
||||
#cmakedefine WITH_SSH1 1
|
||||
|
||||
/* Define to 1 if you want to enable server support */
|
||||
#cmakedefine WITH_SERVER 1
|
||||
|
||||
/* Define to 1 if you want to enable debug output for crypto functions */
|
||||
#cmakedefine DEBUG_CRYPTO 1
|
||||
|
||||
/* Define to 1 if you want to enable pcap output support (experimental) */
|
||||
#cmakedefine WITH_PCAP 1
|
||||
|
||||
/* Define to 1 if you want to enable calltrace debug output */
|
||||
#cmakedefine DEBUG_CALLTRACE 1
|
||||
|
||||
/*************************** ENDIAN *****************************/
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#cmakedefine WORDS_BIGENDIAN 1
|
||||
|
||||
/************************* MS Windows ***************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef _MSC_VER
|
||||
/* On Microsoft compilers define inline to __inline on all others use inline */
|
||||
# undef inline
|
||||
# define inline __inline
|
||||
|
||||
# undef strdup
|
||||
# define strdup _strdup
|
||||
# endif // _MSC_VER
|
||||
#endif /* _WIN32 */
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
/* config.h. Manually tweaked for Windows. */
|
||||
|
||||
/* Define to 1 if you have the `cfmakeraw' function. */
|
||||
#define HAVE_CFMAKERAW 1
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||
/* #undef HAVE_DOPRNT */
|
||||
|
||||
/* Define to 1 if you have the `endpwent' function. */
|
||||
/* #undef HAVE_ENDPWENT */
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <gcrypt.h> header file. */
|
||||
/* #undef HAVE_GCRYPT_H */
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#define HAVE_GETADDRINFO 1
|
||||
|
||||
/* Define to 1 if you have the `gethostbyname' function. */
|
||||
#define HAVE_GETHOSTBYNAME 1
|
||||
|
||||
/* Define to 1 if you have the `getpass' function. */
|
||||
/* #undef HAVE_GETPASS */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||
#define HAVE_LIBCRYPTO 1
|
||||
|
||||
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
|
||||
/* #undef HAVE_LIBGCRYPT */
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#define HAVE_LIBZ 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
/* #undef HAVE_NETDB_H */
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
/* #undef HAVE_NETINET_IN_H */
|
||||
|
||||
/* Define to 1 if you have the <openssl/aes.h> header file. */
|
||||
#define HAVE_OPENSSL_AES_H 1
|
||||
|
||||
/* Define to 1 if you have the <openssl/blowfish.h> header file. */
|
||||
#define HAVE_OPENSSL_BLOWFISH_H 1
|
||||
|
||||
/* Define to 1 if you have the <openssl/des.h> header file. */
|
||||
#define HAVE_OPENSSL_DES_H 1
|
||||
|
||||
/* Define to 1 if you have the `poll' function. */
|
||||
/* #undef HAVE_POLL */
|
||||
|
||||
/* Define to 1 if you have the <pty.h> header file. */
|
||||
/* #undef HAVE_PTY_H */
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
|
||||
and to 0 otherwise. */
|
||||
#define HAVE_REALLOC 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#define HAVE_SELECT 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define to 1 if you want to enable SSH1 */
|
||||
/* #undef HAVE_SSH1 */
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strchr' function. */
|
||||
#define HAVE_STRCHR 1
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strstr' function. */
|
||||
#define HAVE_STRSTR 1
|
||||
|
||||
/* Define to 1 if you have the <sys/poll.h> header file. */
|
||||
/* #undef HAVE_SYS_POLL_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#define HAVE_SYS_SELECT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
/* #undef HAVE_SYS_SOCKET_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <termios.h> header file. */
|
||||
/* #undef HAVE_TERMIOS_H */
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the `vprintf' function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the <zlib.h> header file. */
|
||||
#define HAVE_ZLIB_H 1
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "libssh"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "aris@0xbadc0de.be"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libssh"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libssh 0.2"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libssh"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "0.2.1-win-svn"
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#define RETSIGTYPE void
|
||||
|
||||
/* Define to the type of arg 1 for `select'. */
|
||||
#define SELECT_TYPE_ARG1 int
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for `select'. */
|
||||
#define SELECT_TYPE_ARG234 (fd_set *)
|
||||
|
||||
/* Define to the type of arg 5 for `select'. */
|
||||
#define SELECT_TYPE_ARG5 (struct timeval *)
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "0.2.1-win-svn"
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to rpl_realloc if the replacement function should be used. */
|
||||
/* #undef realloc */
|
||||
135
configure.ac
135
configure.ac
@@ -1,135 +0,0 @@
|
||||
# -*- Autoconf -*-
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT([libssh], 0.2.1-svn, [aris@0xbadc0de.be])
|
||||
AM_INIT_AUTOMAKE(1.9)
|
||||
AC_CONFIG_SRCDIR([sample.c])
|
||||
AC_CONFIG_HEADER([config.h])
|
||||
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
# LT Version numbers, remember to change them just *before* a release.
|
||||
# (Interfaces removed: CURRENT++, AGE=0, REVISION=0)
|
||||
# (Interfaces added: CURRENT++, AGE++, REVISION=0)
|
||||
# (No interfaces changed: REVISION++)
|
||||
LIBSSH_CURRENT=3
|
||||
LIBSSH_AGE=1
|
||||
LIBSSH_REVISION=0
|
||||
AC_SUBST(LIBSSH_CURRENT)
|
||||
AC_SUBST(LIBSSH_AGE)
|
||||
AC_SUBST(LIBSSH_REVISION)
|
||||
|
||||
# Check for the OS.
|
||||
AC_CANONICAL_HOST
|
||||
case "$host" in
|
||||
*-apple*)
|
||||
LIBSSH_LDFLAGS="-prebind -seg1addr 0x3a000000 -headerpad_max_install_names"
|
||||
;;
|
||||
*)
|
||||
LIBSSH_LDFLAGS=""
|
||||
;;
|
||||
esac
|
||||
AC_SUBST(LIBSSH_LDFLAGS)
|
||||
|
||||
AC_MSG_CHECKING([version script options])
|
||||
case "$host" in
|
||||
*-*-linux*)
|
||||
LIBSSH_VERS="$LIBSSH_LDFLAGS -Wl,--version-script,libssh.vers"
|
||||
;;
|
||||
*-*-gnu*)
|
||||
LIBSSH_VERS="$LIBSSH_LDFLAGS -Wl,--version-script,libssh.vers"
|
||||
;;
|
||||
esac
|
||||
AC_ARG_WITH([versioned-symbol],
|
||||
AC_HELP_STRING([--with-versioned-symbol],[Use versioned symbols]),
|
||||
[if test "$withval" = "yes"; then
|
||||
LIBSSH_VERS="$LIBSSH_LDFLAGS -Wl,--version-script,libssh.vers"
|
||||
else
|
||||
LIBSSH_VERS=""
|
||||
fi], [ : ])
|
||||
|
||||
AC_SUBST(LIBSSH_VERS)
|
||||
|
||||
enable_ssh1=${enable_ssh1:-"no"}
|
||||
AC_ARG_ENABLE(ssh1, AC_HELP_STRING([--enable-ssh1], [enable SSH1 support]))
|
||||
AC_MSG_CHECKING([for SSH1 support])
|
||||
if test "$enable_ssh1" = "yes" ; then
|
||||
AC_DEFINE(HAVE_SSH1,1,[Define to 1 if you want to enable SSH1])
|
||||
fi
|
||||
AC_MSG_RESULT([$enable_ssh1])
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_LIBTOOL
|
||||
AC_C_BIGENDIAN
|
||||
|
||||
AC_CHECK_PROG([DOXYGEN], [doxygen], [yes], [no])
|
||||
AM_CONDITIONAL([HAS_DOXYGEN], [test x"$DOXYGEN" = xyes])
|
||||
|
||||
# Checks for libraries.
|
||||
with_gcrypt=${with_gcrypt:-"no"}
|
||||
AC_ARG_WITH([libgcrypt],
|
||||
AC_HELP_STRING([--with-libgcrypt],[Use libgcrypt instead of libcrypto]),
|
||||
[if test "$withval" = "yes"; then
|
||||
with_gcrypt="yes"
|
||||
AC_CHECK_LIB([gcrypt], [gcry_md_open])
|
||||
fi], [ : ])
|
||||
|
||||
if test "$with_gcrypt" = "no"; then
|
||||
AC_CHECK_LIB([crypto], [BN_init])
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB([z], [deflateInit_])
|
||||
AC_SEARCH_LIBS([hstrerror],[nsl resolv])
|
||||
AC_SEARCH_LIBS([getaddrinfo],[nsl socket])
|
||||
AC_SEARCH_LIBS([gethostbyname],[nsl resolv])
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h \
|
||||
sys/time.h termios.h unistd.h openssl/aes.h openssl/blowfish.h \
|
||||
openssl/des.h zlib.h sys/poll.h stdint.h pty.h gcrypt.h])
|
||||
|
||||
#Warn user when no openssl available
|
||||
if test "$with_gcrypt" = "no" && (test "$ac_cv_header_openssl_aes_h" != "yes" ||
|
||||
test "$ac_cv_header_openssl_blowfish_h" != "yes"); then
|
||||
echo "Can't find valid openssl files [e.g openssl/aes.h]"
|
||||
echo "Please install Openssl-devel"
|
||||
exit
|
||||
fi
|
||||
|
||||
#Warn user when no libgcrypt available
|
||||
if test "$with_gcrypt" = "yes" && test "$ac_cv_header_gcrypt_h" != "yes"; then
|
||||
echo "Can't find valid libgcrypt files [e.g gcrypt.h]"
|
||||
echo "Please install libgcrypt-devel"
|
||||
exit
|
||||
fi
|
||||
|
||||
#if ! test x"$ac_cv_header_zlib_h" != x"yes"; then
|
||||
# echo "Can't find zlib.h"
|
||||
# echo "Compression support won't be compiled in"
|
||||
#fi
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
AC_HEADER_TIME
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_FUNC_MEMCMP
|
||||
AC_FUNC_REALLOC
|
||||
AC_FUNC_SELECT_ARGTYPES
|
||||
AC_TYPE_SIGNAL
|
||||
AC_FUNC_VPRINTF
|
||||
AC_CHECK_FUNCS([endpwent getaddrinfo gethostbyname getpass memmove memset \
|
||||
cfmakeraw select socket strchr strdup strerror strstr poll])
|
||||
|
||||
AC_CONFIG_FILES([Makefile
|
||||
libssh/Makefile
|
||||
include/Makefile
|
||||
include/libssh/Makefile])
|
||||
AC_OUTPUT
|
||||
7
debian/README.Debian
vendored
7
debian/README.Debian
vendored
@@ -1,7 +0,0 @@
|
||||
libssh for Debian
|
||||
----------------------
|
||||
|
||||
This is a package for the library libssh with the soname 2.
|
||||
There are some other projects which have nearly the same name, so be careful.
|
||||
|
||||
-- Laurent Bigonville <bigon@bigon.be> Fri, 27 Jul 2007 14:59:00 +0200
|
||||
50
debian/changelog
vendored
50
debian/changelog
vendored
@@ -1,50 +0,0 @@
|
||||
libssh (0.2+svn20070321-5) UNRELEASED; urgency=low
|
||||
|
||||
* NOT RELEASED YET
|
||||
* Use now official Vcs-* field
|
||||
* Use new Homepage field instead of old pseudo-field
|
||||
* BumpStandards-Version to 3.7.3 (no further changes)
|
||||
* debian/libssh-2-doc.doc-base: fix doc-base-unknown-section
|
||||
|
||||
-- Laurent Bigonville <bigon@bigon.be> Thu, 08 Nov 2007 05:59:18 +0100
|
||||
|
||||
libssh (0.2+svn20070321-4) unstable; urgency=low
|
||||
|
||||
* debian/control:
|
||||
- Add XS-Vcs-Svn and XS-Vcs-Browser fields.
|
||||
- Change to ${binary:Version} for versionized dependencies.
|
||||
* Add debian/README.Debian to disambiguate the package name
|
||||
|
||||
-- Laurent Bigonville <bigon@bigon.be> Fri, 27 Jul 2007 15:00:06 +0200
|
||||
|
||||
libssh (0.2+svn20070321-3) unstable; urgency=low
|
||||
|
||||
* Fix wrong versionized Replaces for -doc package
|
||||
|
||||
-- Laurent Bigonville <bigon@bigon.be> Thu, 5 Apr 2007 17:58:27 +0200
|
||||
|
||||
libssh (0.2+svn20070321-2) unstable; urgency=low
|
||||
|
||||
* Split devel package into devel and documentation packages
|
||||
|
||||
-- Laurent Bigonville <bigon@bigon.be> Mon, 26 Mar 2007 15:29:51 +0200
|
||||
|
||||
libssh (0.2+svn20070321-1) unstable; urgency=low
|
||||
|
||||
* New svn snapshot:
|
||||
- Fix broken include in include/libssh/server.h (Closes: #410020)
|
||||
- Fix nasty bug in server side code
|
||||
|
||||
-- Laurent Bigonville <bigon@bigon.be> Mon, 26 Mar 2007 15:06:40 +0200
|
||||
|
||||
libssh (0.2-1) unstable; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
-- Laurent Bigonville <bigon@bigon.be> Fri, 29 Dec 2006 07:40:20 +0100
|
||||
|
||||
libssh (0.2~rc-1) unstable; urgency=low
|
||||
|
||||
* Initial release (Closes: #316872)
|
||||
|
||||
-- Jean-Philippe Garcia Ballester <giga@le-pec.org> Wed, 20 Dec 2006 23:56:50 +0100
|
||||
1
debian/compat
vendored
1
debian/compat
vendored
@@ -1 +0,0 @@
|
||||
5
|
||||
65
debian/control
vendored
65
debian/control
vendored
@@ -1,65 +0,0 @@
|
||||
Source: libssh
|
||||
Section: libs
|
||||
Priority: optional
|
||||
Maintainer: Jean-Philippe Garcia Ballester <giga@le-pec.org>
|
||||
Uploaders: Laurent Bigonville <bigon@bigon.be>
|
||||
Build-Depends: cdbs, debhelper (>= 5), libgcrypt11-dev, libz-dev, doxygen
|
||||
Standards-Version: 3.7.3
|
||||
Vcs-Svn: svn://svn.berlios.de/libssh/trunk
|
||||
Vcs-Browser: http://svn.berlios.de/wsvn/libssh/trunk/
|
||||
Homepage: http://0xbadc0de.be/wiki/doku.php?id=libssh:libssh
|
||||
|
||||
Package: libssh-2
|
||||
Section: libs
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Description: A tiny C SSH library
|
||||
The ssh library was designed to be used by programmers needing a working SSH
|
||||
implementation by the mean of a library. The complete control of the client
|
||||
is made by the programmer. With libssh, you can remotely execute programs,
|
||||
transfer files, use a secure and transparent tunnel for your remote programs.
|
||||
With its SFTP implementation, you can play with remote files easily.
|
||||
|
||||
Package: libssh-2-dev
|
||||
Provides: libssh-dev
|
||||
Section: libdevel
|
||||
Architecture: any
|
||||
Depends: libssh-2 (= ${binary:Version}), libgcrypt11-dev, zlib1g-dev
|
||||
Suggests: libssh-2-doc
|
||||
Conflicts: libssh-dev
|
||||
Description: A tiny C SSH library. Development files
|
||||
The ssh library was designed to be used by programmers needing a working SSH
|
||||
implementation by the mean of a library. The complete control of the client
|
||||
is made by the programmer. With libssh, you can remotely execute programs,
|
||||
transfer files, use a secure and transparent tunnel for your remote programs.
|
||||
With its SFTP implementation, you can play with remote files easily.
|
||||
.
|
||||
This package contains development files.
|
||||
|
||||
Package: libssh-2-dbg
|
||||
Priority: extra
|
||||
Section: libdevel
|
||||
Architecture: any
|
||||
Depends: libssh-2 (= ${binary:Version})
|
||||
Description: A tiny C SSH library. Debug symbols
|
||||
The ssh library was designed to be used by programmers needing a working SSH
|
||||
implementation by the mean of a library. The complete control of the client
|
||||
is made by the programmer. With libssh, you can remotely execute programs,
|
||||
transfer files, use a secure and transparent tunnel for your remote programs.
|
||||
With its SFTP implementation, you can play with remote files easily.
|
||||
.
|
||||
This package contains debug symbols.
|
||||
|
||||
Package: libssh-2-doc
|
||||
Section: doc
|
||||
Architecture: all
|
||||
Suggests: doc-base
|
||||
Replaces: libssh-2-dev (<< 0.2+svn20070321-2)
|
||||
Description: A tiny C SSH library. Documentation files
|
||||
The ssh library was designed to be used by programmers needing a working SSH
|
||||
implementation by the mean of a library. The complete control of the client
|
||||
is made by the programmer. With libssh, you can remotely execute programs,
|
||||
transfer files, use a secure and transparent tunnel for your remote programs.
|
||||
With its SFTP implementation, you can play with remote files easily.
|
||||
.
|
||||
This package contains documentation files.
|
||||
33
debian/copyright
vendored
33
debian/copyright
vendored
@@ -1,33 +0,0 @@
|
||||
This package was debianized by Laurent Bigonville <bigon@bigon.be> on
|
||||
Thu, 16 Nov 2006 20:34:01 +0100.
|
||||
|
||||
It was downloaded from http://www.0xbadc0de.be/
|
||||
|
||||
Upstream Author: Aris Adamantiadis (aka spacewalker) <aris@0xbadc0de.be>
|
||||
|
||||
Copyright: 2003 Aris Adamantiadis
|
||||
|
||||
License:
|
||||
|
||||
This package is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This package is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this package; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
On Debian systems, the complete text of the GNU Lesser General
|
||||
Public License can be found in `/usr/share/common-licenses/LGPL'.
|
||||
|
||||
|
||||
The Debian packaging is
|
||||
(C) 2005-2006, Jean-Philippe Garcia Ballester <giga@le-pec.org>,
|
||||
(C) 2006-2007, Laurent Bigonville <bigon@bigon.be> and
|
||||
is licensed under the GPL, see `/usr/share/common-licenses/GPL'.
|
||||
2
debian/libssh-2-dev.install
vendored
2
debian/libssh-2-dev.install
vendored
@@ -1,2 +0,0 @@
|
||||
debian/tmp/usr/include/*
|
||||
debian/tmp/usr/lib/libssh.{a,la,so}
|
||||
9
debian/libssh-2-doc.doc-base
vendored
9
debian/libssh-2-doc.doc-base
vendored
@@ -1,9 +0,0 @@
|
||||
Document: libssh
|
||||
Title: Debian libssh Manual
|
||||
Author: Aris Adamantiadis <aris@0xbadc0de.be>
|
||||
Abstract: This manual describes libssh API.
|
||||
Section: Apps/Programming
|
||||
|
||||
Format: HTML
|
||||
Index: /usr/share/doc/libssh-2-doc/html/index.html
|
||||
Files: /usr/share/doc/libssh-2-doc/html/*
|
||||
1
debian/libssh-2-doc.docs
vendored
1
debian/libssh-2-doc.docs
vendored
@@ -1 +0,0 @@
|
||||
debian/tmp/usr/share/doc/libssh/html
|
||||
1
debian/libssh-2-doc.examples
vendored
1
debian/libssh-2-doc.examples
vendored
@@ -1 +0,0 @@
|
||||
debian/tmp/usr/share/doc/libssh/examples/*
|
||||
1
debian/libssh-2-doc.manpages
vendored
1
debian/libssh-2-doc.manpages
vendored
@@ -1 +0,0 @@
|
||||
doxygen/man/man3/ssh_*
|
||||
1
debian/libssh-2.install
vendored
1
debian/libssh-2.install
vendored
@@ -1 +0,0 @@
|
||||
debian/tmp/usr/lib/libssh.so.*
|
||||
2
debian/libssh-2.lintian-overrides
vendored
2
debian/libssh-2.lintian-overrides
vendored
@@ -1,2 +0,0 @@
|
||||
# We use libssh-2 name to avoid name clash with libssh2 package.
|
||||
libssh-2: package-name-doesnt-match-sonames libssh2
|
||||
21
debian/rules
vendored
21
debian/rules
vendored
@@ -1,21 +0,0 @@
|
||||
#!/usr/bin/make -f
|
||||
# Sample debian/rules that uses cdbs. Originaly written by Robert Millan.
|
||||
# This file is public domain.
|
||||
|
||||
DEB_AUTO_CLEANUP_RCS := yes
|
||||
|
||||
# Add here any variable or target overrides you need
|
||||
|
||||
|
||||
include /usr/share/cdbs/1/class/autotools.mk
|
||||
include /usr/share/cdbs/1/rules/debhelper.mk
|
||||
#include /usr/share/cdbs/1/rules/simple-patchsys.mk
|
||||
|
||||
DEB_CONFIGURE_EXTRA_FLAGS = --with-libgcrypt --enable-ssh1
|
||||
DEB_DBG_PACKAGE_libssh-2 = libssh-2-dbg
|
||||
|
||||
install/libssh-2::
|
||||
install -D -m 644 debian/libssh-2.lintian-overrides debian/libssh-2/usr/share/lintian/overrides/libssh-2
|
||||
|
||||
install/libssh-2-doc::
|
||||
make install-doc DESTDIR=debian/tmp
|
||||
2
debian/watch
vendored
2
debian/watch
vendored
@@ -1,2 +0,0 @@
|
||||
version=3
|
||||
http://0xbadc0de.be/libssh/libssh-(.*)\.tgz
|
||||
5
doc/CMakeLists.txt
Normal file
5
doc/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
#
|
||||
# Build the documentation
|
||||
#
|
||||
include(UseDoxygen OPTIONAL)
|
||||
|
||||
1445
doc/doxy.config.in
Normal file
1445
doc/doxy.config.in
Normal file
File diff suppressed because it is too large
Load Diff
12
doc/mainpage.dox
Normal file
12
doc/mainpage.dox
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @mainpage
|
||||
* This manual documents the libssh C API.
|
||||
*
|
||||
* There are several other places to look for libssh information, such as the
|
||||
* <a href="http://dev.libssh.org/wiki/Tutorial" target="_blank">tutorial</a>
|
||||
* and the specification; those can be found at the <a
|
||||
* href="http://www.libssh.org/" target="_blank">libssh website</a>.
|
||||
*
|
||||
* To be continued...
|
||||
*/
|
||||
|
||||
38
examples/CMakeLists.txt
Normal file
38
examples/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
project(libssh-examples C)
|
||||
|
||||
set(examples_SRCS
|
||||
authentication.c
|
||||
knownhosts.c
|
||||
connect_ssh.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${LIBSSH_PUBLIC_INCLUDE_DIRS}
|
||||
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
add_executable(libssh_scp libssh_scp.c ${examples_SRCS})
|
||||
add_executable(scp_download scp_download.c ${examples_SRCS})
|
||||
add_executable(samplessh sample.c ${examples_SRCS})
|
||||
add_executable(exec exec.c ${examples_SRCS})
|
||||
|
||||
target_link_libraries(libssh_scp ${LIBSSH_SHARED_LIBRARY})
|
||||
target_link_libraries(scp_download ${LIBSSH_SHARED_LIBRARY})
|
||||
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
|
||||
target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY})
|
||||
|
||||
include_directories(
|
||||
${LIBSSH_PUBLIC_INCLUDE_DIRS}
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
|
||||
if (WITH_SFTP)
|
||||
add_executable(samplesftp samplesftp.c ${examples_SRCS})
|
||||
target_link_libraries(samplesftp ${LIBSSH_SHARED_LIBRARY})
|
||||
endif (WITH_SFTP)
|
||||
|
||||
if (WITH_SERVER)
|
||||
add_executable(samplesshd samplesshd.c)
|
||||
target_link_libraries(samplesshd ${LIBSSH_SHARED_LIBRARY})
|
||||
endif (WITH_SERVER)
|
||||
|
||||
125
examples/authentication.c
Normal file
125
examples/authentication.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* authentication.c
|
||||
* This file contains an example of how to do an authentication to a
|
||||
* SSH server using libssh
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2003-2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
The goal is to show the API in action. It's not a reference on how terminal
|
||||
clients must be made or how a client should react.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include "examples_common.h"
|
||||
|
||||
int authenticate_kbdint(ssh_session session){
|
||||
int err=ssh_userauth_kbdint(session,NULL,NULL);
|
||||
const char *name, *instruction, *prompt;
|
||||
char *ptr;
|
||||
char buffer[128];
|
||||
int i,n;
|
||||
char echo;
|
||||
while (err==SSH_AUTH_INFO){
|
||||
name=ssh_userauth_kbdint_getname(session);
|
||||
instruction=ssh_userauth_kbdint_getinstruction(session);
|
||||
n=ssh_userauth_kbdint_getnprompts(session);
|
||||
if(strlen(name)>0)
|
||||
printf("%s\n",name);
|
||||
if(strlen(instruction)>0)
|
||||
printf("%s\n",instruction);
|
||||
for(i=0;i<n;++i){
|
||||
prompt=ssh_userauth_kbdint_getprompt(session,i,&echo);
|
||||
if(echo){
|
||||
printf("%s",prompt);
|
||||
fgets(buffer,sizeof(buffer),stdin);
|
||||
buffer[sizeof(buffer)-1]=0;
|
||||
if((ptr=strchr(buffer,'\n')))
|
||||
*ptr=0;
|
||||
if (ssh_userauth_kbdint_setanswer(session,i,buffer) < 0) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
memset(buffer,0,strlen(buffer));
|
||||
} else {
|
||||
ptr=getpass(prompt);
|
||||
if (ssh_userauth_kbdint_setanswer(session,i,ptr) < 0) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
err=ssh_userauth_kbdint(session,NULL,NULL);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int authenticate_console(ssh_session session){
|
||||
int rc;
|
||||
int method;
|
||||
char *password;
|
||||
char *banner;
|
||||
|
||||
// Try to authenticate
|
||||
rc = ssh_userauth_none(session, NULL);
|
||||
if (rc == SSH_AUTH_ERROR) {
|
||||
perror("Authentication failed.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
method = ssh_auth_list(session);
|
||||
while (rc != SSH_AUTH_SUCCESS) {
|
||||
|
||||
// Try to authenticate with public key first
|
||||
if (method & SSH_AUTH_METHOD_PUBLICKEY) {
|
||||
rc = ssh_userauth_autopubkey(session, NULL);
|
||||
if (rc == SSH_AUTH_ERROR) {
|
||||
perror("Authentication failed.");
|
||||
return rc;
|
||||
} else if (rc == SSH_AUTH_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to authenticate with keyboard interactive";
|
||||
if (method & SSH_AUTH_METHOD_INTERACTIVE) {
|
||||
rc = authenticate_kbdint(session);
|
||||
if (rc == SSH_AUTH_ERROR) {
|
||||
perror("Authentication failed.");
|
||||
return rc;
|
||||
} else if (rc == SSH_AUTH_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
password=getpass("Password: ");
|
||||
// Try to authenticate with password
|
||||
if (method & SSH_AUTH_METHOD_PASSWORD) {
|
||||
rc = ssh_userauth_password(session, NULL, password);
|
||||
if (rc == SSH_AUTH_ERROR) {
|
||||
perror("Authentication failed.");
|
||||
return rc;
|
||||
} else if (rc == SSH_AUTH_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
banner = ssh_get_issue_banner(session);
|
||||
if (banner) {
|
||||
printf("%s\n",banner);
|
||||
free(banner);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
63
examples/connect_ssh.c
Normal file
63
examples/connect_ssh.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* connect_ssh.c
|
||||
* This file contains an example of how to connect to a
|
||||
* SSH server using libssh
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
The goal is to show the API in action. It's not a reference on how terminal
|
||||
clients must be made or how a client should react.
|
||||
*/
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include "examples_common.h"
|
||||
#include <stdio.h>
|
||||
|
||||
ssh_session connect_ssh(const char *host, const char *user,int verbosity){
|
||||
ssh_session session;
|
||||
int auth=0;
|
||||
|
||||
session=ssh_new();
|
||||
if (session == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(user != NULL){
|
||||
if (ssh_options_set(session, SSH_OPTIONS_USER, user) < 0) {
|
||||
ssh_disconnect(session);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ssh_options_set(session, SSH_OPTIONS_HOST, host) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
|
||||
if(ssh_connect(session)){
|
||||
fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session));
|
||||
ssh_disconnect(session);
|
||||
return NULL;
|
||||
}
|
||||
if(verify_knownhost(session)<0){
|
||||
ssh_disconnect(session);
|
||||
return NULL;
|
||||
}
|
||||
auth=authenticate_console(session);
|
||||
if(auth==SSH_AUTH_SUCCESS){
|
||||
return session;
|
||||
} else if(auth==SSH_AUTH_DENIED){
|
||||
fprintf(stderr,"Authentication failed\n");
|
||||
} else {
|
||||
fprintf(stderr,"Error while authenticating : %s\n",ssh_get_error(session));
|
||||
}
|
||||
ssh_disconnect(session);
|
||||
return NULL;
|
||||
}
|
||||
22
examples/examples_common.h
Normal file
22
examples/examples_common.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Copyright 2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
The goal is to show the API in action. It's not a reference on how terminal
|
||||
clients must be made or how a client should react.
|
||||
*/
|
||||
#ifndef EXAMPLES_COMMON_H_
|
||||
#define EXAMPLES_COMMON_H_
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
int authenticate_console(ssh_session session);
|
||||
int authenticate_kbdint(ssh_session session);
|
||||
int verify_knownhost(ssh_session session);
|
||||
ssh_session connect_ssh(const char *hostname, const char *user, int verbosity);
|
||||
|
||||
#endif /* EXAMPLES_COMMON_H_ */
|
||||
67
examples/exec.c
Normal file
67
examples/exec.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* simple exec example */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include "examples_common.h"
|
||||
|
||||
int main(void) {
|
||||
ssh_session session;
|
||||
ssh_channel channel;
|
||||
ssh_buffer buf;
|
||||
int rc;
|
||||
|
||||
session = connect_ssh("localhost", NULL, 0);
|
||||
if (session == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
channel = channel_new(session);;
|
||||
if (channel == NULL) {
|
||||
ssh_disconnect(session);
|
||||
ssh_finalize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = channel_open_session(channel);
|
||||
if (rc < 0) {
|
||||
channel_close(channel);
|
||||
ssh_disconnect(session);
|
||||
ssh_finalize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = channel_request_exec(channel, "ps aux");
|
||||
if (rc < 0) {
|
||||
channel_close(channel);
|
||||
ssh_disconnect(session);
|
||||
ssh_finalize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (channel_is_open(channel)) {
|
||||
while (channel_poll(channel, 0) >= 0) {
|
||||
buf = buffer_new();
|
||||
rc = channel_read_buffer(channel, buf, 0, 0);
|
||||
if (rc < 0) {
|
||||
buffer_free(buf);
|
||||
channel_close(channel);
|
||||
ssh_disconnect(session);
|
||||
ssh_finalize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("%s\n", (char *) buffer_get(buf));
|
||||
|
||||
buffer_free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
channel_send_eof(channel);
|
||||
channel_close(channel);
|
||||
|
||||
ssh_disconnect(session);
|
||||
ssh_finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
88
examples/knownhosts.c
Normal file
88
examples/knownhosts.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* knownhosts.c
|
||||
* This file contains an example of how verify the identity of a
|
||||
* SSH server using libssh
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2003-2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
The goal is to show the API in action. It's not a reference on how terminal
|
||||
clients must be made or how a client should react.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include "examples_common.h"
|
||||
|
||||
int verify_knownhost(ssh_session session){
|
||||
char *hexa;
|
||||
int state;
|
||||
char buf[10];
|
||||
unsigned char *hash = NULL;
|
||||
int hlen;
|
||||
|
||||
state=ssh_is_server_known(session);
|
||||
|
||||
hlen = ssh_get_pubkey_hash(session, &hash);
|
||||
if (hlen < 0) {
|
||||
return -1;
|
||||
}
|
||||
switch(state){
|
||||
case SSH_SERVER_KNOWN_OK:
|
||||
break; /* ok */
|
||||
case SSH_SERVER_KNOWN_CHANGED:
|
||||
fprintf(stderr,"Host key for server changed : server's one is now :\n");
|
||||
ssh_print_hexa("Public key hash",hash, hlen);
|
||||
free(hash);
|
||||
fprintf(stderr,"For security reason, connection will be stopped\n");
|
||||
return -1;
|
||||
case SSH_SERVER_FOUND_OTHER:
|
||||
fprintf(stderr,"The host key for this server was not found but an other type of key exists.\n");
|
||||
fprintf(stderr,"An attacker might change the default server key to confuse your client"
|
||||
"into thinking the key does not exist\n"
|
||||
"We advise you to rerun the client with -d or -r for more safety.\n");
|
||||
return -1;
|
||||
case SSH_SERVER_FILE_NOT_FOUND:
|
||||
fprintf(stderr,"Could not find known host file. If you accept the host key here,\n");
|
||||
fprintf(stderr,"the file will be automatically created.\n");
|
||||
/* fallback to SSH_SERVER_NOT_KNOWN behavior */
|
||||
case SSH_SERVER_NOT_KNOWN:
|
||||
hexa = ssh_get_hexa(hash, hlen);
|
||||
fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
|
||||
fprintf(stderr, "Public key hash: %s\n", hexa);
|
||||
free(hexa);
|
||||
fgets(buf,sizeof(buf),stdin);
|
||||
if(strncasecmp(buf,"yes",3)!=0){
|
||||
return -1;
|
||||
}
|
||||
fprintf(stderr,"This new key will be written on disk for further usage. do you agree ?\n");
|
||||
fgets(buf,sizeof(buf),stdin);
|
||||
if(strncasecmp(buf,"yes",3)==0){
|
||||
if (ssh_write_knownhost(session) < 0) {
|
||||
free(hash);
|
||||
fprintf(stderr, "error %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SSH_SERVER_ERROR:
|
||||
free(hash);
|
||||
fprintf(stderr,"%s",ssh_get_error(session));
|
||||
return -1;
|
||||
}
|
||||
free(hash);
|
||||
return 0;
|
||||
}
|
||||
304
examples/libssh_scp.c
Normal file
304
examples/libssh_scp.c
Normal file
@@ -0,0 +1,304 @@
|
||||
/* libssh_scp.c
|
||||
* Sample implementation of a SCP client
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include "examples_common.h"
|
||||
|
||||
char **sources;
|
||||
int nsources;
|
||||
char *destination;
|
||||
int verbosity=0;
|
||||
|
||||
struct location {
|
||||
int is_ssh;
|
||||
char *user;
|
||||
char *host;
|
||||
char *path;
|
||||
ssh_session session;
|
||||
ssh_scp scp;
|
||||
FILE *file;
|
||||
};
|
||||
|
||||
enum {
|
||||
READ,
|
||||
WRITE
|
||||
};
|
||||
|
||||
static void usage(const char *argv0){
|
||||
fprintf(stderr,"Usage : %s [options] [[user@]host1:]file1 ... \n"
|
||||
" [[user@]host2:]destination\n"
|
||||
"sample scp client - libssh-%s\n",
|
||||
// "Options :\n",
|
||||
// " -r : use RSA to verify host public key\n",
|
||||
argv0,
|
||||
ssh_version(0));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int opts(int argc, char **argv){
|
||||
int i;
|
||||
while((i=getopt(argc,argv,"v"))!=-1){
|
||||
switch(i){
|
||||
case 'v':
|
||||
verbosity++;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"unknown option %c\n",optopt);
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
nsources=argc-optind-1;
|
||||
if(nsources < 1){
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
sources=malloc((nsources + 1) * sizeof(char *));
|
||||
if(sources == NULL)
|
||||
return -1;
|
||||
for(i=0;i<nsources;++i){
|
||||
sources[i] = argv[optind];
|
||||
optind++;
|
||||
}
|
||||
sources[i]=NULL;
|
||||
destination=argv[optind];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct location *parse_location(char *loc){
|
||||
struct location *location=malloc(sizeof(struct location));
|
||||
char *ptr;
|
||||
|
||||
location->host=location->user=NULL;
|
||||
ptr=strchr(loc,':');
|
||||
if(ptr != NULL){
|
||||
location->is_ssh=1;
|
||||
location->path=strdup(ptr+1);
|
||||
*ptr='\0';
|
||||
ptr=strchr(loc,'@');
|
||||
if(ptr != NULL){
|
||||
location->host=strdup(ptr+1);
|
||||
*ptr='\0';
|
||||
location->user=strdup(loc);
|
||||
} else {
|
||||
location->host=strdup(loc);
|
||||
}
|
||||
} else {
|
||||
location->is_ssh=0;
|
||||
location->path=strdup(loc);
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
static int open_location(struct location *loc, int flag){
|
||||
if(loc->is_ssh && flag==WRITE){
|
||||
loc->session=connect_ssh(loc->host,loc->user,verbosity);
|
||||
if(!loc->session){
|
||||
fprintf(stderr,"Couldn't connect to %s\n",loc->host);
|
||||
return -1;
|
||||
}
|
||||
loc->scp=ssh_scp_new(loc->session,SSH_SCP_WRITE,loc->path);
|
||||
if(!loc->scp){
|
||||
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
|
||||
return -1;
|
||||
}
|
||||
if(ssh_scp_init(loc->scp)==SSH_ERROR){
|
||||
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
|
||||
ssh_scp_free(loc->scp);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
} else if(loc->is_ssh && flag==READ){
|
||||
loc->session=connect_ssh(loc->host, loc->user,verbosity);
|
||||
if(!loc->session){
|
||||
fprintf(stderr,"Couldn't connect to %s\n",loc->host);
|
||||
return -1;
|
||||
}
|
||||
loc->scp=ssh_scp_new(loc->session,SSH_SCP_READ,loc->path);
|
||||
if(!loc->scp){
|
||||
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
|
||||
return -1;
|
||||
}
|
||||
if(ssh_scp_init(loc->scp)==SSH_ERROR){
|
||||
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
|
||||
ssh_scp_free(loc->scp);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
loc->file=fopen(loc->path,flag==READ ? "r":"w");
|
||||
if(!loc->file){
|
||||
if(errno==EISDIR){
|
||||
if(chdir(loc->path)){
|
||||
fprintf(stderr,"Error changing directory to %s: %s\n",loc->path,strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr,"Error opening %s: %s\n",loc->path,strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** @brief copies files from source location to destination
|
||||
* @param src source location
|
||||
* @param dest destination location
|
||||
* @param recursive Copy also directories
|
||||
*/
|
||||
static int do_copy(struct location *src, struct location *dest, int recursive){
|
||||
int size;
|
||||
socket_t fd;
|
||||
struct stat s;
|
||||
int w,r;
|
||||
char buffer[16384];
|
||||
int total=0;
|
||||
int mode;
|
||||
char *filename;
|
||||
/* recursive mode doesn't work yet */
|
||||
(void)recursive;
|
||||
/* Get the file name and size*/
|
||||
if(!src->is_ssh){
|
||||
fd=fileno(src->file);
|
||||
fstat(fd,&s);
|
||||
size=s.st_size;
|
||||
mode=s.st_mode;
|
||||
filename=ssh_basename(src->path);
|
||||
} else {
|
||||
size=0;
|
||||
do {
|
||||
r=ssh_scp_pull_request(src->scp);
|
||||
if(r==SSH_SCP_REQUEST_NEWDIR){
|
||||
ssh_scp_deny_request(src->scp,"Not in recursive mode");
|
||||
continue;
|
||||
}
|
||||
if(r==SSH_SCP_REQUEST_NEWFILE){
|
||||
size=ssh_scp_request_get_size(src->scp);
|
||||
filename=strdup(ssh_scp_request_get_filename(src->scp));
|
||||
mode=ssh_scp_request_get_permissions(src->scp);
|
||||
//ssh_scp_accept_request(src->scp);
|
||||
break;
|
||||
}
|
||||
if(r==SSH_ERROR){
|
||||
fprintf(stderr,"Error: %s\n",ssh_get_error(src->session));
|
||||
return -1;
|
||||
}
|
||||
} while(r != SSH_SCP_REQUEST_NEWFILE);
|
||||
}
|
||||
|
||||
if(dest->is_ssh){
|
||||
r=ssh_scp_push_file(dest->scp,src->path,size,0644);
|
||||
// snprintf(buffer,sizeof(buffer),"C0644 %d %s\n",size,src->path);
|
||||
if(r==SSH_ERROR){
|
||||
fprintf(stderr,"error: %s\n",ssh_get_error(dest->session));
|
||||
ssh_scp_free(dest->scp);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if(!dest->file){
|
||||
dest->file=fopen(filename,"w");
|
||||
if(!dest->file){
|
||||
fprintf(stderr,"Cannot open %s for writing: %s\n",filename,strerror(errno));
|
||||
if(src->is_ssh)
|
||||
ssh_scp_deny_request(src->scp,"Cannot open local file");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(src->is_ssh){
|
||||
ssh_scp_accept_request(src->scp);
|
||||
}
|
||||
}
|
||||
do {
|
||||
if(src->is_ssh){
|
||||
r=ssh_scp_read(src->scp,buffer,sizeof(buffer));
|
||||
if(r==SSH_ERROR){
|
||||
fprintf(stderr,"Error reading scp: %s\n",ssh_get_error(src->session));
|
||||
return -1;
|
||||
}
|
||||
if(r==0)
|
||||
break;
|
||||
} else {
|
||||
r=fread(buffer,1,sizeof(buffer),src->file);
|
||||
if(r==0)
|
||||
break;
|
||||
if(r<0){
|
||||
fprintf(stderr,"Error reading file: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(dest->is_ssh){
|
||||
w=ssh_scp_write(dest->scp,buffer,r);
|
||||
if(w == SSH_ERROR){
|
||||
fprintf(stderr,"Error writing in scp: %s\n",ssh_get_error(dest->session));
|
||||
ssh_scp_free(dest->scp);
|
||||
dest->scp=NULL;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
w=fwrite(buffer,r,1,dest->file);
|
||||
if(w<=0){
|
||||
fprintf(stderr,"Error writing in local file: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
total+=r;
|
||||
|
||||
} while(total < size);
|
||||
printf("wrote %d bytes\n",total);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
struct location *dest, *src;
|
||||
int i;
|
||||
int r;
|
||||
if(opts(argc,argv)<0)
|
||||
return EXIT_FAILURE;
|
||||
dest=parse_location(destination);
|
||||
if(open_location(dest,WRITE)<0)
|
||||
return EXIT_FAILURE;
|
||||
for(i=0;i<nsources;++i){
|
||||
src=parse_location(sources[i]);
|
||||
if(open_location(src,READ)<0){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(do_copy(src,dest,0) < 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(dest->is_ssh){
|
||||
r=ssh_scp_close(dest->scp);
|
||||
if(r == SSH_ERROR){
|
||||
fprintf(stderr,"Error closing scp: %s\n",ssh_get_error(dest->session));
|
||||
ssh_scp_free(dest->scp);
|
||||
dest->scp=NULL;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
fclose(dest->file);
|
||||
dest->file=NULL;
|
||||
}
|
||||
ssh_disconnect(dest->session);
|
||||
ssh_finalize();
|
||||
return 0;
|
||||
}
|
||||
515
examples/sample.c
Normal file
515
examples/sample.c
Normal file
@@ -0,0 +1,515 @@
|
||||
/* client.c */
|
||||
/*
|
||||
Copyright 2003-2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
The goal is to show the API in action. It's not a reference on how terminal
|
||||
clients must be made or how a client should react.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#ifdef HAVE_PTY_H
|
||||
#include <pty.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <libssh/callbacks.h>
|
||||
#include <libssh/libssh.h>
|
||||
#include <libssh/sftp.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "examples_common.h"
|
||||
#define MAXCMD 10
|
||||
char *host;
|
||||
char *user;
|
||||
char *cmds[MAXCMD];
|
||||
struct termios terminal;
|
||||
|
||||
#ifdef WITH_PCAP
|
||||
/* this header file won't be necessary in the future */
|
||||
#include <libssh/pcap.h>
|
||||
char *pcap_file=NULL;
|
||||
#endif
|
||||
|
||||
static int auth_callback(const char *prompt, char *buf, size_t len,
|
||||
int echo, int verify, void *userdata) {
|
||||
char *answer = NULL;
|
||||
char *ptr;
|
||||
|
||||
(void) verify;
|
||||
(void) userdata;
|
||||
|
||||
if (echo) {
|
||||
while ((answer = fgets(buf, len, stdin)) == NULL);
|
||||
if ((ptr = strchr(buf, '\n'))) {
|
||||
ptr = '\0';
|
||||
}
|
||||
} else {
|
||||
answer = getpass(prompt);
|
||||
}
|
||||
|
||||
if (answer == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(buf, answer, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ssh_callbacks_struct cb = {
|
||||
.auth_function=auth_callback,
|
||||
.userdata=NULL
|
||||
};
|
||||
|
||||
static void add_cmd(char *cmd){
|
||||
int n;
|
||||
for(n=0;cmds[n] && (n<MAXCMD);n++);
|
||||
if(n==MAXCMD)
|
||||
return;
|
||||
cmds[n]=strdup(cmd);
|
||||
}
|
||||
|
||||
static void usage(){
|
||||
fprintf(stderr,"Usage : ssh [options] [login@]hostname\n"
|
||||
"sample client - libssh-%s\n"
|
||||
"Options :\n"
|
||||
" -l user : log in as user\n"
|
||||
" -p port : connect to port\n"
|
||||
" -d : use DSS to verify host public key\n"
|
||||
" -r : use RSA to verify host public key\n"
|
||||
#ifdef WITH_PCAP
|
||||
" -P file : create a pcap debugging file\n"
|
||||
#endif
|
||||
,
|
||||
ssh_version(0));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int opts(int argc, char **argv){
|
||||
int i;
|
||||
// for(i=0;i<argc;i++)
|
||||
// printf("%d : %s\n",i,argv[i]);
|
||||
/* insert your own arguments here */
|
||||
while((i=getopt(argc,argv,"P:"))!=-1){
|
||||
switch(i){
|
||||
#ifdef WITH_PCAP
|
||||
case 'P':
|
||||
pcap_file=optarg;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
fprintf(stderr,"unknown option %c\n",optopt);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
if(optind < argc)
|
||||
host=argv[optind++];
|
||||
while(optind < argc)
|
||||
add_cmd(argv[optind++]);
|
||||
if(host==NULL)
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef HAVE_CFMAKERAW
|
||||
static void cfmakeraw(struct termios *termios_p){
|
||||
termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
|
||||
termios_p->c_oflag &= ~OPOST;
|
||||
termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
||||
termios_p->c_cflag &= ~(CSIZE|PARENB);
|
||||
termios_p->c_cflag |= CS8;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void do_cleanup(int i) {
|
||||
/* unused variable */
|
||||
(void) i;
|
||||
|
||||
tcsetattr(0,TCSANOW,&terminal);
|
||||
}
|
||||
|
||||
static void do_exit(int i) {
|
||||
/* unused variable */
|
||||
(void) i;
|
||||
|
||||
do_cleanup(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ssh_channel chan;
|
||||
int signal_delayed=0;
|
||||
|
||||
static void sigwindowchanged(int i){
|
||||
(void) i;
|
||||
signal_delayed=1;
|
||||
}
|
||||
|
||||
static void setsignal(void){
|
||||
signal(SIGWINCH, sigwindowchanged);
|
||||
signal_delayed=0;
|
||||
}
|
||||
|
||||
static void sizechanged(void){
|
||||
struct winsize win = { 0, 0, 0, 0 };
|
||||
ioctl(1, TIOCGWINSZ, &win);
|
||||
channel_change_pty_size(chan,win.ws_col, win.ws_row);
|
||||
// printf("Changed pty size\n");
|
||||
setsignal();
|
||||
}
|
||||
|
||||
/* There are two flavors of select loop: the one based on
|
||||
* ssh_select and the one based on channel_select.
|
||||
* The ssh_select one permits you to give your own file descriptors to
|
||||
* follow. It is thus a complete select loop.
|
||||
* The second one only selects on channels. It is simplier to use
|
||||
* but doesn't permit you to fill in your own file descriptor. It is
|
||||
* more adapted if you can't use ssh_select as a main loop (because
|
||||
* you already have another main loop system).
|
||||
*/
|
||||
|
||||
#ifdef USE_CHANNEL_SELECT
|
||||
|
||||
/* channel_select base main loop, with a standard select(2)
|
||||
*/
|
||||
static void select_loop(ssh_session session,ssh_channel channel){
|
||||
fd_set fds;
|
||||
struct timeval timeout;
|
||||
char buffer[4096];
|
||||
ssh_buffer readbuf=buffer_new();
|
||||
ssh_channel channels[2];
|
||||
int lus;
|
||||
int eof=0;
|
||||
int maxfd;
|
||||
int ret;
|
||||
while(channel){
|
||||
/* when a signal is caught, ssh_select will return
|
||||
* with SSH_EINTR, which means it should be started
|
||||
* again. It lets you handle the signal the faster you
|
||||
* can, like in this window changed example. Of course, if
|
||||
* your signal handler doesn't call libssh at all, you're
|
||||
* free to handle signals directly in sighandler.
|
||||
*/
|
||||
do{
|
||||
FD_ZERO(&fds);
|
||||
if(!eof)
|
||||
FD_SET(0,&fds);
|
||||
timeout.tv_sec=30;
|
||||
timeout.tv_usec=0;
|
||||
FD_SET(ssh_get_fd(session),&fds);
|
||||
maxfd=ssh_get_fd(session)+1;
|
||||
ret=select(maxfd,&fds,NULL,NULL,&timeout);
|
||||
if(ret==EINTR)
|
||||
continue;
|
||||
if(FD_ISSET(0,&fds)){
|
||||
lus=read(0,buffer,sizeof(buffer));
|
||||
if(lus)
|
||||
channel_write(channel,buffer,lus);
|
||||
else {
|
||||
eof=1;
|
||||
channel_send_eof(channel);
|
||||
}
|
||||
}
|
||||
if(FD_ISSET(ssh_get_fd(session),&fds)){
|
||||
ssh_set_fd_toread(session);
|
||||
}
|
||||
channels[0]=channel; // set the first channel we want to read from
|
||||
channels[1]=NULL;
|
||||
ret=channel_select(channels,NULL,NULL,NULL); // no specific timeout - just poll
|
||||
if(signal_delayed)
|
||||
sizechanged();
|
||||
} while (ret==EINTR || ret==SSH_EINTR);
|
||||
|
||||
// we already looked for input from stdin. Now, we are looking for input from the channel
|
||||
|
||||
if(channel && channel_is_closed(channel)){
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
|
||||
channel_free(channel);
|
||||
channel=NULL;
|
||||
channels[0]=NULL;
|
||||
}
|
||||
if(channels[0]){
|
||||
while(channel && channel_is_open(channel) && channel_poll(channel,0)){
|
||||
lus=channel_read_buffer(channel,readbuf,0,0);
|
||||
if(lus==-1){
|
||||
fprintf(stderr, "Error reading channel: %s\n",
|
||||
ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
if(lus==0){
|
||||
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
|
||||
channel_free(channel);
|
||||
channel=channels[0]=NULL;
|
||||
} else
|
||||
write(1,buffer_get(readbuf),lus);
|
||||
}
|
||||
while(channel && channel_is_open(channel) && channel_poll(channel,1)){ /* stderr */
|
||||
lus=channel_read_buffer(channel,readbuf,0,1);
|
||||
if(lus==-1){
|
||||
fprintf(stderr, "Error reading channel: %s\n",
|
||||
ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
if(lus==0){
|
||||
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
channel_free(channel);
|
||||
channel=channels[0]=NULL;
|
||||
} else
|
||||
write(2,buffer_get(readbuf),lus);
|
||||
}
|
||||
}
|
||||
if(channel && channel_is_closed(channel)){
|
||||
channel_free(channel);
|
||||
channel=NULL;
|
||||
}
|
||||
}
|
||||
buffer_free(readbuf);
|
||||
}
|
||||
#else /* CHANNEL_SELECT */
|
||||
|
||||
static void select_loop(ssh_session session,ssh_channel channel){
|
||||
fd_set fds;
|
||||
struct timeval timeout;
|
||||
char buffer[4096];
|
||||
/* channels will be set to the channels to poll.
|
||||
* outchannels will contain the result of the poll
|
||||
*/
|
||||
ssh_channel channels[2], outchannels[2];
|
||||
int lus;
|
||||
int eof=0;
|
||||
int maxfd;
|
||||
int ret;
|
||||
while(channel){
|
||||
do{
|
||||
FD_ZERO(&fds);
|
||||
if(!eof)
|
||||
FD_SET(0,&fds);
|
||||
timeout.tv_sec=30;
|
||||
timeout.tv_usec=0;
|
||||
FD_SET(ssh_get_fd(session),&fds);
|
||||
maxfd=ssh_get_fd(session)+1;
|
||||
channels[0]=channel; // set the first channel we want to read from
|
||||
channels[1]=NULL;
|
||||
ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout);
|
||||
if(signal_delayed)
|
||||
sizechanged();
|
||||
if(ret==EINTR)
|
||||
continue;
|
||||
if(FD_ISSET(0,&fds)){
|
||||
lus=read(0,buffer,sizeof(buffer));
|
||||
if(lus)
|
||||
channel_write(channel,buffer,lus);
|
||||
else {
|
||||
eof=1;
|
||||
channel_send_eof(channel);
|
||||
}
|
||||
}
|
||||
if(channel && channel_is_closed(channel)){
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
|
||||
channel_free(channel);
|
||||
channel=NULL;
|
||||
channels[0]=NULL;
|
||||
}
|
||||
if(outchannels[0]){
|
||||
while(channel && channel_is_open(channel) && channel_poll(channel,0)){
|
||||
lus=channel_read(channel,buffer,sizeof(buffer),0);
|
||||
if(lus==-1){
|
||||
fprintf(stderr, "Error reading channel: %s\n",
|
||||
ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
if(lus==0){
|
||||
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
|
||||
channel_free(channel);
|
||||
channel=channels[0]=NULL;
|
||||
} else
|
||||
write(1,buffer,lus);
|
||||
}
|
||||
while(channel && channel_is_open(channel) && channel_poll(channel,1)){ /* stderr */
|
||||
lus=channel_read(channel,buffer,sizeof(buffer),1);
|
||||
if(lus==-1){
|
||||
fprintf(stderr, "Error reading channel: %s\n",
|
||||
ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
if(lus==0){
|
||||
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
channel_free(channel);
|
||||
channel=channels[0]=NULL;
|
||||
} else
|
||||
write(2,buffer,lus);
|
||||
}
|
||||
}
|
||||
if(channel && channel_is_closed(channel)){
|
||||
channel_free(channel);
|
||||
channel=NULL;
|
||||
}
|
||||
} while (ret==EINTR || ret==SSH_EINTR);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void shell(ssh_session session){
|
||||
ssh_channel channel;
|
||||
struct termios terminal_local;
|
||||
int interactive=isatty(0);
|
||||
channel = channel_new(session);
|
||||
if(interactive){
|
||||
tcgetattr(0,&terminal_local);
|
||||
memcpy(&terminal,&terminal_local,sizeof(struct termios));
|
||||
}
|
||||
if(channel_open_session(channel)){
|
||||
printf("error opening channel : %s\n",ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
chan=channel;
|
||||
if(interactive){
|
||||
channel_request_pty(channel);
|
||||
sizechanged();
|
||||
}
|
||||
if(channel_request_shell(channel)){
|
||||
printf("Requesting shell : %s\n",ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
if(interactive){
|
||||
cfmakeraw(&terminal_local);
|
||||
tcsetattr(0,TCSANOW,&terminal_local);
|
||||
setsignal();
|
||||
}
|
||||
signal(SIGTERM,do_cleanup);
|
||||
select_loop(session,channel);
|
||||
if(interactive)
|
||||
do_cleanup(0);
|
||||
}
|
||||
|
||||
static void batch_shell(ssh_session session){
|
||||
ssh_channel channel;
|
||||
char buffer[1024];
|
||||
int i,s=0;
|
||||
for(i=0;i<MAXCMD && cmds[i];++i)
|
||||
s+=snprintf(buffer+s,sizeof(buffer)-s,"%s ",cmds[i]);
|
||||
channel=channel_new(session);
|
||||
channel_open_session(channel);
|
||||
if(channel_request_exec(channel,buffer)){
|
||||
printf("error executing \"%s\" : %s\n",buffer,ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
select_loop(session,channel);
|
||||
}
|
||||
|
||||
static int client(ssh_session session){
|
||||
int auth=0;
|
||||
char *banner;
|
||||
int state;
|
||||
if (user)
|
||||
if (ssh_options_set(session, SSH_OPTIONS_USER, user) < 0)
|
||||
return -1;
|
||||
if (ssh_options_set(session, SSH_OPTIONS_HOST ,host) < 0)
|
||||
return -1;
|
||||
|
||||
ssh_options_parse_config(session, NULL);
|
||||
|
||||
if(ssh_connect(session)){
|
||||
fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session));
|
||||
return -1;
|
||||
}
|
||||
state=verify_knownhost(session);
|
||||
if (state != 0)
|
||||
return -1;
|
||||
ssh_userauth_none(session, NULL);
|
||||
banner=ssh_get_issue_banner(session);
|
||||
if(banner){
|
||||
printf("%s\n",banner);
|
||||
free(banner);
|
||||
}
|
||||
auth=authenticate_console(session);
|
||||
if(auth != SSH_AUTH_SUCCESS){
|
||||
return -1;
|
||||
}
|
||||
ssh_log(session, SSH_LOG_FUNCTIONS, "Authentication success");
|
||||
if(!cmds[0])
|
||||
shell(session);
|
||||
else
|
||||
batch_shell(session);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WITH_PCAP
|
||||
ssh_pcap_file pcap;
|
||||
void set_pcap(ssh_session session);
|
||||
void set_pcap(ssh_session session){
|
||||
if(!pcap_file)
|
||||
return;
|
||||
pcap=ssh_pcap_file_new();
|
||||
if(ssh_pcap_file_open(pcap,pcap_file) == SSH_ERROR){
|
||||
printf("Error opening pcap file\n");
|
||||
ssh_pcap_file_free(pcap);
|
||||
pcap=NULL;
|
||||
return;
|
||||
}
|
||||
ssh_set_pcap_file(session,pcap);
|
||||
}
|
||||
|
||||
void cleanup_pcap(void);
|
||||
void cleanup_pcap(){
|
||||
ssh_pcap_file_free(pcap);
|
||||
pcap=NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv){
|
||||
ssh_session session;
|
||||
|
||||
session = ssh_new();
|
||||
|
||||
ssh_callbacks_init(&cb);
|
||||
ssh_set_callbacks(session,&cb);
|
||||
|
||||
if(ssh_options_getopt(session, &argc, argv)) {
|
||||
fprintf(stderr, "error parsing command line :%s\n",
|
||||
ssh_get_error(session));
|
||||
usage();
|
||||
}
|
||||
opts(argc,argv);
|
||||
signal(SIGTERM, do_exit);
|
||||
#ifdef WITH_PCAP
|
||||
set_pcap(session);
|
||||
#endif
|
||||
client(session);
|
||||
|
||||
ssh_disconnect(session);
|
||||
ssh_free(session);
|
||||
#ifdef WITH_PCAP
|
||||
cleanup_pcap();
|
||||
#endif
|
||||
|
||||
ssh_finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
263
examples/samplesftp.c
Normal file
263
examples/samplesftp.c
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
Copyright 2003-2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
The goal is to show the API in action. It's not a reference on how terminal
|
||||
clients must be made or how a client should react.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include <libssh/sftp.h>
|
||||
|
||||
#include "examples_common.h"
|
||||
#ifdef WITH_SFTP
|
||||
|
||||
int verbosity;
|
||||
char *destination;
|
||||
|
||||
static void do_sftp(ssh_session session){
|
||||
sftp_session sftp=sftp_new(session);
|
||||
sftp_dir dir;
|
||||
sftp_attributes file;
|
||||
sftp_statvfs_t sftpstatvfs;
|
||||
struct statvfs sysstatvfs;
|
||||
sftp_file fichier;
|
||||
sftp_file to;
|
||||
int len=1;
|
||||
unsigned int i;
|
||||
char data[8000]={0};
|
||||
char *lnk;
|
||||
|
||||
unsigned int count;
|
||||
|
||||
if(!sftp){
|
||||
fprintf(stderr, "sftp error initialising channel: %s\n",
|
||||
ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
if(sftp_init(sftp)){
|
||||
fprintf(stderr, "error initialising sftp: %s\n",
|
||||
ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Additional SFTP extensions provided by the server:\n");
|
||||
count = sftp_extensions_get_count(sftp);
|
||||
for (i = 0; i < count; i++) {
|
||||
printf("\t%s, version: %s\n",
|
||||
sftp_extensions_get_name(sftp, i),
|
||||
sftp_extensions_get_data(sftp, i));
|
||||
}
|
||||
|
||||
/* test symlink and readlink */
|
||||
if (sftp_symlink(sftp, "/tmp/this_is_the_link",
|
||||
"/tmp/sftp_symlink_test") < 0) {
|
||||
fprintf(stderr, "Could not create link (%s)\n", ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
|
||||
lnk = sftp_readlink(sftp, "/tmp/sftp_symlink_test");
|
||||
if (lnk == NULL) {
|
||||
fprintf(stderr, "Could not read link (%s)\n", ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
printf("readlink /tmp/sftp_symlink_test: %s\n", lnk);
|
||||
|
||||
sftp_unlink(sftp, "/tmp/sftp_symlink_test");
|
||||
|
||||
if (sftp_extension_supported(sftp, "statvfs@openssh.com", "2")) {
|
||||
sftpstatvfs = sftp_statvfs(sftp, "/tmp");
|
||||
if (sftpstatvfs == NULL) {
|
||||
fprintf(stderr, "statvfs failed (%s)\n", ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
|
||||
printf("sftp statvfs:\n"
|
||||
"\tfile system block size: %llu\n"
|
||||
"\tfundamental fs block size: %llu\n"
|
||||
"\tnumber of blocks (unit f_frsize): %llu\n"
|
||||
"\tfree blocks in file system: %llu\n"
|
||||
"\tfree blocks for non-root: %llu\n"
|
||||
"\ttotal file inodes: %llu\n"
|
||||
"\tfree file inodes: %llu\n"
|
||||
"\tfree file inodes for to non-root: %llu\n"
|
||||
"\tfile system id: %llu\n"
|
||||
"\tbit mask of f_flag values: %llu\n"
|
||||
"\tmaximum filename length: %llu\n",
|
||||
(unsigned long long) sftpstatvfs->f_bsize,
|
||||
(unsigned long long) sftpstatvfs->f_frsize,
|
||||
(unsigned long long) sftpstatvfs->f_blocks,
|
||||
(unsigned long long) sftpstatvfs->f_bfree,
|
||||
(unsigned long long) sftpstatvfs->f_bavail,
|
||||
(unsigned long long) sftpstatvfs->f_files,
|
||||
(unsigned long long) sftpstatvfs->f_ffree,
|
||||
(unsigned long long) sftpstatvfs->f_favail,
|
||||
(unsigned long long) sftpstatvfs->f_fsid,
|
||||
(unsigned long long) sftpstatvfs->f_flag,
|
||||
(unsigned long long) sftpstatvfs->f_namemax);
|
||||
|
||||
sftp_statvfs_free(sftpstatvfs);
|
||||
|
||||
if (statvfs("/tmp", &sysstatvfs) < 0) {
|
||||
fprintf(stderr, "statvfs failed (%s)\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
printf("sys statvfs:\n"
|
||||
"\tfile system block size: %llu\n"
|
||||
"\tfundamental fs block size: %llu\n"
|
||||
"\tnumber of blocks (unit f_frsize): %llu\n"
|
||||
"\tfree blocks in file system: %llu\n"
|
||||
"\tfree blocks for non-root: %llu\n"
|
||||
"\ttotal file inodes: %llu\n"
|
||||
"\tfree file inodes: %llu\n"
|
||||
"\tfree file inodes for to non-root: %llu\n"
|
||||
"\tfile system id: %llu\n"
|
||||
"\tbit mask of f_flag values: %llu\n"
|
||||
"\tmaximum filename length: %llu\n",
|
||||
(unsigned long long) sysstatvfs.f_bsize,
|
||||
(unsigned long long) sysstatvfs.f_frsize,
|
||||
(unsigned long long) sysstatvfs.f_blocks,
|
||||
(unsigned long long) sysstatvfs.f_bfree,
|
||||
(unsigned long long) sysstatvfs.f_bavail,
|
||||
(unsigned long long) sysstatvfs.f_files,
|
||||
(unsigned long long) sysstatvfs.f_ffree,
|
||||
(unsigned long long) sysstatvfs.f_favail,
|
||||
(unsigned long long) sysstatvfs.f_fsid,
|
||||
(unsigned long long) sysstatvfs.f_flag,
|
||||
(unsigned long long) sysstatvfs.f_namemax);
|
||||
}
|
||||
|
||||
/* the connection is made */
|
||||
/* opening a directory */
|
||||
dir=sftp_opendir(sftp,"./");
|
||||
if(!dir) {
|
||||
fprintf(stderr, "Directory not opened(%s)\n", ssh_get_error(session));
|
||||
return ;
|
||||
}
|
||||
/* reading the whole directory, file by file */
|
||||
while((file=sftp_readdir(sftp,dir))){
|
||||
fprintf(stderr, "%30s(%.8o) : %.5d.%.5d : %.10llu bytes\n",
|
||||
file->name,
|
||||
file->permissions,
|
||||
file->uid,
|
||||
file->gid,
|
||||
(long long unsigned int) file->size);
|
||||
sftp_attributes_free(file);
|
||||
}
|
||||
/* when file=NULL, an error has occured OR the directory listing is end of file */
|
||||
if(!sftp_dir_eof(dir)){
|
||||
fprintf(stderr, "Error: %s\n", ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
if(sftp_closedir(dir)){
|
||||
fprintf(stderr, "Error: %s\n", ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
/* this will open a file and copy it into your /home directory */
|
||||
/* the small buffer size was intended to stress the library. of course, you can use a buffer till 20kbytes without problem */
|
||||
|
||||
fichier=sftp_open(sftp,"/usr/bin/ssh",O_RDONLY, 0);
|
||||
if(!fichier){
|
||||
fprintf(stderr, "Error opening /usr/bin/ssh: %s\n",
|
||||
ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
/* open a file for writing... */
|
||||
to=sftp_open(sftp,"ssh-copy",O_WRONLY | O_CREAT, 0700);
|
||||
if(!to){
|
||||
fprintf(stderr, "Error opening ssh-copy for writing: %s\n",
|
||||
ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
while((len=sftp_read(fichier,data,4096)) > 0){
|
||||
if(sftp_write(to,data,len)!=len){
|
||||
fprintf(stderr, "Error writing %d bytes: %s\n",
|
||||
len, ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("finished\n");
|
||||
if(len<0)
|
||||
fprintf(stderr, "Error reading file: %s\n", ssh_get_error(session));
|
||||
sftp_close(fichier);
|
||||
sftp_close(to);
|
||||
printf("fichiers ferm\n");
|
||||
to=sftp_open(sftp,"/tmp/grosfichier",O_WRONLY|O_CREAT, 0644);
|
||||
for(i=0;i<1000;++i){
|
||||
len=sftp_write(to,data,8000);
|
||||
printf("wrote %d bytes\n",len);
|
||||
if(len != 8000){
|
||||
printf("chunk %d : %d (%s)\n",i,len,ssh_get_error(session));
|
||||
}
|
||||
}
|
||||
sftp_close(to);
|
||||
|
||||
/* close the sftp session */
|
||||
sftp_free(sftp);
|
||||
printf("sftp session terminated\n");
|
||||
}
|
||||
|
||||
static void usage(const char *argv0){
|
||||
fprintf(stderr,"Usage : %s [-v] remotehost\n"
|
||||
"sample sftp test client - libssh-%s\n"
|
||||
"Options :\n"
|
||||
" -v : increase log verbosity\n",
|
||||
argv0,
|
||||
ssh_version(0));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int opts(int argc, char **argv){
|
||||
int i;
|
||||
while((i=getopt(argc,argv,"v"))!=-1){
|
||||
switch(i){
|
||||
case 'v':
|
||||
verbosity++;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"unknown option %c\n",optopt);
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
destination=argv[optind];
|
||||
if(destination == NULL){
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
ssh_session session;
|
||||
if(opts(argc,argv)<0)
|
||||
return EXIT_FAILURE;
|
||||
session=connect_ssh(destination,NULL,verbosity);
|
||||
if(session == NULL)
|
||||
return EXIT_FAILURE;
|
||||
do_sftp(session);
|
||||
ssh_disconnect(session);
|
||||
ssh_free(session);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
269
examples/samplesshd.c
Normal file
269
examples/samplesshd.c
Normal file
@@ -0,0 +1,269 @@
|
||||
/* This is a sample implementation of a libssh based SSH server */
|
||||
/*
|
||||
Copyright 2003-2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
The goal is to show the API in action. It's not a reference on how terminal
|
||||
clients must be made or how a client should react.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include <libssh/server.h>
|
||||
|
||||
#ifdef HAVE_ARGP_H
|
||||
#include <argp.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#ifndef KEYS_FOLDER
|
||||
#ifdef _WIN32
|
||||
#define KEYS_FOLDER
|
||||
#else
|
||||
#define KEYS_FOLDER "/etc/ssh/"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int auth_password(char *user, char *password){
|
||||
if(strcmp(user,"aris"))
|
||||
return 0;
|
||||
if(strcmp(password,"lala"))
|
||||
return 0;
|
||||
return 1; // authenticated
|
||||
}
|
||||
#ifdef HAVE_ARGP_H
|
||||
const char *argp_program_version = "libssh server example "
|
||||
SSH_STRINGIFY(LIBSSH_VERSION);
|
||||
const char *argp_program_bug_address = "<libssh@libssh.org>";
|
||||
|
||||
/* Program documentation. */
|
||||
static char doc[] = "libssh -- a Secure Shell protocol implementation";
|
||||
|
||||
/* A description of the arguments we accept. */
|
||||
static char args_doc[] = "BINDADDR";
|
||||
|
||||
/* The options we understand. */
|
||||
static struct argp_option options[] = {
|
||||
{
|
||||
.name = "port",
|
||||
.key = 'p',
|
||||
.arg = "PORT",
|
||||
.flags = 0,
|
||||
.doc = "Set the port to bind.",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "hostkey",
|
||||
.key = 'k',
|
||||
.arg = "FILE",
|
||||
.flags = 0,
|
||||
.doc = "Set the host key.",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "dsakey",
|
||||
.key = 'd',
|
||||
.arg = "FILE",
|
||||
.flags = 0,
|
||||
.doc = "Set the dsa key.",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "rsakey",
|
||||
.key = 'r',
|
||||
.arg = "FILE",
|
||||
.flags = 0,
|
||||
.doc = "Set the rsa key.",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "verbose",
|
||||
.key = 'v',
|
||||
.arg = NULL,
|
||||
.flags = 0,
|
||||
.doc = "Get verbose output.",
|
||||
.group = 0
|
||||
},
|
||||
{NULL, 0, 0, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* Parse a single option. */
|
||||
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
||||
/* Get the input argument from argp_parse, which we
|
||||
* know is a pointer to our arguments structure.
|
||||
*/
|
||||
ssh_bind sshbind = state->input;
|
||||
|
||||
switch (key) {
|
||||
case 'p':
|
||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, arg);
|
||||
break;
|
||||
case 'd':
|
||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, arg);
|
||||
break;
|
||||
case 'k':
|
||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
|
||||
break;
|
||||
case 'r':
|
||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
|
||||
break;
|
||||
case 'v':
|
||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
if (state->arg_num >= 1) {
|
||||
/* Too many arguments. */
|
||||
argp_usage (state);
|
||||
}
|
||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, arg);
|
||||
break;
|
||||
case ARGP_KEY_END:
|
||||
if (state->arg_num < 1) {
|
||||
/* Not enough arguments. */
|
||||
argp_usage (state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Our argp parser. */
|
||||
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
|
||||
#endif /* HAVE_ARGP_H */
|
||||
|
||||
int main(int argc, char **argv){
|
||||
ssh_session session;
|
||||
ssh_bind sshbind;
|
||||
ssh_message message;
|
||||
ssh_channel chan=0;
|
||||
ssh_buffer buf;
|
||||
int auth=0;
|
||||
int sftp=0;
|
||||
int i;
|
||||
int r;
|
||||
|
||||
sshbind=ssh_bind_new();
|
||||
session=ssh_new();
|
||||
|
||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, KEYS_FOLDER "ssh_host_dsa_key");
|
||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_key");
|
||||
|
||||
#ifdef HAVE_ARGP_H
|
||||
/*
|
||||
* Parse our arguments; every option seen by parse_opt will
|
||||
* be reflected in arguments.
|
||||
*/
|
||||
argp_parse (&argp, argc, argv, 0, 0, sshbind);
|
||||
#endif
|
||||
if(ssh_bind_listen(sshbind)<0){
|
||||
printf("Error listening to socket: %s\n",ssh_get_error(sshbind));
|
||||
return 1;
|
||||
}
|
||||
r=ssh_bind_accept(sshbind,session);
|
||||
if(r==SSH_ERROR){
|
||||
printf("error accepting a connection : %s\n",ssh_get_error(sshbind));
|
||||
return 1;
|
||||
}
|
||||
if(ssh_accept(session)){
|
||||
printf("ssh_accept: %s\n",ssh_get_error(session));
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
message=ssh_message_get(session);
|
||||
if(!message)
|
||||
break;
|
||||
switch(ssh_message_type(message)){
|
||||
case SSH_REQUEST_AUTH:
|
||||
switch(ssh_message_subtype(message)){
|
||||
case SSH_AUTH_METHOD_PASSWORD:
|
||||
printf("User %s wants to auth with pass %s\n",
|
||||
ssh_message_auth_user(message),
|
||||
ssh_message_auth_password(message));
|
||||
if(auth_password(ssh_message_auth_user(message),
|
||||
ssh_message_auth_password(message))){
|
||||
auth=1;
|
||||
ssh_message_auth_reply_success(message,0);
|
||||
break;
|
||||
}
|
||||
// not authenticated, send default message
|
||||
case SSH_AUTH_METHOD_NONE:
|
||||
default:
|
||||
ssh_message_auth_set_methods(message,SSH_AUTH_METHOD_PASSWORD);
|
||||
ssh_message_reply_default(message);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ssh_message_reply_default(message);
|
||||
}
|
||||
ssh_message_free(message);
|
||||
} while (!auth);
|
||||
if(!auth){
|
||||
printf("auth error: %s\n",ssh_get_error(session));
|
||||
ssh_disconnect(session);
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
message=ssh_message_get(session);
|
||||
if(message){
|
||||
switch(ssh_message_type(message)){
|
||||
case SSH_REQUEST_CHANNEL_OPEN:
|
||||
if(ssh_message_subtype(message)==SSH_CHANNEL_SESSION){
|
||||
chan=ssh_message_channel_request_open_reply_accept(message);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ssh_message_reply_default(message);
|
||||
}
|
||||
ssh_message_free(message);
|
||||
}
|
||||
} while(message && !chan);
|
||||
if(!chan){
|
||||
printf("error : %s\n",ssh_get_error(session));
|
||||
ssh_finalize();
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
message=ssh_message_get(session);
|
||||
if(message && ssh_message_type(message)==SSH_REQUEST_CHANNEL &&
|
||||
ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_SHELL){
|
||||
// if(!strcmp(ssh_message_channel_request_subsystem(message),"sftp")){
|
||||
sftp=1;
|
||||
ssh_message_channel_request_reply_success(message);
|
||||
break;
|
||||
// }
|
||||
}
|
||||
if(!sftp){
|
||||
ssh_message_reply_default(message);
|
||||
}
|
||||
ssh_message_free(message);
|
||||
} while (message && !sftp);
|
||||
if(!sftp){
|
||||
printf("error : %s\n",ssh_get_error(session));
|
||||
return 1;
|
||||
}
|
||||
printf("it works !\n");
|
||||
buf=buffer_new();
|
||||
do{
|
||||
i=channel_read_buffer(chan,buf,0,0);
|
||||
if(i>0)
|
||||
write(1,buffer_get(buf),buffer_get_len(buf));
|
||||
} while (i>0);
|
||||
buffer_free(buf);
|
||||
ssh_disconnect(session);
|
||||
ssh_bind_free(sshbind);
|
||||
ssh_finalize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
149
examples/scp_download.c
Normal file
149
examples/scp_download.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/* scp_download.c
|
||||
* Sample implementation of a tiny SCP downloader client
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2009 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
You are free to copy this file, modify it in any way, consider it being public
|
||||
domain. This does not apply to the rest of the library though, but it is
|
||||
allowed to cut-and-paste working code from this file to any license of
|
||||
program.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include "examples_common.h"
|
||||
|
||||
int verbosity=0;
|
||||
const char *createcommand="rm -fr /tmp/libssh_tests && mkdir /tmp/libssh_tests && cd /tmp/libssh_tests && date > a && date > b && mkdir c && date > d";
|
||||
char *host=NULL;
|
||||
static void usage(const char *argv0){
|
||||
fprintf(stderr,"Usage : %s [options] host\n"
|
||||
"sample tiny scp downloader client - libssh-%s\n"
|
||||
"This program will create files in /tmp and try to fetch them\n",
|
||||
// "Options :\n",
|
||||
// " -r : use RSA to verify host public key\n",
|
||||
argv0,
|
||||
ssh_version(0));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int opts(int argc, char **argv){
|
||||
int i;
|
||||
while((i=getopt(argc,argv,"v"))!=-1){
|
||||
switch(i){
|
||||
case 'v':
|
||||
verbosity++;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"unknown option %c\n",optopt);
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
host = argv[optind];
|
||||
if(host == NULL)
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void create_files(ssh_session session){
|
||||
ssh_channel channel=channel_new(session);
|
||||
char buffer[1];
|
||||
if(channel == NULL){
|
||||
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(channel_open_session(channel) != SSH_OK){
|
||||
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(channel_request_exec(channel,createcommand) != SSH_OK){
|
||||
fprintf(stderr,"Error executing command: %s\n",ssh_get_error(session));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while(!channel_is_eof(channel)){
|
||||
channel_read(channel,buffer,1,1);
|
||||
write(1,buffer,1);
|
||||
}
|
||||
channel_close(channel);
|
||||
channel_free(channel);
|
||||
}
|
||||
|
||||
|
||||
static int fetch_files(ssh_session session){
|
||||
int size;
|
||||
char buffer[16384];
|
||||
int mode;
|
||||
char *filename;
|
||||
int r;
|
||||
ssh_scp scp=ssh_scp_new(session, SSH_SCP_READ | SSH_SCP_RECURSIVE, "/tmp/libssh_tests/*");
|
||||
if(ssh_scp_init(scp) != SSH_OK){
|
||||
fprintf(stderr,"error initializing scp: %s\n",ssh_get_error(session));
|
||||
return -1;
|
||||
}
|
||||
printf("Trying to download 3 files (a,b,d) and 1 directory (c)\n");
|
||||
do {
|
||||
|
||||
r=ssh_scp_pull_request(scp);
|
||||
switch(r){
|
||||
case SSH_SCP_REQUEST_NEWFILE:
|
||||
size=ssh_scp_request_get_size(scp);
|
||||
filename=strdup(ssh_scp_request_get_filename(scp));
|
||||
mode=ssh_scp_request_get_permissions(scp);
|
||||
printf("downloading file %s, size %d, perms 0%o\n",filename,size,mode);
|
||||
free(filename);
|
||||
ssh_scp_accept_request(scp);
|
||||
r=ssh_scp_read(scp,buffer,sizeof(buffer));
|
||||
if(r==SSH_ERROR){
|
||||
fprintf(stderr,"Error reading scp: %s\n",ssh_get_error(session));
|
||||
return -1;
|
||||
}
|
||||
printf("done\n");
|
||||
break;
|
||||
case SSH_ERROR:
|
||||
fprintf(stderr,"Error: %s\n",ssh_get_error(session));
|
||||
return -1;
|
||||
case SSH_SCP_REQUEST_WARNING:
|
||||
fprintf(stderr,"Warning: %s\n",ssh_scp_request_get_warning(scp));
|
||||
break;
|
||||
case SSH_SCP_REQUEST_NEWDIR:
|
||||
filename=strdup(ssh_scp_request_get_filename(scp));
|
||||
mode=ssh_scp_request_get_permissions(scp);
|
||||
printf("downloading directory %s, perms 0%o\n",filename,mode);
|
||||
free(filename);
|
||||
ssh_scp_accept_request(scp);
|
||||
break;
|
||||
case SSH_SCP_REQUEST_ENDDIR:
|
||||
printf("End of directory\n");
|
||||
break;
|
||||
case SSH_SCP_REQUEST_EOF:
|
||||
printf("End of requests\n");
|
||||
goto end;
|
||||
}
|
||||
} while (1);
|
||||
end:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
ssh_session session;
|
||||
if(opts(argc,argv)<0)
|
||||
return EXIT_FAILURE;
|
||||
session=connect_ssh(host,NULL,verbosity);
|
||||
if(session == NULL)
|
||||
return EXIT_FAILURE;
|
||||
create_files(session);
|
||||
fetch_files(session);
|
||||
ssh_disconnect(session);
|
||||
ssh_finalize();
|
||||
return 0;
|
||||
}
|
||||
3
include/CMakeLists.txt
Normal file
3
include/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
project(headers C)
|
||||
|
||||
add_subdirectory(libssh)
|
||||
@@ -1 +0,0 @@
|
||||
SUBDIRS = libssh
|
||||
38
include/libssh/CMakeLists.txt
Normal file
38
include/libssh/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
project(libssh-headers C)
|
||||
|
||||
set(libssh_HDRS
|
||||
callbacks.h
|
||||
libssh.h
|
||||
ssh2.h
|
||||
)
|
||||
|
||||
if (WITH_SFTP)
|
||||
set(libssh_HDRS
|
||||
${libssh_HDRS}
|
||||
sftp.h
|
||||
)
|
||||
endif (WITH_SFTP)
|
||||
|
||||
if (WITH_SSH1)
|
||||
set(libssh_HDRS
|
||||
${libssh_HDRS}
|
||||
ssh1.h
|
||||
)
|
||||
endif (WITH_SSH1)
|
||||
|
||||
if (WITH_SERVER)
|
||||
set(libssh_HDRS
|
||||
${libssh_HDRS}
|
||||
server.h
|
||||
)
|
||||
endif (WITH_SERVER)
|
||||
|
||||
install(
|
||||
FILES
|
||||
${libssh_HDRS}
|
||||
DESTINATION
|
||||
${INCLUDE_INSTALL_DIR}/${APPLICATION_NAME}
|
||||
COMPONENT
|
||||
headers
|
||||
)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
libsshdir = $(includedir)/libssh
|
||||
libssh_HEADERS = crypto.h libssh.h priv.h server.h sftp.h ssh1.h ssh2.h
|
||||
nodist_libssh_HEADERS = config.h
|
||||
|
||||
config.h:
|
||||
$(LN_S) $(top_builddir)/config.h ./config.h
|
||||
|
||||
DISTCLEANFILES = config.h
|
||||
97
include/libssh/agent.h
Normal file
97
include/libssh/agent.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef __AGENT_H
|
||||
#define __AGENT_H
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
/* Messages for the authentication agent connection. */
|
||||
#define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1
|
||||
#define SSH_AGENT_RSA_IDENTITIES_ANSWER 2
|
||||
#define SSH_AGENTC_RSA_CHALLENGE 3
|
||||
#define SSH_AGENT_RSA_RESPONSE 4
|
||||
#define SSH_AGENT_FAILURE 5
|
||||
#define SSH_AGENT_SUCCESS 6
|
||||
#define SSH_AGENTC_ADD_RSA_IDENTITY 7
|
||||
#define SSH_AGENTC_REMOVE_RSA_IDENTITY 8
|
||||
#define SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9
|
||||
|
||||
/* private OpenSSH extensions for SSH2 */
|
||||
#define SSH2_AGENTC_REQUEST_IDENTITIES 11
|
||||
#define SSH2_AGENT_IDENTITIES_ANSWER 12
|
||||
#define SSH2_AGENTC_SIGN_REQUEST 13
|
||||
#define SSH2_AGENT_SIGN_RESPONSE 14
|
||||
#define SSH2_AGENTC_ADD_IDENTITY 17
|
||||
#define SSH2_AGENTC_REMOVE_IDENTITY 18
|
||||
#define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19
|
||||
|
||||
/* smartcard */
|
||||
#define SSH_AGENTC_ADD_SMARTCARD_KEY 20
|
||||
#define SSH_AGENTC_REMOVE_SMARTCARD_KEY 21
|
||||
|
||||
/* lock/unlock the agent */
|
||||
#define SSH_AGENTC_LOCK 22
|
||||
#define SSH_AGENTC_UNLOCK 23
|
||||
|
||||
/* add key with constraints */
|
||||
#define SSH_AGENTC_ADD_RSA_ID_CONSTRAINED 24
|
||||
#define SSH2_AGENTC_ADD_ID_CONSTRAINED 25
|
||||
#define SSH_AGENTC_ADD_SMARTCARD_KEY_CONSTRAINED 26
|
||||
|
||||
#define SSH_AGENT_CONSTRAIN_LIFETIME 1
|
||||
#define SSH_AGENT_CONSTRAIN_CONFIRM 2
|
||||
|
||||
/* extended failure messages */
|
||||
#define SSH2_AGENT_FAILURE 30
|
||||
|
||||
/* additional error code for ssh.com's ssh-agent2 */
|
||||
#define SSH_COM_AGENT2_FAILURE 102
|
||||
|
||||
#define SSH_AGENT_OLD_SIGNATURE 0x01
|
||||
|
||||
struct ssh_agent_struct {
|
||||
struct socket *sock;
|
||||
ssh_buffer ident;
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
#ifndef _WIN32
|
||||
/* agent.c */
|
||||
/**
|
||||
* @brief Create a new ssh agent structure.
|
||||
*
|
||||
* @return An allocated ssh agent structure or NULL on error.
|
||||
*/
|
||||
struct ssh_agent_struct *agent_new(struct ssh_session_struct *session);
|
||||
|
||||
void agent_close(struct ssh_agent_struct *agent);
|
||||
|
||||
/**
|
||||
* @brief Free an allocated ssh agent structure.
|
||||
*
|
||||
* @param agent The ssh agent structure to free.
|
||||
*/
|
||||
void agent_free(struct ssh_agent_struct *agent);
|
||||
|
||||
/**
|
||||
* @brief Check if the ssh agent is running.
|
||||
*
|
||||
* @param session The ssh session to check for the agent.
|
||||
*
|
||||
* @return 1 if it is running, 0 if not.
|
||||
*/
|
||||
int agent_is_running(struct ssh_session_struct *session);
|
||||
|
||||
int agent_get_ident_count(struct ssh_session_struct *session);
|
||||
|
||||
struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *session,
|
||||
char **comment);
|
||||
|
||||
struct ssh_public_key_struct *agent_get_first_ident(struct ssh_session_struct *session,
|
||||
char **comment);
|
||||
|
||||
ssh_string agent_sign_data(struct ssh_session_struct *session,
|
||||
struct ssh_buffer_struct *data,
|
||||
struct ssh_public_key_struct *pubkey);
|
||||
#endif
|
||||
|
||||
#endif /* __AGENT_H */
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
62
include/libssh/buffer.h
Normal file
62
include/libssh/buffer.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef BUFFER_H_
|
||||
#define BUFFER_H_
|
||||
|
||||
/* Describes a buffer state */
|
||||
struct ssh_buffer_struct {
|
||||
char *data;
|
||||
uint32_t used;
|
||||
uint32_t allocated;
|
||||
uint32_t pos;
|
||||
};
|
||||
|
||||
int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
|
||||
int buffer_add_u8(ssh_buffer buffer, uint8_t data);
|
||||
int buffer_add_u16(ssh_buffer buffer, uint16_t data);
|
||||
int buffer_add_u32(ssh_buffer buffer, uint32_t data);
|
||||
int buffer_add_u64(ssh_buffer buffer, uint64_t data);
|
||||
int buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
|
||||
int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
|
||||
int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
|
||||
int buffer_reinit(ssh_buffer buffer);
|
||||
|
||||
/* buffer_get_rest returns a pointer to the current position into the buffer */
|
||||
void *buffer_get_rest(ssh_buffer buffer);
|
||||
/* buffer_get_rest_len returns the number of bytes which can be read */
|
||||
uint32_t buffer_get_rest_len(ssh_buffer buffer);
|
||||
|
||||
/* buffer_read_*() returns the number of bytes read, except for ssh strings */
|
||||
int buffer_get_u8(ssh_buffer buffer, uint8_t *data);
|
||||
int buffer_get_u32(ssh_buffer buffer, uint32_t *data);
|
||||
int buffer_get_u64(ssh_buffer buffer, uint64_t *data);
|
||||
|
||||
uint32_t buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
|
||||
/* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
|
||||
ssh_string buffer_get_ssh_string(ssh_buffer buffer);
|
||||
/* gets a string out of a SSH-1 mpint */
|
||||
ssh_string buffer_get_mpint(ssh_buffer buffer);
|
||||
/* buffer_pass_bytes acts as if len bytes have been read (used for padding) */
|
||||
uint32_t buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
|
||||
uint32_t buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
|
||||
|
||||
#endif /* BUFFER_H_ */
|
||||
113
include/libssh/callbacks.h
Normal file
113
include/libssh/callbacks.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be>
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* callback.h
|
||||
* This file includes the public declarations for the libssh callback mechanism
|
||||
*/
|
||||
|
||||
#ifndef _SSH_CALLBACK_H
|
||||
#define _SSH_CALLBACK_H
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SSH authentication callback.
|
||||
*
|
||||
* @param prompt Prompt to be displayed.
|
||||
* @param buf Buffer to save the password. You should null-terminate it.
|
||||
* @param len Length of the buffer.
|
||||
* @param echo Enable or disable the echo of what you type.
|
||||
* @param verify Should the password be verified?
|
||||
* @param userdata Userdata to be passed to the callback function. Useful
|
||||
* for GUI applications.
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
|
||||
int echo, int verify, void *userdata);
|
||||
typedef void (*ssh_log_callback) (ssh_session session, int priority,
|
||||
const char *message, void *userdata);
|
||||
/** this callback will be called with status going from 0.0 to 1.0 during
|
||||
* connection */
|
||||
typedef void (*ssh_status_callback) (ssh_session session, float status,
|
||||
void *userdata);
|
||||
|
||||
struct ssh_callbacks_struct {
|
||||
/** size of this structure. internal, shoud be set with ssh_callbacks_init()*/
|
||||
size_t size;
|
||||
/** User-provided data. User is free to set anything he wants here */
|
||||
void *userdata;
|
||||
/** this functions will be called if e.g. a keyphrase is needed. */
|
||||
ssh_auth_callback auth_function;
|
||||
/** this function will be called each time a loggable event happens. */
|
||||
ssh_log_callback log_function;
|
||||
/** this function gets called during connection time to indicate the percentage
|
||||
* of connection steps completed.
|
||||
*/
|
||||
void (*connect_status_function)(void *userdata, float status);
|
||||
};
|
||||
|
||||
typedef struct ssh_callbacks_struct * ssh_callbacks;
|
||||
|
||||
/** Initializes an ssh_callbacks_struct
|
||||
* A call to this macro is mandatory when you have set a new
|
||||
* ssh_callback_struct structure. Its goal is to maintain the binary
|
||||
* compatibility with future versions of libssh as the structure
|
||||
* evolves with time.
|
||||
*/
|
||||
#define ssh_callbacks_init(p) do {\
|
||||
(p)->size=sizeof(*(p)); \
|
||||
} while(0);
|
||||
|
||||
/**
|
||||
* @brief Set the callback functions.
|
||||
*
|
||||
* This functions sets the callback structure to use your own callback
|
||||
* functions for auth, logging and status.
|
||||
*
|
||||
* @code
|
||||
* struct ssh_callbacks_struct cb;
|
||||
* memset(&cb, 0, sizeof(struct ssh_callbacks_struct));
|
||||
* cb.userdata = data;
|
||||
* cb.auth_function = my_auth_function;
|
||||
*
|
||||
* ssh_callbacks_init(&cb);
|
||||
* ssh_set_callbacks(session, &cb);
|
||||
* @endcode
|
||||
*
|
||||
* @param session The session to set the callback structure.
|
||||
*
|
||||
* @param cb The callback itself.
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_SSH_CALLBACK_H */
|
||||
58
include/libssh/channels.h
Normal file
58
include/libssh/channels.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef CHANNELS_H_
|
||||
#define CHANNELS_H_
|
||||
#include "libssh/priv.h"
|
||||
|
||||
struct ssh_channel_struct {
|
||||
struct ssh_channel_struct *prev;
|
||||
struct ssh_channel_struct *next;
|
||||
ssh_session session; /* SSH_SESSION pointer */
|
||||
uint32_t local_channel;
|
||||
uint32_t local_window;
|
||||
int local_eof;
|
||||
uint32_t local_maxpacket;
|
||||
|
||||
uint32_t remote_channel;
|
||||
uint32_t remote_window;
|
||||
int remote_eof; /* end of file received */
|
||||
uint32_t remote_maxpacket;
|
||||
int open; /* shows if the channel is still opened */
|
||||
int delayed_close;
|
||||
ssh_buffer stdout_buffer;
|
||||
ssh_buffer stderr_buffer;
|
||||
void *userarg;
|
||||
int version;
|
||||
int blocking;
|
||||
int exit_status;
|
||||
};
|
||||
|
||||
void channel_handle(ssh_session session, int type);
|
||||
ssh_channel channel_new(ssh_session session);
|
||||
int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
||||
int is_stderr);
|
||||
uint32_t ssh_channel_new_id(ssh_session session);
|
||||
ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id);
|
||||
int channel_write_common(ssh_channel channel, const void *data,
|
||||
uint32_t len, int is_stderr);
|
||||
|
||||
#endif /* CHANNELS_H_ */
|
||||
@@ -1,44 +1,69 @@
|
||||
/*
|
||||
Copyright 2003 Aris Adamantiadis
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2003,2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
This file is part of the SSH Library
|
||||
/*
|
||||
* crypto.h is an include file for internal cryptographic structures of libssh
|
||||
*/
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
#ifndef _CRYPTO_H_
|
||||
#define _CRYPTO_H_
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
#include "config.h"
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
|
||||
/* Crypto.h is an include file for internal structures of libssh */
|
||||
/* It hasn't to be into the final development set of files (and btw the filename would cause problems on most systems) */
|
||||
/* Openssl has (really) stupid defines */
|
||||
#ifdef set_key
|
||||
#undef set_key
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
#include <gcrypt.h>
|
||||
#endif
|
||||
#include "libssh/wrapper.h"
|
||||
|
||||
#ifdef cbc_encrypt
|
||||
#undef cbc_encrypt
|
||||
#endif
|
||||
#ifdef cbc_decrypt
|
||||
#undef cbc_decrypt
|
||||
#endif
|
||||
#ifdef des_set_key
|
||||
#undef des_set_key
|
||||
#endif
|
||||
#ifdef GCRYPT
|
||||
#include <gcrypt.h>
|
||||
#endif
|
||||
|
||||
struct ssh_crypto_struct {
|
||||
bignum e,f,x,k,y;
|
||||
unsigned char session_id[SHA_DIGEST_LEN];
|
||||
|
||||
unsigned char encryptIV[SHA_DIGEST_LEN*2];
|
||||
unsigned char decryptIV[SHA_DIGEST_LEN*2];
|
||||
|
||||
unsigned char decryptkey[SHA_DIGEST_LEN*2];
|
||||
unsigned char encryptkey[SHA_DIGEST_LEN*2];
|
||||
|
||||
unsigned char encryptMAC[SHA_DIGEST_LEN];
|
||||
unsigned char decryptMAC[SHA_DIGEST_LEN];
|
||||
unsigned char hmacbuf[EVP_MAX_MD_SIZE];
|
||||
struct crypto_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
|
||||
ssh_string server_pubkey;
|
||||
const char *server_pubkey_type;
|
||||
int do_compress_out; /* idem */
|
||||
int do_compress_in; /* don't set them, set the option instead */
|
||||
void *compress_out_ctx; /* don't touch it */
|
||||
void *compress_in_ctx; /* really, don't */
|
||||
};
|
||||
|
||||
struct crypto_struct {
|
||||
char *name; /* ssh name of the algorithm */
|
||||
const char *name; /* ssh name of the algorithm */
|
||||
unsigned int blocksize; /* blocksize of the algo */
|
||||
unsigned int keylen; /* length of the key structure */
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
@@ -48,15 +73,23 @@ struct crypto_struct {
|
||||
#endif
|
||||
unsigned int keysize; /* bytes of key used. != keylen */
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
void (*set_encrypt_key)(struct crypto_struct *cipher, void *key, void *IV); /* sets the new key for immediate use */
|
||||
void (*set_decrypt_key)(struct crypto_struct *cipher, void *key, void *IV);
|
||||
void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out,unsigned long len);
|
||||
void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out,unsigned long len);
|
||||
/* sets the new key for immediate use */
|
||||
int (*set_encrypt_key)(struct crypto_struct *cipher, void *key, void *IV);
|
||||
int (*set_decrypt_key)(struct crypto_struct *cipher, void *key, void *IV);
|
||||
void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out,
|
||||
unsigned long len);
|
||||
void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out,
|
||||
unsigned long len);
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
void (*set_encrypt_key)(struct crypto_struct *cipher, void *key); /* sets the new key for immediate use */
|
||||
void (*set_decrypt_key)(struct crypto_struct *cipher, void *key);
|
||||
void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out,unsigned long len,void *IV);
|
||||
void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out,unsigned long len,void *IV);
|
||||
/* sets the new key for immediate use */
|
||||
int (*set_encrypt_key)(struct crypto_struct *cipher, void *key);
|
||||
int (*set_decrypt_key)(struct crypto_struct *cipher, void *key);
|
||||
void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out,
|
||||
unsigned long len, void *IV);
|
||||
void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out,
|
||||
unsigned long len, void *IV);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
#endif /* _CRYPTO_H_ */
|
||||
|
||||
57
include/libssh/dh.h
Normal file
57
include/libssh/dh.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef DH_H_
|
||||
#define DH_H_
|
||||
#include "config.h"
|
||||
|
||||
/* DH key generation */
|
||||
#include "libssh/keys.h"
|
||||
|
||||
void ssh_print_bignum(const char *which,bignum num);
|
||||
int dh_generate_e(ssh_session session);
|
||||
int dh_generate_f(ssh_session session);
|
||||
int dh_generate_x(ssh_session session);
|
||||
int dh_generate_y(ssh_session session);
|
||||
|
||||
int ssh_crypto_init(void);
|
||||
void ssh_crypto_finalize(void);
|
||||
|
||||
ssh_string dh_get_e(ssh_session session);
|
||||
ssh_string dh_get_f(ssh_session session);
|
||||
int dh_import_f(ssh_session session,ssh_string f_string);
|
||||
int dh_import_e(ssh_session session, ssh_string e_string);
|
||||
void dh_import_pubkey(ssh_session session,ssh_string pubkey_string);
|
||||
int dh_build_k(ssh_session session);
|
||||
int make_sessionid(ssh_session session);
|
||||
/* add data for the final cookie */
|
||||
int hashbufin_add_cookie(ssh_session session, unsigned char *cookie);
|
||||
int hashbufout_add_cookie(ssh_session session);
|
||||
int generate_session_keys(ssh_session session);
|
||||
int sig_verify(ssh_session session, ssh_public_key pubkey,
|
||||
SIGNATURE *signature, unsigned char *digest, int size);
|
||||
/* returns 1 if server signature ok, 0 otherwise. The NEXT crypto is checked, not the current one */
|
||||
int signature_verify(ssh_session session,ssh_string signature);
|
||||
bignum make_string_bn(ssh_string string);
|
||||
ssh_string make_bignum_string(bignum num);
|
||||
|
||||
|
||||
#endif /* DH_H_ */
|
||||
33
include/libssh/keyfiles.h
Normal file
33
include/libssh/keyfiles.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef KEYFILES_H_
|
||||
#define KEYFILES_H_
|
||||
|
||||
/* in keyfiles.c */
|
||||
|
||||
ssh_private_key _privatekey_from_file(void *session, const char *filename,
|
||||
int type);
|
||||
ssh_string try_publickey_from_file(ssh_session session,
|
||||
struct ssh_keys_struct keytab,
|
||||
char **privkeyfile, int *type);
|
||||
|
||||
#endif /* KEYFILES_H_ */
|
||||
84
include/libssh/keys.h
Normal file
84
include/libssh/keys.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef KEYS_H_
|
||||
#define KEYS_H_
|
||||
|
||||
#include "config.h"
|
||||
#include "libssh/libssh.h"
|
||||
#include "libssh/wrapper.h"
|
||||
|
||||
struct ssh_public_key_struct {
|
||||
int type;
|
||||
const char *type_c; /* Don't free it ! it is static */
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_t dsa_pub;
|
||||
gcry_sexp_t rsa_pub;
|
||||
#elif HAVE_LIBCRYPTO
|
||||
DSA *dsa_pub;
|
||||
RSA *rsa_pub;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct ssh_private_key_struct {
|
||||
int type;
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_t dsa_priv;
|
||||
gcry_sexp_t rsa_priv;
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
DSA *dsa_priv;
|
||||
RSA *rsa_priv;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct signature_struct {
|
||||
int type;
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_t dsa_sign;
|
||||
gcry_sexp_t rsa_sign;
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
DSA_SIG *dsa_sign;
|
||||
ssh_string rsa_sign;
|
||||
#endif
|
||||
} SIGNATURE;
|
||||
|
||||
const char *ssh_type_to_char(int type);
|
||||
int ssh_type_from_name(const char *name);
|
||||
ssh_buffer ssh_userauth_build_digest(ssh_session session, ssh_message msg, char *service);
|
||||
|
||||
ssh_private_key privatekey_make_dss(ssh_session session, ssh_buffer buffer);
|
||||
ssh_private_key privatekey_make_rsa(ssh_session session, ssh_buffer buffer,
|
||||
const char *type);
|
||||
ssh_private_key privatekey_from_string(ssh_session session, ssh_string privkey_s);
|
||||
|
||||
ssh_public_key publickey_make_dss(ssh_session session, ssh_buffer buffer);
|
||||
ssh_public_key publickey_make_rsa(ssh_session session, ssh_buffer buffer, int type);
|
||||
ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s);
|
||||
SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,ssh_public_key pubkey,int needed_type);
|
||||
void signature_free(SIGNATURE *sign);
|
||||
ssh_string ssh_do_sign_with_agent(struct ssh_session_struct *session,
|
||||
struct ssh_buffer_struct *buf, struct ssh_public_key_struct *publickey);
|
||||
ssh_string ssh_do_sign(ssh_session session,ssh_buffer sigbuf,
|
||||
ssh_private_key privatekey);
|
||||
ssh_string ssh_sign_session_id(ssh_session session, ssh_private_key privatekey);
|
||||
ssh_string ssh_encrypt_rsa1(ssh_session session, ssh_string data, ssh_public_key key);
|
||||
|
||||
#endif /* KEYS_H_ */
|
||||
@@ -1,65 +1,121 @@
|
||||
/*
|
||||
Copyright (c) 2003-2008 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2003-2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _LIBSSH_H
|
||||
#define _LIBSSH_H
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifdef LIBSSH_STATIC
|
||||
#define LIBSSH_API
|
||||
#else
|
||||
//visual studio hasn't inttypes.h so it doesn't know uint32_t
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
#ifdef LIBSSH_EXPORTS
|
||||
#ifdef __GNUC__
|
||||
#define LIBSSH_API __attribute__((dllexport))
|
||||
#else
|
||||
#define LIBSSH_API __declspec(dllexport)
|
||||
#endif
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
#define LIBSSH_API __attribute__((dllimport))
|
||||
#else
|
||||
#define LIBSSH_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if __GNUC__ >= 4
|
||||
#define LIBSSH_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define LIBSSH_API
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* Visual Studio hasn't inttypes.h so it doesn't know uint32_t */
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef int mode_t;
|
||||
#else /* _MSC_VER */
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#include <sys/select.h> /* for fd_set * */
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <winsock2.h>
|
||||
#else /* _WIN32 */
|
||||
#include <sys/select.h> /* for fd_set * */
|
||||
#include <netdb.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#define SSH_STRINGIFY(s) SSH_TOSTRING(s)
|
||||
#define SSH_TOSTRING(s) #s
|
||||
|
||||
/* libssh version macros */
|
||||
#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
|
||||
#define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c
|
||||
#define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c)
|
||||
|
||||
/* libssh version */
|
||||
#define LIBSSH_VERSION_MAJOR 0
|
||||
#define LIBSSH_VERSION_MINOR 4
|
||||
#define LIBSSH_VERSION_MICRO 1
|
||||
|
||||
#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
|
||||
LIBSSH_VERSION_MINOR, \
|
||||
LIBSSH_VERSION_MICRO)
|
||||
#define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \
|
||||
LIBSSH_VERSION_MINOR, \
|
||||
LIBSSH_VERSION_MICRO)
|
||||
|
||||
/* GCC have printf type attribute check. */
|
||||
#ifdef __GNUC__
|
||||
#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
|
||||
#else
|
||||
#define PRINTF_ATTRIBUTE(a,b)
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define SSH_DEPRECATED __attribute__ ((deprecated))
|
||||
#else
|
||||
#define SSH_DEPRECATED
|
||||
#endif
|
||||
|
||||
|
||||
#define LIBSSH_VERSION "libssh-0.2.1-svn"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct string_struct STRING;
|
||||
typedef struct buffer_struct BUFFER;
|
||||
typedef struct public_key_struct PUBLIC_KEY;
|
||||
typedef struct private_key_struct PRIVATE_KEY;
|
||||
typedef struct ssh_options_struct SSH_OPTIONS;
|
||||
typedef struct channel_struct CHANNEL;
|
||||
typedef struct ssh_session SSH_SESSION;
|
||||
typedef struct ssh_kbdint SSH_KBDINT;
|
||||
|
||||
/* integer values */
|
||||
typedef uint32_t u32;
|
||||
typedef uint16_t u16;
|
||||
typedef uint64_t u64;
|
||||
typedef uint8_t u8;
|
||||
typedef struct ssh_agent_struct* ssh_agent;
|
||||
typedef struct ssh_buffer_struct* ssh_buffer;
|
||||
typedef struct ssh_channel_struct* ssh_channel;
|
||||
typedef struct ssh_message_struct* ssh_message;
|
||||
typedef struct ssh_pcap_file_struct* ssh_pcap_file;
|
||||
typedef struct ssh_private_key_struct* ssh_private_key;
|
||||
typedef struct ssh_public_key_struct* ssh_public_key;
|
||||
typedef struct ssh_scp_struct* ssh_scp;
|
||||
typedef struct ssh_session_struct* ssh_session;
|
||||
typedef struct ssh_string_struct* ssh_string;
|
||||
|
||||
/* Socket type */
|
||||
#ifdef _WIN32
|
||||
@@ -69,68 +125,103 @@ typedef int socket_t;
|
||||
#endif
|
||||
|
||||
/* the offsets of methods */
|
||||
#define SSH_KEX 0
|
||||
#define SSH_HOSTKEYS 1
|
||||
#define SSH_CRYPT_C_S 2
|
||||
#define SSH_CRYPT_S_C 3
|
||||
#define SSH_MAC_C_S 4
|
||||
#define SSH_MAC_S_C 5
|
||||
#define SSH_COMP_C_S 6
|
||||
#define SSH_COMP_S_C 7
|
||||
#define SSH_LANG_C_S 8
|
||||
#define SSH_LANG_S_C 9
|
||||
enum ssh_kex_types_e {
|
||||
SSH_KEX=0,
|
||||
SSH_HOSTKEYS,
|
||||
SSH_CRYPT_C_S,
|
||||
SSH_CRYPT_S_C,
|
||||
SSH_MAC_C_S,
|
||||
SSH_MAC_S_C,
|
||||
SSH_COMP_C_S,
|
||||
SSH_COMP_S_C,
|
||||
SSH_LANG_C_S,
|
||||
SSH_LANG_S_C
|
||||
};
|
||||
|
||||
#define SSH_CRYPT 2
|
||||
#define SSH_MAC 3
|
||||
#define SSH_COMP 4
|
||||
#define SSH_LANG 5
|
||||
|
||||
#define SSH_AUTH_SUCCESS 0
|
||||
#define SSH_AUTH_DENIED 1
|
||||
#define SSH_AUTH_PARTIAL 2
|
||||
#define SSH_AUTH_INFO 3
|
||||
#define SSH_AUTH_ERROR -1
|
||||
enum ssh_auth_e {
|
||||
SSH_AUTH_SUCCESS=0,
|
||||
SSH_AUTH_DENIED,
|
||||
SSH_AUTH_PARTIAL,
|
||||
SSH_AUTH_INFO,
|
||||
SSH_AUTH_ERROR=-1
|
||||
};
|
||||
|
||||
#define SSH_AUTH_METHOD_PASSWORD 0x0001
|
||||
#define SSH_AUTH_METHOD_PUBLICKEY 0x0002
|
||||
#define SSH_AUTH_METHOD_HOSTBASED 0x0004
|
||||
#define SSH_AUTH_METHOD_INTERACTIVE 0x0008
|
||||
/* auth flags */
|
||||
#define SSH_AUTH_METHOD_UNKNOWN 0
|
||||
#define SSH_AUTH_METHOD_NONE 0x0001
|
||||
#define SSH_AUTH_METHOD_PASSWORD 0x0002
|
||||
#define SSH_AUTH_METHOD_PUBLICKEY 0x0004
|
||||
#define SSH_AUTH_METHOD_HOSTBASED 0x0008
|
||||
#define SSH_AUTH_METHOD_INTERACTIVE 0x0010
|
||||
|
||||
/* messages */
|
||||
enum ssh_requests_e {
|
||||
SSH_REQUEST_AUTH=1,
|
||||
SSH_REQUEST_CHANNEL_OPEN,
|
||||
SSH_REQUEST_CHANNEL,
|
||||
SSH_REQUEST_SERVICE,
|
||||
SSH_REQUEST_GLOBAL,
|
||||
};
|
||||
|
||||
enum ssh_channel_type_e {
|
||||
SSH_CHANNEL_UNKNOWN=0,
|
||||
SSH_CHANNEL_SESSION,
|
||||
SSH_CHANNEL_DIRECT_TCPIP,
|
||||
SSH_CHANNEL_FORWARDED_TCPIP,
|
||||
SSH_CHANNEL_X11
|
||||
};
|
||||
|
||||
enum ssh_channel_requests_e {
|
||||
SSH_CHANNEL_REQUEST_UNKNOWN=0,
|
||||
SSH_CHANNEL_REQUEST_PTY,
|
||||
SSH_CHANNEL_REQUEST_EXEC,
|
||||
SSH_CHANNEL_REQUEST_SHELL,
|
||||
SSH_CHANNEL_REQUEST_ENV,
|
||||
SSH_CHANNEL_REQUEST_SUBSYSTEM,
|
||||
SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
|
||||
};
|
||||
|
||||
/* status flags */
|
||||
#define SSH_CLOSED 0x01
|
||||
#define SSH_READ_PENDING 0x02
|
||||
#define SSH_CLOSED_ERROR 0x04
|
||||
|
||||
#define SSH_CLOSED (1<<0)
|
||||
#define SSH_READ_PENDING (1<<1)
|
||||
#define SSH_CLOSED_ERROR (1<<2)
|
||||
|
||||
#define SSH_SERVER_ERROR -1
|
||||
#define SSH_SERVER_NOT_KNOWN 0
|
||||
#define SSH_SERVER_KNOWN_OK 1
|
||||
#define SSH_SERVER_KNOWN_CHANGED 2
|
||||
#define SSH_SERVER_FOUND_OTHER 3
|
||||
enum ssh_server_known_e {
|
||||
SSH_SERVER_ERROR=-1,
|
||||
SSH_SERVER_NOT_KNOWN=0,
|
||||
SSH_SERVER_KNOWN_OK,
|
||||
SSH_SERVER_KNOWN_CHANGED,
|
||||
SSH_SERVER_FOUND_OTHER,
|
||||
SSH_SERVER_FILE_NOT_FOUND,
|
||||
};
|
||||
|
||||
#ifndef MD5_DIGEST_LEN
|
||||
#define MD5_DIGEST_LEN 16
|
||||
#endif
|
||||
/* errors */
|
||||
|
||||
#define SSH_NO_ERROR 0
|
||||
#define SSH_REQUEST_DENIED 1
|
||||
#define SSH_FATAL 2
|
||||
#define SSH_EINTR 3
|
||||
enum ssh_error_types_e {
|
||||
SSH_NO_ERROR=0,
|
||||
SSH_REQUEST_DENIED,
|
||||
SSH_FATAL,
|
||||
SSH_EINTR
|
||||
};
|
||||
|
||||
/* error return codes */
|
||||
/* Error return codes */
|
||||
#define SSH_OK 0 /* No error */
|
||||
#define SSH_ERROR -1 /* error of some kind */
|
||||
#define SSH_AGAIN 1 /* the nonblocking call must be repeated */
|
||||
#define SSH_ERROR -1 /* Error of some kind */
|
||||
#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
|
||||
#define SSH_EOF -127 /* We have already a eof */
|
||||
|
||||
char *ssh_get_error(void *error);
|
||||
int ssh_get_error_code(void *error);
|
||||
void ssh_say(int priority, const char *format, ...);
|
||||
void ssh_set_verbosity(int num);
|
||||
/** \addtogroup ssh_log
|
||||
* @{
|
||||
*/
|
||||
/** \brief Verbosity level for logging and help to debugging
|
||||
/** \brief Verbosity level for logging and help to debugging
|
||||
*/
|
||||
|
||||
enum {
|
||||
@@ -140,177 +231,217 @@ enum {
|
||||
/** Only rare and noteworthy events
|
||||
*/
|
||||
SSH_LOG_RARE,
|
||||
/** High level protocol informations
|
||||
/** High level protocol informations
|
||||
*/
|
||||
SSH_LOG_PROTOCOL,
|
||||
/** Lower level protocol infomations, packet level
|
||||
*/
|
||||
SSH_LOG_PACKET,
|
||||
SSH_LOG_PACKET,
|
||||
/** Every function path
|
||||
*/
|
||||
SSH_LOG_FUNCTIONS
|
||||
SSH_LOG_FUNCTIONS
|
||||
};
|
||||
/** @}
|
||||
*/
|
||||
/*#define SSH_LOG_NOLOG 0 // no log
|
||||
#define SSH_LOG_RARE 1 // rare conditions
|
||||
#define SSH_LOG_ENTRY 2 // user-accessible entrypoints
|
||||
#define SSH_LOG_PACKET 3 // packet id and size
|
||||
#define SSH_LOG_FUNCTIONS 4 // every function in and return
|
||||
*/
|
||||
/* log.c */
|
||||
void ssh_log(SSH_SESSION *session, int prioriry, char *format, ...);
|
||||
|
||||
/* session.c */
|
||||
SSH_SESSION *ssh_new();
|
||||
void ssh_set_options(SSH_SESSION *session, SSH_OPTIONS *options);
|
||||
socket_t ssh_get_fd(SSH_SESSION *session);
|
||||
void ssh_silent_disconnect(SSH_SESSION *session);
|
||||
int ssh_get_version(SSH_SESSION *session);
|
||||
void ssh_set_fd_toread(SSH_SESSION *session);
|
||||
void ssh_set_fd_towrite(SSH_SESSION *session);
|
||||
void ssh_set_fd_except(SSH_SESSION *session);
|
||||
enum ssh_options_e {
|
||||
SSH_OPTIONS_HOST,
|
||||
SSH_OPTIONS_PORT,
|
||||
SSH_OPTIONS_PORT_STR,
|
||||
SSH_OPTIONS_FD,
|
||||
SSH_OPTIONS_USER,
|
||||
SSH_OPTIONS_SSH_DIR,
|
||||
SSH_OPTIONS_IDENTITY,
|
||||
SSH_OPTIONS_KNOWNHOSTS,
|
||||
SSH_OPTIONS_TIMEOUT,
|
||||
SSH_OPTIONS_TIMEOUT_USEC,
|
||||
SSH_OPTIONS_SSH1,
|
||||
SSH_OPTIONS_SSH2,
|
||||
SSH_OPTIONS_LOG_VERBOSITY,
|
||||
SSH_OPTIONS_LOG_VERBOSITY_STR,
|
||||
|
||||
SSH_OPTIONS_CIPHERS_C_S,
|
||||
SSH_OPTIONS_CIPHERS_S_C,
|
||||
SSH_OPTIONS_COMPRESSION_C_S,
|
||||
SSH_OPTIONS_COMPRESSION_S_C
|
||||
};
|
||||
|
||||
/* client.c */
|
||||
int ssh_connect(SSH_SESSION *session);
|
||||
void ssh_disconnect(SSH_SESSION *session);
|
||||
int ssh_service_request(SSH_SESSION *session,char *service);
|
||||
char *ssh_get_issue_banner(SSH_SESSION *session);
|
||||
/* get copyright informations */
|
||||
const char *ssh_copyright();
|
||||
/* string.h */
|
||||
enum {
|
||||
/** Code is going to write/create remote files */
|
||||
SSH_SCP_WRITE,
|
||||
/** Code is going to read remote files */
|
||||
SSH_SCP_READ,
|
||||
SSH_SCP_RECURSIVE=0x10
|
||||
};
|
||||
|
||||
/* You can use these functions, they won't change */
|
||||
/* makestring returns a newly allocated string from a char * ptr */
|
||||
STRING *string_from_char(const char *what);
|
||||
/* it returns the string len in host byte orders. str->size is big endian warning ! */
|
||||
int string_len(STRING *str);
|
||||
STRING *string_new(unsigned int size);
|
||||
/* string_fill copies the data in the string. it does NOT check for boundary so allocate enough place with string_new */
|
||||
void string_fill(STRING *str, const void *data,int len);
|
||||
/* returns a newly allocated char array with the str string and a final nul caracter */
|
||||
char *string_to_char(STRING *str);
|
||||
STRING *string_copy(STRING *str);
|
||||
/* burns the data inside a string */
|
||||
void string_burn(STRING *str);
|
||||
void *string_data(STRING *str);
|
||||
void string_free(STRING *str);
|
||||
enum ssh_scp_request_types {
|
||||
/** A new directory is going to be pulled */
|
||||
SSH_SCP_REQUEST_NEWDIR=1,
|
||||
/** A new file is going to be pulled */
|
||||
SSH_SCP_REQUEST_NEWFILE,
|
||||
/** End of requests */
|
||||
SSH_SCP_REQUEST_EOF,
|
||||
/** End of directory */
|
||||
SSH_SCP_REQUEST_ENDDIR,
|
||||
/** Warning received */
|
||||
SSH_SCP_REQUEST_WARNING
|
||||
};
|
||||
|
||||
/* deprecated */
|
||||
void ssh_crypto_init();
|
||||
LIBSSH_API void buffer_free(ssh_buffer buffer);
|
||||
LIBSSH_API void *buffer_get(ssh_buffer buffer);
|
||||
LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer);
|
||||
LIBSSH_API ssh_buffer buffer_new(void);
|
||||
|
||||
/* useful for debug */
|
||||
void ssh_print_hexa(char *descr, const unsigned char *what, int len);
|
||||
int ssh_get_random(void *where,int len,int strong);
|
||||
|
||||
/* this one can be called by the client to see the hash of the public key before accepting it */
|
||||
int ssh_get_pubkey_hash(SSH_SESSION *session,unsigned char hash[MD5_DIGEST_LEN]);
|
||||
STRING *ssh_get_pubkey(SSH_SESSION *session);
|
||||
|
||||
/* in connect.c */
|
||||
int ssh_fd_poll(SSH_SESSION *session,int *write, int *except);
|
||||
int ssh_select(CHANNEL **channels,CHANNEL **outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout);
|
||||
|
||||
void publickey_free(PUBLIC_KEY *key);
|
||||
|
||||
/* in keyfiles.c */
|
||||
|
||||
PRIVATE_KEY *privatekey_from_file(SSH_SESSION *session,char *filename,int type,char *passphrase);
|
||||
STRING *publickey_to_string(PUBLIC_KEY *key);
|
||||
PUBLIC_KEY *publickey_from_privatekey(PRIVATE_KEY *prv);
|
||||
void private_key_free(PRIVATE_KEY *prv);
|
||||
STRING *publickey_from_file(SSH_SESSION *session, char *filename,int *_type);
|
||||
STRING *publickey_from_next_file(SSH_SESSION *session,char **pub_keys_path,char **keys_path,
|
||||
char **privkeyfile,int *type,int *count);
|
||||
int ssh_is_server_known(SSH_SESSION *session);
|
||||
int ssh_write_knownhost(SSH_SESSION *session);
|
||||
|
||||
/* in channels.c */
|
||||
|
||||
CHANNEL *channel_new(SSH_SESSION *session);
|
||||
int channel_open_forward(CHANNEL *channel,char *remotehost, int remoteport, char *sourcehost, int localport);
|
||||
int channel_open_session(CHANNEL *channel);
|
||||
void channel_free(CHANNEL *channel);
|
||||
int channel_request_pty(CHANNEL *channel);
|
||||
int channel_request_pty_size(CHANNEL *channel, char *term,int cols, int rows);
|
||||
int channel_change_pty_size(CHANNEL *channel,int cols,int rows);
|
||||
int channel_request_shell(CHANNEL *channel);
|
||||
int channel_request_subsystem(CHANNEL *channel, char *system);
|
||||
int channel_request_env(CHANNEL *channel,char *name, char *value);
|
||||
int channel_request_exec(CHANNEL *channel, char *cmd);
|
||||
int channel_request_sftp(CHANNEL *channel);
|
||||
int channel_write(CHANNEL *channel,void *data,int len);
|
||||
int channel_send_eof(CHANNEL *channel);
|
||||
int channel_is_eof(CHANNEL *channel);
|
||||
int channel_read(CHANNEL *channel, BUFFER *buffer,int bytes,int is_stderr);
|
||||
int channel_poll(CHANNEL *channel, int is_stderr);
|
||||
int channel_close(CHANNEL *channel);
|
||||
int channel_read_nonblocking(CHANNEL *channel, char *dest, int len, int is_stderr);
|
||||
int channel_is_open(CHANNEL *channel);
|
||||
int channel_is_closed(CHANNEL *channel);
|
||||
int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptchans, struct
|
||||
LIBSSH_API ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms);
|
||||
LIBSSH_API int channel_change_pty_size(ssh_channel channel,int cols,int rows);
|
||||
LIBSSH_API ssh_channel channel_forward_accept(ssh_session session, int timeout_ms);
|
||||
LIBSSH_API int channel_close(ssh_channel channel);
|
||||
LIBSSH_API int channel_forward_cancel(ssh_session session, const char *address, int port);
|
||||
LIBSSH_API int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
||||
LIBSSH_API void channel_free(ssh_channel channel);
|
||||
LIBSSH_API int channel_get_exit_status(ssh_channel channel);
|
||||
LIBSSH_API ssh_session channel_get_session(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_closed(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_eof(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_open(ssh_channel channel);
|
||||
LIBSSH_API ssh_channel channel_new(ssh_session session);
|
||||
LIBSSH_API int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
int remoteport, const char *sourcehost, int localport);
|
||||
LIBSSH_API int channel_open_session(ssh_channel channel);
|
||||
LIBSSH_API int channel_poll(ssh_channel channel, int is_stderr);
|
||||
LIBSSH_API int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
||||
LIBSSH_API int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
||||
int is_stderr);
|
||||
LIBSSH_API int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
int is_stderr);
|
||||
LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value);
|
||||
LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd);
|
||||
LIBSSH_API int channel_request_pty(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_pty_size(ssh_channel channel, const char *term,
|
||||
int cols, int rows);
|
||||
LIBSSH_API int channel_request_shell(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signum);
|
||||
LIBSSH_API int channel_request_sftp(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *subsystem);
|
||||
LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
||||
const char *cookie, int screen_number);
|
||||
LIBSSH_API int channel_send_eof(ssh_channel channel);
|
||||
LIBSSH_API int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
||||
timeval * timeout);
|
||||
/* in options.c */
|
||||
LIBSSH_API void channel_set_blocking(ssh_channel channel, int blocking);
|
||||
LIBSSH_API int channel_write(ssh_channel channel, const void *data, uint32_t len);
|
||||
|
||||
SSH_OPTIONS *ssh_options_new();
|
||||
SSH_OPTIONS *ssh_options_copy(SSH_OPTIONS *opt);
|
||||
int ssh_options_set_wanted_algos(SSH_OPTIONS *opt, int algo, const char *list);
|
||||
void ssh_options_set_username(SSH_OPTIONS *opt, const char *username);
|
||||
void ssh_options_set_port(SSH_OPTIONS *opt, unsigned int port);
|
||||
int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv);
|
||||
void ssh_options_set_host(SSH_OPTIONS *opt, const char *host);
|
||||
void ssh_options_set_fd(SSH_OPTIONS *opt, socket_t fd);
|
||||
void ssh_options_set_bind(SSH_OPTIONS *opt, const char *bindaddr, int port);
|
||||
void ssh_options_set_identity(SSH_OPTIONS *opt, const char *identity);
|
||||
void ssh_options_set_status_callback(SSH_OPTIONS *opt, void (*callback)
|
||||
(void *arg, float status), void *arg);
|
||||
void ssh_options_set_timeout(SSH_OPTIONS *opt, long seconds, long usec);
|
||||
void ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir);
|
||||
void ssh_options_set_known_hosts_file(SSH_OPTIONS *opt, const char *dir);
|
||||
void ssh_options_allow_ssh1(SSH_OPTIONS *opt, int allow);
|
||||
void ssh_options_allow_ssh2(SSH_OPTIONS *opt, int allow);
|
||||
void ssh_options_set_dsa_server_key(SSH_OPTIONS *opt, const char *dsakey);
|
||||
void ssh_options_set_rsa_server_key(SSH_OPTIONS *opt, const char *rsakey);
|
||||
void ssh_options_set_log_function(SSH_OPTIONS *opt,
|
||||
void (*callback)(const char *message, SSH_SESSION *session, int verbosity ));
|
||||
void ssh_options_set_log_verbosity(SSH_OPTIONS *opt, int verbosity);
|
||||
LIBSSH_API void privatekey_free(ssh_private_key prv);
|
||||
LIBSSH_API ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
||||
int type, const char *passphrase);
|
||||
LIBSSH_API void publickey_free(ssh_public_key key);
|
||||
LIBSSH_API ssh_string publickey_from_file(ssh_session session, const char *filename,
|
||||
int *type);
|
||||
LIBSSH_API ssh_public_key publickey_from_privatekey(ssh_private_key prv);
|
||||
LIBSSH_API ssh_string publickey_to_string(ssh_public_key key);
|
||||
|
||||
LIBSSH_API int ssh_auth_list(ssh_session session);
|
||||
LIBSSH_API char *ssh_basename (const char *path);
|
||||
LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash);
|
||||
LIBSSH_API int ssh_connect(ssh_session session);
|
||||
LIBSSH_API const char *ssh_copyright(void);
|
||||
LIBSSH_API void ssh_disconnect(ssh_session session);
|
||||
LIBSSH_API char *ssh_dirname (const char *path);
|
||||
LIBSSH_API int ssh_finalize(void);
|
||||
LIBSSH_API void ssh_free(ssh_session session);
|
||||
LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session);
|
||||
LIBSSH_API const char *ssh_get_error(void *error);
|
||||
LIBSSH_API int ssh_get_error_code(void *error);
|
||||
LIBSSH_API socket_t ssh_get_fd(ssh_session session);
|
||||
LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
|
||||
LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
|
||||
LIBSSH_API int ssh_get_openssh_version(ssh_session session);
|
||||
LIBSSH_API ssh_string ssh_get_pubkey(ssh_session session);
|
||||
LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
|
||||
LIBSSH_API int ssh_get_random(void *where,int len,int strong);
|
||||
LIBSSH_API int ssh_get_version(ssh_session session);
|
||||
LIBSSH_API int ssh_get_status(ssh_session session);
|
||||
LIBSSH_API int ssh_init(void);
|
||||
LIBSSH_API int ssh_is_server_known(ssh_session session);
|
||||
LIBSSH_API void ssh_log(ssh_session session, int prioriry, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
|
||||
LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_channel_request_reply_success(ssh_message msg);
|
||||
LIBSSH_API void ssh_message_free(ssh_message msg);
|
||||
LIBSSH_API ssh_message ssh_message_get(ssh_session session);
|
||||
LIBSSH_API ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype);
|
||||
LIBSSH_API int ssh_message_subtype(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_type(ssh_message msg);
|
||||
LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode);
|
||||
LIBSSH_API ssh_session ssh_new(void);
|
||||
|
||||
LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest);
|
||||
LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv);
|
||||
LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename);
|
||||
LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
||||
const void *value);
|
||||
LIBSSH_API int ssh_pcap_file_close(ssh_pcap_file pcap);
|
||||
LIBSSH_API void ssh_pcap_file_free(ssh_pcap_file pcap);
|
||||
LIBSSH_API ssh_pcap_file ssh_pcap_file_new(void);
|
||||
LIBSSH_API int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename);
|
||||
LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
|
||||
LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
|
||||
LIBSSH_API int ssh_scp_close(ssh_scp scp);
|
||||
LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason);
|
||||
LIBSSH_API void ssh_scp_free(ssh_scp scp);
|
||||
LIBSSH_API int ssh_scp_init(ssh_scp scp);
|
||||
LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp);
|
||||
LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location);
|
||||
LIBSSH_API int ssh_scp_pull_request(ssh_scp scp);
|
||||
LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode);
|
||||
LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms);
|
||||
LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size);
|
||||
LIBSSH_API const char *ssh_scp_request_get_filename(ssh_scp scp);
|
||||
LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp);
|
||||
LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp);
|
||||
LIBSSH_API const char *ssh_scp_request_get_warning(ssh_scp scp);
|
||||
LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len);
|
||||
LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
|
||||
fd_set *readfds, struct timeval *timeout);
|
||||
LIBSSH_API int ssh_service_request(ssh_session session, const char *service);
|
||||
LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking);
|
||||
LIBSSH_API void ssh_set_fd_except(ssh_session session);
|
||||
LIBSSH_API void ssh_set_fd_toread(ssh_session session);
|
||||
LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
|
||||
LIBSSH_API void ssh_silent_disconnect(ssh_session session);
|
||||
LIBSSH_API int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile);
|
||||
#ifndef _WIN32
|
||||
LIBSSH_API int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
||||
ssh_public_key publickey);
|
||||
#endif
|
||||
LIBSSH_API int ssh_userauth_autopubkey(ssh_session session, const char *passphrase);
|
||||
LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods);
|
||||
LIBSSH_API const char *ssh_userauth_kbdint_getinstruction(ssh_session session);
|
||||
LIBSSH_API const char *ssh_userauth_kbdint_getname(ssh_session session);
|
||||
LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session);
|
||||
LIBSSH_API const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo);
|
||||
LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
|
||||
const char *answer);
|
||||
LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username);
|
||||
LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username);
|
||||
LIBSSH_API int ssh_userauth_offer_pubkey(ssh_session session, const char *username, int type, ssh_string publickey);
|
||||
LIBSSH_API int ssh_userauth_password(ssh_session session, const char *username, const char *password);
|
||||
LIBSSH_API int ssh_userauth_pubkey(ssh_session session, const char *username, ssh_string publickey, ssh_private_key privatekey);
|
||||
LIBSSH_API const char *ssh_version(int req_version);
|
||||
LIBSSH_API int ssh_write_knownhost(ssh_session session);
|
||||
|
||||
LIBSSH_API void string_burn(ssh_string str);
|
||||
LIBSSH_API ssh_string string_copy(ssh_string str);
|
||||
LIBSSH_API void *string_data(ssh_string str);
|
||||
LIBSSH_API int string_fill(ssh_string str, const void *data, size_t len);
|
||||
LIBSSH_API void string_free(ssh_string str);
|
||||
LIBSSH_API ssh_string string_from_char(const char *what);
|
||||
LIBSSH_API size_t string_len(ssh_string str);
|
||||
LIBSSH_API ssh_string string_new(size_t size);
|
||||
LIBSSH_API char *string_to_char(ssh_string str);
|
||||
|
||||
|
||||
/* buffer.c */
|
||||
|
||||
/** creates a new buffer
|
||||
*/
|
||||
BUFFER *buffer_new();
|
||||
void buffer_free(BUFFER *buffer);
|
||||
/* buffer_get returns a pointer to the begining of the buffer. no position is taken into account */
|
||||
void *buffer_get(BUFFER *buffer);
|
||||
/* same here */
|
||||
int buffer_get_len(BUFFER *buffer);
|
||||
|
||||
|
||||
/* in auth.c */
|
||||
/* these functions returns AUTH_ERROR is some serious error has happened,
|
||||
AUTH_SUCCESS if success,
|
||||
AUTH_PARTIAL if partial success,
|
||||
AUTH_DENIED if refused */
|
||||
int ssh_userauth_list(SSH_SESSION *session, const char *username);
|
||||
int ssh_userauth_none(SSH_SESSION *session, const char *username);
|
||||
int ssh_userauth_password(SSH_SESSION *session, const char *username, const char *password);
|
||||
int ssh_userauth_offer_pubkey(SSH_SESSION *session, const char *username, int type, STRING *publickey);
|
||||
int ssh_userauth_pubkey(SSH_SESSION *session, const char *username, STRING *publickey, PRIVATE_KEY *privatekey);
|
||||
int ssh_userauth_autopubkey(SSH_SESSION *session);
|
||||
int ssh_userauth_kbdint(SSH_SESSION *session, const char *user, const char *submethods);
|
||||
int ssh_userauth_kbdint_getnprompts(SSH_SESSION *session);
|
||||
char *ssh_userauth_kbdint_getname(SSH_SESSION *session);
|
||||
char *ssh_userauth_kbdint_getinstruction(SSH_SESSION *session);
|
||||
char *ssh_userauth_kbdint_getprompt(SSH_SESSION *session, int i, char *echo);
|
||||
void ssh_userauth_kbdint_setanswer(SSH_SESSION *session, unsigned int i, const char *answer);
|
||||
|
||||
|
||||
/* init.c */
|
||||
int ssh_finalize();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* _LIBSSH_H */
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
|
||||
84
include/libssh/messages.h
Normal file
84
include/libssh/messages.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef MESSAGES_H_
|
||||
#define MESSAGES_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
struct ssh_auth_request {
|
||||
char *username;
|
||||
int method;
|
||||
char *password;
|
||||
struct ssh_public_key_struct *public_key;
|
||||
char signature_state;
|
||||
};
|
||||
|
||||
struct ssh_channel_request_open {
|
||||
int type;
|
||||
uint32_t sender;
|
||||
uint32_t window;
|
||||
uint32_t packet_size;
|
||||
char *originator;
|
||||
uint16_t originator_port;
|
||||
char *destination;
|
||||
uint16_t destination_port;
|
||||
};
|
||||
|
||||
struct ssh_service_request {
|
||||
char *service;
|
||||
};
|
||||
|
||||
struct ssh_channel_request {
|
||||
int type;
|
||||
ssh_channel channel;
|
||||
uint8_t want_reply;
|
||||
/* pty-req type specifics */
|
||||
char *TERM;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t pxwidth;
|
||||
uint32_t pxheight;
|
||||
ssh_string modes;
|
||||
|
||||
/* env type request */
|
||||
char *var_name;
|
||||
char *var_value;
|
||||
/* exec type request */
|
||||
char *command;
|
||||
/* subsystem */
|
||||
char *subsystem;
|
||||
};
|
||||
|
||||
struct ssh_message_struct {
|
||||
ssh_session session;
|
||||
int type;
|
||||
struct ssh_auth_request auth_request;
|
||||
struct ssh_channel_request_open channel_request_open;
|
||||
struct ssh_channel_request channel_request;
|
||||
struct ssh_service_request service_request;
|
||||
};
|
||||
|
||||
|
||||
void message_handle(ssh_session session, uint32_t type);
|
||||
int ssh_execute_message_callbacks(ssh_session session);
|
||||
|
||||
#endif /* MESSAGES_H_ */
|
||||
69
include/libssh/misc.h
Normal file
69
include/libssh/misc.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef MISC_H_
|
||||
#define MISC_H_
|
||||
|
||||
/* in misc.c */
|
||||
/* gets the user home dir. */
|
||||
char *ssh_get_user_home_dir(void);
|
||||
int ssh_file_readaccess_ok(const char *file);
|
||||
|
||||
/* macro for byte ordering */
|
||||
uint64_t ntohll(uint64_t);
|
||||
#define htonll(x) ntohll(x)
|
||||
|
||||
/* list processing */
|
||||
|
||||
struct ssh_list {
|
||||
struct ssh_iterator *root;
|
||||
struct ssh_iterator *end;
|
||||
};
|
||||
|
||||
struct ssh_iterator {
|
||||
struct ssh_iterator *next;
|
||||
const void *data;
|
||||
};
|
||||
|
||||
struct ssh_list *ssh_list_new(void);
|
||||
void ssh_list_free(struct ssh_list *list);
|
||||
struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
|
||||
int ssh_list_add(struct ssh_list *list, const void *data);
|
||||
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
|
||||
|
||||
/** @brief fetch the head element of a list and remove it from list
|
||||
* @param list the ssh_list to use
|
||||
* @return the first element of the list
|
||||
*/
|
||||
const void *_ssh_list_get_head(struct ssh_list *list);
|
||||
|
||||
#define ssh_iterator_value(type, iterator)\
|
||||
((type)((iterator)->data))
|
||||
|
||||
/** @brief fetch the head element of a list and remove it from list
|
||||
* @param type type of the element to return
|
||||
* @param list the ssh_list to use
|
||||
* @return the first element of the list
|
||||
*/
|
||||
#define ssh_list_get_head(type, ssh_list)\
|
||||
((type)_ssh_list_get_head(ssh_list))
|
||||
|
||||
#endif /* MISC_H_ */
|
||||
41
include/libssh/packet.h
Normal file
41
include/libssh/packet.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef PACKET_H_
|
||||
#define PACKET_H_
|
||||
|
||||
/* this structure should go someday */
|
||||
typedef struct packet_struct {
|
||||
int valid;
|
||||
uint32_t len;
|
||||
uint8_t type;
|
||||
} PACKET;
|
||||
|
||||
void packet_parse(ssh_session session);
|
||||
int packet_send(ssh_session session);
|
||||
|
||||
int packet_read(ssh_session session);
|
||||
int packet_translate(ssh_session session);
|
||||
int packet_wait(ssh_session session,int type,int blocking);
|
||||
int packet_flush(ssh_session session, int enforce_blocking);
|
||||
|
||||
|
||||
#endif /* PACKET_H_ */
|
||||
26
include/libssh/pcap.h
Normal file
26
include/libssh/pcap.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef PCAP_H_
|
||||
#define PCAP_H_
|
||||
|
||||
#include "config.h"
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifdef WITH_PCAP
|
||||
typedef struct ssh_pcap_context_struct* ssh_pcap_context;
|
||||
|
||||
int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, uint32_t original_len);
|
||||
|
||||
ssh_pcap_context ssh_pcap_context_new(ssh_session session);
|
||||
void ssh_pcap_context_free(ssh_pcap_context ctx);
|
||||
|
||||
enum ssh_pcap_direction{
|
||||
SSH_PCAP_DIR_IN,
|
||||
SSH_PCAP_DIR_OUT
|
||||
};
|
||||
void ssh_pcap_context_set_file(ssh_pcap_context, ssh_pcap_file);
|
||||
int ssh_pcap_context_write(ssh_pcap_context,enum ssh_pcap_direction direction, void *data,
|
||||
uint32_t len, uint32_t origlen);
|
||||
|
||||
|
||||
#endif /* WITH_PCAP */
|
||||
#endif /* PCAP_H_ */
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
102
include/libssh/poll.h
Normal file
102
include/libssh/poll.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef POLL_H_
|
||||
#define POLL_H_
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_POLL
|
||||
|
||||
#include <poll.h>
|
||||
typedef struct pollfd ssh_pollfd_t;
|
||||
|
||||
#else /* HAVE_POLL */
|
||||
|
||||
/* poll emulation support */
|
||||
|
||||
typedef struct ssh_pollfd_struct {
|
||||
socket_t fd; /* file descriptor */
|
||||
short events; /* requested events */
|
||||
short revents; /* returned events */
|
||||
} ssh_pollfd_t;
|
||||
|
||||
/* poll.c */
|
||||
#ifndef POLLIN
|
||||
# define POLLIN 0x001 /* There is data to read. */
|
||||
#endif
|
||||
#ifndef POLLPRI
|
||||
#define POLLPRI 0x002 /* There is urgent data to read. */
|
||||
#endif
|
||||
#ifndef POLLOUT
|
||||
#define POLLOUT 0x004 /* Writing now will not block. */
|
||||
#endif
|
||||
|
||||
#ifndef POLLERR
|
||||
#define POLLERR 0x008 /* Error condition. */
|
||||
#endif
|
||||
#ifndef POLLHUP
|
||||
#define POLLHUP 0x010 /* Hung up. */
|
||||
#endif
|
||||
#ifndef POLLNVAL
|
||||
#define POLLNVAL 0x020 /* Invalid polling request. */
|
||||
#endif
|
||||
|
||||
typedef unsigned long int nfds_t;
|
||||
#endif /* HAVE_POLL */
|
||||
|
||||
int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout);
|
||||
typedef struct ssh_poll_ctx_struct *ssh_poll_ctx;
|
||||
typedef struct ssh_poll_handle_struct *ssh_poll_handle;
|
||||
|
||||
/**
|
||||
* @brief SSH poll callback.
|
||||
*
|
||||
* @param p Poll object this callback belongs to.
|
||||
* @param fd The raw socket.
|
||||
* @param revents The current poll events on the socket.
|
||||
* @param userdata Userdata to be passed to the callback function.
|
||||
*
|
||||
* @return 0 on success, < 0 if you removed the poll object from
|
||||
* it's poll context.
|
||||
*/
|
||||
typedef int (*ssh_poll_callback)(ssh_poll_handle p, int fd, int revents,
|
||||
void *userdata);
|
||||
|
||||
|
||||
ssh_poll_handle ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb,
|
||||
void *userdata);
|
||||
void ssh_poll_free(ssh_poll_handle p);
|
||||
ssh_poll_ctx ssh_poll_get_ctx(ssh_poll_handle p);
|
||||
short ssh_poll_get_events(ssh_poll_handle p);
|
||||
void ssh_poll_set_events(ssh_poll_handle p, short events);
|
||||
void ssh_poll_add_events(ssh_poll_handle p, short events);
|
||||
void ssh_poll_remove_events(ssh_poll_handle p, short events);
|
||||
socket_t ssh_poll_get_fd(ssh_poll_handle p);
|
||||
void ssh_poll_set_callback(ssh_poll_handle p, ssh_poll_callback cb, void *userdata);
|
||||
ssh_poll_ctx ssh_poll_ctx_new(size_t chunk_size);
|
||||
void ssh_poll_ctx_free(ssh_poll_ctx ctx);
|
||||
int ssh_poll_ctx_add(ssh_poll_ctx ctx, ssh_poll_handle p);
|
||||
void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p);
|
||||
int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout);
|
||||
|
||||
|
||||
|
||||
#endif /* POLL_H_ */
|
||||
@@ -1,622 +1,201 @@
|
||||
/*
|
||||
Copyright (c) 2003-2008 Aris Adamantiadis
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2003-2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
|
||||
/* priv.h file */
|
||||
/* This include file contains everything you shouldn't deal with in user programs. */
|
||||
/* Consider that anything in this file might change without notice; libssh.h file will keep */
|
||||
/* backward compatibility on binary & source */
|
||||
/*
|
||||
* priv.h file
|
||||
* This include file contains everything you shouldn't deal with in
|
||||
* user programs. Consider that anything in this file might change
|
||||
* without notice; libssh.h file will keep backward compatibility
|
||||
* on binary & source
|
||||
*/
|
||||
|
||||
#ifndef _LIBSSH_PRIV_H
|
||||
#define _LIBSSH_PRIV_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
/** Imitate define of inttypes.h */
|
||||
#define PRIdS "Id"
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define strtoull _strtoui64
|
||||
#define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define PRIdS "zd"
|
||||
#endif
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
/* Debugging constants */
|
||||
|
||||
/* Define this if you want to debug crypto systems */
|
||||
/* it's usefull when you are debugging the lib */
|
||||
/*#define DEBUG_CRYPTO */
|
||||
|
||||
#include "libssh/callbacks.h"
|
||||
#include "libssh/crypto.h"
|
||||
/* some constants */
|
||||
#define MAX_PACKET_LEN 262144
|
||||
#define ERROR_BUFFERLEN 1024
|
||||
#define CLIENTBANNER1 "SSH-1.5-" LIBSSH_VERSION
|
||||
#define CLIENTBANNER2 "SSH-2.0-" LIBSSH_VERSION
|
||||
#define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
|
||||
#define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
|
||||
#define KBDINT_MAX_PROMPT 256 /* more than openssh's :) */
|
||||
/* some types for public keys */
|
||||
#define TYPE_DSS 1
|
||||
#define TYPE_RSA 2
|
||||
#define TYPE_RSA1 3
|
||||
|
||||
/* profiling constants. Don't touch them unless you know what you do */
|
||||
#ifdef HAVE_LIBCRYPTO
|
||||
#define OPENSSL_BIGNUMS
|
||||
#endif
|
||||
enum public_key_types_e{
|
||||
TYPE_DSS=1,
|
||||
TYPE_RSA,
|
||||
TYPE_RSA1
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* wrapper things */
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
#include <gcrypt.h>
|
||||
typedef gcry_md_hd_t SHACTX;
|
||||
typedef gcry_md_hd_t MD5CTX;
|
||||
typedef gcry_md_hd_t HMACCTX;
|
||||
#ifdef MD5_DIGEST_LEN
|
||||
#undef MD5_DIGEST_LEN
|
||||
#endif
|
||||
#define SHA_DIGEST_LEN 20
|
||||
#define MD5_DIGEST_LEN 16
|
||||
#define EVP_MAX_MD_SIZE 36
|
||||
|
||||
typedef gcry_mpi_t bignum;
|
||||
|
||||
#define bignum_new() gcry_mpi_new(0)
|
||||
#define bignum_free(num) gcry_mpi_release(num)
|
||||
#define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
|
||||
#define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
|
||||
#define bignum_bn2dec(num) my_gcry_bn2dec(num)
|
||||
#define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
|
||||
#define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
|
||||
#define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
|
||||
#define bignum_rand(num,bits) gcry_mpi_randomize(num,bits,GCRY_STRONG_RANDOM),gcry_mpi_set_bit(num,bits-1),gcry_mpi_set_bit(num,0)
|
||||
#define bignum_mod_exp(dest,generator,exp,modulo) gcry_mpi_powm(dest,generator,exp,modulo)
|
||||
#define bignum_num_bits(num) gcry_mpi_get_nbits(num)
|
||||
#define bignum_num_bytes(num) ((gcry_mpi_get_nbits(num)+7)/8)
|
||||
#define bignum_is_bit_set(num,bit) gcry_mpi_test_bit(num,bit)
|
||||
#define bignum_bn2bin(num,datalen,data) gcry_mpi_print(GCRYMPI_FMT_USG,data,datalen,NULL,num)
|
||||
#define bignum_cmp(num1,num2) gcry_mpi_cmp(num1,num2)
|
||||
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/hmac.h>
|
||||
typedef SHA_CTX* SHACTX;
|
||||
typedef MD5_CTX* MD5CTX;
|
||||
typedef HMAC_CTX* HMACCTX;
|
||||
#ifdef MD5_DIGEST_LEN
|
||||
#undef MD5_DIGEST_LEN
|
||||
#endif
|
||||
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
|
||||
#define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
|
||||
|
||||
#endif /* OPENSSL_CRYPTO */
|
||||
#ifdef OPENSSL_BIGNUMS
|
||||
#include <openssl/bn.h>
|
||||
typedef BIGNUM* bignum;
|
||||
typedef BN_CTX* bignum_CTX;
|
||||
|
||||
#define bignum_new() BN_new()
|
||||
#define bignum_free(num) BN_clear_free(num)
|
||||
#define bignum_set_word(bn,n) BN_set_word(bn,n)
|
||||
#define bignum_bin2bn(bn,datalen,data) BN_bin2bn(bn,datalen,data)
|
||||
#define bignum_bn2dec(num) BN_bn2dec(num)
|
||||
#define bignum_dec2bn(bn,data) BN_dec2bn(data,bn)
|
||||
#define bignum_bn2hex(num) BN_bn2hex(num)
|
||||
#define bignum_rand(rnd, bits, top, bottom) BN_rand(rnd,bits,top,bottom)
|
||||
#define bignum_ctx_new() BN_CTX_new()
|
||||
#define bignum_ctx_free(num) BN_CTX_free(num)
|
||||
#define bignum_mod_exp(dest,generator,exp,modulo,ctx) BN_mod_exp(dest,generator,exp,modulo,ctx)
|
||||
#define bignum_num_bytes(num) BN_num_bytes(num)
|
||||
#define bignum_num_bits(num) BN_num_bits(num)
|
||||
#define bignum_is_bit_set(num,bit) BN_is_bit_set(num,bit)
|
||||
#define bignum_bn2bin(num,ptr) BN_bn2bin(num,ptr)
|
||||
#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
|
||||
|
||||
#endif /* OPENSSL_BIGNUMS */
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
/* wrapper.c */
|
||||
MD5CTX md5_init(void);
|
||||
void md5_update(MD5CTX c, const void *data, unsigned long len);
|
||||
void md5_final(unsigned char *md,MD5CTX c);
|
||||
SHACTX sha1_init(void);
|
||||
void sha1_update(SHACTX c, const void *data, unsigned long len);
|
||||
void sha1_final(unsigned char *md,SHACTX c);
|
||||
void sha1(unsigned char *digest,int len,unsigned char *hash);
|
||||
#define HMAC_SHA1 1
|
||||
#define HMAC_MD5 2
|
||||
HMACCTX hmac_init(const void *key,int len,int type);
|
||||
void hmac_update(HMACCTX c, const void *data, unsigned long len);
|
||||
void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
|
||||
|
||||
/* strings and buffers */
|
||||
/* must be 32 bits number + immediatly our data */
|
||||
struct string_struct {
|
||||
u32 size;
|
||||
unsigned char string[MAX_PACKET_LEN];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/** Describes a buffer state at a moment
|
||||
*/
|
||||
struct buffer_struct {
|
||||
char *data;
|
||||
int used;
|
||||
int allocated;
|
||||
int pos;
|
||||
};
|
||||
|
||||
/* i should remove it one day */
|
||||
typedef struct packet_struct {
|
||||
int valid;
|
||||
u32 len;
|
||||
u8 type;
|
||||
} PACKET;
|
||||
|
||||
typedef struct kex_struct {
|
||||
unsigned char cookie[16];
|
||||
char **methods;
|
||||
} KEX;
|
||||
|
||||
struct public_key_struct {
|
||||
int type;
|
||||
char *type_c; /* Don't free it ! it is static */
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_t dsa_pub;
|
||||
gcry_sexp_t rsa_pub;
|
||||
#elif HAVE_LIBCRYPTO
|
||||
DSA *dsa_pub;
|
||||
RSA *rsa_pub;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct private_key_struct {
|
||||
int type;
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_t dsa_priv;
|
||||
gcry_sexp_t rsa_priv;
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
DSA *dsa_priv;
|
||||
RSA *rsa_priv;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct signature_struct {
|
||||
int type;
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_t dsa_sign;
|
||||
gcry_sexp_t rsa_sign;
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
DSA_SIG *dsa_sign;
|
||||
STRING *rsa_sign;
|
||||
#endif
|
||||
} SIGNATURE;
|
||||
|
||||
|
||||
struct error_struct {
|
||||
/* error handling */
|
||||
int error_code;
|
||||
unsigned int error_code;
|
||||
char error_buffer[ERROR_BUFFERLEN];
|
||||
};
|
||||
|
||||
struct ssh_options_struct {
|
||||
struct error_struct error;
|
||||
char *banner; /* explicit banner to send */
|
||||
char *username;
|
||||
char *host;
|
||||
char *bindaddr;
|
||||
int bindport;
|
||||
char *identity;
|
||||
char *ssh_dir;
|
||||
char *known_hosts_file;
|
||||
socket_t fd; /* specificaly wanted file descriptor, don't connect host */
|
||||
int port;
|
||||
int dont_verify_hostkey; /* Don't spare time, don't check host key ! unneeded to say it's dangerous and not safe */
|
||||
int use_nonexisting_algo; /* if user sets a not supported algorithm for kex, don't complain */
|
||||
char *wanted_methods[10]; /* the kex methods can be choosed. better use the kex fonctions to do that */
|
||||
void *wanted_cookie; /* wants a specific cookie to be sent ? if null, generate a new one */
|
||||
void *passphrase_function; /* this functions will be called if a keyphrase is needed. look keyfiles.c for more info */
|
||||
void (*connect_status_function)(void *arg, float status); /* status callback function */
|
||||
void *connect_status_arg; /* arbitrary argument */
|
||||
long timeout; /* seconds */
|
||||
long timeout_usec;
|
||||
int ssh2allowed;
|
||||
int ssh1allowed;
|
||||
char *dsakey;
|
||||
char *rsakey; /* host key for server implementation */
|
||||
int log_verbosity;
|
||||
void (*log_function)(const char *message, SSH_SESSION *session, int verbosity); //log callback
|
||||
/* TODO: remove that include */
|
||||
#include "libssh/wrapper.h"
|
||||
|
||||
struct ssh_keys_struct {
|
||||
const char *privatekey;
|
||||
const char *publickey;
|
||||
};
|
||||
|
||||
typedef struct ssh_crypto_struct {
|
||||
bignum e,f,x,k,y;
|
||||
unsigned char session_id[SHA_DIGEST_LEN];
|
||||
|
||||
unsigned char encryptIV[SHA_DIGEST_LEN*2];
|
||||
unsigned char decryptIV[SHA_DIGEST_LEN*2];
|
||||
struct ssh_message_struct;
|
||||
|
||||
unsigned char decryptkey[SHA_DIGEST_LEN*2];
|
||||
unsigned char encryptkey[SHA_DIGEST_LEN*2];
|
||||
|
||||
unsigned char encryptMAC[SHA_DIGEST_LEN];
|
||||
unsigned char decryptMAC[SHA_DIGEST_LEN];
|
||||
unsigned char hmacbuf[EVP_MAX_MD_SIZE];
|
||||
struct crypto_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
|
||||
STRING *server_pubkey;
|
||||
char *server_pubkey_type;
|
||||
int do_compress_out; /* idem */
|
||||
int do_compress_in; /* don't set them, set the option instead */
|
||||
void *compress_out_ctx; /* don't touch it */
|
||||
void *compress_in_ctx; /* really, don't */
|
||||
} CRYPTO;
|
||||
|
||||
struct channel_struct {
|
||||
struct channel_struct *prev;
|
||||
struct channel_struct *next;
|
||||
SSH_SESSION *session; /* SSH_SESSION pointer */
|
||||
u32 local_channel;
|
||||
u32 local_window;
|
||||
int local_eof;
|
||||
u32 local_maxpacket;
|
||||
|
||||
u32 remote_channel;
|
||||
u32 remote_window;
|
||||
int remote_eof; /* end of file received */
|
||||
u32 remote_maxpacket;
|
||||
int open; /* shows if the channel is still opened */
|
||||
int delayed_close;
|
||||
BUFFER *stdout_buffer;
|
||||
BUFFER *stderr_buffer;
|
||||
void *userarg;
|
||||
int version;
|
||||
int blocking;
|
||||
};
|
||||
|
||||
struct ssh_session {
|
||||
struct error_struct error;
|
||||
struct socket *socket;
|
||||
SSH_OPTIONS *options;
|
||||
char *serverbanner;
|
||||
char *clientbanner;
|
||||
int protoversion;
|
||||
int server;
|
||||
int client;
|
||||
u32 send_seq;
|
||||
u32 recv_seq;
|
||||
/* status flags */
|
||||
int closed;
|
||||
int closed_by_except;
|
||||
|
||||
int connected;
|
||||
/* !=0 when the user got a session handle */
|
||||
int alive;
|
||||
/* two previous are deprecated */
|
||||
int auth_service_asked;
|
||||
|
||||
/* socket status */
|
||||
int blocking; // functions should block
|
||||
|
||||
STRING *banner; /* that's the issue banner from
|
||||
the server */
|
||||
char *remotebanner; /* that's the SSH- banner from
|
||||
remote host. */
|
||||
char *discon_msg; /* disconnect message from
|
||||
the remote host */
|
||||
BUFFER *in_buffer;
|
||||
PACKET in_packet;
|
||||
BUFFER *out_buffer;
|
||||
|
||||
/* the states are used by the nonblocking stuff to remember */
|
||||
/* where it was before being interrupted */
|
||||
int packet_state;
|
||||
int dh_handshake_state;
|
||||
STRING *dh_server_signature; //information used by dh_handshake.
|
||||
|
||||
KEX server_kex;
|
||||
KEX client_kex;
|
||||
BUFFER *in_hashbuf;
|
||||
BUFFER *out_hashbuf;
|
||||
CRYPTO *current_crypto;
|
||||
CRYPTO *next_crypto; /* next_crypto is going to be used after a SSH2_MSG_NEWKEYS */
|
||||
|
||||
CHANNEL *channels; /* linked list of channels */
|
||||
int maxchannel;
|
||||
int exec_channel_opened; /* version 1 only. more
|
||||
info in channels1.c */
|
||||
|
||||
/* keyb interactive data */
|
||||
struct ssh_kbdint *kbdint;
|
||||
int version; /* 1 or 2 */
|
||||
/* server host keys */
|
||||
PRIVATE_KEY *rsa_key;
|
||||
PRIVATE_KEY *dsa_key;
|
||||
/* auths accepted by server */
|
||||
int auth_methods;
|
||||
int hostkeys; /* contains type of host key wanted by client, in server impl */
|
||||
struct ssh_message *ssh_message; /* ssh message */
|
||||
int log_verbosity; /*cached copy of the option structure */
|
||||
int log_indent; /* indentation level in enter_function logs */
|
||||
};
|
||||
|
||||
struct ssh_kbdint {
|
||||
u32 nprompts;
|
||||
char *name;
|
||||
char *instruction;
|
||||
char **prompts;
|
||||
unsigned char *echo; /* bool array */
|
||||
char **answers;
|
||||
};
|
||||
|
||||
/* server data */
|
||||
|
||||
struct ssh_bind_struct {
|
||||
struct error_struct error;
|
||||
socket_t bindfd;
|
||||
SSH_OPTIONS *options;
|
||||
int blocking;
|
||||
int toaccept;
|
||||
struct error_struct error;
|
||||
|
||||
ssh_callbacks callbacks; /* Callbacks to user functions */
|
||||
|
||||
/* options */
|
||||
char *wanted_methods[10];
|
||||
char *banner;
|
||||
char *dsakey;
|
||||
char *rsakey;
|
||||
char *bindaddr;
|
||||
socket_t bindfd;
|
||||
unsigned int bindport;
|
||||
unsigned int log_verbosity;
|
||||
|
||||
int blocking;
|
||||
int toaccept;
|
||||
};
|
||||
|
||||
struct ssh_auth_request {
|
||||
char *username;
|
||||
int method;
|
||||
char *password;
|
||||
};
|
||||
|
||||
struct ssh_channel_request_open {
|
||||
int type;
|
||||
u32 sender;
|
||||
u32 window;
|
||||
u32 packet_size;
|
||||
char *originator;
|
||||
u16 orignator_port;
|
||||
char *destination;
|
||||
u16 destination_port;
|
||||
};
|
||||
|
||||
struct ssh_channel_request {
|
||||
int type;
|
||||
CHANNEL *channel;
|
||||
u8 want_reply;
|
||||
/* pty-req type specifics */
|
||||
char *TERM;
|
||||
u32 width;
|
||||
u32 height;
|
||||
u32 pxwidth;
|
||||
u32 pxheight;
|
||||
STRING *modes;
|
||||
|
||||
/* env type request */
|
||||
char *var_name;
|
||||
char *var_value;
|
||||
/* exec type request */
|
||||
char *command;
|
||||
/* subsystem */
|
||||
char *subsystem;
|
||||
};
|
||||
|
||||
struct ssh_message {
|
||||
SSH_SESSION *session;
|
||||
int type;
|
||||
struct ssh_auth_request auth_request;
|
||||
struct ssh_channel_request_open channel_request_open;
|
||||
struct ssh_channel_request channel_request;
|
||||
};
|
||||
|
||||
/* socket.c */
|
||||
|
||||
struct socket;
|
||||
void ssh_socket_init();
|
||||
struct socket *ssh_socket_new(SSH_SESSION *session);
|
||||
void ssh_socket_free(struct socket *s);
|
||||
void ssh_socket_set_fd(struct socket *s, socket_t fd);
|
||||
socket_t ssh_socket_get_fd(struct socket *s);
|
||||
void ssh_socket_close(struct socket *s);
|
||||
int ssh_socket_read(struct socket *s, void *buffer, int len);
|
||||
int ssh_socket_write(struct socket *s,const void *buffer, int len);
|
||||
int ssh_socket_is_open(struct socket *s);
|
||||
int ssh_socket_fd_isset(struct socket *s, fd_set *set);
|
||||
void ssh_socket_fd_set(struct socket *s, fd_set *set, int *fd_max);
|
||||
int ssh_socket_completeread(struct socket *s, void *buffer, int len);
|
||||
int ssh_socket_wait_for_data(struct socket *s, SSH_SESSION *session,int len);
|
||||
int ssh_socket_nonblocking_flush(struct socket *s);
|
||||
int ssh_socket_blocking_flush(struct socket *s);
|
||||
int ssh_socket_poll(struct socket *s, int *write, int *except);
|
||||
void ssh_socket_set_towrite(struct socket *s);
|
||||
void ssh_socket_set_toread(struct socket *s);
|
||||
void ssh_socket_set_except(struct socket *s);
|
||||
int ssh_socket_get_status(struct socket *s);
|
||||
int ssh_socket_data_available(struct socket *s);
|
||||
int ssh_socket_data_writable(struct socket *s);
|
||||
/* session.c */
|
||||
|
||||
void ssh_cleanup(SSH_SESSION *session);
|
||||
|
||||
/* client.c */
|
||||
|
||||
int ssh_send_banner(SSH_SESSION *session, int is_server);
|
||||
char *ssh_get_banner(SSH_SESSION *session);
|
||||
int ssh_send_banner(ssh_session session, int is_server);
|
||||
char *ssh_get_banner(ssh_session session);
|
||||
|
||||
/* config.c */
|
||||
int ssh_config_parse_file(ssh_session session, const char *filename);
|
||||
|
||||
/* errors.c */
|
||||
void ssh_set_error(void *error,int code,char *descr,...);
|
||||
|
||||
/* in dh.c */
|
||||
/* DH key generation */
|
||||
void dh_generate_e(SSH_SESSION *session);
|
||||
void ssh_print_bignum(char *which,bignum num);
|
||||
void dh_generate_x(SSH_SESSION *session);
|
||||
void dh_generate_y(SSH_SESSION *session);
|
||||
void dh_generate_f(SSH_SESSION *session);
|
||||
void ssh_crypto_finalize();
|
||||
STRING *dh_get_e(SSH_SESSION *session);
|
||||
STRING *dh_get_f(SSH_SESSION *session);
|
||||
void dh_import_f(SSH_SESSION *session,STRING *f_string);
|
||||
void dh_import_e(SSH_SESSION *session, STRING *e_string);
|
||||
void dh_import_pubkey(SSH_SESSION *session,STRING *pubkey_string);
|
||||
void dh_build_k(SSH_SESSION *session);
|
||||
void make_sessionid(SSH_SESSION *session);
|
||||
/* add data for the final cookie */
|
||||
void hashbufin_add_cookie(SSH_SESSION *session,unsigned char *cookie);
|
||||
void hashbufout_add_cookie(SSH_SESSION *session);
|
||||
void generate_session_keys(SSH_SESSION *session);
|
||||
/* returns 1 if server signature ok, 0 otherwise. The NEXT crypto is checked, not the current one */
|
||||
int signature_verify(SSH_SESSION *session,STRING *signature);
|
||||
bignum make_string_bn(STRING *string);
|
||||
STRING *make_bignum_string(bignum num);
|
||||
void ssh_set_error(void *error, int code, const char *descr, ...) PRINTF_ATTRIBUTE(3, 4);
|
||||
void ssh_set_error_oom(void *);
|
||||
void ssh_set_error_invalid(void *, const char *);
|
||||
|
||||
/* in crypt.c */
|
||||
u32 packet_decrypt_len(SSH_SESSION *session,char *crypted);
|
||||
int packet_decrypt(SSH_SESSION *session, void *packet,unsigned int len);
|
||||
unsigned char *packet_encrypt(SSH_SESSION *session,void *packet,unsigned int len);
|
||||
uint32_t packet_decrypt_len(ssh_session session,char *crypted);
|
||||
int packet_decrypt(ssh_session session, void *packet,unsigned int len);
|
||||
unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len);
|
||||
/* it returns the hmac buffer if exists*/
|
||||
int packet_hmac_verify(SSH_SESSION *session,BUFFER *buffer,unsigned char *mac);
|
||||
int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac);
|
||||
|
||||
/* in packet.c */
|
||||
|
||||
void packet_parse(SSH_SESSION *session);
|
||||
int packet_send(SSH_SESSION *session);
|
||||
|
||||
int packet_read(SSH_SESSION *session);
|
||||
int packet_translate(SSH_SESSION *session);
|
||||
int packet_wait(SSH_SESSION *session,int type,int blocking);
|
||||
int packet_flush(SSH_SESSION *session, int enforce_blocking);
|
||||
/* connect.c */
|
||||
SSH_SESSION *ssh_session_new();
|
||||
socket_t ssh_connect_host(SSH_SESSION *session, const char *host,const char
|
||||
int ssh_regex_init(void);
|
||||
void ssh_regex_finalize(void);
|
||||
ssh_session ssh_session_new(void);
|
||||
socket_t ssh_connect_host(ssh_session session, const char *host,const char
|
||||
*bind_addr, int port, long timeout, long usec);
|
||||
|
||||
/* in kex.c */
|
||||
extern char *ssh_kex_nums[];
|
||||
void ssh_send_kex(SSH_SESSION *session,int server_kex);
|
||||
void ssh_list_kex(KEX *kex);
|
||||
int set_kex(SSH_SESSION *session);
|
||||
int ssh_get_kex(SSH_SESSION *session, int server_kex);
|
||||
extern const char *ssh_kex_nums[];
|
||||
int ssh_send_kex(ssh_session session, int server_kex);
|
||||
void ssh_list_kex(ssh_session session, KEX *kex);
|
||||
int set_kex(ssh_session session);
|
||||
int ssh_get_kex(ssh_session session, int server_kex);
|
||||
int verify_existing_algo(int algo, const char *name);
|
||||
char **space_tokenize(const char *chain);
|
||||
int ssh_get_kex1(SSH_SESSION *session);
|
||||
int ssh_get_kex1(ssh_session session);
|
||||
char *ssh_find_matching(const char *in_d, const char *what_d);
|
||||
|
||||
/* in keyfiles.c */
|
||||
|
||||
PRIVATE_KEY *_privatekey_from_file(void *session,char *filename,int type);
|
||||
|
||||
/* in keys.c */
|
||||
char *ssh_type_to_char(int type);
|
||||
PUBLIC_KEY *publickey_make_dss(SSH_SESSION *session, BUFFER *buffer);
|
||||
PUBLIC_KEY *publickey_make_rsa(SSH_SESSION *session, BUFFER *buffer,char *type);
|
||||
PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s);
|
||||
SIGNATURE *signature_from_string(SSH_SESSION *session, STRING *signature,PUBLIC_KEY *pubkey,int needed_type);
|
||||
void signature_free(SIGNATURE *sign);
|
||||
STRING *ssh_do_sign(SSH_SESSION *session,BUFFER *sigbuf,
|
||||
PRIVATE_KEY *privatekey);
|
||||
STRING *ssh_sign_session_id(SSH_SESSION *session, PRIVATE_KEY *privatekey);
|
||||
STRING *ssh_encrypt_rsa1(SSH_SESSION *session, STRING *data, PUBLIC_KEY *key);
|
||||
/* channel.c */
|
||||
void channel_handle(SSH_SESSION *session, int type);
|
||||
CHANNEL *channel_new(SSH_SESSION *session);
|
||||
void channel_default_bufferize(CHANNEL *channel, void *data, int len,
|
||||
int is_stderr);
|
||||
u32 ssh_channel_new_id(SSH_SESSION *session);
|
||||
CHANNEL *ssh_channel_from_local(SSH_SESSION *session,u32 num);
|
||||
|
||||
/* options.c */
|
||||
|
||||
void ssh_options_free(SSH_OPTIONS *opt);
|
||||
/* this function must be called when no specific username has been asked. it has to guess it */
|
||||
int ssh_options_default_username(SSH_OPTIONS *opt);
|
||||
int ssh_options_default_ssh_dir(SSH_OPTIONS *opt);
|
||||
int ssh_options_default_known_hosts_file(SSH_OPTIONS *opt);
|
||||
|
||||
/* buffer.c */
|
||||
void buffer_add_ssh_string(BUFFER *buffer,STRING *string);
|
||||
void buffer_add_u8(BUFFER *buffer, u8 data);
|
||||
void buffer_add_u32(BUFFER *buffer, u32 data);
|
||||
void buffer_add_u64(BUFFER *buffer,u64 data);
|
||||
void buffer_add_data(BUFFER *buffer,const void *data, int len);
|
||||
void buffer_add_data_begin(BUFFER *buffer,const void *data,int len);
|
||||
void buffer_add_buffer(BUFFER *buffer, BUFFER *source);
|
||||
void buffer_reinit(BUFFER *buffer);
|
||||
|
||||
/* buffer_get_rest returns a pointer to the current position into the buffer */
|
||||
void *buffer_get_rest(BUFFER *buffer);
|
||||
/* buffer_get_rest_len returns the number of bytes which can be read */
|
||||
int buffer_get_rest_len(BUFFER *buffer);
|
||||
|
||||
/* buffer_read_*() returns the number of bytes read, except for ssh strings */
|
||||
int buffer_get_u8(BUFFER *buffer,u8 *data);
|
||||
int buffer_get_u32(BUFFER *buffer,u32 *data);
|
||||
int buffer_get_u64(BUFFER *buffer, u64 *data);
|
||||
|
||||
int buffer_get_data(BUFFER *buffer,void *data,int requestedlen);
|
||||
/* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
|
||||
STRING *buffer_get_ssh_string(BUFFER *buffer);
|
||||
/* gets a string out of a SSH-1 mpint */
|
||||
STRING *buffer_get_mpint(BUFFER *buffer);
|
||||
/* buffer_pass_bytes acts as if len bytes have been read (used for padding) */
|
||||
int buffer_pass_bytes_end(BUFFER *buffer,int len);
|
||||
int buffer_pass_bytes(BUFFER *buffer, int len);
|
||||
|
||||
/* in base64.c */
|
||||
BUFFER *base64_to_bin(char *source);
|
||||
unsigned char *bin_to_base64(unsigned char *source, int len);
|
||||
ssh_buffer base64_to_bin(const char *source);
|
||||
unsigned char *bin_to_base64(const unsigned char *source, int len);
|
||||
|
||||
/* gzip.c */
|
||||
int compress_buffer(SSH_SESSION *session,BUFFER *buf);
|
||||
int decompress_buffer(SSH_SESSION *session,BUFFER *buf);
|
||||
|
||||
/* wrapper.c */
|
||||
int crypt_set_algorithms(SSH_SESSION *);
|
||||
int crypt_set_algorithms_server(SSH_SESSION *session);
|
||||
CRYPTO *crypto_new();
|
||||
void crypto_free(CRYPTO *crypto);
|
||||
int compress_buffer(ssh_session session,ssh_buffer buf);
|
||||
int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen);
|
||||
|
||||
/* crc32.c */
|
||||
u32 ssh_crc32(char *buffer, int len);
|
||||
uint32_t ssh_crc32(const char *buf, uint32_t len);
|
||||
|
||||
/* auth1.c */
|
||||
int ssh_userauth1_none(SSH_SESSION *session, char *username);
|
||||
int ssh_userauth1_offer_pubkey(SSH_SESSION *session, char *username,
|
||||
int type, STRING *pubkey);
|
||||
int ssh_userauth1_password(SSH_SESSION *session, char *username,
|
||||
char *password);
|
||||
/* in misc.c */
|
||||
/* gets the user home dir. */
|
||||
char *ssh_get_user_home_dir();
|
||||
int ssh_file_readaccess_ok(char *file);
|
||||
|
||||
/* macro for byte ordering */
|
||||
u64 ntohll(u64);
|
||||
#define htonll(x) ntohll(x)
|
||||
int ssh_userauth1_none(ssh_session session, const char *username);
|
||||
int ssh_userauth1_offer_pubkey(ssh_session session, const char *username,
|
||||
int type, ssh_string pubkey);
|
||||
int ssh_userauth1_password(ssh_session session, const char *username,
|
||||
const char *password);
|
||||
|
||||
/* channels1.c */
|
||||
int channel_open_session1(CHANNEL *channel);
|
||||
int channel_request_pty_size1(CHANNEL *channel, char *terminal,int cols,
|
||||
int rows);
|
||||
int channel_change_pty_size1(CHANNEL *channel, int cols, int rows);
|
||||
int channel_request_shell1(CHANNEL *channel);
|
||||
int channel_request_exec1(CHANNEL *channel, char *cmd);
|
||||
void channel_handle1(SSH_SESSION *session,int type);
|
||||
int channel_write1(CHANNEL *channel, void *data, int len);
|
||||
int channel_open_session1(ssh_channel channel);
|
||||
int channel_request_pty_size1(ssh_channel channel, const char *terminal,
|
||||
int cols, int rows);
|
||||
int channel_change_pty_size1(ssh_channel channel, int cols, int rows);
|
||||
int channel_request_shell1(ssh_channel channel);
|
||||
int channel_request_exec1(ssh_channel channel, const char *cmd);
|
||||
int channel_handle1(ssh_session session, int type);
|
||||
int channel_write1(ssh_channel channel, const void *data, int len);
|
||||
|
||||
/* session.c */
|
||||
|
||||
int ssh_handle_packets(SSH_SESSION *session);
|
||||
/* match.c */
|
||||
int match_hostname(const char *host, const char *pattern, unsigned int len);
|
||||
|
||||
/* log.c */
|
||||
|
||||
/* misc.c */
|
||||
#ifdef _WIN32
|
||||
int gettimeofday(struct timeval *__p, void *__t);
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifndef __FUNCTION__
|
||||
#if defined(__SUNPRO_C)
|
||||
#define __FUNCTION__ __func__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define _enter_function(sess) \
|
||||
do {\
|
||||
if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \
|
||||
@@ -633,8 +212,33 @@ int ssh_handle_packets(SSH_SESSION *session);
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
#ifdef DEBUG_CALLTRACE
|
||||
#define enter_function() _enter_function(session)
|
||||
#define leave_function() _leave_function(session)
|
||||
#else
|
||||
#define enter_function() (void)session
|
||||
#define leave_function() (void)session
|
||||
#endif
|
||||
|
||||
/* options.c */
|
||||
|
||||
char *dir_expand_dup(ssh_session session, const char *value, int allowsshdir);
|
||||
int ssh_options_set_algo(ssh_session session, int algo, const char *list);
|
||||
|
||||
/** Free memory space */
|
||||
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
|
||||
|
||||
/** Zero a structure */
|
||||
#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
|
||||
|
||||
/** Zero a structure given a pointer to the structure */
|
||||
#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
|
||||
|
||||
/** Get the size of an array */
|
||||
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
/** Overwrite the complete string with 'X' */
|
||||
#define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
|
||||
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
/* gcrypt_missing.c */
|
||||
@@ -643,7 +247,8 @@ char *my_gcry_bn2dec(bignum bn);
|
||||
#endif /* !HAVE_LIBGCRYPT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBSSH_PRIV_H */
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
|
||||
56
include/libssh/scp.h
Normal file
56
include/libssh/scp.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2003-2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _SCP_H
|
||||
#define _SCP_H
|
||||
|
||||
enum ssh_scp_states {
|
||||
SSH_SCP_NEW, //Data structure just created
|
||||
SSH_SCP_WRITE_INITED, //Gave our intention to write
|
||||
SSH_SCP_WRITE_WRITING,//File was opened and currently writing
|
||||
SSH_SCP_READ_INITED, //Gave our intention to read
|
||||
SSH_SCP_READ_REQUESTED, //We got a read request
|
||||
SSH_SCP_READ_READING, //File is opened and reading
|
||||
SSH_SCP_ERROR, //Something bad happened
|
||||
SSH_SCP_TERMINATED //Transfer finished
|
||||
};
|
||||
|
||||
struct ssh_scp_struct {
|
||||
ssh_session session;
|
||||
int mode;
|
||||
int recursive;
|
||||
ssh_channel channel;
|
||||
char *location;
|
||||
enum ssh_scp_states state;
|
||||
size_t filelen;
|
||||
size_t processed;
|
||||
enum ssh_scp_request_types request_type;
|
||||
char *request_name;
|
||||
char *warning;
|
||||
int request_mode;
|
||||
};
|
||||
|
||||
int ssh_scp_read_string(ssh_scp scp, char *buffer, size_t len);
|
||||
int ssh_scp_integer_mode(const char *mode);
|
||||
char *ssh_scp_string_mode(int mode);
|
||||
int ssh_scp_response(ssh_scp scp, char **response);
|
||||
|
||||
#endif
|
||||
@@ -1,22 +1,30 @@
|
||||
/* Public include file for server support */
|
||||
/*
|
||||
Copyright 2004 Aris Adamantiadis
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2003-2008 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
/**
|
||||
* @defgroup ssh_server SSH Server
|
||||
* @addtogroup ssh_server
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
@@ -28,67 +36,152 @@ MA 02111-1307, USA. */
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ssh_bind_struct SSH_BIND;
|
||||
enum ssh_bind_options_e {
|
||||
SSH_BIND_OPTIONS_BINDADDR,
|
||||
SSH_BIND_OPTIONS_BINDPORT,
|
||||
SSH_BIND_OPTIONS_BINDPORT_STR,
|
||||
SSH_BIND_OPTIONS_HOSTKEY,
|
||||
SSH_BIND_OPTIONS_DSAKEY,
|
||||
SSH_BIND_OPTIONS_RSAKEY,
|
||||
SSH_BIND_OPTIONS_BANNER,
|
||||
SSH_BIND_OPTIONS_LOG_VERBOSITY,
|
||||
SSH_BIND_OPTIONS_LOG_VERBOSITY_STR
|
||||
};
|
||||
|
||||
SSH_BIND *ssh_bind_new();
|
||||
void ssh_bind_set_options(SSH_BIND *ssh_bind, SSH_OPTIONS *options);
|
||||
int ssh_bind_listen(SSH_BIND *ssh_bind);
|
||||
void ssh_bind_set_blocking(SSH_BIND *ssh_bind,int blocking);
|
||||
int ssh_bind_get_fd(SSH_BIND *ssh_bind);
|
||||
int ssh_bind_set_toaccept(SSH_BIND *ssh_bind);
|
||||
SSH_SESSION *ssh_bind_accept(SSH_BIND *ssh_bind);
|
||||
void ssh_bind_free(SSH_BIND *ssh_bind);
|
||||
int ssh_accept(SSH_SESSION *session);
|
||||
//typedef struct ssh_bind_struct SSH_BIND;
|
||||
typedef struct ssh_bind_struct* ssh_bind;
|
||||
|
||||
/**
|
||||
* @brief Creates a new SSH server bind.
|
||||
*
|
||||
* @return A newly allocated ssh_bind session pointer.
|
||||
*/
|
||||
LIBSSH_API ssh_bind ssh_bind_new(void);
|
||||
|
||||
/**
|
||||
* @brief Set the opitons for the current SSH server bind.
|
||||
*
|
||||
* @param ssh_bind The ssh server bind to use.
|
||||
*
|
||||
* @param options The option structure to set.
|
||||
*/
|
||||
LIBSSH_API int ssh_bind_options_set(ssh_bind sshbind,
|
||||
enum ssh_bind_options_e type, const void *value);
|
||||
|
||||
/**
|
||||
* @brief Start listening to the socket.
|
||||
*
|
||||
* @param ssh_bind_o The ssh server bind to use.
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
LIBSSH_API int ssh_bind_listen(ssh_bind ssh_bind_o);
|
||||
|
||||
/**
|
||||
* @brief Set the session to blocking/nonblocking mode.
|
||||
*
|
||||
* @param ssh_bind_o The ssh server bind to use.
|
||||
*
|
||||
* @param blocking Zero for nonblocking mode.
|
||||
*/
|
||||
LIBSSH_API void ssh_bind_set_blocking(ssh_bind ssh_bind_o, int blocking);
|
||||
|
||||
/**
|
||||
* @brief Recover the file descriptor from the session.
|
||||
*
|
||||
* @param ssh_bind_o The ssh server bind to get the fd from.
|
||||
*
|
||||
* @return The file descriptor.
|
||||
*/
|
||||
LIBSSH_API socket_t ssh_bind_get_fd(ssh_bind ssh_bind_o);
|
||||
|
||||
/**
|
||||
* @brief Set the file descriptor for a session.
|
||||
*
|
||||
* @param ssh_bind_o The ssh server bind to set the fd.
|
||||
*
|
||||
* @param fd The file descriptssh_bind B
|
||||
*/
|
||||
LIBSSH_API void ssh_bind_set_fd(ssh_bind ssh_bind_o, socket_t fd);
|
||||
|
||||
/**
|
||||
* @brief Allow the file descriptor to accept new sessions.
|
||||
*
|
||||
* @param ssh_bind_o The ssh server bind to use.
|
||||
*/
|
||||
LIBSSH_API void ssh_bind_fd_toaccept(ssh_bind ssh_bind_o);
|
||||
|
||||
/**
|
||||
* @brief Accept an incoming ssh connection and initialize the session.
|
||||
*
|
||||
* @param ssh_bind_o The ssh server bind to accept a connection.
|
||||
* @param session A preallocated ssh session
|
||||
* @see ssh_new
|
||||
* @return A newly allocated ssh session, NULL on error.
|
||||
*/
|
||||
LIBSSH_API int ssh_bind_accept(ssh_bind ssh_bind_o, ssh_session session);
|
||||
|
||||
/**
|
||||
* @brief Free a ssh servers bind.
|
||||
*
|
||||
* @param ssh_bind_o The ssh server bind to free.
|
||||
*/
|
||||
LIBSSH_API void ssh_bind_free(ssh_bind ssh_bind_o);
|
||||
|
||||
/**
|
||||
* @brief Exchange the banner and cryptographic keys.
|
||||
*
|
||||
* @param session The ssh session to accept a connection.
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
LIBSSH_API int ssh_accept(ssh_session session);
|
||||
|
||||
LIBSSH_API int channel_write_stderr(ssh_channel channel, const void *data, uint32_t len);
|
||||
|
||||
/* messages.c */
|
||||
LIBSSH_API int ssh_message_reply_default(ssh_message msg);
|
||||
|
||||
#define SSH_AUTH_REQUEST 1
|
||||
#define SSH_CHANNEL_REQUEST_OPEN 2
|
||||
#define SSH_CHANNEL_REQUEST 3
|
||||
LIBSSH_API char *ssh_message_auth_user(ssh_message msg);
|
||||
LIBSSH_API char *ssh_message_auth_password(ssh_message msg);
|
||||
LIBSSH_API ssh_public_key ssh_message_auth_publickey(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_auth_reply_success(ssh_message msg,int partial);
|
||||
LIBSSH_API int ssh_message_auth_reply_pk_ok(ssh_message msg, ssh_string algo, ssh_string pubkey);
|
||||
LIBSSH_API int ssh_message_auth_set_methods(ssh_message msg, int methods);
|
||||
|
||||
#define SSH_AUTH_NONE (1<<0)
|
||||
#define SSH_AUTH_PASSWORD (1<<1)
|
||||
#define SSH_AUTH_HOSTBASED (1<<2)
|
||||
#define SSH_AUTH_PUBLICKEY (1<<3)
|
||||
#define SSH_AUTH_KEYBINT (1<<4)
|
||||
#define SSH_AUTH_UNKNOWN 0
|
||||
LIBSSH_API int ssh_message_service_reply_success(ssh_message msg);
|
||||
LIBSSH_API char *ssh_message_service_service(ssh_message msg);
|
||||
|
||||
#define SSH_CHANNEL_SESSION 1
|
||||
#define SSH_CHANNEL_TCPIP 2
|
||||
#define SSH_CHANNEL_X11 3
|
||||
#define SSH_CHANNEL_UNKNOWN 4
|
||||
LIBSSH_API void ssh_set_message_callback(ssh_session session,
|
||||
int(*ssh_message_callback)(ssh_session session, ssh_message msg));
|
||||
|
||||
#define SSH_CHANNEL_REQUEST_PTY 1
|
||||
#define SSH_CHANNEL_REQUEST_EXEC 2
|
||||
#define SSH_CHANNEL_REQUEST_SHELL 3
|
||||
#define SSH_CHANNEL_REQUEST_ENV 4
|
||||
#define SSH_CHANNEL_REQUEST_SUBSYSTEM 5
|
||||
#define SSH_CHANNEL_REQUEST_WINDOW_CHANGE 6
|
||||
#define SSH_CHANNEL_REQUEST_UNKNOWN 7
|
||||
LIBSSH_API char *ssh_message_channel_request_open_originator(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_channel_request_open_originator_port(ssh_message msg);
|
||||
LIBSSH_API char *ssh_message_channel_request_open_destination(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_channel_request_open_destination_port(ssh_message msg);
|
||||
|
||||
typedef struct ssh_message SSH_MESSAGE;
|
||||
LIBSSH_API ssh_channel ssh_message_channel_request_channel(ssh_message msg);
|
||||
|
||||
SSH_MESSAGE *ssh_message_get(SSH_SESSION *session);
|
||||
int ssh_message_type(SSH_MESSAGE *msg);
|
||||
int ssh_message_subtype(SSH_MESSAGE *msg);
|
||||
int ssh_message_reply_default(SSH_MESSAGE *msg);
|
||||
void ssh_message_free(SSH_MESSAGE *msg);
|
||||
LIBSSH_API char *ssh_message_channel_request_pty_term(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_channel_request_pty_width(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_channel_request_pty_height(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_channel_request_pty_pxwidth(ssh_message msg);
|
||||
LIBSSH_API int ssh_message_channel_request_pty_pxheight(ssh_message msg);
|
||||
|
||||
char *ssh_message_auth_user(SSH_MESSAGE *msg);
|
||||
char *ssh_message_auth_password(SSH_MESSAGE *msg);
|
||||
int ssh_message_auth_reply_success(SSH_MESSAGE *msg,int partial);
|
||||
void ssh_message_auth_set_methods(SSH_MESSAGE *msg, int methods);
|
||||
LIBSSH_API char *ssh_message_channel_request_env_name(ssh_message msg);
|
||||
LIBSSH_API char *ssh_message_channel_request_env_value(ssh_message msg);
|
||||
|
||||
CHANNEL *ssh_message_channel_request_open_reply_accept(SSH_MESSAGE *msg);
|
||||
LIBSSH_API char *ssh_message_channel_request_command(ssh_message msg);
|
||||
|
||||
CHANNEL *ssh_message_channel_request_channel(SSH_MESSAGE *msg);
|
||||
// returns the TERM env variable
|
||||
char *ssh_message_channel_request_pty_term(SSH_MESSAGE *msg);
|
||||
char *ssh_message_channel_request_subsystem(SSH_MESSAGE *msg);
|
||||
int ssh_message_channel_request_reply_success(SSH_MESSAGE *msg);
|
||||
LIBSSH_API char *ssh_message_channel_request_subsystem(ssh_message msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* SERVER_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
|
||||
121
include/libssh/session.h
Normal file
121
include/libssh/session.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef SESSION_H_
|
||||
#define SESSION_H_
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/packet.h"
|
||||
#include "libssh/pcap.h"
|
||||
|
||||
typedef struct ssh_kbdint_struct* ssh_kbdint;
|
||||
|
||||
struct ssh_session_struct {
|
||||
struct error_struct error;
|
||||
struct socket *socket;
|
||||
char *serverbanner;
|
||||
char *clientbanner;
|
||||
int protoversion;
|
||||
int server;
|
||||
int client;
|
||||
int openssh;
|
||||
uint32_t send_seq;
|
||||
uint32_t recv_seq;
|
||||
/* status flags */
|
||||
int closed;
|
||||
int closed_by_except;
|
||||
|
||||
int connected;
|
||||
/* !=0 when the user got a session handle */
|
||||
int alive;
|
||||
/* two previous are deprecated */
|
||||
int auth_service_asked;
|
||||
|
||||
/* socket status */
|
||||
int blocking; // functions should block
|
||||
|
||||
ssh_string banner; /* that's the issue banner from
|
||||
the server */
|
||||
char *remotebanner; /* that's the SSH- banner from
|
||||
remote host. */
|
||||
char *discon_msg; /* disconnect message from
|
||||
the remote host */
|
||||
ssh_buffer in_buffer;
|
||||
PACKET in_packet;
|
||||
ssh_buffer out_buffer;
|
||||
|
||||
/* the states are used by the nonblocking stuff to remember */
|
||||
/* where it was before being interrupted */
|
||||
int packet_state;
|
||||
int dh_handshake_state;
|
||||
ssh_string dh_server_signature; //information used by dh_handshake.
|
||||
|
||||
KEX server_kex;
|
||||
KEX client_kex;
|
||||
ssh_buffer in_hashbuf;
|
||||
ssh_buffer out_hashbuf;
|
||||
struct ssh_crypto_struct *current_crypto;
|
||||
struct ssh_crypto_struct *next_crypto; /* next_crypto is going to be used after a SSH2_MSG_NEWKEYS */
|
||||
|
||||
ssh_channel channels; /* linked list of channels */
|
||||
int maxchannel;
|
||||
int exec_channel_opened; /* version 1 only. more
|
||||
info in channels1.c */
|
||||
ssh_agent agent; /* ssh agent */
|
||||
|
||||
/* keyb interactive data */
|
||||
struct ssh_kbdint_struct *kbdint;
|
||||
int version; /* 1 or 2 */
|
||||
/* server host keys */
|
||||
ssh_private_key rsa_key;
|
||||
ssh_private_key dsa_key;
|
||||
/* auths accepted by server */
|
||||
int auth_methods;
|
||||
int hostkeys; /* contains type of host key wanted by client, in server impl */
|
||||
struct ssh_list *ssh_message_list; /* list of delayed SSH messages */
|
||||
int (*ssh_message_callback)( struct ssh_session_struct *session, ssh_message msg);
|
||||
int log_verbosity; /*cached copy of the option structure */
|
||||
int log_indent; /* indentation level in enter_function logs */
|
||||
|
||||
ssh_callbacks callbacks; /* Callbacks to user functions */
|
||||
|
||||
/* options */
|
||||
#ifdef WITH_PCAP
|
||||
ssh_pcap_context pcap_ctx; /* pcap debugging context */
|
||||
#endif
|
||||
char *username;
|
||||
char *host;
|
||||
char *bindaddr; /* TODO: check if needed */
|
||||
char *xbanner; /* TODO: looks like it is not needed */
|
||||
char *identity;
|
||||
char *sshdir;
|
||||
char *knownhosts;
|
||||
char *wanted_methods[10];
|
||||
unsigned long timeout; /* seconds */
|
||||
unsigned long timeout_usec;
|
||||
unsigned int port;
|
||||
socket_t fd;
|
||||
int ssh2;
|
||||
int ssh1;
|
||||
};
|
||||
|
||||
int ssh_handle_packets(ssh_session session);
|
||||
|
||||
#endif /* SESSION_H_ */
|
||||
@@ -1,194 +1,793 @@
|
||||
/* sftp headers */
|
||||
/*
|
||||
Copyright 2003-2005 Aris Adamantiadis
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2003-2008 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
/**
|
||||
* @file sftp.h
|
||||
*
|
||||
* @brief SFTP handling functions
|
||||
*
|
||||
* SFTP commands are channeled by the ssh sftp subsystem. Every packet is
|
||||
* sent/read using a sftp_packet type structure. Related to these packets,
|
||||
* most of the server answers are messages having an ID and a message
|
||||
* specific part. It is described by sftp_message when reading a message,
|
||||
* the sftp system puts it into the queue, so the process having asked for
|
||||
* it can fetch it, while continuing to read for other messages (it is
|
||||
* unspecified in which order messages may be sent back to the client
|
||||
*
|
||||
* @defgroup ssh_sftp SFTP Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SFTP_H
|
||||
#define SFTP_H
|
||||
#include <libssh/libssh.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "libssh.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct sftp_session_struct {
|
||||
SSH_SESSION *session;
|
||||
CHANNEL *channel;
|
||||
#ifdef _WIN32
|
||||
#ifndef uid_t
|
||||
typedef uint32_t uid_t;
|
||||
#endif /* uid_t */
|
||||
#ifndef gid_t
|
||||
typedef uint32_t gid_t;
|
||||
#endif /* gid_t */
|
||||
#ifdef _MSC_VER
|
||||
#ifndef ssize_t
|
||||
typedef _W64 SSIZE_T ssize_t;
|
||||
#endif /* ssize_t */
|
||||
#endif /* _MSC_VER */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
typedef struct sftp_attributes_struct* sftp_attributes;
|
||||
typedef struct sftp_client_message_struct* sftp_client_message;
|
||||
typedef struct sftp_dir_struct* sftp_dir;
|
||||
typedef struct sftp_ext_struct *sftp_ext;
|
||||
typedef struct sftp_file_struct* sftp_file;
|
||||
typedef struct sftp_message_struct* sftp_message;
|
||||
typedef struct sftp_packet_struct* sftp_packet;
|
||||
typedef struct sftp_request_queue_struct* sftp_request_queue;
|
||||
typedef struct sftp_session_struct* sftp_session;
|
||||
typedef struct sftp_status_message_struct* sftp_status_message;
|
||||
typedef struct sftp_statvfs_struct* sftp_statvfs_t;
|
||||
|
||||
struct sftp_session_struct {
|
||||
ssh_session session;
|
||||
ssh_channel channel;
|
||||
int server_version;
|
||||
int client_version;
|
||||
int version;
|
||||
struct request_queue *queue;
|
||||
u32 id_counter;
|
||||
sftp_request_queue queue;
|
||||
uint32_t id_counter;
|
||||
int errnum;
|
||||
void **handles;
|
||||
} SFTP_SESSION ;
|
||||
sftp_ext ext;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
SFTP_SESSION *sftp;
|
||||
u8 type;
|
||||
BUFFER *payload;
|
||||
} SFTP_PACKET;
|
||||
struct sftp_packet_struct {
|
||||
sftp_session sftp;
|
||||
uint8_t type;
|
||||
ssh_buffer payload;
|
||||
};
|
||||
|
||||
/* file handler */
|
||||
typedef struct sftp_file{
|
||||
SFTP_SESSION *sftp;
|
||||
struct sftp_file_struct {
|
||||
sftp_session sftp;
|
||||
char *name;
|
||||
u64 offset;
|
||||
STRING *handle;
|
||||
uint64_t offset;
|
||||
ssh_string handle;
|
||||
int eof;
|
||||
int nonblocking;
|
||||
} SFTP_FILE ;
|
||||
};
|
||||
|
||||
typedef struct sftp_dir {
|
||||
SFTP_SESSION *sftp;
|
||||
struct sftp_dir_struct {
|
||||
sftp_session sftp;
|
||||
char *name;
|
||||
STRING *handle; /* handle to directory */
|
||||
BUFFER *buffer; /* contains raw attributes from server which haven't been parsed */
|
||||
u32 count; /* counts the number of following attributes structures into buffer */
|
||||
ssh_string handle; /* handle to directory */
|
||||
ssh_buffer buffer; /* contains raw attributes from server which haven't been parsed */
|
||||
uint32_t count; /* counts the number of following attributes structures into buffer */
|
||||
int eof; /* end of directory listing */
|
||||
} SFTP_DIR;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
SFTP_SESSION *sftp;
|
||||
u8 packet_type;
|
||||
BUFFER *payload;
|
||||
u32 id;
|
||||
} SFTP_MESSAGE;
|
||||
struct sftp_message_struct {
|
||||
sftp_session sftp;
|
||||
uint8_t packet_type;
|
||||
ssh_buffer payload;
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
/* this is a bunch of all data that could be into a message */
|
||||
typedef struct sftp_client_message{
|
||||
SFTP_SESSION *sftp;
|
||||
u8 type;
|
||||
u32 id;
|
||||
struct sftp_client_message_struct {
|
||||
sftp_session sftp;
|
||||
uint8_t type;
|
||||
uint32_t id;
|
||||
char *filename; /* can be "path" */
|
||||
u32 flags;
|
||||
struct sftp_attributes *attr;
|
||||
STRING *handle;
|
||||
u64 offset;
|
||||
u32 len;
|
||||
uint32_t flags;
|
||||
sftp_attributes attr;
|
||||
ssh_string handle;
|
||||
uint64_t offset;
|
||||
uint32_t len;
|
||||
int attr_num;
|
||||
BUFFER *attrbuf; /* used by sftp_reply_attrs */
|
||||
STRING *data; /* can be newpath of rename() */
|
||||
} SFTP_CLIENT_MESSAGE;
|
||||
ssh_buffer attrbuf; /* used by sftp_reply_attrs */
|
||||
ssh_string data; /* can be newpath of rename() */
|
||||
};
|
||||
|
||||
typedef struct request_queue{
|
||||
struct request_queue *next;
|
||||
SFTP_MESSAGE *message;
|
||||
} REQUEST_QUEUE;
|
||||
struct sftp_request_queue_struct {
|
||||
sftp_request_queue next;
|
||||
sftp_message message;
|
||||
};
|
||||
|
||||
/* SSH_FXP_MESSAGE described into .7 page 26 */
|
||||
typedef struct {
|
||||
u32 id;
|
||||
u32 status;
|
||||
STRING *error;
|
||||
STRING *lang;
|
||||
struct sftp_status_message_struct {
|
||||
uint32_t id;
|
||||
uint32_t status;
|
||||
ssh_string error;
|
||||
ssh_string lang;
|
||||
char *errormsg;
|
||||
char *langmsg;
|
||||
} STATUS_MESSAGE;
|
||||
};
|
||||
|
||||
/* don't worry much of these aren't really used */
|
||||
typedef struct sftp_attributes{
|
||||
struct sftp_attributes_struct {
|
||||
char *name;
|
||||
char *longname; /* some weird stuff */
|
||||
u32 flags;
|
||||
u8 type;
|
||||
u64 size;
|
||||
u32 uid;
|
||||
u32 gid;
|
||||
uint32_t flags;
|
||||
uint8_t type;
|
||||
uint64_t size;
|
||||
uint32_t uid;
|
||||
uint32_t gid;
|
||||
char *owner;
|
||||
char *group;
|
||||
u32 permissions;
|
||||
u64 atime64;
|
||||
u32 atime;
|
||||
u32 atime_nseconds;
|
||||
u64 createtime;
|
||||
u32 createtime_nseconds;
|
||||
u64 mtime64;
|
||||
u32 mtime;
|
||||
u32 mtime_nseconds;
|
||||
STRING *acl;
|
||||
u32 extended_count;
|
||||
STRING *extended_type;
|
||||
STRING *extended_data;
|
||||
} SFTP_ATTRIBUTES;
|
||||
uint32_t permissions;
|
||||
uint64_t atime64;
|
||||
uint32_t atime;
|
||||
uint32_t atime_nseconds;
|
||||
uint64_t createtime;
|
||||
uint32_t createtime_nseconds;
|
||||
uint64_t mtime64;
|
||||
uint32_t mtime;
|
||||
uint32_t mtime_nseconds;
|
||||
ssh_string acl;
|
||||
uint32_t extended_count;
|
||||
ssh_string extended_type;
|
||||
ssh_string extended_data;
|
||||
};
|
||||
|
||||
struct sftp_statvfs_struct {
|
||||
uint64_t f_bsize; /* file system block size */
|
||||
uint64_t f_frsize; /* fundamental fs block size */
|
||||
uint64_t f_blocks; /* number of blocks (unit f_frsize) */
|
||||
uint64_t f_bfree; /* free blocks in file system */
|
||||
uint64_t f_bavail; /* free blocks for non-root */
|
||||
uint64_t f_files; /* total file inodes */
|
||||
uint64_t f_ffree; /* free file inodes */
|
||||
uint64_t f_favail; /* free file inodes for to non-root */
|
||||
uint64_t f_fsid; /* file system id */
|
||||
uint64_t f_flag; /* bit mask of f_flag values */
|
||||
uint64_t f_namemax; /* maximum filename length */
|
||||
};
|
||||
|
||||
#define LIBSFTP_VERSION 3
|
||||
|
||||
SFTP_SESSION *sftp_new(SSH_SESSION *session);
|
||||
void sftp_free(SFTP_SESSION *sftp);
|
||||
int sftp_init(SFTP_SESSION *sftp);
|
||||
int sftp_get_error(SFTP_SESSION *sftp);
|
||||
SFTP_DIR *sftp_opendir(SFTP_SESSION *session, const char *path);
|
||||
/* reads one file and attribute from opened directory. fails at end */
|
||||
SFTP_ATTRIBUTES *sftp_readdir(SFTP_SESSION *session, SFTP_DIR *dir);
|
||||
/* returns 1 if the directory was EOF */
|
||||
int sftp_dir_eof(SFTP_DIR *dir);
|
||||
SFTP_ATTRIBUTES *sftp_stat(SFTP_SESSION *session, const char *path);
|
||||
SFTP_ATTRIBUTES *sftp_lstat(SFTP_SESSION *session, const char *path);
|
||||
/* sftp_lstat stats a file but doesn't follow symlinks */
|
||||
SFTP_ATTRIBUTES *sftp_fstat(SFTP_FILE *file);
|
||||
void sftp_attributes_free(SFTP_ATTRIBUTES *file);
|
||||
int sftp_dir_close(SFTP_DIR *dir);
|
||||
int sftp_file_close(SFTP_FILE *file);
|
||||
/* access are the sames than the ones from ansi fopen() */
|
||||
SFTP_FILE *sftp_open(SFTP_SESSION *session, const char *file, int access, SFTP_ATTRIBUTES *attr);
|
||||
int sftp_read(SFTP_FILE *file, void *dest, int len);
|
||||
u32 sftp_async_read_begin(SFTP_FILE *file, int len);
|
||||
int sftp_async_read(SFTP_FILE *file, void *data, int len, u32 id);
|
||||
int sftp_write(SFTP_FILE *file, const void *source, int len);
|
||||
void sftp_seek(SFTP_FILE *file, int new_offset);
|
||||
void sftp_seek64(SFTP_FILE *file, u64 new_offset);
|
||||
unsigned long sftp_tell(SFTP_FILE *file);
|
||||
void sftp_rewind(SFTP_FILE *file);
|
||||
int sftp_rm(SFTP_SESSION *sftp, char *file);
|
||||
int sftp_rmdir(SFTP_SESSION *sftp, const char *directory);
|
||||
int sftp_mkdir(SFTP_SESSION *sftp, const char *directory, SFTP_ATTRIBUTES *attr);
|
||||
int sftp_rename(SFTP_SESSION *sftp, const char *original, const char *newname);
|
||||
int sftp_setstat(SFTP_SESSION *sftp, const char *file, SFTP_ATTRIBUTES *attr);
|
||||
char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path);
|
||||
/**
|
||||
* @brief Start a new sftp session.
|
||||
*
|
||||
* @param session The ssh session to use.
|
||||
*
|
||||
* @return A new sftp session or NULL on error.
|
||||
*/
|
||||
LIBSSH_API sftp_session sftp_new(ssh_session session);
|
||||
|
||||
#ifndef NO_SERVER
|
||||
SFTP_SESSION *sftp_server_new(SSH_SESSION *session, CHANNEL *chan);
|
||||
int sftp_server_init(SFTP_SESSION *sftp);
|
||||
#endif
|
||||
/**
|
||||
* @brief Close and deallocate a sftp session.
|
||||
*
|
||||
* @param sftp The sftp session handle to free.
|
||||
*/
|
||||
LIBSSH_API void sftp_free(sftp_session sftp);
|
||||
|
||||
/**
|
||||
* @brief Initialize the sftp session with the server.
|
||||
*
|
||||
* @param sftp The sftp session to initialize.
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_init(sftp_session sftp);
|
||||
|
||||
/**
|
||||
* @brief Get the last sftp error.
|
||||
*
|
||||
* Use this function to get the latest error set by a posix like sftp function.
|
||||
*
|
||||
* @param sftp The sftp session where the error is saved.
|
||||
*
|
||||
* @return The saved error (see server responses), < 0 if an error
|
||||
* in the function occured.
|
||||
*/
|
||||
LIBSSH_API int sftp_get_error(sftp_session sftp);
|
||||
|
||||
/**
|
||||
* @brief Get the count of extensions provided by the server.
|
||||
*
|
||||
* @param sftp The sftp session to use.
|
||||
*
|
||||
* @return The count of extensions provided by the server, 0 on error or
|
||||
* not available.
|
||||
*/
|
||||
LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp);
|
||||
|
||||
/**
|
||||
* @brief Get the name of the extension provided by the server.
|
||||
*
|
||||
* @param sftp The sftp session to use.
|
||||
*
|
||||
* @param indexn The index number of the extension name you want.
|
||||
*
|
||||
* @return The name of the extension.
|
||||
*/
|
||||
LIBSSH_API const char *sftp_extensions_get_name(sftp_session sftp, unsigned int indexn);
|
||||
|
||||
/**
|
||||
* @brief Get the data of the extension provided by the server.
|
||||
*
|
||||
* This is normally the version number of the extension.
|
||||
*
|
||||
* @param sftp The sftp session to use.
|
||||
*
|
||||
* @param indexn The index number of the extension data you want.
|
||||
*
|
||||
* @return The data of the extension.
|
||||
*/
|
||||
LIBSSH_API const char *sftp_extensions_get_data(sftp_session sftp, unsigned int indexn);
|
||||
|
||||
/**
|
||||
* @brief Check if the given extension is supported.
|
||||
*
|
||||
* @param sftp The sftp session to use.
|
||||
*
|
||||
* @param name The name of the extension.
|
||||
*
|
||||
* @param data The data of the extension.
|
||||
*
|
||||
* @return 1 if supported, 0 if not.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* sftp_extension_supported(sftp, "statvfs@openssh.com", "2");
|
||||
* @endcode
|
||||
*/
|
||||
LIBSSH_API int sftp_extension_supported(sftp_session sftp, const char *name,
|
||||
const char *data);
|
||||
|
||||
/**
|
||||
* @brief Open a directory used to obtain directory entries.
|
||||
|
||||
* @param session The sftp session handle to open the directory.
|
||||
* @param path The path of the directory to open.
|
||||
*
|
||||
* @return A sftp directory handle or NULL on error with ssh and
|
||||
* sftp error set.
|
||||
*
|
||||
* @see sftp_readdir
|
||||
* @see sftp_closedir
|
||||
*/
|
||||
LIBSSH_API sftp_dir sftp_opendir(sftp_session session, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Get a single file attributes structure of a directory.
|
||||
*
|
||||
* @param session The sftp session handle to read the directory entry.
|
||||
* @param dir The opened sftp directory handle to read from.
|
||||
*
|
||||
* @return A file attribute structure or NULL at the end of the
|
||||
* directory.
|
||||
*
|
||||
* @see sftp_opendir()
|
||||
* @see sftp_attribute_free()
|
||||
* @see sftp_closedir()
|
||||
*/
|
||||
LIBSSH_API sftp_attributes sftp_readdir(sftp_session session, sftp_dir dir);
|
||||
|
||||
/**
|
||||
* @brief Tell if the directory has reached EOF (End Of File).
|
||||
*
|
||||
* @param dir The sftp directory handle.
|
||||
*
|
||||
* @return 1 if the directory is EOF, 0 if not.
|
||||
*
|
||||
* @see sftp_readdir()
|
||||
*/
|
||||
LIBSSH_API int sftp_dir_eof(sftp_dir dir);
|
||||
|
||||
/**
|
||||
* @brief Get information about a file or directory.
|
||||
*
|
||||
* @param session The sftp session handle.
|
||||
* @param path The path to the file or directory to obtain the
|
||||
* information.
|
||||
*
|
||||
* @return The sftp attributes structure of the file or directory,
|
||||
* NULL on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Get information about a file or directory.
|
||||
*
|
||||
* Identical to sftp_stat, but if the file or directory is a symbolic link,
|
||||
* then the link itself is stated, not the file that it refers to.
|
||||
*
|
||||
* @param session The sftp session handle.
|
||||
* @param path The path to the file or directory to obtain the
|
||||
* information.
|
||||
*
|
||||
* @return The sftp attributes structure of the file or directory,
|
||||
* NULL on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Get information about a file or directory from a file handle.
|
||||
*
|
||||
* @param file The sftp file handle to get the stat information.
|
||||
*
|
||||
* @return The sftp attributes structure of the file or directory,
|
||||
* NULL on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API sftp_attributes sftp_fstat(sftp_file file);
|
||||
|
||||
/**
|
||||
* @brief Free a sftp attribute structure.
|
||||
*
|
||||
* @param file The sftp attribute structure to free.
|
||||
*/
|
||||
LIBSSH_API void sftp_attributes_free(sftp_attributes file);
|
||||
|
||||
/**
|
||||
* @brief Close a directory handle opened by sftp_opendir().
|
||||
*
|
||||
* @param dir The sftp directory handle to close.
|
||||
*
|
||||
* @return Returns SSH_NO_ERROR or SSH_ERROR if an error occured.
|
||||
*/
|
||||
LIBSSH_API int sftp_closedir(sftp_dir dir);
|
||||
|
||||
/**
|
||||
* @brief Close an open file handle.
|
||||
*
|
||||
* @param file The open sftp file handle to close.
|
||||
*
|
||||
* @return Returns SSH_NO_ERROR or SSH_ERROR if an error occured.
|
||||
*
|
||||
* @see sftp_open()
|
||||
*/
|
||||
LIBSSH_API int sftp_close(sftp_file file);
|
||||
|
||||
/**
|
||||
* @brief Open a file on the server.
|
||||
*
|
||||
* @param session The sftp session handle.
|
||||
*
|
||||
* @param file The file to be opened.
|
||||
*
|
||||
* @param accesstype Is one of O_RDONLY, O_WRONLY or O_RDWR which request
|
||||
* opening the file read-only,write-only or read/write.
|
||||
* Acesss may also be bitwise-or'd with one or more of
|
||||
* the following:
|
||||
* O_CREAT - If the file does not exist it will be
|
||||
* created.
|
||||
* O_EXCL - When used with O_CREAT, if the file already
|
||||
* exists it is an error and the open will fail.
|
||||
* O_TRUNC - If the file already exists it will be
|
||||
* truncated.
|
||||
*
|
||||
* @param mode Mode specifies the permissions to use if a new file is
|
||||
* created. It is modified by the process's umask in
|
||||
* the usual way: The permissions of the created file are
|
||||
* (mode & ~umask)
|
||||
*
|
||||
* @return A sftp file handle, NULL on error with ssh and sftp
|
||||
* error set.
|
||||
*/
|
||||
LIBSSH_API sftp_file sftp_open(sftp_session session, const char *file, int accesstype,
|
||||
mode_t mode);
|
||||
|
||||
LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle);
|
||||
|
||||
LIBSSH_API void sftp_file_set_blocking(sftp_file handle);
|
||||
|
||||
/**
|
||||
* @brief Read from a file using an opened sftp file handle.
|
||||
*
|
||||
* @param file The opened sftp file handle to be read from.
|
||||
*
|
||||
* @param buf Pointer to buffer to recieve read data.
|
||||
*
|
||||
* @param count Size of the buffer in bytes.
|
||||
*
|
||||
* @return Number of bytes written, < 0 on error with ssh and sftp
|
||||
* error set.
|
||||
*/
|
||||
LIBSSH_API ssize_t sftp_read(sftp_file file, void *buf, size_t count);
|
||||
|
||||
/**
|
||||
* @brief Start an asynchronous read from a file using an opened sftp file handle.
|
||||
*
|
||||
* Its goal is to avoid the slowdowns related to the request/response pattern
|
||||
* of a synchronous read. To do so, you must call 2 functions:
|
||||
*
|
||||
* sftp_async_read_begin() and sftp_async_read().
|
||||
*
|
||||
* The first step is to call sftp_async_read_begin(). This function returns a
|
||||
* request identifier. The second step is to call sftp_async_read() using the
|
||||
* returned identifier.
|
||||
*
|
||||
* @param file The opened sftp file handle to be read from.
|
||||
*
|
||||
* @param len Size to read in bytes.
|
||||
*
|
||||
* @return An identifier corresponding to the sent request, < 0 on
|
||||
* error.
|
||||
*
|
||||
* @warning When calling this function, the internal offset is
|
||||
* updated corresponding to the len parameter.
|
||||
*
|
||||
* @warning A call to sftp_async_read_begin() sends a request to
|
||||
* the server. When the server answers, libssh allocates
|
||||
* memory to store it until sftp_async_read() is called.
|
||||
* Not calling sftp_async_read() will lead to memory
|
||||
* leaks.
|
||||
*
|
||||
* @see sftp_async_read()
|
||||
* @see sftp_open()
|
||||
*/
|
||||
LIBSSH_API int sftp_async_read_begin(sftp_file file, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Wait for an asynchronous read to complete and save the data.
|
||||
*
|
||||
* @param file The opened sftp file handle to be read from.
|
||||
*
|
||||
* @param data Pointer to buffer to recieve read data.
|
||||
*
|
||||
* @param len Size of the buffer in bytes. It should be bigger or
|
||||
* equal to the length parameter of the
|
||||
* sftp_async_read_begin() call.
|
||||
*
|
||||
* @param id The identifier returned by the sftp_async_read_begin()
|
||||
* function.
|
||||
*
|
||||
* @return Number of bytes read, 0 on EOF, SSH_ERROR if an error
|
||||
* occured, SSH_AGAIN if the file is opened in nonblocking
|
||||
* mode and the request hasn't been executed yet.
|
||||
*
|
||||
* @warning A call to this function with an invalid identifier
|
||||
* will never return.
|
||||
*
|
||||
* @see sftp_async_read_begin()
|
||||
*/
|
||||
LIBSSH_API int sftp_async_read(sftp_file file, void *data, uint32_t len, uint32_t id);
|
||||
|
||||
/**
|
||||
* @brief Write to a file using an opened sftp file handle.
|
||||
*
|
||||
* @param file Open sftp file handle to write to.
|
||||
*
|
||||
* @param buf Pointer to buffer to write data.
|
||||
*
|
||||
* @param count Size of buffer in bytes.
|
||||
*
|
||||
* @return Number of bytes written, < 0 on error with ssh and sftp
|
||||
* error set.
|
||||
*
|
||||
* @see sftp_open()
|
||||
* @see sftp_read()
|
||||
* @see sftp_close()
|
||||
*/
|
||||
LIBSSH_API ssize_t sftp_write(sftp_file file, const void *buf, size_t count);
|
||||
|
||||
/**
|
||||
* @brief Seek to a specific location in a file.
|
||||
*
|
||||
* @param file Open sftp file handle to seek in.
|
||||
*
|
||||
* @param new_offset Offset in bytes to seek.
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
LIBSSH_API int sftp_seek(sftp_file file, uint32_t new_offset);
|
||||
|
||||
/**
|
||||
* @brief Seek to a specific location in a file. This is the
|
||||
* 64bit version.
|
||||
*
|
||||
* @param file Open sftp file handle to seek in.
|
||||
*
|
||||
* @param new_offset Offset in bytes to seek.
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
LIBSSH_API int sftp_seek64(sftp_file file, uint64_t new_offset);
|
||||
|
||||
/**
|
||||
* @brief Report current byte position in file.
|
||||
*
|
||||
* @param file Open sftp file handle.
|
||||
*
|
||||
* @return The offset of the current byte relative to the beginning
|
||||
* of the file associated with the file descriptor. < 0 on
|
||||
* error.
|
||||
*/
|
||||
LIBSSH_API unsigned long sftp_tell(sftp_file file);
|
||||
|
||||
/**
|
||||
* @brief Report current byte position in file.
|
||||
*
|
||||
* @param file Open sftp file handle.
|
||||
*
|
||||
* @return The offset of the current byte relative to the beginning
|
||||
* of the file associated with the file descriptor. < 0 on
|
||||
* error.
|
||||
*/
|
||||
LIBSSH_API uint64_t sftp_tell64(sftp_file file);
|
||||
|
||||
/**
|
||||
* @brief Rewinds the position of the file pointer to the beginning of the
|
||||
* file.
|
||||
*
|
||||
* @param file Open sftp file handle.
|
||||
*/
|
||||
LIBSSH_API void sftp_rewind(sftp_file file);
|
||||
|
||||
/**
|
||||
* @brief Unlink (delete) a file.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param file The file to unlink/delete.
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file);
|
||||
|
||||
/**
|
||||
* @brief Remove a directoy.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param directory The directory to remove.
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory);
|
||||
|
||||
/**
|
||||
* @brief Create a directory.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param directory The directory to create.
|
||||
*
|
||||
* @param mode Specifies the permissions to use. It is modified by the
|
||||
* process's umask in the usual way:
|
||||
* The permissions of the created file are (mode & ~umask)
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief Rename or move a file or directory.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param original The original url (source url) of file or directory to
|
||||
* be moved.
|
||||
*
|
||||
* @param newname The new url (destination url) of the file or directory
|
||||
* after the move.
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname);
|
||||
|
||||
/**
|
||||
* @brief Set file attributes on a file, directory or symbolic link.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param file The file which attributes should be changed.
|
||||
*
|
||||
* @param attr The file attributes structure with the attributes set
|
||||
* which should be changed.
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr);
|
||||
|
||||
/**
|
||||
* @brief Change the file owner and group
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param file The file which owner and group should be changed.
|
||||
*
|
||||
* @param owner The new owner which should be set.
|
||||
*
|
||||
* @param group The new group which should be set.
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_t group);
|
||||
|
||||
/**
|
||||
* @brief Change permissions of a file
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param file The file which owner and group should be changed.
|
||||
*
|
||||
* @param mode Specifies the permissions to use. It is modified by the
|
||||
* process's umask in the usual way:
|
||||
* The permissions of the created file are (mode & ~umask)
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief Change the last modification and access time of a file.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param file The file which owner and group should be changed.
|
||||
*
|
||||
* @param times A timeval structure which contains the desired access
|
||||
* and modification time.
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_utimes(sftp_session sftp, const char *file, const struct timeval *times);
|
||||
|
||||
/**
|
||||
* @brief Create a symbolic link.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param target Specifies the target of the symlink.
|
||||
*
|
||||
* @param dest Specifies the path name of the symlink to be created.
|
||||
*
|
||||
* @return 0 on success, < 0 on error with ssh and sftp error set.
|
||||
*/
|
||||
LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *dest);
|
||||
|
||||
/**
|
||||
* @brief Read the value of a symbolic link.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param path Specifies the path name of the symlink to be read.
|
||||
*
|
||||
* @return The target of the link, NULL on error.
|
||||
*/
|
||||
LIBSSH_API char *sftp_readlink(sftp_session sftp, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Get information about a mounted file system.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param path The pathname of any file within the mounted file system.
|
||||
*
|
||||
* @return A statvfs structure or NULL on error.
|
||||
*/
|
||||
LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Get information about a mounted file system.
|
||||
*
|
||||
* @param file An opened file.
|
||||
*
|
||||
* @return A statvfs structure or NULL on error.
|
||||
*/
|
||||
LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file);
|
||||
|
||||
/**
|
||||
* @brief Free the memory of an allocated statvfs.
|
||||
*
|
||||
* @param statvfs_o The statvfs to free.
|
||||
*/
|
||||
LIBSSH_API void sftp_statvfs_free(sftp_statvfs_t statvfs_o);
|
||||
|
||||
/**
|
||||
* @brief Canonicalize a sftp path.
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @param path The path to be canonicalized.
|
||||
*
|
||||
* @return The canonicalize path, NULL on error.
|
||||
*/
|
||||
LIBSSH_API char *sftp_canonicalize_path(sftp_session sftp, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Get the version of the SFTP protocol supported by the server
|
||||
*
|
||||
* @param sftp The sftp session handle.
|
||||
*
|
||||
* @return The server version.
|
||||
*/
|
||||
LIBSSH_API int sftp_server_version(sftp_session sftp);
|
||||
|
||||
#ifdef WITH_SERVER
|
||||
/**
|
||||
* @brief Create a new sftp server session.
|
||||
*
|
||||
* @param session The ssh session to use.
|
||||
*
|
||||
* @param chan The ssh channel to use.
|
||||
*
|
||||
* @return A new sftp server session.
|
||||
*/
|
||||
LIBSSH_API sftp_session sftp_server_new(ssh_session session, ssh_channel chan);
|
||||
|
||||
/**
|
||||
* @brief Intialize the sftp server.
|
||||
*
|
||||
* @param sftp The sftp session to init.
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
LIBSSH_API int sftp_server_init(sftp_session sftp);
|
||||
#endif /* WITH_SERVER */
|
||||
|
||||
/* this is not a public interface */
|
||||
#define SFTP_HANDLES 256
|
||||
SFTP_PACKET *sftp_packet_read(SFTP_SESSION *sftp);
|
||||
int sftp_packet_write(SFTP_SESSION *sftp,u8 type, BUFFER *payload);
|
||||
void sftp_packet_free(SFTP_PACKET *packet);
|
||||
void buffer_add_attributes(BUFFER *buffer, SFTP_ATTRIBUTES *attr);
|
||||
SFTP_ATTRIBUTES *sftp_parse_attr(SFTP_SESSION *session, BUFFER *buf,int expectname);
|
||||
sftp_packet sftp_packet_read(sftp_session sftp);
|
||||
int sftp_packet_write(sftp_session sftp,uint8_t type, ssh_buffer payload);
|
||||
void sftp_packet_free(sftp_packet packet);
|
||||
int buffer_add_attributes(ssh_buffer buffer, sftp_attributes attr);
|
||||
sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,int expectname);
|
||||
/* sftpserver.c */
|
||||
|
||||
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp);
|
||||
void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg);
|
||||
int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, char *name, SFTP_ATTRIBUTES *attr);
|
||||
int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, STRING *handle);
|
||||
STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info);
|
||||
int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr);
|
||||
void *sftp_handle(SFTP_SESSION *sftp, STRING *handle);
|
||||
int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status, char *message);
|
||||
int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, char *file, char *longname,
|
||||
SFTP_ATTRIBUTES *attr);
|
||||
int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg);
|
||||
int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, void *data, int len);
|
||||
void sftp_handle_remove(SFTP_SESSION *sftp, void *handle);
|
||||
sftp_client_message sftp_get_client_message(sftp_session sftp);
|
||||
void sftp_client_message_free(sftp_client_message msg);
|
||||
int sftp_reply_name(sftp_client_message msg, const char *name,
|
||||
sftp_attributes attr);
|
||||
int sftp_reply_handle(sftp_client_message msg, ssh_string handle);
|
||||
ssh_string sftp_handle_alloc(sftp_session sftp, void *info);
|
||||
int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr);
|
||||
void *sftp_handle(sftp_session sftp, ssh_string handle);
|
||||
int sftp_reply_status(sftp_client_message msg, uint32_t status, const char *message);
|
||||
int sftp_reply_names_add(sftp_client_message msg, const char *file,
|
||||
const char *longname, sftp_attributes attr);
|
||||
int sftp_reply_names(sftp_client_message msg);
|
||||
int sftp_reply_data(sftp_client_message msg, const void *data, int len);
|
||||
void sftp_handle_remove(sftp_session sftp, void *handle);
|
||||
|
||||
/* SFTP commands and constants */
|
||||
#define SSH_FXP_INIT 1
|
||||
@@ -270,6 +869,11 @@ void sftp_handle_remove(SFTP_SESSION *sftp, void *handle);
|
||||
#define SSH_FXF_EXCL 0x20
|
||||
#define SSH_FXF_TEXT 0x40
|
||||
|
||||
/* rename flags */
|
||||
#define SSH_FXF_RENAME_OVERWRITE 0x00000001
|
||||
#define SSH_FXF_RENAME_ATOMIC 0x00000002
|
||||
#define SSH_FXF_RENAME_NATIVE 0x00000004
|
||||
|
||||
#define SFTP_OPEN SSH_FXP_OPEN
|
||||
#define SFTP_CLOSE SSH_FXP_CLOSE
|
||||
#define SFTP_READ SSH_FXP_READ
|
||||
@@ -289,9 +893,15 @@ void sftp_handle_remove(SFTP_SESSION *sftp, void *handle);
|
||||
#define SFTP_READLINK SSH_FXP_READLINK
|
||||
#define SFTP_SYMLINK SSH_FXP_SYMLINK
|
||||
|
||||
/* openssh flags */
|
||||
#define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */
|
||||
#define SSH_FXE_STATVFS_ST_NOSUID 0x2 /* no setuid */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} ;
|
||||
#endif
|
||||
|
||||
#endif /* SFTP_H */
|
||||
|
||||
/** @} */
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
|
||||
55
include/libssh/socket.h
Normal file
55
include/libssh/socket.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef SOCKET_H_
|
||||
#define SOCKET_H_
|
||||
|
||||
/* socket.c */
|
||||
|
||||
struct socket;
|
||||
int ssh_socket_init(void);
|
||||
struct socket *ssh_socket_new(ssh_session session);
|
||||
void ssh_socket_free(struct socket *s);
|
||||
void ssh_socket_set_fd(struct socket *s, socket_t fd);
|
||||
socket_t ssh_socket_get_fd(struct socket *s);
|
||||
#ifndef _WIN32
|
||||
int ssh_socket_unix(struct socket *s, const char *path);
|
||||
#endif
|
||||
void ssh_socket_close(struct socket *s);
|
||||
int ssh_socket_read(struct socket *s, void *buffer, int len);
|
||||
int ssh_socket_write(struct socket *s,const void *buffer, int len);
|
||||
int ssh_socket_is_open(struct socket *s);
|
||||
int ssh_socket_fd_isset(struct socket *s, fd_set *set);
|
||||
void ssh_socket_fd_set(struct socket *s, fd_set *set, int *fd_max);
|
||||
int ssh_socket_completeread(struct socket *s, void *buffer, uint32_t len);
|
||||
int ssh_socket_completewrite(struct socket *s, const void *buffer, uint32_t len);
|
||||
int ssh_socket_wait_for_data(struct socket *s, ssh_session session, uint32_t len);
|
||||
int ssh_socket_nonblocking_flush(struct socket *s);
|
||||
int ssh_socket_blocking_flush(struct socket *s);
|
||||
int ssh_socket_poll(struct socket *s, int *writeable, int *except);
|
||||
void ssh_socket_set_towrite(struct socket *s);
|
||||
void ssh_socket_set_toread(struct socket *s);
|
||||
void ssh_socket_set_except(struct socket *s);
|
||||
int ssh_socket_get_status(struct socket *s);
|
||||
int ssh_socket_data_available(struct socket *s);
|
||||
int ssh_socket_data_writable(struct socket *s);
|
||||
|
||||
#endif /* SOCKET_H_ */
|
||||
42
include/libssh/string.h
Normal file
42
include/libssh/string.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef STRING_H_
|
||||
#define STRING_H_
|
||||
#include "libssh/priv.h"
|
||||
|
||||
/* must be 32 bits number + immediately our data */
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
struct ssh_string_struct {
|
||||
uint32_t size;
|
||||
unsigned char string[MAX_PACKET_LEN];
|
||||
}
|
||||
#if !defined(__SUNPRO_C) && !defined(_MSC_VER)
|
||||
__attribute__ ((packed))
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack()
|
||||
#endif
|
||||
;
|
||||
|
||||
#endif /* STRING_H_ */
|
||||
114
include/libssh/wrapper.h
Normal file
114
include/libssh/wrapper.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef WRAPPER_H_
|
||||
#define WRAPPER_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef MD5_DIGEST_LEN
|
||||
#undef MD5_DIGEST_LEN
|
||||
#endif
|
||||
/* wrapper things */
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
#include <gcrypt.h>
|
||||
typedef gcry_md_hd_t SHACTX;
|
||||
typedef gcry_md_hd_t MD5CTX;
|
||||
typedef gcry_md_hd_t HMACCTX;
|
||||
#define SHA_DIGEST_LEN 20
|
||||
#define MD5_DIGEST_LEN 16
|
||||
#define EVP_MAX_MD_SIZE 36
|
||||
|
||||
typedef gcry_mpi_t bignum;
|
||||
|
||||
#define bignum_new() gcry_mpi_new(0)
|
||||
#define bignum_free(num) gcry_mpi_release(num)
|
||||
#define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
|
||||
#define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
|
||||
#define bignum_bn2dec(num) my_gcry_bn2dec(num)
|
||||
#define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
|
||||
#define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
|
||||
#define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
|
||||
#define bignum_rand(num,bits) gcry_mpi_randomize(num,bits,GCRY_STRONG_RANDOM),gcry_mpi_set_bit(num,bits-1),gcry_mpi_set_bit(num,0)
|
||||
#define bignum_mod_exp(dest,generator,exp,modulo) gcry_mpi_powm(dest,generator,exp,modulo)
|
||||
#define bignum_num_bits(num) gcry_mpi_get_nbits(num)
|
||||
#define bignum_num_bytes(num) ((gcry_mpi_get_nbits(num)+7)/8)
|
||||
#define bignum_is_bit_set(num,bit) gcry_mpi_test_bit(num,bit)
|
||||
#define bignum_bn2bin(num,datalen,data) gcry_mpi_print(GCRYMPI_FMT_USG,data,datalen,NULL,num)
|
||||
#define bignum_cmp(num1,num2) gcry_mpi_cmp(num1,num2)
|
||||
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/hmac.h>
|
||||
typedef SHA_CTX* SHACTX;
|
||||
typedef MD5_CTX* MD5CTX;
|
||||
typedef HMAC_CTX* HMACCTX;
|
||||
|
||||
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
|
||||
#define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
|
||||
|
||||
#include <openssl/bn.h>
|
||||
typedef BIGNUM* bignum;
|
||||
typedef BN_CTX* bignum_CTX;
|
||||
|
||||
#define bignum_new() BN_new()
|
||||
#define bignum_free(num) BN_clear_free(num)
|
||||
#define bignum_set_word(bn,n) BN_set_word(bn,n)
|
||||
#define bignum_bin2bn(bn,datalen,data) BN_bin2bn(bn,datalen,data)
|
||||
#define bignum_bn2dec(num) BN_bn2dec(num)
|
||||
#define bignum_dec2bn(bn,data) BN_dec2bn(data,bn)
|
||||
#define bignum_bn2hex(num) BN_bn2hex(num)
|
||||
#define bignum_rand(rnd, bits, top, bottom) BN_rand(rnd,bits,top,bottom)
|
||||
#define bignum_ctx_new() BN_CTX_new()
|
||||
#define bignum_ctx_free(num) BN_CTX_free(num)
|
||||
#define bignum_mod_exp(dest,generator,exp,modulo,ctx) BN_mod_exp(dest,generator,exp,modulo,ctx)
|
||||
#define bignum_num_bytes(num) BN_num_bytes(num)
|
||||
#define bignum_num_bits(num) BN_num_bits(num)
|
||||
#define bignum_is_bit_set(num,bit) BN_is_bit_set(num,bit)
|
||||
#define bignum_bn2bin(num,ptr) BN_bn2bin(num,ptr)
|
||||
#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
|
||||
|
||||
#endif /* OPENSSL_CRYPTO */
|
||||
|
||||
MD5CTX md5_init(void);
|
||||
void md5_update(MD5CTX c, const void *data, unsigned long len);
|
||||
void md5_final(unsigned char *md,MD5CTX c);
|
||||
SHACTX sha1_init(void);
|
||||
void sha1_update(SHACTX c, const void *data, unsigned long len);
|
||||
void sha1_final(unsigned char *md,SHACTX c);
|
||||
void sha1(unsigned char *digest,int len,unsigned char *hash);
|
||||
#define HMAC_SHA1 1
|
||||
#define HMAC_MD5 2
|
||||
HMACCTX hmac_init(const void *key,int len,int type);
|
||||
void hmac_update(HMACCTX c, const void *data, unsigned long len);
|
||||
void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
|
||||
|
||||
int crypt_set_algorithms(ssh_session );
|
||||
int crypt_set_algorithms_server(ssh_session session);
|
||||
struct ssh_crypto_struct *crypto_new(void);
|
||||
void crypto_free(struct ssh_crypto_struct *crypto);
|
||||
|
||||
|
||||
#endif /* WRAPPER_H_ */
|
||||
@@ -1,999 +0,0 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2000, Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
wspiapi.h
|
||||
|
||||
Abstract:
|
||||
The file contains protocol independent API functions.
|
||||
|
||||
Revision History:
|
||||
Wed Jul 12 10:50:31 2000, Created
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _WSPIAPI_H_
|
||||
#define _WSPIAPI_H_
|
||||
|
||||
#include <stdio.h> // sprintf()
|
||||
#include <stdlib.h> // calloc(), strtoul()
|
||||
#include <malloc.h> // calloc()
|
||||
#include <string.h> // strlen(), strcmp(), strstr()
|
||||
|
||||
#define WspiapiMalloc(tSize) calloc(1, (tSize))
|
||||
#define WspiapiFree(p) free(p)
|
||||
#define WspiapiSwap(a, b, c) { (c) = (a); (a) = (b); (b) = (c); }
|
||||
#define getaddrinfo WspiapiGetAddrInfo
|
||||
#define getnameinfo WspiapiGetNameInfo
|
||||
#define freeaddrinfo WspiapiFreeAddrInfo
|
||||
|
||||
typedef int (WINAPI *WSPIAPI_PGETADDRINFO) (
|
||||
IN const char *nodename,
|
||||
IN const char *servname,
|
||||
IN const struct addrinfo *hints,
|
||||
OUT struct addrinfo **res);
|
||||
|
||||
typedef int (WINAPI *WSPIAPI_PGETNAMEINFO) (
|
||||
IN const struct sockaddr *sa,
|
||||
IN socklen_t salen,
|
||||
OUT char *host,
|
||||
IN size_t hostlen,
|
||||
OUT char *serv,
|
||||
IN size_t servlen,
|
||||
IN int flags);
|
||||
|
||||
typedef void (WINAPI *WSPIAPI_PFREEADDRINFO) (
|
||||
IN struct addrinfo *ai);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// v4 only versions of getaddrinfo and friends.
|
||||
// NOTE: gai_strerror is inlined in ws2tcpip.h
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
__inline
|
||||
char *
|
||||
WINAPI
|
||||
WspiapiStrdup (
|
||||
IN const char * pszString)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
allocates enough storage via calloc() for a copy of the string,
|
||||
copies the string into the new memory, and returns a pointer to it.
|
||||
|
||||
Arguments
|
||||
pszString string to copy into new memory
|
||||
|
||||
Return Value
|
||||
a pointer to the newly allocated storage with the string in it.
|
||||
NULL if enough memory could not be allocated, or string was NULL.
|
||||
|
||||
--*/
|
||||
{
|
||||
char *pszMemory;
|
||||
|
||||
if (!pszString)
|
||||
return(NULL);
|
||||
|
||||
pszMemory = (char *) WspiapiMalloc(strlen(pszString) + 1);
|
||||
if (!pszMemory)
|
||||
return(NULL);
|
||||
|
||||
return(strcpy(pszMemory, pszString));
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
BOOL
|
||||
WINAPI
|
||||
WspiapiParseV4Address (
|
||||
IN const char * pszAddress,
|
||||
OUT PDWORD pdwAddress)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
get the IPv4 address (in network byte order) from its string
|
||||
representation. the syntax should be a.b.c.d.
|
||||
|
||||
Arguments
|
||||
pszArgument string representation of the IPv4 address
|
||||
ptAddress pointer to the resulting IPv4 address
|
||||
|
||||
Return Value
|
||||
Returns FALSE if there is an error, TRUE for success.
|
||||
|
||||
--*/
|
||||
{
|
||||
DWORD dwAddress = 0;
|
||||
const char *pcNext = NULL;
|
||||
int iCount = 0;
|
||||
|
||||
// ensure there are 3 '.' (periods)
|
||||
for (pcNext = pszAddress; *pcNext != '\0'; pcNext++)
|
||||
if (*pcNext == '.')
|
||||
iCount++;
|
||||
if (iCount != 3)
|
||||
return FALSE;
|
||||
|
||||
// return an error if dwAddress is INADDR_NONE (255.255.255.255)
|
||||
// since this is never a valid argument to getaddrinfo.
|
||||
dwAddress = inet_addr(pszAddress);
|
||||
if (dwAddress == INADDR_NONE)
|
||||
return FALSE;
|
||||
|
||||
*pdwAddress = dwAddress;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
struct addrinfo *
|
||||
WINAPI
|
||||
WspiapiNewAddrInfo (
|
||||
IN int iSocketType,
|
||||
IN int iProtocol,
|
||||
IN WORD wPort,
|
||||
IN DWORD dwAddress)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
allocate an addrinfo structure and populate fields.
|
||||
IPv4 specific internal function, not exported.
|
||||
|
||||
Arguments
|
||||
iSocketType SOCK_*. can be wildcarded (zero).
|
||||
iProtocol IPPROTO_*. can be wildcarded (zero).
|
||||
wPort port number of service (in network order).
|
||||
dwAddress IPv4 address (in network order).
|
||||
|
||||
Return Value
|
||||
returns an addrinfo struct, or NULL if out of memory.
|
||||
|
||||
--*/
|
||||
{
|
||||
struct addrinfo *ptNew;
|
||||
struct sockaddr_in *ptAddress;
|
||||
|
||||
// allocate a new addrinfo structure.
|
||||
ptNew =
|
||||
(struct addrinfo *) WspiapiMalloc(sizeof(struct addrinfo));
|
||||
if (!ptNew)
|
||||
return NULL;
|
||||
|
||||
ptAddress =
|
||||
(struct sockaddr_in *) WspiapiMalloc(sizeof(struct sockaddr_in));
|
||||
if (!ptAddress)
|
||||
{
|
||||
WspiapiFree(ptNew);
|
||||
return NULL;
|
||||
}
|
||||
ptAddress->sin_family = AF_INET;
|
||||
ptAddress->sin_port = wPort;
|
||||
ptAddress->sin_addr.s_addr = dwAddress;
|
||||
|
||||
// fill in the fields...
|
||||
ptNew->ai_family = PF_INET;
|
||||
ptNew->ai_socktype = iSocketType;
|
||||
ptNew->ai_protocol = iProtocol;
|
||||
ptNew->ai_addrlen = sizeof(struct sockaddr_in);
|
||||
ptNew->ai_addr = (struct sockaddr *) ptAddress;
|
||||
|
||||
return ptNew;
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
int
|
||||
WINAPI
|
||||
WspiapiQueryDNS(
|
||||
IN const char *pszNodeName,
|
||||
IN int iSocketType,
|
||||
IN int iProtocol,
|
||||
IN WORD wPort,
|
||||
OUT char *pszAlias,
|
||||
OUT struct addrinfo **pptResult)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
helper routine for WspiapiLookupNode.
|
||||
performs name resolution by querying the DNS for A records.
|
||||
*pptResult would need to be freed if an error is returned.
|
||||
|
||||
Arguments
|
||||
pszNodeName name of node to resolve.
|
||||
iSocketType SOCK_*. can be wildcarded (zero).
|
||||
iProtocol IPPROTO_*. can be wildcarded (zero).
|
||||
wPort port number of service (in network order).
|
||||
pszAlias where to return the alias.
|
||||
pptResult where to return the result.
|
||||
|
||||
Return Value
|
||||
Returns 0 on success, an EAI_* style error value otherwise.
|
||||
|
||||
--*/
|
||||
{
|
||||
struct addrinfo **pptNext = pptResult;
|
||||
struct hostent *ptHost = NULL;
|
||||
char **ppAddresses;
|
||||
|
||||
*pptNext = NULL;
|
||||
pszAlias[0] = '\0';
|
||||
|
||||
ptHost = gethostbyname(pszNodeName);
|
||||
if (ptHost)
|
||||
{
|
||||
if ((ptHost->h_addrtype == AF_INET) &&
|
||||
(ptHost->h_length == sizeof(struct in_addr)))
|
||||
{
|
||||
for (ppAddresses = ptHost->h_addr_list;
|
||||
*ppAddresses != NULL;
|
||||
ppAddresses++)
|
||||
{
|
||||
// create an addrinfo structure...
|
||||
*pptNext = WspiapiNewAddrInfo(
|
||||
iSocketType,
|
||||
iProtocol,
|
||||
wPort,
|
||||
((struct in_addr *) *ppAddresses)->s_addr);
|
||||
if (!*pptNext)
|
||||
return EAI_MEMORY;
|
||||
|
||||
pptNext = &((*pptNext)->ai_next);
|
||||
}
|
||||
}
|
||||
|
||||
// pick up the canonical name.
|
||||
strcpy(pszAlias, ptHost->h_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (WSAGetLastError())
|
||||
{
|
||||
case WSAHOST_NOT_FOUND: return EAI_NONAME;
|
||||
case WSATRY_AGAIN: return EAI_AGAIN;
|
||||
case WSANO_RECOVERY: return EAI_FAIL;
|
||||
case WSANO_DATA: return EAI_NODATA;
|
||||
default: return EAI_NONAME;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
int
|
||||
WINAPI
|
||||
WspiapiLookupNode(
|
||||
IN const char *pszNodeName,
|
||||
IN int iSocketType,
|
||||
IN int iProtocol,
|
||||
IN WORD wPort,
|
||||
IN BOOL bAI_CANONNAME,
|
||||
OUT struct addrinfo **pptResult)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
resolve a nodename and return a list of addrinfo structures.
|
||||
IPv4 specific internal function, not exported.
|
||||
*pptResult would need to be freed if an error is returned.
|
||||
|
||||
NOTE: if bAI_CANONNAME is true, the canonical name should be
|
||||
returned in the first addrinfo structure.
|
||||
|
||||
Arguments
|
||||
pszNodeName name of node to resolve.
|
||||
iSocketType SOCK_*. can be wildcarded (zero).
|
||||
iProtocol IPPROTO_*. can be wildcarded (zero).
|
||||
wPort port number of service (in network order).
|
||||
bAI_CANONNAME whether the AI_CANONNAME flag is set.
|
||||
pptResult where to return result.
|
||||
|
||||
Return Value
|
||||
Returns 0 on success, an EAI_* style error value otherwise.
|
||||
|
||||
--*/
|
||||
{
|
||||
int iError = 0;
|
||||
int iAliasCount = 0;
|
||||
|
||||
char szFQDN1[NI_MAXHOST] = "";
|
||||
char szFQDN2[NI_MAXHOST] = "";
|
||||
char *pszName = szFQDN1;
|
||||
char *pszAlias = szFQDN2;
|
||||
char *pszScratch = NULL;
|
||||
strcpy(pszName, pszNodeName);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
iError = WspiapiQueryDNS(pszNodeName,
|
||||
iSocketType,
|
||||
iProtocol,
|
||||
wPort,
|
||||
pszAlias,
|
||||
pptResult);
|
||||
if (iError)
|
||||
break;
|
||||
|
||||
// if we found addresses, then we are done.
|
||||
if (*pptResult)
|
||||
break;
|
||||
|
||||
// stop infinite loops due to DNS misconfiguration. there appears
|
||||
// to be no particular recommended limit in RFCs 1034 and 1035.
|
||||
if ((!strlen(pszAlias)) ||
|
||||
(!strcmp(pszName, pszAlias)) ||
|
||||
(++iAliasCount == 16))
|
||||
{
|
||||
iError = EAI_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
// there was a new CNAME, look again.
|
||||
WspiapiSwap(pszName, pszAlias, pszScratch);
|
||||
}
|
||||
|
||||
if (!iError && bAI_CANONNAME)
|
||||
{
|
||||
(*pptResult)->ai_canonname = WspiapiStrdup(pszAlias);
|
||||
if (!(*pptResult)->ai_canonname)
|
||||
iError = EAI_MEMORY;
|
||||
}
|
||||
|
||||
return iError;
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
int
|
||||
WINAPI
|
||||
WspiapiClone (
|
||||
IN WORD wPort,
|
||||
IN struct addrinfo *ptResult)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
clone every addrinfo structure in ptResult for the UDP service.
|
||||
ptResult would need to be freed if an error is returned.
|
||||
|
||||
Arguments
|
||||
wPort port number of UDP service.
|
||||
ptResult list of addrinfo structures, each
|
||||
of whose node needs to be cloned.
|
||||
|
||||
Return Value
|
||||
Returns 0 on success, an EAI_MEMORY on allocation failure.
|
||||
|
||||
--*/
|
||||
{
|
||||
struct addrinfo *ptNext = NULL;
|
||||
struct addrinfo *ptNew = NULL;
|
||||
|
||||
for (ptNext = ptResult; ptNext != NULL; )
|
||||
{
|
||||
// create an addrinfo structure...
|
||||
ptNew = WspiapiNewAddrInfo(
|
||||
SOCK_DGRAM,
|
||||
ptNext->ai_protocol,
|
||||
wPort,
|
||||
((struct sockaddr_in *) ptNext->ai_addr)->sin_addr.s_addr);
|
||||
if (!ptNew)
|
||||
break;
|
||||
|
||||
// link the cloned addrinfo
|
||||
ptNew->ai_next = ptNext->ai_next;
|
||||
ptNext->ai_next = ptNew;
|
||||
ptNext = ptNew->ai_next;
|
||||
}
|
||||
|
||||
if (ptNext != NULL)
|
||||
return EAI_MEMORY;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
void
|
||||
WINAPI
|
||||
WspiapiLegacyFreeAddrInfo (
|
||||
IN struct addrinfo *ptHead)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
Free an addrinfo structure (or chain of structures).
|
||||
As specified in RFC 2553, Section 6.4.
|
||||
|
||||
Arguments
|
||||
ptHead structure (chain) to free
|
||||
|
||||
--*/
|
||||
{
|
||||
struct addrinfo *ptNext; // next strcture to free
|
||||
|
||||
for (ptNext = ptHead; ptNext != NULL; ptNext = ptHead)
|
||||
{
|
||||
if (ptNext->ai_canonname)
|
||||
WspiapiFree(ptNext->ai_canonname);
|
||||
|
||||
if (ptNext->ai_addr)
|
||||
WspiapiFree(ptNext->ai_addr);
|
||||
|
||||
ptHead = ptNext->ai_next;
|
||||
WspiapiFree(ptNext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
int
|
||||
WINAPI
|
||||
WspiapiLegacyGetAddrInfo(
|
||||
IN const char *pszNodeName,
|
||||
IN const char *pszServiceName,
|
||||
IN const struct addrinfo *ptHints,
|
||||
OUT struct addrinfo **pptResult)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
Protocol-independent name-to-address translation.
|
||||
As specified in RFC 2553, Section 6.4.
|
||||
This is the hacked version that only supports IPv4.
|
||||
|
||||
Arguments
|
||||
pszNodeName node name to lookup.
|
||||
pszServiceName service name to lookup.
|
||||
ptHints hints about how to process request.
|
||||
pptResult where to return result.
|
||||
|
||||
Return Value
|
||||
returns zero if successful, an EAI_* error code if not.
|
||||
|
||||
--*/
|
||||
{
|
||||
int iError = 0;
|
||||
int iFlags = 0;
|
||||
int iFamily = PF_UNSPEC;
|
||||
int iSocketType = 0;
|
||||
int iProtocol = 0;
|
||||
WORD wPort = 0;
|
||||
DWORD dwAddress = 0;
|
||||
|
||||
struct servent *ptService = NULL;
|
||||
char *pc = NULL;
|
||||
BOOL bClone = FALSE;
|
||||
WORD wTcpPort = 0;
|
||||
WORD wUdpPort = 0;
|
||||
|
||||
|
||||
// initialize pptResult with default return value.
|
||||
*pptResult = NULL;
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// validate arguments...
|
||||
//
|
||||
|
||||
// both the node name and the service name can't be NULL.
|
||||
if ((!pszNodeName) && (!pszServiceName))
|
||||
return EAI_NONAME;
|
||||
|
||||
// validate hints.
|
||||
if (ptHints)
|
||||
{
|
||||
// all members other than ai_flags, ai_family, ai_socktype
|
||||
// and ai_protocol must be zero or a null pointer.
|
||||
if ((ptHints->ai_addrlen != 0) ||
|
||||
(ptHints->ai_canonname != NULL) ||
|
||||
(ptHints->ai_addr != NULL) ||
|
||||
(ptHints->ai_next != NULL))
|
||||
{
|
||||
return EAI_FAIL;
|
||||
}
|
||||
|
||||
// the spec has the "bad flags" error code, so presumably we
|
||||
// should check something here. insisting that there aren't
|
||||
// any unspecified flags set would break forward compatibility,
|
||||
// however. so we just check for non-sensical combinations.
|
||||
//
|
||||
// we cannot come up with a canonical name given a null node name.
|
||||
iFlags = ptHints->ai_flags;
|
||||
if ((iFlags & AI_CANONNAME) && !pszNodeName)
|
||||
return EAI_BADFLAGS;
|
||||
|
||||
// we only support a limited number of protocol families.
|
||||
iFamily = ptHints->ai_family;
|
||||
if ((iFamily != PF_UNSPEC) && (iFamily != PF_INET))
|
||||
return EAI_FAMILY;
|
||||
|
||||
// we only support only these socket types.
|
||||
iSocketType = ptHints->ai_socktype;
|
||||
if ((iSocketType != 0) &&
|
||||
(iSocketType != SOCK_STREAM) &&
|
||||
(iSocketType != SOCK_DGRAM) &&
|
||||
(iSocketType != SOCK_RAW))
|
||||
return EAI_SOCKTYPE;
|
||||
|
||||
// REVIEW: What if ai_socktype and ai_protocol are at odds?
|
||||
iProtocol = ptHints->ai_protocol;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// do service lookup...
|
||||
|
||||
if (pszServiceName)
|
||||
{
|
||||
wPort = (WORD) strtoul(pszServiceName, &pc, 10);
|
||||
if (*pc == '\0') // numeric port string
|
||||
{
|
||||
wPort = wTcpPort = wUdpPort = htons(wPort);
|
||||
if (iSocketType == 0)
|
||||
{
|
||||
bClone = TRUE;
|
||||
iSocketType = SOCK_STREAM;
|
||||
}
|
||||
}
|
||||
else // non numeric port string
|
||||
{
|
||||
if ((iSocketType == 0) || (iSocketType == SOCK_DGRAM))
|
||||
{
|
||||
ptService = getservbyname(pszServiceName, "udp");
|
||||
if (ptService)
|
||||
wPort = wUdpPort = ptService->s_port;
|
||||
}
|
||||
|
||||
if ((iSocketType == 0) || (iSocketType == SOCK_STREAM))
|
||||
{
|
||||
ptService = getservbyname(pszServiceName, "tcp");
|
||||
if (ptService)
|
||||
wPort = wTcpPort = ptService->s_port;
|
||||
}
|
||||
|
||||
// assumes 0 is an invalid service port...
|
||||
if (wPort == 0) // no service exists
|
||||
return (iSocketType ? EAI_SERVICE : EAI_NONAME);
|
||||
|
||||
if (iSocketType == 0)
|
||||
{
|
||||
// if both tcp and udp, process tcp now & clone udp later.
|
||||
iSocketType = (wTcpPort) ? SOCK_STREAM : SOCK_DGRAM;
|
||||
bClone = (wTcpPort && wUdpPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// do node name lookup...
|
||||
|
||||
// if we weren't given a node name,
|
||||
// return the wildcard or loopback address (depending on AI_PASSIVE).
|
||||
//
|
||||
// if we have a numeric host address string,
|
||||
// return the binary address.
|
||||
//
|
||||
if ((!pszNodeName) || (WspiapiParseV4Address(pszNodeName, &dwAddress)))
|
||||
{
|
||||
if (!pszNodeName)
|
||||
{
|
||||
dwAddress = htonl((iFlags & AI_PASSIVE)
|
||||
? INADDR_ANY
|
||||
: INADDR_LOOPBACK);
|
||||
}
|
||||
|
||||
// create an addrinfo structure...
|
||||
*pptResult =
|
||||
WspiapiNewAddrInfo(iSocketType, iProtocol, wPort, dwAddress);
|
||||
if (!(*pptResult))
|
||||
iError = EAI_MEMORY;
|
||||
|
||||
if (!iError && pszNodeName)
|
||||
{
|
||||
// implementation specific behavior: set AI_NUMERICHOST
|
||||
// to indicate that we got a numeric host address string.
|
||||
(*pptResult)->ai_flags |= AI_NUMERICHOST;
|
||||
|
||||
// return the numeric address string as the canonical name
|
||||
if (iFlags & AI_CANONNAME)
|
||||
{
|
||||
(*pptResult)->ai_canonname =
|
||||
WspiapiStrdup(inet_ntoa(*((struct in_addr *) &dwAddress)));
|
||||
if (!(*pptResult)->ai_canonname)
|
||||
iError = EAI_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if we do not have a numeric host address string and
|
||||
// AI_NUMERICHOST flag is set, return an error!
|
||||
else if (iFlags & AI_NUMERICHOST)
|
||||
{
|
||||
iError = EAI_NONAME;
|
||||
}
|
||||
|
||||
|
||||
// since we have a non-numeric node name,
|
||||
// we have to do a regular node name lookup.
|
||||
else
|
||||
{
|
||||
iError = WspiapiLookupNode(pszNodeName,
|
||||
iSocketType,
|
||||
iProtocol,
|
||||
wPort,
|
||||
(iFlags & AI_CANONNAME),
|
||||
pptResult);
|
||||
}
|
||||
|
||||
if (!iError && bClone)
|
||||
{
|
||||
iError = WspiapiClone(wUdpPort, *pptResult);
|
||||
}
|
||||
|
||||
if (iError)
|
||||
{
|
||||
WspiapiLegacyFreeAddrInfo(*pptResult);
|
||||
*pptResult = NULL;
|
||||
}
|
||||
|
||||
return (iError);
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
int
|
||||
WINAPI
|
||||
WspiapiLegacyGetNameInfo(
|
||||
IN const struct sockaddr *ptSocketAddress,
|
||||
IN socklen_t tSocketLength,
|
||||
OUT char *pszNodeName,
|
||||
IN size_t tNodeLength,
|
||||
OUT char *pszServiceName,
|
||||
IN size_t tServiceLength,
|
||||
IN int iFlags)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
protocol-independent address-to-name translation.
|
||||
as specified in RFC 2553, Section 6.5.
|
||||
this is the hacked version that only supports IPv4.
|
||||
|
||||
Arguments
|
||||
ptSocketAddress socket address to translate.
|
||||
tSocketLength length of above socket address.
|
||||
pszNodeName where to return the node name.
|
||||
tNodeLength size of above buffer.
|
||||
pszServiceName where to return the service name.
|
||||
tServiceLength size of above buffer.
|
||||
iFlags flags of type NI_*.
|
||||
|
||||
Return Value
|
||||
returns zero if successful, an EAI_* error code if not.
|
||||
|
||||
--*/
|
||||
{
|
||||
struct servent *ptService;
|
||||
WORD wPort;
|
||||
char szBuffer[] = "65535";
|
||||
char *pszService = szBuffer;
|
||||
|
||||
struct hostent *ptHost;
|
||||
struct in_addr tAddress;
|
||||
char *pszNode = NULL;
|
||||
char *pc = NULL;
|
||||
|
||||
|
||||
// sanity check ptSocketAddress and tSocketLength.
|
||||
if (!ptSocketAddress)
|
||||
return EAI_FAIL;
|
||||
|
||||
if ((ptSocketAddress->sa_family != AF_INET) ||
|
||||
(tSocketLength != sizeof(struct sockaddr_in)))
|
||||
{
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
|
||||
if (!(pszNodeName && tNodeLength) &&
|
||||
!(pszServiceName && tServiceLength))
|
||||
{
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
// the draft has the "bad flags" error code, so presumably we
|
||||
// should check something here. insisting that there aren't
|
||||
// any unspecified flags set would break forward compatibility,
|
||||
// however. so we just check for non-sensical combinations.
|
||||
if ((iFlags & NI_NUMERICHOST) && (iFlags & NI_NAMEREQD))
|
||||
{
|
||||
return EAI_BADFLAGS;
|
||||
}
|
||||
|
||||
// translate the port to a service name (if requested).
|
||||
if (pszServiceName && tServiceLength)
|
||||
{
|
||||
wPort = ((struct sockaddr_in *) ptSocketAddress)->sin_port;
|
||||
|
||||
if (iFlags & NI_NUMERICSERV)
|
||||
{
|
||||
// return numeric form of the address.
|
||||
sprintf(szBuffer, "%u", ntohs(wPort));
|
||||
}
|
||||
else
|
||||
{
|
||||
// return service name corresponding to port.
|
||||
ptService = getservbyport(wPort,
|
||||
(iFlags & NI_DGRAM) ? "udp" : NULL);
|
||||
if (ptService && ptService->s_name)
|
||||
{
|
||||
// lookup successful.
|
||||
pszService = ptService->s_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
// DRAFT: return numeric form of the port!
|
||||
sprintf(szBuffer, "%u", ntohs(wPort));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (tServiceLength > strlen(pszService))
|
||||
strcpy(pszServiceName, pszService);
|
||||
else
|
||||
return EAI_FAIL;
|
||||
}
|
||||
|
||||
|
||||
// translate the address to a node name (if requested).
|
||||
if (pszNodeName && tNodeLength)
|
||||
{
|
||||
// this is the IPv4-only version, so we have an IPv4 address.
|
||||
tAddress = ((struct sockaddr_in *) ptSocketAddress)->sin_addr;
|
||||
|
||||
if (iFlags & NI_NUMERICHOST)
|
||||
{
|
||||
// return numeric form of the address.
|
||||
pszNode = inet_ntoa(tAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
// return node name corresponding to address.
|
||||
ptHost = gethostbyaddr((char *) &tAddress,
|
||||
sizeof(struct in_addr),
|
||||
AF_INET);
|
||||
if (ptHost && ptHost->h_name)
|
||||
{
|
||||
// DNS lookup successful.
|
||||
// stop copying at a "." if NI_NOFQDN is specified.
|
||||
pszNode = ptHost->h_name;
|
||||
if ((iFlags & NI_NOFQDN) && (pc = strchr(pszNode, '.')))
|
||||
*pc = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
// DNS lookup failed. return numeric form of the address.
|
||||
if (iFlags & NI_NAMEREQD)
|
||||
{
|
||||
switch (WSAGetLastError())
|
||||
{
|
||||
case WSAHOST_NOT_FOUND: return EAI_NONAME;
|
||||
case WSATRY_AGAIN: return EAI_AGAIN;
|
||||
case WSANO_RECOVERY: return EAI_FAIL;
|
||||
default: return EAI_NONAME;
|
||||
}
|
||||
}
|
||||
else
|
||||
pszNode = inet_ntoa(tAddress);
|
||||
}
|
||||
}
|
||||
|
||||
if (tNodeLength > strlen(pszNode))
|
||||
strcpy(pszNodeName, pszNode);
|
||||
else
|
||||
return EAI_FAIL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char const *pszName;
|
||||
FARPROC pfAddress;
|
||||
} WSPIAPI_FUNCTION;
|
||||
|
||||
#define WSPIAPI_FUNCTION_ARRAY \
|
||||
{ \
|
||||
"getaddrinfo", (FARPROC) WspiapiLegacyGetAddrInfo, \
|
||||
"getnameinfo", (FARPROC) WspiapiLegacyGetNameInfo, \
|
||||
"freeaddrinfo", (FARPROC) WspiapiLegacyFreeAddrInfo, \
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
FARPROC
|
||||
WINAPI
|
||||
WspiapiLoad(
|
||||
IN WORD wFunction)
|
||||
/*++
|
||||
|
||||
Routine Description
|
||||
try to locate the address family independent name resolution routines
|
||||
(i.e. getaddrinfo, getnameinfo, freeaddrinfo, gai_strerror).
|
||||
|
||||
Locks
|
||||
this function call is not synchronized. hence the library containing
|
||||
the routines might be loaded multiple times. another option is to
|
||||
synchronize through a spin lock using a static local variable and the
|
||||
InterlockedExchange operation.
|
||||
|
||||
|
||||
Arguments
|
||||
wFunction ordinal # of the function to get the pointer to
|
||||
0 getaddrinfo
|
||||
1 getnameinfo
|
||||
2 freeaddrinfo
|
||||
|
||||
Return Value
|
||||
address of the library/legacy routine
|
||||
|
||||
--*/
|
||||
{
|
||||
HMODULE hLibrary = NULL;
|
||||
|
||||
// these static variables store state across calls, across threads.
|
||||
static BOOL bInitialized = FALSE;
|
||||
static WSPIAPI_FUNCTION rgtGlobal[] = WSPIAPI_FUNCTION_ARRAY;
|
||||
static const int iNumGlobal = (sizeof(rgtGlobal) /
|
||||
sizeof(WSPIAPI_FUNCTION));
|
||||
|
||||
// we overwrite rgtGlobal only if all routines exist in library.
|
||||
WSPIAPI_FUNCTION rgtLocal[] = WSPIAPI_FUNCTION_ARRAY;
|
||||
FARPROC fScratch = NULL;
|
||||
int i = 0;
|
||||
|
||||
|
||||
if (bInitialized) // WspiapiLoad has already been called once
|
||||
return (rgtGlobal[wFunction].pfAddress);
|
||||
|
||||
do // breakout loop
|
||||
{
|
||||
// in Whistler and beyond...
|
||||
// the routines are present in the WinSock 2 library (ws2_32.dll).
|
||||
// printf("Looking in ws2_32 for getaddrinfo...\n");
|
||||
hLibrary = LoadLibraryA("ws2_32");
|
||||
if (hLibrary != NULL)
|
||||
{
|
||||
fScratch = GetProcAddress(hLibrary, "getaddrinfo");
|
||||
if (fScratch == NULL)
|
||||
{
|
||||
FreeLibrary(hLibrary);
|
||||
hLibrary = NULL;
|
||||
}
|
||||
}
|
||||
if (hLibrary != NULL)
|
||||
break;
|
||||
|
||||
|
||||
// in the IPv6 Technology Preview...
|
||||
// the routines are present in the IPv6 WinSock library (wship6.dll).
|
||||
// printf("Looking in wship6 for getaddrinfo...\n");
|
||||
hLibrary = LoadLibraryA("wship6");
|
||||
if (hLibrary != NULL)
|
||||
{
|
||||
fScratch = GetProcAddress(hLibrary, "getaddrinfo");
|
||||
if (fScratch == NULL)
|
||||
{
|
||||
FreeLibrary(hLibrary);
|
||||
hLibrary = NULL;
|
||||
}
|
||||
}
|
||||
} while (FALSE);
|
||||
|
||||
|
||||
if (hLibrary != NULL)
|
||||
{
|
||||
// use routines from this library...
|
||||
// since getaddrinfo is here, we expect all routines to be here,
|
||||
// but will fall back to IPv4-only if any of them is missing.
|
||||
for (i = 0; i < iNumGlobal; i++)
|
||||
{
|
||||
rgtLocal[i].pfAddress
|
||||
= GetProcAddress(hLibrary, rgtLocal[i].pszName);
|
||||
if (rgtLocal[i].pfAddress == NULL)
|
||||
{
|
||||
FreeLibrary(hLibrary);
|
||||
hLibrary = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hLibrary != NULL)
|
||||
{
|
||||
// printf("found!\n");
|
||||
for (i = 0; i < iNumGlobal; i++)
|
||||
rgtGlobal[i].pfAddress = rgtLocal[i].pfAddress;
|
||||
}
|
||||
}
|
||||
|
||||
bInitialized = TRUE;
|
||||
return (rgtGlobal[wFunction].pfAddress);
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
int
|
||||
WINAPI
|
||||
WspiapiGetAddrInfo(
|
||||
IN const char *nodename,
|
||||
IN const char *servname,
|
||||
IN const struct addrinfo *hints,
|
||||
OUT struct addrinfo **res)
|
||||
{
|
||||
static WSPIAPI_PGETADDRINFO pfGetAddrInfo = NULL;
|
||||
|
||||
if (!pfGetAddrInfo)
|
||||
pfGetAddrInfo = (WSPIAPI_PGETADDRINFO) WspiapiLoad(0);
|
||||
return ((*pfGetAddrInfo)
|
||||
(nodename, servname, hints, res));
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
int
|
||||
WINAPI
|
||||
WspiapiGetNameInfo (
|
||||
IN const struct sockaddr *sa,
|
||||
IN socklen_t salen,
|
||||
OUT char *host,
|
||||
IN size_t hostlen,
|
||||
OUT char *serv,
|
||||
IN size_t servlen,
|
||||
IN int flags)
|
||||
{
|
||||
static WSPIAPI_PGETNAMEINFO pfGetNameInfo = NULL;
|
||||
|
||||
if (!pfGetNameInfo)
|
||||
pfGetNameInfo = (WSPIAPI_PGETNAMEINFO) WspiapiLoad(1);
|
||||
return ((*pfGetNameInfo)
|
||||
(sa, salen, host, hostlen, serv, servlen, flags));
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline
|
||||
void
|
||||
WINAPI
|
||||
WspiapiFreeAddrInfo (
|
||||
IN struct addrinfo *ai)
|
||||
{
|
||||
static WSPIAPI_PFREEADDRINFO pfFreeAddrInfo = NULL;
|
||||
|
||||
if (!pfFreeAddrInfo)
|
||||
pfFreeAddrInfo = (WSPIAPI_PFREEADDRINFO) WspiapiLoad(2);
|
||||
(*pfFreeAddrInfo)(ai);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _WSPIAPI_H_
|
||||
15
lib.bat
15
lib.bat
@@ -1,15 +0,0 @@
|
||||
@SET VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE
|
||||
@SET VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio .NET 2003
|
||||
@SET FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework
|
||||
@SET FrameworkVersion=v1.1.4322
|
||||
@SET FrameworkSDKDir=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1
|
||||
@set DevEnvDir=%VSINSTALLDIR%
|
||||
|
||||
@rem
|
||||
@rem Root of Visual C++ installed files.
|
||||
@rem
|
||||
@set MSVCDir=%VCINSTALLDIR%\VC7
|
||||
@set PATH=%DevEnvDir%;%MSVCDir%\BIN;%VCINSTALLDIR%\Common7\Tools;%VCINSTALLDIR%\Common7\Tools\bin\prerelease;%VCINSTALLDIR%\Common7\Tools\bin;%FrameworkSDKDir%\bin;%FrameworkDir%\%FrameworkVersion%;%PATH%;
|
||||
@set INCLUDE=%MSVCDir%\ATLMFC\INCLUDE;%MSVCDir%\INCLUDE;%MSVCDir%\PlatformSDK\include\prerelease;%MSVCDir%\PlatformSDK\include;%FrameworkSDKDir%\include;%INCLUDE%
|
||||
@set LIB=%MSVCDir%\ATLMFC\LIB;%MSVCDir%\LIB;%MSVCDir%\PlatformSDK\lib\prerelease;%MSVCDir%\PlatformSDK\lib;%FrameworkSDKDir%\lib;%LIB%
|
||||
"c:\Program files\Microsoft Visual Studio .NET 2003\vc7\bin\lib.exe" /machine:i386 /def:libssh.def
|
||||
427
libssh.dev
427
libssh.dev
@@ -1,427 +0,0 @@
|
||||
[Project]
|
||||
FileName=libssh.dev
|
||||
Name=libssh
|
||||
UnitCount=38
|
||||
Type=1
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
Includes=
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=
|
||||
IsCpp=0
|
||||
Icon=
|
||||
ExeOutput=
|
||||
ObjectOutput=
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=libssh.exe
|
||||
HostApplication=
|
||||
Folders=include
|
||||
CommandLine=
|
||||
UseCustomMakefile=1
|
||||
CustomMakefile=Makefile.Windows
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=0
|
||||
CompilerSettings=0000000000000000000000
|
||||
|
||||
[Unit1]
|
||||
FileName=libssh\init.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit2]
|
||||
FileName=libssh\kex.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit3]
|
||||
FileName=libssh\keyfiles.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit4]
|
||||
FileName=libssh\keys.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit5]
|
||||
FileName=libssh\messages.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit6]
|
||||
FileName=libssh\misc.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit7]
|
||||
FileName=libssh\options.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit8]
|
||||
FileName=libssh\packet.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit9]
|
||||
FileName=libssh\server.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit10]
|
||||
FileName=libssh\session.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit11]
|
||||
FileName=libssh\sftp.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit12]
|
||||
FileName=libssh\sftpserver.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit13]
|
||||
FileName=libssh\socket.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit14]
|
||||
FileName=libssh\string.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit15]
|
||||
FileName=libssh\wrapper.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit16]
|
||||
FileName=libssh\auth1.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit17]
|
||||
FileName=libssh\auth.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit18]
|
||||
FileName=libssh\base64.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit19]
|
||||
FileName=libssh\buffer.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit20]
|
||||
FileName=libssh\channels1.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit21]
|
||||
FileName=libssh\channels.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit22]
|
||||
FileName=libssh\client.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit23]
|
||||
FileName=libssh\connect.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit24]
|
||||
FileName=libssh\crc32.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit25]
|
||||
FileName=libssh\crypt.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit26]
|
||||
FileName=libssh\dh.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit27]
|
||||
FileName=libssh\error.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit28]
|
||||
FileName=libssh\gcrypt_missing.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit29]
|
||||
FileName=libssh\gzip.c
|
||||
CompileCpp=0
|
||||
Folder=libssh
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit30]
|
||||
FileName=include\libssh\crypto.h
|
||||
CompileCpp=0
|
||||
Folder=include
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit31]
|
||||
FileName=include\libssh\libssh.h
|
||||
CompileCpp=0
|
||||
Folder=include
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit32]
|
||||
FileName=include\libssh\priv.h
|
||||
CompileCpp=0
|
||||
Folder=include
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit33]
|
||||
FileName=include\libssh\server.h
|
||||
CompileCpp=0
|
||||
Folder=include
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit34]
|
||||
FileName=include\libssh\sftp.h
|
||||
CompileCpp=0
|
||||
Folder=include
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit35]
|
||||
FileName=include\libssh\ssh1.h
|
||||
CompileCpp=0
|
||||
Folder=include
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit36]
|
||||
FileName=include\libssh\ssh2.h
|
||||
CompileCpp=0
|
||||
Folder=include
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[VersionInfo]
|
||||
Major=0
|
||||
Minor=1
|
||||
Release=1
|
||||
Build=1
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
|
||||
[Unit37]
|
||||
FileName=lib.bat
|
||||
Folder=libssh
|
||||
Compile=0
|
||||
Link=0
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit38]
|
||||
FileName=Makefile.Windows
|
||||
Folder=libssh
|
||||
Compile=0
|
||||
Link=0
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
200
libssh/CMakeLists.txt
Normal file
200
libssh/CMakeLists.txt
Normal file
@@ -0,0 +1,200 @@
|
||||
project(libssh-library C)
|
||||
|
||||
set(LIBSSH_PUBLIC_INCLUDE_DIRS
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}
|
||||
CACHE INTERNAL "libssh public include directories"
|
||||
)
|
||||
|
||||
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
||||
${CMAKE_BINARY_DIR}
|
||||
${ZLIB_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(LIBSSH_SHARED_LIBRARY
|
||||
ssh_shared
|
||||
CACHE INTERNAL "libssh shared library"
|
||||
)
|
||||
|
||||
if (WITH_STATIC_LIB)
|
||||
set(LIBSSH_STATIC_LIBRARY
|
||||
ssh_static
|
||||
CACHE INTERNAL "libssh static library"
|
||||
)
|
||||
endif (WITH_STATIC_LIB)
|
||||
|
||||
set(LIBSSH_LINK_LIBRARIES
|
||||
${LIBSSH_REQUIRED_LIBRARIES}
|
||||
${ZLIB_LIBRARIES}
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
set(LIBSSH_LINK_LIBRARIES
|
||||
${LIBSSH_LINK_LIBRARIES}
|
||||
ws2_32
|
||||
)
|
||||
endif (WIN32)
|
||||
|
||||
if (HAVE_LIBSOCKET)
|
||||
set(LIBSSH_LINK_LIBRARIES
|
||||
${LIBSSH_LINK_LIBRARIES}
|
||||
socket
|
||||
)
|
||||
endif (HAVE_LIBSOCKET)
|
||||
|
||||
if (CRYPTO_LIBRARY)
|
||||
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
||||
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
||||
${OPENSSL_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(LIBSSH_LINK_LIBRARIES
|
||||
${LIBSSH_LINK_LIBRARIES}
|
||||
${CRYPTO_LIBRARY}
|
||||
)
|
||||
endif (CRYPTO_LIBRARY)
|
||||
|
||||
if (GCRYPT_LIBRARY)
|
||||
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
||||
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
||||
${GCRYPT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(LIBSSH_LINK_LIBRARIES
|
||||
${LIBSSH_LINK_LIBRARIES}
|
||||
${GCRYPT_LIBRARY}
|
||||
)
|
||||
endif (GCRYPT_LIBRARY)
|
||||
|
||||
set(libssh_SRCS
|
||||
agent.c
|
||||
auth.c
|
||||
base64.c
|
||||
buffer.c
|
||||
callbacks.c
|
||||
channels.c
|
||||
client.c
|
||||
config.c
|
||||
connect.c
|
||||
crc32.c
|
||||
crypt.c
|
||||
dh.c
|
||||
error.c
|
||||
gcrypt_missing.c
|
||||
gzip.c
|
||||
init.c
|
||||
kex.c
|
||||
keyfiles.c
|
||||
keys.c
|
||||
log.c
|
||||
match.c
|
||||
messages.c
|
||||
misc.c
|
||||
options.c
|
||||
packet.c
|
||||
poll.c
|
||||
session.c
|
||||
scp.c
|
||||
socket.c
|
||||
string.c
|
||||
wrapper.c
|
||||
)
|
||||
|
||||
if (WITH_PCAP)
|
||||
set(libssh_SRCS
|
||||
${libssh_SRCS}
|
||||
pcap.c
|
||||
)
|
||||
|
||||
endif (WITH_PCAP)
|
||||
|
||||
if (WITH_SFTP)
|
||||
set(libssh_SRCS
|
||||
${libssh_SRCS}
|
||||
sftp.c
|
||||
)
|
||||
|
||||
if (WITH_SERVER)
|
||||
set(libssh_SRCS
|
||||
${libssh_SRCS}
|
||||
sftpserver.c
|
||||
)
|
||||
endif (WITH_SERVER)
|
||||
endif (WITH_SFTP)
|
||||
|
||||
if (WITH_SSH1)
|
||||
set(libssh_SRCS
|
||||
${libssh_SRCS}
|
||||
auth1.c
|
||||
channels1.c
|
||||
)
|
||||
endif (WITH_SSH1)
|
||||
|
||||
if (WITH_SERVER)
|
||||
set(libssh_SRCS
|
||||
${libssh_SRCS}
|
||||
server.c
|
||||
)
|
||||
endif (WITH_SERVER)
|
||||
|
||||
include_directories(
|
||||
${LIBSSH_PUBLIC_INCLUDE_DIRS}
|
||||
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
add_library(${LIBSSH_SHARED_LIBRARY} SHARED ${libssh_SRCS})
|
||||
|
||||
target_link_libraries(${LIBSSH_SHARED_LIBRARY} ${LIBSSH_LINK_LIBRARIES})
|
||||
|
||||
set_target_properties(
|
||||
${LIBSSH_SHARED_LIBRARY}
|
||||
PROPERTIES
|
||||
VERSION
|
||||
${LIBRARY_VERSION}
|
||||
SOVERSION
|
||||
${LIBRARY_SOVERSION}
|
||||
OUTPUT_NAME
|
||||
ssh
|
||||
DEFINE_SYMBOL
|
||||
LIBSSH_EXPORTS
|
||||
)
|
||||
|
||||
if (WITH_VISIBILITY_HIDDEN)
|
||||
set_target_properties(${LIBSSH_SHARED_LIBRARY} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
|
||||
endif (WITH_VISIBILITY_HIDDEN)
|
||||
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
${LIBSSH_SHARED_LIBRARY}
|
||||
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
|
||||
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
|
||||
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
|
||||
COMPONENT libraries
|
||||
)
|
||||
|
||||
if (WITH_STATIC_LIB)
|
||||
add_library(${LIBSSH_STATIC_LIBRARY} STATIC ${libssh_SRCS})
|
||||
|
||||
set_target_properties(
|
||||
${LIBSSH_STATIC_LIBRARY}
|
||||
PROPERTIES
|
||||
VERSION
|
||||
${LIBRARY_VERSION}
|
||||
SOVERSION
|
||||
${LIBRARY_SOVERSION}
|
||||
COMPILE_FLAGS
|
||||
"-DLIBSSH_STATIC"
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
${LIBSSH_STATIC_LIBRARY}
|
||||
DESTINATION
|
||||
${LIB_INSTALL_DIR}
|
||||
COMPONENT
|
||||
libraries
|
||||
)
|
||||
endif (WITH_STATIC_LIB)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
lib_LTLIBRARIES = libssh.la
|
||||
|
||||
libssh_la_SOURCES = auth1.c auth.c base64.c buffer.c \
|
||||
channels1.c channels.c client.c connect.c \
|
||||
crc32.c crypt.c dh.c error.c gcrypt_missing.c \
|
||||
gzip.c init.c kex.c keyfiles.c \
|
||||
keys.c messages.c misc.c options.c \
|
||||
packet.c server.c session.c sftp.c \
|
||||
sftpserver.c string.c wrapper.c \
|
||||
socket.c log.c match.c
|
||||
|
||||
libssh_la_CPPFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
libssh_la_LDFLAGS = -version-info $(LIBSSH_CURRENT):$(LIBSSH_REVISION):$(LIBSSH_AGE)
|
||||
502
libssh/agent.c
Normal file
502
libssh/agent.c
Normal file
@@ -0,0 +1,502 @@
|
||||
/*
|
||||
* agent.c - ssh agent functions
|
||||
*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2008-2009 by Andreas Schneider <mail@cynapses.org>
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* This file is based on authfd.c from OpenSSH */
|
||||
|
||||
/*
|
||||
* How does the ssh-agent work?
|
||||
*
|
||||
* a) client sends a request to get a list of all keys
|
||||
* the agent returns the cound and all public keys
|
||||
* b) iterate over them to check if the server likes one
|
||||
* c) the client sends a sign request to the agent
|
||||
* type, pubkey as blob, data to sign, flags
|
||||
* the agent returns the signed data
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "libssh/agent.h"
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/socket.h"
|
||||
#include "libssh/buffer.h"
|
||||
#include "libssh/session.h"
|
||||
#include "libssh/keys.h"
|
||||
|
||||
/* macro to check for "agent failure" message */
|
||||
#define agent_failed(x) \
|
||||
(((x) == SSH_AGENT_FAILURE) || ((x) == SSH_COM_AGENT2_FAILURE) || \
|
||||
((x) == SSH2_AGENT_FAILURE))
|
||||
|
||||
static uint32_t agent_get_u32(const void *vp) {
|
||||
const uint8_t *p = (const uint8_t *)vp;
|
||||
uint32_t v;
|
||||
|
||||
v = (uint32_t)p[0] << 24;
|
||||
v |= (uint32_t)p[1] << 16;
|
||||
v |= (uint32_t)p[2] << 8;
|
||||
v |= (uint32_t)p[3];
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
static void agent_put_u32(void *vp, uint32_t v) {
|
||||
uint8_t *p = (uint8_t *)vp;
|
||||
|
||||
p[0] = (uint8_t)(v >> 24) & 0xff;
|
||||
p[1] = (uint8_t)(v >> 16) & 0xff;
|
||||
p[2] = (uint8_t)(v >> 8) & 0xff;
|
||||
p[3] = (uint8_t)v & 0xff;
|
||||
}
|
||||
|
||||
static size_t atomicio(struct socket *s, void *buf, size_t n, int do_read) {
|
||||
char *b = buf;
|
||||
size_t pos = 0;
|
||||
ssize_t res;
|
||||
struct pollfd pfd;
|
||||
int fd = ssh_socket_get_fd(s);
|
||||
|
||||
pfd.fd = fd;
|
||||
pfd.events = do_read ? POLLIN : POLLOUT;
|
||||
|
||||
while (n > pos) {
|
||||
if (do_read) {
|
||||
res = read(fd, b + pos, n - pos);
|
||||
} else {
|
||||
res = write(fd, b + pos, n - pos);
|
||||
}
|
||||
switch (res) {
|
||||
case -1:
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
#ifdef EWOULDBLOCK
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
#else
|
||||
if (errno == EAGAIN) {
|
||||
#endif
|
||||
(void) poll(&pfd, 1, -1);
|
||||
continue;
|
||||
}
|
||||
return 0;
|
||||
case 0:
|
||||
errno = EPIPE;
|
||||
return pos;
|
||||
default:
|
||||
pos += (size_t) res;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
ssh_agent agent_new(struct ssh_session_struct *session) {
|
||||
ssh_agent agent = NULL;
|
||||
|
||||
agent = malloc(sizeof(struct ssh_agent_struct));
|
||||
if (agent == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ZERO_STRUCTP(agent);
|
||||
|
||||
agent->count = 0;
|
||||
agent->sock = ssh_socket_new(session);
|
||||
if (agent->sock == NULL) {
|
||||
SAFE_FREE(agent);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return agent;
|
||||
}
|
||||
|
||||
void agent_close(struct ssh_agent_struct *agent) {
|
||||
if (agent == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getenv("SSH_AUTH_SOCK")) {
|
||||
ssh_socket_close(agent->sock);
|
||||
}
|
||||
}
|
||||
|
||||
void agent_free(ssh_agent agent) {
|
||||
if (agent) {
|
||||
if (agent->ident) {
|
||||
buffer_free(agent->ident);
|
||||
}
|
||||
if (agent->sock) {
|
||||
agent_close(agent);
|
||||
ssh_socket_free(agent->sock);
|
||||
}
|
||||
SAFE_FREE(agent);
|
||||
}
|
||||
}
|
||||
|
||||
static int agent_connect(ssh_session session) {
|
||||
const char *auth_sock = NULL;
|
||||
|
||||
if (session == NULL || session->agent == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
auth_sock = getenv("SSH_AUTH_SOCK");
|
||||
|
||||
if (auth_sock && *auth_sock) {
|
||||
if (ssh_socket_unix(session->agent->sock, auth_sock) < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int agent_decode_reply(struct ssh_session_struct *session, int type) {
|
||||
switch (type) {
|
||||
case SSH_AGENT_FAILURE:
|
||||
case SSH2_AGENT_FAILURE:
|
||||
case SSH_COM_AGENT2_FAILURE:
|
||||
ssh_log(session, SSH_LOG_RARE, "SSH_AGENT_FAILURE");
|
||||
return 0;
|
||||
case SSH_AGENT_SUCCESS:
|
||||
return 1;
|
||||
default:
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Bad response from authentication agent: %d", type);
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int agent_talk(struct ssh_session_struct *session,
|
||||
struct ssh_buffer_struct *request, struct ssh_buffer_struct *reply) {
|
||||
uint32_t len = 0;
|
||||
uint8_t payload[1024] = {0};
|
||||
|
||||
len = buffer_get_len(request);
|
||||
ssh_log(session, SSH_LOG_PACKET, "agent_talk - len of request: %u", len);
|
||||
agent_put_u32(payload, len);
|
||||
|
||||
/* send length and then the request packet */
|
||||
if (atomicio(session->agent->sock, payload, 4, 0) == 4) {
|
||||
if (atomicio(session->agent->sock, buffer_get_rest(request), len, 0)
|
||||
!= len) {
|
||||
ssh_log(session, SSH_LOG_PACKET, "atomicio sending request failed: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ssh_log(session, SSH_LOG_PACKET,
|
||||
"atomicio sending request length failed: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* wait for response, read the length of the response packet */
|
||||
if (atomicio(session->agent->sock, payload, 4, 1) != 4) {
|
||||
ssh_log(session, SSH_LOG_PACKET, "atomicio read response length failed: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = agent_get_u32(payload);
|
||||
if (len > 256 * 1024) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Authentication response too long: %u", len);
|
||||
return -1;
|
||||
}
|
||||
ssh_log(session, SSH_LOG_PACKET, "agent_talk - response length: %u", len);
|
||||
|
||||
while (len > 0) {
|
||||
size_t n = len;
|
||||
if (n > sizeof(payload)) {
|
||||
n = sizeof(payload);
|
||||
}
|
||||
if (atomicio(session->agent->sock, payload, n, 1) != n) {
|
||||
ssh_log(session, SSH_LOG_RARE,
|
||||
"Error reading response from authentication socket.");
|
||||
return -1;
|
||||
}
|
||||
if (buffer_add_data(reply, payload, n) < 0) {
|
||||
ssh_log(session, SSH_LOG_FUNCTIONS,
|
||||
"Not enough space");
|
||||
return -1;
|
||||
}
|
||||
len -= n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int agent_get_ident_count(struct ssh_session_struct *session) {
|
||||
ssh_buffer request = NULL;
|
||||
ssh_buffer reply = NULL;
|
||||
unsigned int type = 0;
|
||||
unsigned int c1 = 0, c2 = 0;
|
||||
uint8_t buf[4] = {0};
|
||||
|
||||
switch (session->version) {
|
||||
case 1:
|
||||
c1 = SSH_AGENTC_REQUEST_RSA_IDENTITIES;
|
||||
c2 = SSH_AGENT_RSA_IDENTITIES_ANSWER;
|
||||
break;
|
||||
case 2:
|
||||
c1 = SSH2_AGENTC_REQUEST_IDENTITIES;
|
||||
c2 = SSH2_AGENT_IDENTITIES_ANSWER;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* send message to the agent requesting the list of identities */
|
||||
request = buffer_new();
|
||||
if (buffer_add_u8(request, c1) < 0) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
return -1;
|
||||
}
|
||||
|
||||
reply = buffer_new();
|
||||
if (reply == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (agent_talk(session, request, reply) < 0) {
|
||||
buffer_free(request);
|
||||
return 0;
|
||||
}
|
||||
buffer_free(request);
|
||||
|
||||
/* get message type and verify the answer */
|
||||
buffer_get_u8(reply, (uint8_t *) &type);
|
||||
ssh_log(session, SSH_LOG_PACKET,
|
||||
"agent_ident_count - answer type: %d, expected answer: %d",
|
||||
type, c2);
|
||||
if (agent_failed(type)) {
|
||||
return 0;
|
||||
} else if (type != c2) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Bad authentication reply message type: %d", type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer_get_u32(reply, (uint32_t *) buf);
|
||||
session->agent->count = agent_get_u32(buf);
|
||||
ssh_log(session, SSH_LOG_PACKET, "agent_ident_count - count: %d",
|
||||
session->agent->count);
|
||||
if (session->agent->count > 1024) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Too many identities in authentication reply: %d",
|
||||
session->agent->count);
|
||||
buffer_free(reply);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (session->agent->ident) {
|
||||
buffer_reinit(session->agent->ident);
|
||||
}
|
||||
session->agent->ident = reply;
|
||||
|
||||
return session->agent->count;
|
||||
}
|
||||
|
||||
/* caller has to free commment */
|
||||
struct ssh_public_key_struct *agent_get_first_ident(struct ssh_session_struct *session,
|
||||
char **comment) {
|
||||
if (agent_get_ident_count(session) > 0) {
|
||||
return agent_get_next_ident(session, comment);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* caller has to free commment */
|
||||
struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *session,
|
||||
char **comment) {
|
||||
struct ssh_public_key_struct *pubkey = NULL;
|
||||
struct ssh_string_struct *blob = NULL;
|
||||
struct ssh_string_struct *tmp = NULL;
|
||||
|
||||
if (session->agent->count == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch(session->version) {
|
||||
case 1:
|
||||
return NULL;
|
||||
case 2:
|
||||
/* get the blob */
|
||||
blob = buffer_get_ssh_string(session->agent->ident);
|
||||
if (blob == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* get the comment */
|
||||
tmp = buffer_get_ssh_string(session->agent->ident);
|
||||
if (tmp == NULL) {
|
||||
string_free(blob);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (comment) {
|
||||
*comment = string_to_char(tmp);
|
||||
} else {
|
||||
string_free(blob);
|
||||
string_free(tmp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
string_free(tmp);
|
||||
|
||||
/* get key from blob */
|
||||
pubkey = publickey_from_string(session, blob);
|
||||
string_free(blob);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
ssh_string agent_sign_data(struct ssh_session_struct *session,
|
||||
struct ssh_buffer_struct *data,
|
||||
struct ssh_public_key_struct *pubkey) {
|
||||
struct ssh_string_struct *blob = NULL;
|
||||
struct ssh_string_struct *sig = NULL;
|
||||
struct ssh_buffer_struct *request = NULL;
|
||||
struct ssh_buffer_struct *reply = NULL;
|
||||
int type = SSH2_AGENT_FAILURE;
|
||||
int flags = 0;
|
||||
uint32_t dlen = 0;
|
||||
|
||||
/* create blob from the pubkey */
|
||||
blob = publickey_to_string(pubkey);
|
||||
|
||||
request = buffer_new();
|
||||
if (request == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* create request */
|
||||
if (buffer_add_u8(request, SSH2_AGENTC_SIGN_REQUEST) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* adds len + blob */
|
||||
if (buffer_add_ssh_string(request, blob) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Add data */
|
||||
dlen = buffer_get_len(data);
|
||||
if (buffer_add_u32(request, htonl(dlen)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_data(request, buffer_get(data), dlen) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (buffer_add_u32(request, htonl(flags)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(blob);
|
||||
|
||||
reply = buffer_new();
|
||||
if (reply == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* send the request */
|
||||
if (agent_talk(session, request, reply) < 0) {
|
||||
buffer_free(request);
|
||||
return NULL;
|
||||
}
|
||||
buffer_free(request);
|
||||
|
||||
/* check if reply is valid */
|
||||
if (buffer_get_u8(reply, (uint8_t *) &type) != sizeof(uint8_t)) {
|
||||
goto error;
|
||||
}
|
||||
if (agent_failed(type)) {
|
||||
ssh_log(session, SSH_LOG_RARE, "Agent reports failure in signing the key");
|
||||
buffer_free(reply);
|
||||
return NULL;
|
||||
} else if (type != SSH2_AGENT_SIGN_RESPONSE) {
|
||||
ssh_set_error(session, SSH_FATAL, "Bad authentication response: %d", type);
|
||||
buffer_free(reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sig = buffer_get_ssh_string(reply);
|
||||
|
||||
buffer_free(reply);
|
||||
|
||||
return sig;
|
||||
error:
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough memory");
|
||||
string_free(blob);
|
||||
buffer_free(request);
|
||||
buffer_free(reply);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int agent_is_running(ssh_session session) {
|
||||
if (session == NULL || session->agent == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ssh_socket_is_open(session->agent->sock)) {
|
||||
return 1;
|
||||
} else {
|
||||
if (agent_connect(session) < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
2133
libssh/auth.c
2133
libssh/auth.c
File diff suppressed because it is too large
Load Diff
274
libssh/auth1.c
274
libssh/auth1.c
@@ -1,85 +1,112 @@
|
||||
/* auth1.c deals with authentication with SSH-1 protocol */
|
||||
/*
|
||||
Copyright (c) 2005-2008 Aris Adamantiadis
|
||||
* auth1.c - authentication with SSH-1 protocol
|
||||
*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2005-2008 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
This file is part of the SSH Library
|
||||
#include "config.h"
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/ssh1.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
static void burn(char *ptr){
|
||||
if(ptr)
|
||||
memset(ptr,'X',strlen(ptr));
|
||||
}
|
||||
*/
|
||||
#ifdef HAVE_SSH1
|
||||
static int wait_auth1_status(SSH_SESSION *session){
|
||||
/* wait for a packet */
|
||||
if(packet_read(session))
|
||||
return SSH_AUTH_ERROR;
|
||||
if(packet_translate(session))
|
||||
return SSH_AUTH_ERROR;
|
||||
switch(session->in_packet.type){
|
||||
case SSH_SMSG_SUCCESS:
|
||||
return SSH_AUTH_SUCCESS;
|
||||
case SSH_SMSG_FAILURE:
|
||||
return SSH_AUTH_DENIED;
|
||||
}
|
||||
ssh_set_error(session,SSH_FATAL,"Was waiting for a SUCCESS or "
|
||||
"FAILURE, got %d",session->in_packet.type);
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/ssh1.h"
|
||||
#include "libssh/buffer.h"
|
||||
#include "libssh/packet.h"
|
||||
#include "libssh/session.h"
|
||||
#include "libssh/string.h"
|
||||
|
||||
#ifdef WITH_SSH1
|
||||
static int wait_auth1_status(ssh_session session) {
|
||||
/* wait for a packet */
|
||||
if (packet_read(session) != SSH_OK) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
if(packet_translate(session) != SSH_OK) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
switch(session->in_packet.type) {
|
||||
case SSH_SMSG_SUCCESS:
|
||||
return SSH_AUTH_SUCCESS;
|
||||
case SSH_SMSG_FAILURE:
|
||||
return SSH_AUTH_DENIED;
|
||||
}
|
||||
|
||||
ssh_set_error(session, SSH_FATAL, "Was waiting for a SUCCESS or "
|
||||
"FAILURE, got %d", session->in_packet.type);
|
||||
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
static int send_username(SSH_SESSION *session, char *username){
|
||||
STRING *user;
|
||||
/* returns SSH_AUTH_SUCCESS or SSH_AUTH_DENIED */
|
||||
if(session->auth_service_asked)
|
||||
return session->auth_service_asked;
|
||||
buffer_add_u8(session->out_buffer,SSH_CMSG_USER);
|
||||
if(!username)
|
||||
if(!(username=session->options->username)){
|
||||
if(ssh_options_default_username(session->options))
|
||||
return session->auth_service_asked=SSH_AUTH_ERROR;
|
||||
else
|
||||
username=session->options->username;
|
||||
}
|
||||
user=string_from_char(username);
|
||||
buffer_add_ssh_string(session->out_buffer,user);
|
||||
free(user);
|
||||
packet_send(session);
|
||||
session->auth_service_asked=wait_auth1_status(session);
|
||||
|
||||
static int send_username(ssh_session session, const char *username) {
|
||||
ssh_string user = NULL;
|
||||
/* returns SSH_AUTH_SUCCESS or SSH_AUTH_DENIED */
|
||||
if(session->auth_service_asked) {
|
||||
return session->auth_service_asked;
|
||||
}
|
||||
|
||||
if (!username) {
|
||||
if(!(username = session->username)) {
|
||||
if (ssh_options_set(session, SSH_OPTIONS_USER, NULL) < 0) {
|
||||
return session->auth_service_asked = SSH_AUTH_ERROR;
|
||||
} else {
|
||||
username = session->username;
|
||||
}
|
||||
}
|
||||
}
|
||||
user = string_from_char(username);
|
||||
if (user == NULL) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_USER) < 0) {
|
||||
string_free(user);
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
if (buffer_add_ssh_string(session->out_buffer, user) < 0) {
|
||||
string_free(user);
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
string_free(user);
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
session->auth_service_asked = wait_auth1_status(session);
|
||||
|
||||
return session->auth_service_asked;
|
||||
}
|
||||
|
||||
/* use the "none" authentication question */
|
||||
|
||||
int ssh_userauth1_none(SSH_SESSION *session,char *username){
|
||||
return send_username(session,username);
|
||||
int ssh_userauth1_none(ssh_session session, const char *username){
|
||||
return send_username(session, username);
|
||||
}
|
||||
|
||||
/*
|
||||
int ssh_userauth_offer_pubkey(SSH_SESSION *session, char *username,int type, STRING *publickey){
|
||||
STRING *user;
|
||||
STRING *service;
|
||||
STRING *method;
|
||||
STRING *algo;
|
||||
int ssh_userauth_offer_pubkey(ssh_session session, char *username,int type, ssh_string publickey){
|
||||
ssh_string user;
|
||||
ssh_string service;
|
||||
ssh_string method;
|
||||
ssh_string algo;
|
||||
int err=SSH_AUTH_ERROR;
|
||||
if(!username)
|
||||
if(!(username=session->options->username)){
|
||||
@@ -115,18 +142,22 @@ int ssh_userauth_offer_pubkey(SSH_SESSION *session, char *username,int type, STR
|
||||
/** \internal
|
||||
* \todo implement ssh1 public key
|
||||
*/
|
||||
int ssh_userauth1_offer_pubkey(SSH_SESSION *session, char *username, int type,
|
||||
STRING *pubkey){
|
||||
return SSH_AUTH_DENIED;
|
||||
int ssh_userauth1_offer_pubkey(ssh_session session, const char *username,
|
||||
int type, ssh_string pubkey) {
|
||||
(void) session;
|
||||
(void) username;
|
||||
(void) type;
|
||||
(void) pubkey;
|
||||
return SSH_AUTH_DENIED;
|
||||
}
|
||||
|
||||
/*
|
||||
int ssh_userauth_pubkey(SSH_SESSION *session, char *username, STRING *publickey, PRIVATE_KEY *privatekey){
|
||||
STRING *user;
|
||||
STRING *service;
|
||||
STRING *method;
|
||||
STRING *algo;
|
||||
STRING *sign;
|
||||
int ssh_userauth_pubkey(ssh_session session, char *username, ssh_string publickey, ssh_private_key privatekey){
|
||||
ssh_string user;
|
||||
ssh_string service;
|
||||
ssh_string method;
|
||||
ssh_string algo;
|
||||
ssh_string sign;
|
||||
int err=SSH_AUTH_ERROR;
|
||||
if(!username)
|
||||
if(!(username=session->options->username)){
|
||||
@@ -167,39 +198,64 @@ int ssh_userauth_pubkey(SSH_SESSION *session, char *username, STRING *publickey,
|
||||
}
|
||||
*/
|
||||
|
||||
int ssh_userauth1_password(SSH_SESSION *session,char *username,char *password){
|
||||
STRING *password_s;
|
||||
int err;
|
||||
err=send_username(session,username);
|
||||
if(err!=SSH_AUTH_DENIED)
|
||||
return err;
|
||||
/* we trick a bit here. A known flaw in SSH1 protocol is that it's
|
||||
* easy to guess password sizes.
|
||||
* not that sure ...
|
||||
*/
|
||||
/* XXX fix me here ! */
|
||||
/* cisco IOS doesn't like when a password is followed by zeroes and random pad. */
|
||||
if(strlen(password)>=0){
|
||||
/* not risky to disclose the size of such a big password .. */
|
||||
password_s=string_from_char(password);
|
||||
} else {
|
||||
/* fill the password string from random things. the strcpy
|
||||
* ensure there is at least a nul byte after the password.
|
||||
* most implementation won't see the garbage at end.
|
||||
* why garbage ? because nul bytes will be compressed by
|
||||
* gzip and disclose password len.
|
||||
*/
|
||||
password_s=string_new(128);
|
||||
ssh_get_random(password_s->string,128,0);
|
||||
strcpy((char *)password_s->string,password);
|
||||
}
|
||||
int ssh_userauth1_password(ssh_session session, const char *username,
|
||||
const char *password) {
|
||||
ssh_string pwd = NULL;
|
||||
int rc;
|
||||
|
||||
buffer_add_u8(session->out_buffer,SSH_CMSG_AUTH_PASSWORD);
|
||||
buffer_add_ssh_string(session->out_buffer,password_s);
|
||||
string_burn(password_s);
|
||||
free(password_s);
|
||||
packet_send(session);
|
||||
return wait_auth1_status(session);
|
||||
rc = send_username(session, username);
|
||||
if (rc != SSH_AUTH_DENIED) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* we trick a bit here. A known flaw in SSH1 protocol is that it's
|
||||
* easy to guess password sizes.
|
||||
* not that sure ...
|
||||
*/
|
||||
|
||||
/* XXX fix me here ! */
|
||||
/* cisco IOS doesn't like when a password is followed by zeroes and random pad. */
|
||||
if(1 || strlen(password) >= 128) {
|
||||
/* not risky to disclose the size of such a big password .. */
|
||||
pwd = string_from_char(password);
|
||||
if (pwd == NULL) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
} else {
|
||||
/* fill the password string from random things. the strcpy
|
||||
* ensure there is at least a nul byte after the password.
|
||||
* most implementation won't see the garbage at end.
|
||||
* why garbage ? because nul bytes will be compressed by
|
||||
* gzip and disclose password len.
|
||||
*/
|
||||
pwd = string_new(128);
|
||||
if (pwd == NULL) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
ssh_get_random( pwd->string, 128, 0);
|
||||
strcpy((char *) pwd->string, password);
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_AUTH_PASSWORD) < 0) {
|
||||
string_burn(pwd);
|
||||
string_free(pwd);
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
if (buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
|
||||
string_burn(pwd);
|
||||
string_free(pwd);
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
string_burn(pwd);
|
||||
string_free(pwd);
|
||||
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
return wait_auth1_status(session);
|
||||
}
|
||||
|
||||
#endif /* HAVE_SSH1 */
|
||||
#endif /* WITH_SSH1 */
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
|
||||
438
libssh/base64.c
438
libssh/base64.c
@@ -1,217 +1,287 @@
|
||||
/* base64 contains the needed support for base64 alphabet system, */
|
||||
/* as described in RFC1521 */
|
||||
/*
|
||||
Copyright 2003-2005 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
* base64.c - support for base64 alphabet system, described in RFC1521
|
||||
*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2005-2005 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* just the dirtiest part of code i ever made */
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libssh/priv.h"
|
||||
static char alphabet[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/" ;
|
||||
#include "libssh/buffer.h"
|
||||
|
||||
/* transformations */
|
||||
#define SET_A(n,i) do { n |= (i&63) <<18; } while (0)
|
||||
#define SET_B(n,i) do { n |= (i&63) <<12; } while (0)
|
||||
#define SET_C(n,i) do { n |= (i&63) << 6; } while (0)
|
||||
#define SET_D(n,i) do { n |= (i&63); } while (0)
|
||||
static char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
|
||||
#define GET_A(n) ((n & 0xff0000) >> 16)
|
||||
#define GET_B(n) ((n & 0xff00) >> 8)
|
||||
#define GET_C(n) (n & 0xff)
|
||||
/* Transformations */
|
||||
#define SET_A(n, i) do { (n) |= ((i) & 63) <<18; } while (0)
|
||||
#define SET_B(n, i) do { (n) |= ((i) & 63) <<12; } while (0)
|
||||
#define SET_C(n, i) do { (n) |= ((i) & 63) << 6; } while (0)
|
||||
#define SET_D(n, i) do { (n) |= ((i) & 63); } while (0)
|
||||
|
||||
static int _base64_to_bin(unsigned char dest[3], char *source,int num);
|
||||
#define GET_A(n) (((n) & 0xff0000) >> 16)
|
||||
#define GET_B(n) (((n) & 0xff00) >> 8)
|
||||
#define GET_C(n) ((n) & 0xff)
|
||||
|
||||
static int _base64_to_bin(unsigned char dest[3], const char *source, int num);
|
||||
static int get_equals(char *string);
|
||||
|
||||
/* first part : base 64 to binary */
|
||||
/* First part: base64 to binary */
|
||||
|
||||
/** \brief base64_to_bin translates a base64 string into a binary one. important,
|
||||
* \returns NULL if something went wrong (ie incorrect char)
|
||||
* \returns BUFFER containing the decoded string
|
||||
* \internal
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @brief Translates a base64 string into a binary one.
|
||||
*
|
||||
* @returns A buffer containing the decoded string, NULL if something went
|
||||
* wrong (e.g. incorrect char).
|
||||
*/
|
||||
ssh_buffer base64_to_bin(const char *source) {
|
||||
ssh_buffer buffer = NULL;
|
||||
unsigned char block[3];
|
||||
char *base64;
|
||||
char *ptr;
|
||||
size_t len;
|
||||
int equals;
|
||||
|
||||
BUFFER *base64_to_bin(char *source){
|
||||
int len;
|
||||
int equals;
|
||||
BUFFER *buffer=buffer_new();
|
||||
unsigned char block[3];
|
||||
base64 = strdup(source);
|
||||
if (base64 == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ptr = base64;
|
||||
|
||||
/* get the number of equals signs, which mirrors the padding */
|
||||
equals=get_equals(source);
|
||||
if(equals>2){
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
/* Get the number of equals signs, which mirrors the padding */
|
||||
equals = get_equals(ptr);
|
||||
if (equals > 2) {
|
||||
SAFE_FREE(base64);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer = buffer_new();
|
||||
if (buffer == NULL) {
|
||||
SAFE_FREE(base64);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = strlen(ptr);
|
||||
while (len > 4) {
|
||||
if (_base64_to_bin(block, ptr, 3) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
len=strlen(source);
|
||||
while(len>4){
|
||||
if(_base64_to_bin(block,source,3)){
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
buffer_add_data(buffer,block,3);
|
||||
len-=4;
|
||||
source+=4;
|
||||
if (buffer_add_data(buffer, block, 3) < 0) {
|
||||
goto error;
|
||||
}
|
||||
/* depending of the number of bytes resting, there are 3 possibilities (from the rfc) */
|
||||
switch(len){
|
||||
/* (1) the final quantum of encoding input is an integral
|
||||
multiple of 24 bits; here, the final unit of encoded output will be
|
||||
an integral multiple of 4 characters with no "=" padding */
|
||||
case 4:
|
||||
if(equals!=0){
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
if(_base64_to_bin(block,source,3)){
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
buffer_add_data(buffer,block,3);
|
||||
return buffer;
|
||||
/*(2) the final quantum of encoding input is exactly 8 bits; here, the final
|
||||
unit of encoded output will be two characters followed by two "="
|
||||
padding characters */
|
||||
case 2:
|
||||
if(equals!=2){
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
if(_base64_to_bin(block,source,1)){
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
buffer_add_data(buffer,block,1);
|
||||
return buffer;
|
||||
/* the final quantum of encoding input is
|
||||
exactly 16 bits; here, the final unit of encoded output will be three
|
||||
characters followed by one "=" padding character */
|
||||
case 3:
|
||||
if(equals!=1){
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
if(_base64_to_bin(block,source,2)){
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
buffer_add_data(buffer,block,2);
|
||||
return buffer;
|
||||
default:
|
||||
/* 4,3,2 are the only padding size allowed */
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
len -= 4;
|
||||
ptr += 4;
|
||||
}
|
||||
|
||||
/*
|
||||
* Depending on the number of bytes resting, there are 3 possibilities
|
||||
* from the RFC.
|
||||
*/
|
||||
switch (len) {
|
||||
/*
|
||||
* (1) The final quantum of encoding input is an integral multiple of
|
||||
* 24 bits. Here, the final unit of encoded output will be an integral
|
||||
* multiple of 4 characters with no "=" padding
|
||||
*/
|
||||
case 4:
|
||||
if (equals != 0) {
|
||||
goto error;
|
||||
}
|
||||
if (_base64_to_bin(block, ptr, 3) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_data(buffer, block, 3) < 0) {
|
||||
goto error;
|
||||
}
|
||||
SAFE_FREE(base64);
|
||||
|
||||
return buffer;
|
||||
/*
|
||||
* (2) The final quantum of encoding input is exactly 8 bits; here, the
|
||||
* final unit of encoded output will be two characters followed by
|
||||
* two "=" padding characters.
|
||||
*/
|
||||
case 2:
|
||||
if (equals != 2){
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (_base64_to_bin(block, ptr, 1) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_data(buffer, block, 1) < 0) {
|
||||
goto error;
|
||||
}
|
||||
SAFE_FREE(base64);
|
||||
|
||||
return buffer;
|
||||
/*
|
||||
* The final quantum of encoding input is exactly 16 bits. Here, the final
|
||||
* unit of encoded output will be three characters followed by one "="
|
||||
* padding character.
|
||||
*/
|
||||
case 3:
|
||||
if (equals != 1) {
|
||||
goto error;
|
||||
}
|
||||
if (_base64_to_bin(block, ptr, 2) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_data(buffer,block,2) < 0) {
|
||||
goto error;
|
||||
}
|
||||
SAFE_FREE(base64);
|
||||
|
||||
return buffer;
|
||||
default:
|
||||
/* 4,3,2 are the only padding size allowed */
|
||||
goto error;
|
||||
}
|
||||
|
||||
error:
|
||||
SAFE_FREE(base64);
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define BLOCK(letter,n) do { ptr=strchr(alphabet,source[n]);\
|
||||
if(!ptr) return -1;\
|
||||
i=ptr-alphabet;\
|
||||
SET_##letter(*block,i);\
|
||||
} while(0)
|
||||
/* returns 0 if ok, -1 if not (ie invalid char into the stuff) */
|
||||
static int to_block4(unsigned long *block, char *source,int num){
|
||||
char *ptr;
|
||||
unsigned int i;
|
||||
*block=0;
|
||||
if(num<1)
|
||||
return 0;
|
||||
BLOCK(A,0); /* 6 bits */
|
||||
BLOCK(B,1); /* 12 */
|
||||
if(num<2)
|
||||
return 0;
|
||||
BLOCK(C,2); /* 18 */
|
||||
if(num < 3)
|
||||
return 0;
|
||||
BLOCK(D,3); /* 24 */
|
||||
#define BLOCK(letter, n) do {ptr = strchr(alphabet, source[n]); \
|
||||
if(!ptr) return -1; \
|
||||
i = ptr - alphabet; \
|
||||
SET_##letter(*block, i); \
|
||||
} while(0)
|
||||
|
||||
/* Returns 0 if ok, -1 if not (ie invalid char into the stuff) */
|
||||
static int to_block4(unsigned long *block, const char *source, int num) {
|
||||
char *ptr;
|
||||
unsigned int i;
|
||||
|
||||
*block = 0;
|
||||
if (num < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLOCK(A, 0); /* 6 bit */
|
||||
BLOCK(B,1); /* 12 bit */
|
||||
|
||||
if (num < 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLOCK(C, 2); /* 18 bit */
|
||||
|
||||
if (num < 3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLOCK(D, 3); /* 24 bit */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* num = numbers of final bytes to be decoded */
|
||||
static int _base64_to_bin(unsigned char dest[3], char *source,int num){
|
||||
unsigned long block;
|
||||
if(to_block4(&block,source,num))
|
||||
return -1;
|
||||
dest[0]=GET_A(block);
|
||||
dest[1]=GET_B(block);
|
||||
dest[2]=GET_C(block);
|
||||
return 0;
|
||||
static int _base64_to_bin(unsigned char dest[3], const char *source, int num) {
|
||||
unsigned long block;
|
||||
|
||||
if (to_block4(&block, source, num) < 0) {
|
||||
return -1;
|
||||
}
|
||||
dest[0] = GET_A(block);
|
||||
dest[1] = GET_B(block);
|
||||
dest[2] = GET_C(block);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* counts the number of "=" signs, and replace them by zeroes */
|
||||
static int get_equals(char *string){
|
||||
char *ptr=string;
|
||||
int num=0;
|
||||
while((ptr=strchr(ptr,'='))){
|
||||
num++;
|
||||
*ptr=0;
|
||||
ptr++;
|
||||
}
|
||||
/* Count the number of "=" signs and replace them by zeroes */
|
||||
static int get_equals(char *string) {
|
||||
char *ptr = string;
|
||||
int num = 0;
|
||||
|
||||
return num;
|
||||
while ((ptr=strchr(ptr,'=')) != NULL) {
|
||||
num++;
|
||||
*ptr = '\0';
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
/* thanks sysk for debugging my mess :) */
|
||||
#define BITS(n) ((1<<n)-1)
|
||||
static void _bin_to_base64(unsigned char *dest, unsigned char source[3], int len){
|
||||
switch (len){
|
||||
case 1:
|
||||
dest[0]=alphabet[(source[0]>>2)];
|
||||
dest[1]=alphabet[((source[0] & BITS(2)) << 4)];
|
||||
dest[2]='=';
|
||||
dest[3]='=';
|
||||
break;
|
||||
case 2:
|
||||
dest[0]=alphabet[source[0]>>2];
|
||||
dest[1]=alphabet[(source[1]>>4) | ((source[0] & BITS(2)) << 4)];
|
||||
dest[2]=alphabet[(source[1]&BITS(4)) << 2];
|
||||
dest[3]='=';
|
||||
break;
|
||||
case 3:
|
||||
dest[0]=alphabet[(source[0]>>2)];
|
||||
dest[1]=alphabet[(source[1]>>4) | ((source[0] & BITS(2)) << 4)];
|
||||
dest[2]=alphabet[ (source[2] >> 6) | (source[1]&BITS(4)) << 2];
|
||||
dest[3]=alphabet[source[2]&BITS(6)];
|
||||
break;
|
||||
}
|
||||
#define BITS(n) ((1 << (n)) - 1)
|
||||
static void _bin_to_base64(unsigned char *dest, const unsigned char source[3],
|
||||
int len) {
|
||||
switch (len) {
|
||||
case 1:
|
||||
dest[0] = alphabet[(source[0] >> 2)];
|
||||
dest[1] = alphabet[((source[0] & BITS(2)) << 4)];
|
||||
dest[2] = '=';
|
||||
dest[3] = '=';
|
||||
break;
|
||||
case 2:
|
||||
dest[0] = alphabet[source[0] >> 2];
|
||||
dest[1] = alphabet[(source[1] >> 4) | ((source[0] & BITS(2)) << 4)];
|
||||
dest[2] = alphabet[(source[1] & BITS(4)) << 2];
|
||||
dest[3] = '=';
|
||||
break;
|
||||
case 3:
|
||||
dest[0] = alphabet[(source[0] >> 2)];
|
||||
dest[1] = alphabet[(source[1] >> 4) | ((source[0] & BITS(2)) << 4)];
|
||||
dest[2] = alphabet[ (source[2] >> 6) | (source[1] & BITS(4)) << 2];
|
||||
dest[3] = alphabet[source[2] & BITS(6)];
|
||||
break;
|
||||
}
|
||||
}
|
||||
/** \brief Converts binary data to a base64 string
|
||||
* \returns the converted string
|
||||
* \internal
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @brief Converts binary data to a base64 string.
|
||||
*
|
||||
* @returns the converted string
|
||||
*/
|
||||
unsigned char *bin_to_base64(unsigned char *source, int len){
|
||||
int flen=len + (3 - (len %3)); /* round to upper 3 multiple */
|
||||
unsigned char *buffer;
|
||||
unsigned char *ptr;
|
||||
flen=(4 * flen)/3 + 1 ;
|
||||
ptr=buffer=malloc(flen);
|
||||
while(len>0){
|
||||
_bin_to_base64(ptr,source,len>3?3:len);
|
||||
ptr+=4;
|
||||
source +=3;
|
||||
len -=3;
|
||||
}
|
||||
ptr[0]=0;
|
||||
return buffer;
|
||||
unsigned char *bin_to_base64(const unsigned char *source, int len) {
|
||||
unsigned char *base64;
|
||||
unsigned char *ptr;
|
||||
int flen = len + (3 - (len % 3)); /* round to upper 3 multiple */
|
||||
flen = (4 * flen) / 3 + 1;
|
||||
|
||||
base64 = malloc(flen);
|
||||
if (base64 == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ptr = base64;
|
||||
|
||||
while(len > 0){
|
||||
_bin_to_base64(ptr, source, len > 3 ? 3 : len);
|
||||
ptr += 4;
|
||||
source += 3;
|
||||
len -= 3;
|
||||
}
|
||||
ptr[0] = '\0';
|
||||
|
||||
return base64;
|
||||
}
|
||||
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
|
||||
403
libssh/buffer.c
403
libssh/buffer.c
@@ -1,27 +1,35 @@
|
||||
/*
|
||||
Copyright (c) 2003-2008 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
* buffer.c - buffer functions
|
||||
*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2003-2009 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libssh/priv.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/buffer.h"
|
||||
/** \defgroup ssh_buffer SSH Buffers
|
||||
* \brief buffer handling
|
||||
*/
|
||||
@@ -30,51 +38,103 @@ MA 02111-1307, USA. */
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** \brief creates a new buffer
|
||||
* \return a new initialized buffer
|
||||
/** \brief checks that preconditions and postconditions are valid
|
||||
* \internal
|
||||
*/
|
||||
BUFFER *buffer_new(){
|
||||
BUFFER *buffer=malloc(sizeof(BUFFER));
|
||||
memset(buffer,0,sizeof(BUFFER));
|
||||
return buffer;
|
||||
|
||||
#ifdef DEBUG_BUFFER
|
||||
static void buffer_verify(struct buffer_struct *buf){
|
||||
int doabort=0;
|
||||
if(buf->data == NULL)
|
||||
return;
|
||||
if(buf->used > buf->allocated){
|
||||
fprintf(stderr,"Buffer error : allocated %u, used %u\n",buf->allocated, buf->used);
|
||||
doabort=1;
|
||||
}
|
||||
if(buf->pos > buf->used){
|
||||
fprintf(stderr,"Buffer error : position %u, used %u\n",buf->pos, buf->used);
|
||||
doabort=1;
|
||||
}
|
||||
if(buf->pos > buf->allocated){
|
||||
fprintf(stderr,"Buffer error : position %u, allocated %u\n",buf->pos, buf->allocated);
|
||||
doabort=1;
|
||||
}
|
||||
if(doabort)
|
||||
abort();
|
||||
}
|
||||
|
||||
#else
|
||||
#define buffer_verify(x)
|
||||
#endif
|
||||
|
||||
/** \brief creates a new buffer
|
||||
* \return a new initialized buffer, NULL on error.
|
||||
*/
|
||||
struct ssh_buffer_struct *buffer_new(void) {
|
||||
struct ssh_buffer_struct *buf = malloc(sizeof(struct ssh_buffer_struct));
|
||||
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(buf, 0, sizeof(struct ssh_buffer_struct));
|
||||
buffer_verify(buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/** \brief deallocate a buffer
|
||||
* \param buffer buffer to free
|
||||
*/
|
||||
void buffer_free(BUFFER *buffer){
|
||||
// printf("buffer %p : free(%p);\n",buffer,buffer->data);
|
||||
if(buffer->data){
|
||||
memset(buffer->data,0,buffer->allocated); /* burn the data */
|
||||
free(buffer->data);
|
||||
}
|
||||
memset(buffer,'x',sizeof (*buffer));
|
||||
free(buffer);
|
||||
void buffer_free(struct ssh_buffer_struct *buffer) {
|
||||
if (buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
buffer_verify(buffer);
|
||||
|
||||
if (buffer->data) {
|
||||
/* burn the data */
|
||||
memset(buffer->data, 0, buffer->allocated);
|
||||
SAFE_FREE(buffer->data);
|
||||
}
|
||||
memset(buffer, 'X', sizeof(*buffer));
|
||||
SAFE_FREE(buffer);
|
||||
}
|
||||
|
||||
static void realloc_buffer(BUFFER *buffer,int needed){
|
||||
int smallest=1;
|
||||
// find the smallest power of two which is greater or equal to needed
|
||||
while(smallest<=needed)
|
||||
smallest <<= 1;
|
||||
needed=smallest;
|
||||
// printf("buffer %p : realloc(%x,%d)=",buffer,buffer->data,needed);
|
||||
buffer->data=realloc(buffer->data,needed);
|
||||
// printf("%p\n",buffer->data);
|
||||
buffer->allocated=needed;
|
||||
static int realloc_buffer(struct ssh_buffer_struct *buffer, int needed) {
|
||||
int smallest = 1;
|
||||
char *new = NULL;
|
||||
buffer_verify(buffer);
|
||||
/* Find the smallest power of two which is greater or equal to needed */
|
||||
while(smallest < needed) {
|
||||
smallest <<= 1;
|
||||
}
|
||||
needed = smallest;
|
||||
new = realloc(buffer->data, needed);
|
||||
if (new == NULL) {
|
||||
return -1;
|
||||
}
|
||||
buffer->data = new;
|
||||
buffer->allocated = needed;
|
||||
buffer_verify(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* \internal
|
||||
* \brief reinitialize a buffer
|
||||
* \param buffer buffer
|
||||
* \return 0 on sucess, < 0 on error
|
||||
*/
|
||||
void buffer_reinit(BUFFER *buffer){
|
||||
memset(buffer->data,0,buffer->used);
|
||||
buffer->used=0;
|
||||
buffer->pos=0;
|
||||
if(buffer->allocated > 127){
|
||||
realloc_buffer(buffer,127);
|
||||
int buffer_reinit(struct ssh_buffer_struct *buffer) {
|
||||
buffer_verify(buffer);
|
||||
memset(buffer->data, 0, buffer->used);
|
||||
buffer->used = 0;
|
||||
buffer->pos = 0;
|
||||
if(buffer->allocated > 127) {
|
||||
if (realloc_buffer(buffer, 127) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
buffer_verify(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
@@ -83,45 +143,91 @@ void buffer_reinit(BUFFER *buffer){
|
||||
* \param data data pointer
|
||||
* \param len length of data
|
||||
*/
|
||||
void buffer_add_data(BUFFER *buffer,const void *data,int len){
|
||||
if(buffer->allocated < buffer->used+len)
|
||||
realloc_buffer(buffer,buffer->used+len);
|
||||
memcpy(buffer->data+buffer->used,data,len);
|
||||
buffer->used+=len;
|
||||
int buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint32_t len) {
|
||||
buffer_verify(buffer);
|
||||
if (buffer->allocated < (buffer->used + len)) {
|
||||
if (realloc_buffer(buffer, buffer->used + len) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(buffer->data+buffer->used, data, len);
|
||||
buffer->used+=len;
|
||||
buffer_verify(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
* \brief add a SSH string to the tail of buffer
|
||||
* \param buffer buffer
|
||||
* \param string SSH String to add
|
||||
* \return 0 on success, -1 on error.
|
||||
*/
|
||||
void buffer_add_ssh_string(BUFFER *buffer,STRING *string){
|
||||
u32 len=ntohl(string->size);
|
||||
buffer_add_data(buffer,string,len+sizeof(u32));
|
||||
int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
|
||||
struct ssh_string_struct *string) {
|
||||
uint32_t len = 0;
|
||||
|
||||
len = string_len(string);
|
||||
if (buffer_add_data(buffer, string, len + sizeof(uint32_t)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
* \brief add a 32 bits unsigned integer to the tail of buffer
|
||||
* \param buffer buffer
|
||||
* \param data 32 bits integer
|
||||
* \return 0 on success, -1 on error.
|
||||
*/
|
||||
void buffer_add_u32(BUFFER *buffer,u32 data){
|
||||
buffer_add_data(buffer,&data,sizeof(data));
|
||||
int buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data){
|
||||
if (buffer_add_data(buffer, &data, sizeof(data)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
* \brief add a 16 bits unsigned integer to the tail of buffer
|
||||
* \param buffer buffer
|
||||
* \param data 16 bits integer
|
||||
* \return 0 on success, -1 on error.
|
||||
*/
|
||||
int buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data){
|
||||
if (buffer_add_data(buffer, &data, sizeof(data)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
* \brief add a 64 bits unsigned integer to the tail of buffer
|
||||
* \param buffer buffer
|
||||
* \param data 64 bits integer
|
||||
* \return 0 on success, -1 on error.
|
||||
*/
|
||||
void buffer_add_u64(BUFFER *buffer,u64 data){
|
||||
buffer_add_data(buffer,&data,sizeof(data));
|
||||
int buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data){
|
||||
if (buffer_add_data(buffer, &data, sizeof(data)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/** \internal
|
||||
* \brief add a 8 bits unsigned integer to the tail of buffer
|
||||
* \param buffer buffer
|
||||
* \param data 8 bits integer
|
||||
* \return 0 on success, -1 on error.
|
||||
*/
|
||||
void buffer_add_u8(BUFFER *buffer,u8 data){
|
||||
buffer_add_data(buffer,&data,sizeof(u8));
|
||||
int buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data){
|
||||
if (buffer_add_data(buffer, &data, sizeof(uint8_t)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
@@ -129,22 +235,36 @@ void buffer_add_u8(BUFFER *buffer,u8 data){
|
||||
* \param buffer buffer
|
||||
* \param data data to add
|
||||
* \param len length of data
|
||||
* \return 0 on success, -1 on error.
|
||||
*/
|
||||
void buffer_add_data_begin(BUFFER *buffer, const void *data, int len){
|
||||
if(buffer->allocated < buffer->used + len)
|
||||
realloc_buffer(buffer,buffer->used+len);
|
||||
memmove(buffer->data+len,buffer->data,buffer->used);
|
||||
memcpy(buffer->data,data,len);
|
||||
buffer->used+=len;
|
||||
int buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
|
||||
uint32_t len) {
|
||||
buffer_verify(buffer);
|
||||
if (buffer->allocated < (buffer->used + len)) {
|
||||
if (realloc_buffer(buffer, buffer->used + len) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
memmove(buffer->data + len, buffer->data, buffer->used);
|
||||
memcpy(buffer->data, data, len);
|
||||
buffer->used += len;
|
||||
buffer_verify(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
* \brief append data from a buffer to tail of another
|
||||
* \param buffer destination buffer
|
||||
* \param source source buffer. Doesn't take position in buffer into account
|
||||
* \return 0 on success, -1 on error.
|
||||
*/
|
||||
void buffer_add_buffer(BUFFER *buffer, BUFFER *source){
|
||||
buffer_add_data(buffer,buffer_get(source),buffer_get_len(source));
|
||||
int buffer_add_buffer(struct ssh_buffer_struct *buffer,
|
||||
struct ssh_buffer_struct *source) {
|
||||
if (buffer_add_data(buffer, buffer_get(source), buffer_get_len(source)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief get a pointer on the head of the buffer
|
||||
@@ -154,8 +274,8 @@ void buffer_add_buffer(BUFFER *buffer, BUFFER *source){
|
||||
* \see buffer_get_rest()
|
||||
* \see buffer_get_len()
|
||||
*/
|
||||
void *buffer_get(BUFFER *buffer){
|
||||
return buffer->data;
|
||||
void *buffer_get(struct ssh_buffer_struct *buffer){
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
@@ -165,8 +285,8 @@ void *buffer_get(BUFFER *buffer){
|
||||
* \see buffer_get_rest_len()
|
||||
* \see buffer_get()
|
||||
*/
|
||||
void *buffer_get_rest(BUFFER *buffer){
|
||||
return buffer->data+buffer->pos;
|
||||
void *buffer_get_rest(struct ssh_buffer_struct *buffer){
|
||||
return buffer->data + buffer->pos;
|
||||
}
|
||||
|
||||
/** \brief get length of the buffer, not counting position
|
||||
@@ -174,7 +294,7 @@ void *buffer_get_rest(BUFFER *buffer){
|
||||
* \return length of the buffer
|
||||
* \see buffer_get()
|
||||
*/
|
||||
int buffer_get_len(BUFFER *buffer){
|
||||
uint32_t buffer_get_len(struct ssh_buffer_struct *buffer){
|
||||
return buffer->used;
|
||||
}
|
||||
|
||||
@@ -184,8 +304,9 @@ int buffer_get_len(BUFFER *buffer){
|
||||
* \return length of the buffer
|
||||
* \see buffer_get_rest()
|
||||
*/
|
||||
int buffer_get_rest_len(BUFFER *buffer){
|
||||
return buffer->used - buffer->pos;
|
||||
uint32_t buffer_get_rest_len(struct ssh_buffer_struct *buffer){
|
||||
buffer_verify(buffer);
|
||||
return buffer->used - buffer->pos;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
@@ -195,7 +316,8 @@ int buffer_get_rest_len(BUFFER *buffer){
|
||||
* \param len number of bytes to eat
|
||||
* \return new size of the buffer
|
||||
*/
|
||||
int buffer_pass_bytes(BUFFER *buffer,int len){
|
||||
uint32_t buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
|
||||
buffer_verify(buffer);
|
||||
if(buffer->used < buffer->pos+len)
|
||||
return 0;
|
||||
buffer->pos+=len;
|
||||
@@ -204,6 +326,7 @@ int buffer_pass_bytes(BUFFER *buffer,int len){
|
||||
buffer->pos=0;
|
||||
buffer->used=0;
|
||||
}
|
||||
buffer_verify(buffer);
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -213,11 +336,13 @@ int buffer_pass_bytes(BUFFER *buffer,int len){
|
||||
* \param len number of bytes to remove from tail
|
||||
* \return new size of the buffer
|
||||
*/
|
||||
int buffer_pass_bytes_end(BUFFER *buffer,int len){
|
||||
if(buffer->used < buffer->pos + len)
|
||||
return 0;
|
||||
buffer->used-=len;
|
||||
return len;
|
||||
uint32_t buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
|
||||
buffer_verify(buffer);
|
||||
if(buffer->used < buffer->pos + len)
|
||||
return 0;
|
||||
buffer->used-=len;
|
||||
buffer_verify(buffer);
|
||||
return len;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
@@ -228,9 +353,14 @@ int buffer_pass_bytes_end(BUFFER *buffer,int len){
|
||||
* \returns 0 if there is not enough data in buffer
|
||||
* \returns len otherwise.
|
||||
*/
|
||||
int buffer_get_data(BUFFER *buffer, void *data, int len){
|
||||
if(buffer->pos+len>buffer->used)
|
||||
return 0; /*no enough data in buffer */
|
||||
uint32_t buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len){
|
||||
/*
|
||||
* Check for a integer overflow first, then check if not enough data is in
|
||||
* the buffer.
|
||||
*/
|
||||
if (buffer->pos + len < len || buffer->pos + len > buffer->used) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(data,buffer->data+buffer->pos,len);
|
||||
buffer->pos+=len;
|
||||
return len; /* no yet support for partial reads (is it really needed ?? ) */
|
||||
@@ -238,33 +368,33 @@ int buffer_get_data(BUFFER *buffer, void *data, int len){
|
||||
/** \internal
|
||||
* \brief gets a 8 bits unsigned int out of the buffer. Adjusts the read pointer.
|
||||
* \param buffer Buffer to read
|
||||
* \param data pointer to a u8 where to store the data
|
||||
* \param data pointer to a uint8_t where to store the data
|
||||
* \returns 0 if there is not enough data in buffer
|
||||
* \returns 1 otherwise.
|
||||
*/
|
||||
int buffer_get_u8(BUFFER *buffer, u8 *data){
|
||||
return buffer_get_data(buffer,data,sizeof(u8));
|
||||
int buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
|
||||
return buffer_get_data(buffer,data,sizeof(uint8_t));
|
||||
}
|
||||
|
||||
/** \internal
|
||||
* \brief gets a 32 bits unsigned int out of the buffer. Adjusts the read pointer.
|
||||
* \param buffer Buffer to read
|
||||
* \param data pointer to a u32 where to store the data
|
||||
* \param data pointer to a uint32_t where to store the data
|
||||
* \returns 0 if there is not enough data in buffer
|
||||
* \returns 4 otherwise.
|
||||
*/
|
||||
int buffer_get_u32(BUFFER *buffer, u32 *data){
|
||||
return buffer_get_data(buffer,data,sizeof(u32));
|
||||
int buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
|
||||
return buffer_get_data(buffer,data,sizeof(uint32_t));
|
||||
}
|
||||
/** \internal
|
||||
* \brief gets a 64 bits unsigned int out of the buffer. Adjusts the read pointer.
|
||||
* \param buffer Buffer to read
|
||||
* \param data pointer to a u64 where to store the data
|
||||
* \param data pointer to a uint64_t where to store the data
|
||||
* \returns 0 if there is not enough data in buffer
|
||||
* \returns 8 otherwise.
|
||||
*/
|
||||
int buffer_get_u64(BUFFER *buffer, u64 *data){
|
||||
return buffer_get_data(buffer,data,sizeof(u64));
|
||||
int buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
|
||||
return buffer_get_data(buffer,data,sizeof(uint64_t));
|
||||
}
|
||||
/** \internal
|
||||
* \brief gets a SSH String out of the buffer. Adjusts the read pointer.
|
||||
@@ -272,23 +402,30 @@ int buffer_get_u64(BUFFER *buffer, u64 *data){
|
||||
* \returns The SSH String read
|
||||
* \returns NULL otherwise.
|
||||
*/
|
||||
STRING *buffer_get_ssh_string(BUFFER *buffer){
|
||||
u32 stringlen;
|
||||
u32 hostlen;
|
||||
STRING *str;
|
||||
if(buffer_get_u32(buffer,&stringlen)==0)
|
||||
return NULL;
|
||||
hostlen=ntohl(stringlen);
|
||||
/* verify if there is enough space in buffer to get it */
|
||||
if(buffer->pos+hostlen>buffer->used)
|
||||
return NULL; /* it is indeed */
|
||||
str=string_new(hostlen);
|
||||
if(buffer_get_data(buffer,str->string,hostlen)!=hostlen){
|
||||
// should never happen
|
||||
free(str);
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer) {
|
||||
uint32_t stringlen;
|
||||
uint32_t hostlen;
|
||||
struct ssh_string_struct *str = NULL;
|
||||
|
||||
if (buffer_get_u32(buffer, &stringlen) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
hostlen = ntohl(stringlen);
|
||||
/* verify if there is enough space in buffer to get it */
|
||||
if ((buffer->pos + hostlen) > buffer->used) {
|
||||
return NULL; /* it is indeed */
|
||||
}
|
||||
str = string_new(hostlen);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (buffer_get_data(buffer, string_data(str), hostlen) != hostlen) {
|
||||
/* should never happen */
|
||||
SAFE_FREE(str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
/** \internal
|
||||
* \brief gets a mpint out of the buffer. Adjusts the read pointer.
|
||||
@@ -298,22 +435,28 @@ STRING *buffer_get_ssh_string(BUFFER *buffer){
|
||||
* \returns NULL otherwise
|
||||
*/
|
||||
|
||||
STRING *buffer_get_mpint(BUFFER *buffer){
|
||||
u16 bits;
|
||||
u32 len;
|
||||
STRING *str;
|
||||
if(buffer_get_data(buffer,&bits,sizeof(u16))!= sizeof(u16))
|
||||
return NULL;
|
||||
bits=ntohs(bits);
|
||||
len=(bits+7)/8;
|
||||
if(buffer->pos+len > buffer->used)
|
||||
return NULL;
|
||||
str=string_new(len);
|
||||
if(buffer_get_data(buffer,str->string,len)!=len){
|
||||
free(str);
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
struct ssh_string_struct *buffer_get_mpint(struct ssh_buffer_struct *buffer) {
|
||||
uint16_t bits;
|
||||
uint32_t len;
|
||||
struct ssh_string_struct *str = NULL;
|
||||
|
||||
if (buffer_get_data(buffer, &bits, sizeof(uint16_t)) != sizeof(uint16_t)) {
|
||||
return NULL;
|
||||
}
|
||||
bits = ntohs(bits);
|
||||
len = (bits + 7) / 8;
|
||||
if ((buffer->pos + len) > buffer->used) {
|
||||
return NULL;
|
||||
}
|
||||
str = string_new(len);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (buffer_get_data(buffer, string_data(str), len) != len) {
|
||||
SAFE_FREE(str);
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
/** @} */
|
||||
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
|
||||
37
libssh/callbacks.c
Normal file
37
libssh/callbacks.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* callbacks.c - callback functions
|
||||
*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2009 by Andreas Schneider <mail@cynapses.org>
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libssh/callbacks.h"
|
||||
#include "libssh/session.h"
|
||||
|
||||
int ssh_set_callbacks(ssh_session session, ssh_callbacks cb) {
|
||||
if (session == NULL || cb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
session->callbacks = cb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
3166
libssh/channels.c
3166
libssh/channels.c
File diff suppressed because it is too large
Load Diff
@@ -1,24 +1,26 @@
|
||||
/* channels1.c */
|
||||
/* Support for SSH-1 type channels */
|
||||
/*
|
||||
Copyright 2005 Aris Adamantiadis
|
||||
|
||||
This file is part of the SSH Library
|
||||
|
||||
The SSH Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The SSH Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
* channels1.c - Support for SSH-1 type channels
|
||||
*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2003-2008 by Aris Adamantiadis
|
||||
* Copyright (c) 2009 by Andreas Schneider <mail@cynapses.org>
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -26,30 +28,43 @@ MA 02111-1307, USA. */
|
||||
#include <stdio.h>
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/ssh1.h"
|
||||
#include "libssh/buffer.h"
|
||||
#include "libssh/packet.h"
|
||||
#include "libssh/channels.h"
|
||||
#include "libssh/session.h"
|
||||
|
||||
#ifdef HAVE_SSH1
|
||||
#ifdef WITH_SSH1
|
||||
|
||||
/* this is a big hack. In fact, SSH-1 doesn't make a clever use of channels.
|
||||
* The whole packets concerning Shells are sent outside of a channel.
|
||||
/*
|
||||
* This is a big hack. In fact, SSH1 doesn't make a clever use of channels.
|
||||
* The whole packets concerning shells are sent outside of a channel.
|
||||
* Thus, an inside limitation of this behaviour is that you can't only
|
||||
* request one Shell.
|
||||
* And i don't even know yet how they managed to imbed two "channel"
|
||||
* into one protocol.
|
||||
* request one shell.
|
||||
* The question is stil how they managed to imbed two "channel" into one
|
||||
* protocol.
|
||||
*/
|
||||
|
||||
int channel_open_session1(CHANNEL *chan){
|
||||
// we guess we are requesting an *exec* channel. It can only have
|
||||
// only one exec channel. so we abort with an error if we need more than
|
||||
SSH_SESSION *session=chan->session;
|
||||
if(session->exec_channel_opened){
|
||||
ssh_set_error(session,SSH_REQUEST_DENIED,"SSH-1 supports only one execution channel. One has already been opened");
|
||||
return -1;
|
||||
}
|
||||
session->exec_channel_opened=1;
|
||||
chan->open=1;
|
||||
ssh_say(2,"Opened a ssh1 channel session\n");
|
||||
return 0;
|
||||
int channel_open_session1(ssh_channel chan) {
|
||||
/*
|
||||
* We guess we are requesting an *exec* channel. It can only have one exec
|
||||
* channel. So we abort with an error if we need more than one.
|
||||
*/
|
||||
ssh_session session = chan->session;
|
||||
if (session->exec_channel_opened) {
|
||||
ssh_set_error(session, SSH_REQUEST_DENIED,
|
||||
"SSH1 supports only one execution channel. "
|
||||
"One has already been opened");
|
||||
return -1;
|
||||
}
|
||||
session->exec_channel_opened = 1;
|
||||
chan->open = 1;
|
||||
chan->local_maxpacket = 32000;
|
||||
chan->local_window = 64000;
|
||||
ssh_log(session, SSH_LOG_PACKET, "Opened a SSH1 channel session");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 10 SSH_CMSG_REQUEST_PTY
|
||||
*
|
||||
* string TERM environment variable value (e.g. vt100)
|
||||
@@ -62,156 +77,238 @@ int channel_open_session1(CHANNEL *chan){
|
||||
* much simplier under ssh2. I just hope the defaults values are ok ...
|
||||
*/
|
||||
|
||||
int channel_request_pty_size1(CHANNEL *channel, char *terminal, int col,
|
||||
int row){
|
||||
STRING *str;
|
||||
SSH_SESSION *session=channel->session;
|
||||
str=string_from_char(terminal);
|
||||
buffer_add_u8(session->out_buffer,SSH_CMSG_REQUEST_PTY);
|
||||
buffer_add_ssh_string(session->out_buffer,str);
|
||||
free(str);
|
||||
buffer_add_u32(session->out_buffer,ntohl(row));
|
||||
buffer_add_u32(session->out_buffer,ntohl(col));
|
||||
buffer_add_u32(session->out_buffer,0); /* x */
|
||||
buffer_add_u32(session->out_buffer,0); /* y */
|
||||
buffer_add_u8(session->out_buffer,0); /* tty things */
|
||||
ssh_say(2,"Opening a ssh1 pty\n");
|
||||
if(packet_send(session))
|
||||
return -1;
|
||||
if(packet_read(session))
|
||||
return -1;
|
||||
if(packet_translate(session))
|
||||
return -1;
|
||||
switch (session->in_packet.type){
|
||||
case SSH_SMSG_SUCCESS:
|
||||
ssh_say(2,"pty : Success\n");
|
||||
return 0;
|
||||
break;
|
||||
case SSH_SMSG_FAILURE:
|
||||
ssh_set_error(session,SSH_REQUEST_DENIED,
|
||||
"Server denied PTY allocation");
|
||||
ssh_say(2,"pty : denied\n");
|
||||
break;
|
||||
default:
|
||||
ssh_say(2,"pty : error\n");
|
||||
ssh_set_error(session,SSH_FATAL,
|
||||
"Received unexpected packet type %d",
|
||||
session->in_packet.type);
|
||||
return -1;
|
||||
}
|
||||
int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col,
|
||||
int row) {
|
||||
ssh_session session = channel->session;
|
||||
ssh_string str = NULL;
|
||||
|
||||
str = string_from_char(terminal);
|
||||
if (str == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_REQUEST_PTY) < 0 ||
|
||||
buffer_add_ssh_string(session->out_buffer, str) < 0) {
|
||||
string_free(str);
|
||||
return -1;
|
||||
}
|
||||
string_free(str);
|
||||
|
||||
if (buffer_add_u32(session->out_buffer, ntohl(row)) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, ntohl(col)) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, 0) < 0 || /* x */
|
||||
buffer_add_u32(session->out_buffer, 0) < 0 || /* y */
|
||||
buffer_add_u8(session->out_buffer, 0) < 0) { /* tty things */
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssh_log(session, SSH_LOG_FUNCTIONS, "Opening a ssh1 pty");
|
||||
if (packet_send(session) != SSH_OK ||
|
||||
packet_read(session) != SSH_OK ||
|
||||
packet_translate(session) != SSH_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (session->in_packet.type) {
|
||||
case SSH_SMSG_SUCCESS:
|
||||
ssh_log(session, SSH_LOG_RARE, "PTY: Success");
|
||||
return 0;
|
||||
break;
|
||||
case SSH_SMSG_FAILURE:
|
||||
ssh_set_error(session, SSH_REQUEST_DENIED,
|
||||
"Server denied PTY allocation");
|
||||
ssh_log(session, SSH_LOG_RARE, "PTY: denied\n");
|
||||
break;
|
||||
default:
|
||||
ssh_log(session, SSH_LOG_RARE, "PTY: error\n");
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Received unexpected packet type %d",
|
||||
session->in_packet.type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int channel_change_pty_size1(CHANNEL *channel, int cols, int rows){
|
||||
SSH_SESSION *session=channel->session;
|
||||
buffer_add_u8(session->out_buffer,SSH_CMSG_WINDOW_SIZE);
|
||||
buffer_add_u32(session->out_buffer,ntohl(rows));
|
||||
buffer_add_u32(session->out_buffer,ntohl(cols));
|
||||
buffer_add_u32(session->out_buffer,0);
|
||||
buffer_add_u32(session->out_buffer,0);
|
||||
if(packet_send(session))
|
||||
return -1;
|
||||
ssh_say(2,"Change pty size send\n");
|
||||
packet_wait(session,SSH_SMSG_SUCCESS,1);
|
||||
switch (session->in_packet.type){
|
||||
case SSH_SMSG_SUCCESS:
|
||||
ssh_say(2,"pty size changed\n");
|
||||
return 0;
|
||||
break;
|
||||
case SSH_SMSG_FAILURE:
|
||||
ssh_say(2,"pty size change denied\n");
|
||||
ssh_set_error(session,SSH_REQUEST_DENIED,"pty size change denied");
|
||||
return -1;
|
||||
}
|
||||
ssh_set_error(session,SSH_FATAL,"Received unexpected packet type %d",
|
||||
session->in_packet.type);
|
||||
int channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
|
||||
ssh_session session = channel->session;
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_WINDOW_SIZE) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, ntohl(rows)) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, ntohl(cols)) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, 0) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (packet_send(session)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssh_log(session, SSH_LOG_RARE, "Change pty size send");
|
||||
|
||||
if (packet_wait(session, SSH_SMSG_SUCCESS, 1) != SSH_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (session->in_packet.type) {
|
||||
case SSH_SMSG_SUCCESS:
|
||||
ssh_log(session, SSH_LOG_RARE, "pty size changed");
|
||||
return 0;
|
||||
case SSH_SMSG_FAILURE:
|
||||
ssh_log(session, SSH_LOG_RARE, "pty size change denied");
|
||||
ssh_set_error(session, SSH_REQUEST_DENIED, "pty size change denied");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssh_set_error(session, SSH_FATAL, "Received unexpected packet type %d",
|
||||
session->in_packet.type);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int channel_request_shell1(CHANNEL *channel){
|
||||
SSH_SESSION *session=channel->session;
|
||||
buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_SHELL);
|
||||
if(packet_send(session))
|
||||
return -1;
|
||||
ssh_say(2,"Launched a shell\n");
|
||||
int channel_request_shell1(ssh_channel channel) {
|
||||
ssh_session session = channel->session;
|
||||
|
||||
if (buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_SHELL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssh_log(session, SSH_LOG_RARE, "Launched a shell");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int channel_request_exec1(ssh_channel channel, const char *cmd) {
|
||||
ssh_session session = channel->session;
|
||||
ssh_string command = NULL;
|
||||
|
||||
command = string_from_char(cmd);
|
||||
if (command == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_EXEC_CMD) < 0 ||
|
||||
buffer_add_ssh_string(session->out_buffer, command) < 0) {
|
||||
string_free(command);
|
||||
return -1;
|
||||
}
|
||||
string_free(command);
|
||||
|
||||
if(packet_send(session) != SSH_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssh_log(session, SSH_LOG_RARE, "Executing %s ...", cmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int channel_rcv_data1(ssh_session session, int is_stderr) {
|
||||
ssh_channel channel = session->channels;
|
||||
ssh_string str = NULL;
|
||||
|
||||
str = buffer_get_ssh_string(session->in_buffer);
|
||||
if (str == NULL) {
|
||||
ssh_log(session, SSH_LOG_FUNCTIONS, "Invalid data packet !\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssh_log(session, SSH_LOG_RARE,
|
||||
"Adding %zu bytes data in %d",
|
||||
string_len(str), is_stderr);
|
||||
|
||||
if (channel_default_bufferize(channel, string_data(str), string_len(str),
|
||||
is_stderr) < 0) {
|
||||
string_free(str);
|
||||
return -1;
|
||||
}
|
||||
string_free(str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int channel_request_exec1(CHANNEL *channel, char *cmd){
|
||||
SSH_SESSION *session=channel->session;
|
||||
STRING *command=string_from_char(cmd);
|
||||
buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_CMD);
|
||||
buffer_add_ssh_string(session->out_buffer,command);
|
||||
free(command);
|
||||
if(packet_send(session))
|
||||
static int channel_rcv_close1(ssh_session session) {
|
||||
ssh_channel channel = session->channels;
|
||||
uint32_t status;
|
||||
|
||||
buffer_get_u32(session->in_buffer, &status);
|
||||
/*
|
||||
* It's much more than a channel closing. spec says it's the last
|
||||
* message sent by server (strange)
|
||||
*/
|
||||
|
||||
/* actually status is lost somewhere */
|
||||
channel->open = 0;
|
||||
channel->remote_eof = 1;
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_EXIT_CONFIRMATION) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int channel_handle1(ssh_session session, int type) {
|
||||
ssh_log(session, SSH_LOG_RARE, "Channel_handle1(%d)", type);
|
||||
switch (type) {
|
||||
case SSH_SMSG_STDOUT_DATA:
|
||||
if (channel_rcv_data1(session,0) < 0) {
|
||||
return -1;
|
||||
ssh_say(2,"executing %s...\n",cmd);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case SSH_SMSG_STDERR_DATA:
|
||||
if (channel_rcv_data1(session,1) < 0) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case SSH_SMSG_EXITSTATUS:
|
||||
if (channel_rcv_close1(session) < 0) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ssh_log(session, SSH_LOG_FUNCTIONS, "Unexepected message %d", type);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void channel_rcv_data1(SSH_SESSION *session, int is_stderr){
|
||||
CHANNEL *channel;
|
||||
STRING *str;
|
||||
channel=session->channels; // Easy. hack this when multiple channel
|
||||
// are comming
|
||||
str=buffer_get_ssh_string(session->in_buffer);
|
||||
if(!str){
|
||||
ssh_say(0,"Invalid data packet !\n");
|
||||
return;
|
||||
int channel_write1(ssh_channel channel, const void *data, int len) {
|
||||
ssh_session session = channel->session;
|
||||
int origlen = len;
|
||||
int effectivelen;
|
||||
const unsigned char *ptr=data;
|
||||
while (len > 0) {
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_STDIN_DATA) < 0) {
|
||||
return -1;
|
||||
}
|
||||
ssh_say(3,"adding %d bytes data in %d\n",string_len(str),is_stderr);
|
||||
channel_default_bufferize(channel,str->string,string_len(str),
|
||||
is_stderr);
|
||||
free(str);
|
||||
}
|
||||
|
||||
static void channel_rcv_close1(SSH_SESSION *session){
|
||||
CHANNEL *channel=session->channels;
|
||||
u32 status;
|
||||
buffer_get_u32(session->in_buffer,&status);
|
||||
/* it's much more than a channel closing. spec says it's the last
|
||||
* message sent by server (strange)
|
||||
*/
|
||||
/* actually status is lost somewhere */
|
||||
channel->open=0;
|
||||
channel->remote_eof=1;
|
||||
buffer_add_u8(session->out_buffer,SSH_CMSG_EXIT_CONFIRMATION);
|
||||
packet_send(session);
|
||||
}
|
||||
|
||||
void channel_handle1(SSH_SESSION *session, int type){
|
||||
ssh_say(3,"Channel_handle1(%d)\n",type);
|
||||
switch (type){
|
||||
case SSH_SMSG_STDOUT_DATA:
|
||||
channel_rcv_data1(session,0);
|
||||
break;
|
||||
case SSH_SMSG_EXITSTATUS:
|
||||
channel_rcv_close1(session);
|
||||
break;
|
||||
default:
|
||||
ssh_say(0,"Unexepected message %d\n",type);
|
||||
effectivelen = len > 32000 ? 32000 : len;
|
||||
|
||||
if (buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
|
||||
buffer_add_data(session->out_buffer, ptr, effectivelen) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int channel_write1(CHANNEL *channel, void *data, int len){
|
||||
SSH_SESSION *session=channel->session;
|
||||
int origlen=len;
|
||||
int effectivelen;
|
||||
while(len>0){
|
||||
buffer_add_u8(session->out_buffer,SSH_CMSG_STDIN_DATA);
|
||||
if(len > 32000)
|
||||
effectivelen=32000;
|
||||
else
|
||||
effectivelen=len;
|
||||
buffer_add_u32(session->out_buffer,htonl(effectivelen));
|
||||
buffer_add_data(session->out_buffer,data,effectivelen);
|
||||
data+=effectivelen;
|
||||
len-=effectivelen;
|
||||
if(packet_send(session))
|
||||
return -1;
|
||||
ptr += effectivelen;
|
||||
len -= effectivelen;
|
||||
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
return -1;
|
||||
}
|
||||
return origlen;
|
||||
}
|
||||
|
||||
return origlen;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SSH1 */
|
||||
#endif /* WITH_SSH1 */
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
|
||||
1012
libssh/client.c
1012
libssh/client.c
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user