Commit 28a76be8f4536619ab15ce452308df78cfc65e39
1 parent
76655d6d
Remove tabs introduced from VNC ACL series
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6727 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
4 changed files
with
736 additions
and
736 deletions
acl.c
@@ -41,8 +41,8 @@ qemu_acl *qemu_acl_find(const char *aclname) | @@ -41,8 +41,8 @@ qemu_acl *qemu_acl_find(const char *aclname) | ||
41 | { | 41 | { |
42 | int i; | 42 | int i; |
43 | for (i = 0 ; i < nacls ; i++) { | 43 | for (i = 0 ; i < nacls ; i++) { |
44 | - if (strcmp(acls[i]->aclname, aclname) == 0) | ||
45 | - return acls[i]; | 44 | + if (strcmp(acls[i]->aclname, aclname) == 0) |
45 | + return acls[i]; | ||
46 | } | 46 | } |
47 | 47 | ||
48 | return NULL; | 48 | return NULL; |
@@ -54,7 +54,7 @@ qemu_acl *qemu_acl_init(const char *aclname) | @@ -54,7 +54,7 @@ qemu_acl *qemu_acl_init(const char *aclname) | ||
54 | 54 | ||
55 | acl = qemu_acl_find(aclname); | 55 | acl = qemu_acl_find(aclname); |
56 | if (acl) | 56 | if (acl) |
57 | - return acl; | 57 | + return acl; |
58 | 58 | ||
59 | acl = qemu_malloc(sizeof(*acl)); | 59 | acl = qemu_malloc(sizeof(*acl)); |
60 | acl->aclname = qemu_strdup(aclname); | 60 | acl->aclname = qemu_strdup(aclname); |
@@ -74,19 +74,19 @@ qemu_acl *qemu_acl_init(const char *aclname) | @@ -74,19 +74,19 @@ qemu_acl *qemu_acl_init(const char *aclname) | ||
74 | } | 74 | } |
75 | 75 | ||
76 | int qemu_acl_party_is_allowed(qemu_acl *acl, | 76 | int qemu_acl_party_is_allowed(qemu_acl *acl, |
77 | - const char *party) | 77 | + const char *party) |
78 | { | 78 | { |
79 | qemu_acl_entry *entry; | 79 | qemu_acl_entry *entry; |
80 | 80 | ||
81 | TAILQ_FOREACH(entry, &acl->entries, next) { | 81 | TAILQ_FOREACH(entry, &acl->entries, next) { |
82 | #ifdef HAVE_FNMATCH_H | 82 | #ifdef HAVE_FNMATCH_H |
83 | - if (fnmatch(entry->match, party, 0) == 0) | ||
84 | - return entry->deny ? 0 : 1; | 83 | + if (fnmatch(entry->match, party, 0) == 0) |
84 | + return entry->deny ? 0 : 1; | ||
85 | #else | 85 | #else |
86 | - /* No fnmatch, so fallback to exact string matching | ||
87 | - * instead of allowing wildcards */ | ||
88 | - if (strcmp(entry->match, party) == 0) | ||
89 | - return entry->deny ? 0 : 1; | 86 | + /* No fnmatch, so fallback to exact string matching |
87 | + * instead of allowing wildcards */ | ||
88 | + if (strcmp(entry->match, party) == 0) | ||
89 | + return entry->deny ? 0 : 1; | ||
90 | #endif | 90 | #endif |
91 | } | 91 | } |
92 | 92 | ||
@@ -103,17 +103,17 @@ void qemu_acl_reset(qemu_acl *acl) | @@ -103,17 +103,17 @@ void qemu_acl_reset(qemu_acl *acl) | ||
103 | * access control list */ | 103 | * access control list */ |
104 | acl->defaultDeny = 1; | 104 | acl->defaultDeny = 1; |
105 | TAILQ_FOREACH(entry, &acl->entries, next) { | 105 | TAILQ_FOREACH(entry, &acl->entries, next) { |
106 | - TAILQ_REMOVE(&acl->entries, entry, next); | ||
107 | - free(entry->match); | ||
108 | - free(entry); | 106 | + TAILQ_REMOVE(&acl->entries, entry, next); |
107 | + free(entry->match); | ||
108 | + free(entry); | ||
109 | } | 109 | } |
110 | acl->nentries = 0; | 110 | acl->nentries = 0; |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | int qemu_acl_append(qemu_acl *acl, | 114 | int qemu_acl_append(qemu_acl *acl, |
115 | - int deny, | ||
116 | - const char *match) | 115 | + int deny, |
116 | + const char *match) | ||
117 | { | 117 | { |
118 | qemu_acl_entry *entry; | 118 | qemu_acl_entry *entry; |
119 | 119 | ||
@@ -129,18 +129,18 @@ int qemu_acl_append(qemu_acl *acl, | @@ -129,18 +129,18 @@ int qemu_acl_append(qemu_acl *acl, | ||
129 | 129 | ||
130 | 130 | ||
131 | int qemu_acl_insert(qemu_acl *acl, | 131 | int qemu_acl_insert(qemu_acl *acl, |
132 | - int deny, | ||
133 | - const char *match, | ||
134 | - int index) | 132 | + int deny, |
133 | + const char *match, | ||
134 | + int index) | ||
135 | { | 135 | { |
136 | qemu_acl_entry *entry; | 136 | qemu_acl_entry *entry; |
137 | qemu_acl_entry *tmp; | 137 | qemu_acl_entry *tmp; |
138 | int i = 0; | 138 | int i = 0; |
139 | 139 | ||
140 | if (index <= 0) | 140 | if (index <= 0) |
141 | - return -1; | 141 | + return -1; |
142 | if (index >= acl->nentries) | 142 | if (index >= acl->nentries) |
143 | - return qemu_acl_append(acl, deny, match); | 143 | + return qemu_acl_append(acl, deny, match); |
144 | 144 | ||
145 | 145 | ||
146 | entry = qemu_malloc(sizeof(*entry)); | 146 | entry = qemu_malloc(sizeof(*entry)); |
@@ -148,29 +148,29 @@ int qemu_acl_insert(qemu_acl *acl, | @@ -148,29 +148,29 @@ int qemu_acl_insert(qemu_acl *acl, | ||
148 | entry->deny = deny; | 148 | entry->deny = deny; |
149 | 149 | ||
150 | TAILQ_FOREACH(tmp, &acl->entries, next) { | 150 | TAILQ_FOREACH(tmp, &acl->entries, next) { |
151 | - i++; | ||
152 | - if (i == index) { | ||
153 | - TAILQ_INSERT_BEFORE(tmp, entry, next); | ||
154 | - acl->nentries++; | ||
155 | - break; | ||
156 | - } | 151 | + i++; |
152 | + if (i == index) { | ||
153 | + TAILQ_INSERT_BEFORE(tmp, entry, next); | ||
154 | + acl->nentries++; | ||
155 | + break; | ||
156 | + } | ||
157 | } | 157 | } |
158 | 158 | ||
159 | return i; | 159 | return i; |
160 | } | 160 | } |
161 | 161 | ||
162 | int qemu_acl_remove(qemu_acl *acl, | 162 | int qemu_acl_remove(qemu_acl *acl, |
163 | - const char *match) | 163 | + const char *match) |
164 | { | 164 | { |
165 | qemu_acl_entry *entry; | 165 | qemu_acl_entry *entry; |
166 | int i = 0; | 166 | int i = 0; |
167 | 167 | ||
168 | TAILQ_FOREACH(entry, &acl->entries, next) { | 168 | TAILQ_FOREACH(entry, &acl->entries, next) { |
169 | - i++; | ||
170 | - if (strcmp(entry->match, match) == 0) { | ||
171 | - TAILQ_REMOVE(&acl->entries, entry, next); | ||
172 | - return i; | ||
173 | - } | 169 | + i++; |
170 | + if (strcmp(entry->match, match) == 0) { | ||
171 | + TAILQ_REMOVE(&acl->entries, entry, next); | ||
172 | + return i; | ||
173 | + } | ||
174 | } | 174 | } |
175 | return -1; | 175 | return -1; |
176 | } | 176 | } |
monitor.c
@@ -160,25 +160,25 @@ void monitor_print_filename(Monitor *mon, const char *filename) | @@ -160,25 +160,25 @@ void monitor_print_filename(Monitor *mon, const char *filename) | ||
160 | int i; | 160 | int i; |
161 | 161 | ||
162 | for (i = 0; filename[i]; i++) { | 162 | for (i = 0; filename[i]; i++) { |
163 | - switch (filename[i]) { | ||
164 | - case ' ': | ||
165 | - case '"': | ||
166 | - case '\\': | ||
167 | - monitor_printf(mon, "\\%c", filename[i]); | ||
168 | - break; | ||
169 | - case '\t': | ||
170 | - monitor_printf(mon, "\\t"); | ||
171 | - break; | ||
172 | - case '\r': | ||
173 | - monitor_printf(mon, "\\r"); | ||
174 | - break; | ||
175 | - case '\n': | ||
176 | - monitor_printf(mon, "\\n"); | ||
177 | - break; | ||
178 | - default: | ||
179 | - monitor_printf(mon, "%c", filename[i]); | ||
180 | - break; | ||
181 | - } | 163 | + switch (filename[i]) { |
164 | + case ' ': | ||
165 | + case '"': | ||
166 | + case '\\': | ||
167 | + monitor_printf(mon, "\\%c", filename[i]); | ||
168 | + break; | ||
169 | + case '\t': | ||
170 | + monitor_printf(mon, "\\t"); | ||
171 | + break; | ||
172 | + case '\r': | ||
173 | + monitor_printf(mon, "\\r"); | ||
174 | + break; | ||
175 | + case '\n': | ||
176 | + monitor_printf(mon, "\\n"); | ||
177 | + break; | ||
178 | + default: | ||
179 | + monitor_printf(mon, "%c", filename[i]); | ||
180 | + break; | ||
181 | + } | ||
182 | } | 182 | } |
183 | } | 183 | } |
184 | 184 | ||
@@ -474,17 +474,17 @@ static void change_vnc_password_cb(Monitor *mon, const char *password, | @@ -474,17 +474,17 @@ static void change_vnc_password_cb(Monitor *mon, const char *password, | ||
474 | static void do_change_vnc(Monitor *mon, const char *target, const char *arg) | 474 | static void do_change_vnc(Monitor *mon, const char *target, const char *arg) |
475 | { | 475 | { |
476 | if (strcmp(target, "passwd") == 0 || | 476 | if (strcmp(target, "passwd") == 0 || |
477 | - strcmp(target, "password") == 0) { | ||
478 | - if (arg) { | 477 | + strcmp(target, "password") == 0) { |
478 | + if (arg) { | ||
479 | char password[9]; | 479 | char password[9]; |
480 | - strncpy(password, arg, sizeof(password)); | ||
481 | - password[sizeof(password) - 1] = '\0'; | 480 | + strncpy(password, arg, sizeof(password)); |
481 | + password[sizeof(password) - 1] = '\0'; | ||
482 | change_vnc_password_cb(mon, password, NULL); | 482 | change_vnc_password_cb(mon, password, NULL); |
483 | } else { | 483 | } else { |
484 | monitor_read_password(mon, change_vnc_password_cb, NULL); | 484 | monitor_read_password(mon, change_vnc_password_cb, NULL); |
485 | } | 485 | } |
486 | } else { | 486 | } else { |
487 | - if (vnc_display_open(NULL, target) < 0) | 487 | + if (vnc_display_open(NULL, target) < 0) |
488 | monitor_printf(mon, "could not start VNC server on %s\n", target); | 488 | monitor_printf(mon, "could not start VNC server on %s\n", target); |
489 | } | 489 | } |
490 | } | 490 | } |
@@ -493,9 +493,9 @@ static void do_change(Monitor *mon, const char *device, const char *target, | @@ -493,9 +493,9 @@ static void do_change(Monitor *mon, const char *device, const char *target, | ||
493 | const char *arg) | 493 | const char *arg) |
494 | { | 494 | { |
495 | if (strcmp(device, "vnc") == 0) { | 495 | if (strcmp(device, "vnc") == 0) { |
496 | - do_change_vnc(mon, target, arg); | 496 | + do_change_vnc(mon, target, arg); |
497 | } else { | 497 | } else { |
498 | - do_change_block(mon, device, target, arg); | 498 | + do_change_block(mon, device, target, arg); |
499 | } | 499 | } |
500 | } | 500 | } |
501 | 501 | ||
@@ -1535,81 +1535,81 @@ static void do_info_balloon(Monitor *mon) | @@ -1535,81 +1535,81 @@ static void do_info_balloon(Monitor *mon) | ||
1535 | 1535 | ||
1536 | static void do_acl(Monitor *mon, | 1536 | static void do_acl(Monitor *mon, |
1537 | const char *command, | 1537 | const char *command, |
1538 | - const char *aclname, | ||
1539 | - const char *match, | ||
1540 | - int has_index, | ||
1541 | - int index) | 1538 | + const char *aclname, |
1539 | + const char *match, | ||
1540 | + int has_index, | ||
1541 | + int index) | ||
1542 | { | 1542 | { |
1543 | qemu_acl *acl; | 1543 | qemu_acl *acl; |
1544 | 1544 | ||
1545 | acl = qemu_acl_find(aclname); | 1545 | acl = qemu_acl_find(aclname); |
1546 | if (!acl) { | 1546 | if (!acl) { |
1547 | - monitor_printf(mon, "acl: unknown list '%s'\n", aclname); | ||
1548 | - return; | 1547 | + monitor_printf(mon, "acl: unknown list '%s'\n", aclname); |
1548 | + return; | ||
1549 | } | 1549 | } |
1550 | 1550 | ||
1551 | if (strcmp(command, "show") == 0) { | 1551 | if (strcmp(command, "show") == 0) { |
1552 | - int i = 0; | ||
1553 | - qemu_acl_entry *entry; | ||
1554 | - monitor_printf(mon, "policy: %s\n", | 1552 | + int i = 0; |
1553 | + qemu_acl_entry *entry; | ||
1554 | + monitor_printf(mon, "policy: %s\n", | ||
1555 | acl->defaultDeny ? "deny" : "allow"); | 1555 | acl->defaultDeny ? "deny" : "allow"); |
1556 | - TAILQ_FOREACH(entry, &acl->entries, next) { | ||
1557 | - i++; | ||
1558 | - monitor_printf(mon, "%d: %s %s\n", i, | 1556 | + TAILQ_FOREACH(entry, &acl->entries, next) { |
1557 | + i++; | ||
1558 | + monitor_printf(mon, "%d: %s %s\n", i, | ||
1559 | entry->deny ? "deny" : "allow", | 1559 | entry->deny ? "deny" : "allow", |
1560 | entry->match); | 1560 | entry->match); |
1561 | - } | 1561 | + } |
1562 | } else if (strcmp(command, "reset") == 0) { | 1562 | } else if (strcmp(command, "reset") == 0) { |
1563 | - qemu_acl_reset(acl); | ||
1564 | - monitor_printf(mon, "acl: removed all rules\n"); | 1563 | + qemu_acl_reset(acl); |
1564 | + monitor_printf(mon, "acl: removed all rules\n"); | ||
1565 | } else if (strcmp(command, "policy") == 0) { | 1565 | } else if (strcmp(command, "policy") == 0) { |
1566 | - if (!match) { | ||
1567 | - monitor_printf(mon, "acl: missing policy parameter\n"); | ||
1568 | - return; | ||
1569 | - } | ||
1570 | - | ||
1571 | - if (strcmp(match, "allow") == 0) { | ||
1572 | - acl->defaultDeny = 0; | ||
1573 | - monitor_printf(mon, "acl: policy set to 'allow'\n"); | ||
1574 | - } else if (strcmp(match, "deny") == 0) { | ||
1575 | - acl->defaultDeny = 1; | ||
1576 | - monitor_printf(mon, "acl: policy set to 'deny'\n"); | ||
1577 | - } else { | ||
1578 | - monitor_printf(mon, "acl: unknown policy '%s', expected 'deny' or 'allow'\n", match); | ||
1579 | - } | 1566 | + if (!match) { |
1567 | + monitor_printf(mon, "acl: missing policy parameter\n"); | ||
1568 | + return; | ||
1569 | + } | ||
1570 | + | ||
1571 | + if (strcmp(match, "allow") == 0) { | ||
1572 | + acl->defaultDeny = 0; | ||
1573 | + monitor_printf(mon, "acl: policy set to 'allow'\n"); | ||
1574 | + } else if (strcmp(match, "deny") == 0) { | ||
1575 | + acl->defaultDeny = 1; | ||
1576 | + monitor_printf(mon, "acl: policy set to 'deny'\n"); | ||
1577 | + } else { | ||
1578 | + monitor_printf(mon, "acl: unknown policy '%s', expected 'deny' or 'allow'\n", match); | ||
1579 | + } | ||
1580 | } else if ((strcmp(command, "allow") == 0) || | 1580 | } else if ((strcmp(command, "allow") == 0) || |
1581 | - (strcmp(command, "deny") == 0)) { | ||
1582 | - int deny = strcmp(command, "deny") == 0 ? 1 : 0; | ||
1583 | - int ret; | ||
1584 | - | ||
1585 | - if (!match) { | ||
1586 | - monitor_printf(mon, "acl: missing match parameter\n"); | ||
1587 | - return; | ||
1588 | - } | ||
1589 | - | ||
1590 | - if (has_index) | ||
1591 | - ret = qemu_acl_insert(acl, deny, match, index); | ||
1592 | - else | ||
1593 | - ret = qemu_acl_append(acl, deny, match); | ||
1594 | - if (ret < 0) | ||
1595 | - monitor_printf(mon, "acl: unable to add acl entry\n"); | ||
1596 | - else | ||
1597 | - monitor_printf(mon, "acl: added rule at position %d\n", ret); | 1581 | + (strcmp(command, "deny") == 0)) { |
1582 | + int deny = strcmp(command, "deny") == 0 ? 1 : 0; | ||
1583 | + int ret; | ||
1584 | + | ||
1585 | + if (!match) { | ||
1586 | + monitor_printf(mon, "acl: missing match parameter\n"); | ||
1587 | + return; | ||
1588 | + } | ||
1589 | + | ||
1590 | + if (has_index) | ||
1591 | + ret = qemu_acl_insert(acl, deny, match, index); | ||
1592 | + else | ||
1593 | + ret = qemu_acl_append(acl, deny, match); | ||
1594 | + if (ret < 0) | ||
1595 | + monitor_printf(mon, "acl: unable to add acl entry\n"); | ||
1596 | + else | ||
1597 | + monitor_printf(mon, "acl: added rule at position %d\n", ret); | ||
1598 | } else if (strcmp(command, "remove") == 0) { | 1598 | } else if (strcmp(command, "remove") == 0) { |
1599 | - int ret; | ||
1600 | - | ||
1601 | - if (!match) { | ||
1602 | - monitor_printf(mon, "acl: missing match parameter\n"); | ||
1603 | - return; | ||
1604 | - } | ||
1605 | - | ||
1606 | - ret = qemu_acl_remove(acl, match); | ||
1607 | - if (ret < 0) | ||
1608 | - monitor_printf(mon, "acl: no matching acl entry\n"); | ||
1609 | - else | ||
1610 | - monitor_printf(mon, "acl: removed rule at position %d\n", ret); | 1599 | + int ret; |
1600 | + | ||
1601 | + if (!match) { | ||
1602 | + monitor_printf(mon, "acl: missing match parameter\n"); | ||
1603 | + return; | ||
1604 | + } | ||
1605 | + | ||
1606 | + ret = qemu_acl_remove(acl, match); | ||
1607 | + if (ret < 0) | ||
1608 | + monitor_printf(mon, "acl: no matching acl entry\n"); | ||
1609 | + else | ||
1610 | + monitor_printf(mon, "acl: removed rule at position %d\n", ret); | ||
1611 | } else { | 1611 | } else { |
1612 | - monitor_printf(mon, "acl: unknown command '%s'\n", command); | 1612 | + monitor_printf(mon, "acl: unknown command '%s'\n", command); |
1613 | } | 1613 | } |
1614 | } | 1614 | } |
1615 | 1615 | ||
@@ -1839,7 +1839,7 @@ static target_long monitor_get_ccr (const struct MonitorDef *md, int val) | @@ -1839,7 +1839,7 @@ static target_long monitor_get_ccr (const struct MonitorDef *md, int val) | ||
1839 | 1839 | ||
1840 | u = 0; | 1840 | u = 0; |
1841 | for (i = 0; i < 8; i++) | 1841 | for (i = 0; i < 8; i++) |
1842 | - u |= env->crf[i] << (32 - (4 * i)); | 1842 | + u |= env->crf[i] << (32 - (4 * i)); |
1843 | 1843 | ||
1844 | return u; | 1844 | return u; |
1845 | } | 1845 | } |
vnc-auth-sasl.c
@@ -31,14 +31,14 @@ | @@ -31,14 +31,14 @@ | ||
31 | void vnc_sasl_client_cleanup(VncState *vs) | 31 | void vnc_sasl_client_cleanup(VncState *vs) |
32 | { | 32 | { |
33 | if (vs->sasl.conn) { | 33 | if (vs->sasl.conn) { |
34 | - vs->sasl.runSSF = vs->sasl.waitWriteSSF = vs->sasl.wantSSF = 0; | ||
35 | - vs->sasl.encodedLength = vs->sasl.encodedOffset = 0; | ||
36 | - vs->sasl.encoded = NULL; | ||
37 | - free(vs->sasl.username); | ||
38 | - free(vs->sasl.mechlist); | ||
39 | - vs->sasl.username = vs->sasl.mechlist = NULL; | ||
40 | - sasl_dispose(&vs->sasl.conn); | ||
41 | - vs->sasl.conn = NULL; | 34 | + vs->sasl.runSSF = vs->sasl.waitWriteSSF = vs->sasl.wantSSF = 0; |
35 | + vs->sasl.encodedLength = vs->sasl.encodedOffset = 0; | ||
36 | + vs->sasl.encoded = NULL; | ||
37 | + free(vs->sasl.username); | ||
38 | + free(vs->sasl.mechlist); | ||
39 | + vs->sasl.username = vs->sasl.mechlist = NULL; | ||
40 | + sasl_dispose(&vs->sasl.conn); | ||
41 | + vs->sasl.conn = NULL; | ||
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
@@ -48,33 +48,33 @@ long vnc_client_write_sasl(VncState *vs) | @@ -48,33 +48,33 @@ long vnc_client_write_sasl(VncState *vs) | ||
48 | long ret; | 48 | long ret; |
49 | 49 | ||
50 | VNC_DEBUG("Write SASL: Pending output %p size %d offset %d Encoded: %p size %d offset %d\n", | 50 | VNC_DEBUG("Write SASL: Pending output %p size %d offset %d Encoded: %p size %d offset %d\n", |
51 | - vs->output.buffer, vs->output.capacity, vs->output.offset, | ||
52 | - vs->sasl.encoded, vs->sasl.encodedLength, vs->sasl.encodedOffset); | 51 | + vs->output.buffer, vs->output.capacity, vs->output.offset, |
52 | + vs->sasl.encoded, vs->sasl.encodedLength, vs->sasl.encodedOffset); | ||
53 | 53 | ||
54 | if (!vs->sasl.encoded) { | 54 | if (!vs->sasl.encoded) { |
55 | - int err; | ||
56 | - err = sasl_encode(vs->sasl.conn, | ||
57 | - (char *)vs->output.buffer, | ||
58 | - vs->output.offset, | ||
59 | - (const char **)&vs->sasl.encoded, | ||
60 | - &vs->sasl.encodedLength); | ||
61 | - if (err != SASL_OK) | ||
62 | - return vnc_client_io_error(vs, -1, EIO); | ||
63 | - | ||
64 | - vs->sasl.encodedOffset = 0; | 55 | + int err; |
56 | + err = sasl_encode(vs->sasl.conn, | ||
57 | + (char *)vs->output.buffer, | ||
58 | + vs->output.offset, | ||
59 | + (const char **)&vs->sasl.encoded, | ||
60 | + &vs->sasl.encodedLength); | ||
61 | + if (err != SASL_OK) | ||
62 | + return vnc_client_io_error(vs, -1, EIO); | ||
63 | + | ||
64 | + vs->sasl.encodedOffset = 0; | ||
65 | } | 65 | } |
66 | 66 | ||
67 | ret = vnc_client_write_buf(vs, | 67 | ret = vnc_client_write_buf(vs, |
68 | - vs->sasl.encoded + vs->sasl.encodedOffset, | ||
69 | - vs->sasl.encodedLength - vs->sasl.encodedOffset); | 68 | + vs->sasl.encoded + vs->sasl.encodedOffset, |
69 | + vs->sasl.encodedLength - vs->sasl.encodedOffset); | ||
70 | if (!ret) | 70 | if (!ret) |
71 | - return 0; | 71 | + return 0; |
72 | 72 | ||
73 | vs->sasl.encodedOffset += ret; | 73 | vs->sasl.encodedOffset += ret; |
74 | if (vs->sasl.encodedOffset == vs->sasl.encodedLength) { | 74 | if (vs->sasl.encodedOffset == vs->sasl.encodedLength) { |
75 | - vs->output.offset = 0; | ||
76 | - vs->sasl.encoded = NULL; | ||
77 | - vs->sasl.encodedOffset = vs->sasl.encodedLength = 0; | 75 | + vs->output.offset = 0; |
76 | + vs->sasl.encoded = NULL; | ||
77 | + vs->sasl.encodedOffset = vs->sasl.encodedLength = 0; | ||
78 | } | 78 | } |
79 | 79 | ||
80 | /* Can't merge this block with one above, because | 80 | /* Can't merge this block with one above, because |
@@ -83,7 +83,7 @@ long vnc_client_write_sasl(VncState *vs) | @@ -83,7 +83,7 @@ long vnc_client_write_sasl(VncState *vs) | ||
83 | * SASL encoded output | 83 | * SASL encoded output |
84 | */ | 84 | */ |
85 | if (vs->output.offset == 0) { | 85 | if (vs->output.offset == 0) { |
86 | - qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); | 86 | + qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); |
87 | } | 87 | } |
88 | 88 | ||
89 | return ret; | 89 | return ret; |
@@ -100,16 +100,16 @@ long vnc_client_read_sasl(VncState *vs) | @@ -100,16 +100,16 @@ long vnc_client_read_sasl(VncState *vs) | ||
100 | 100 | ||
101 | ret = vnc_client_read_buf(vs, encoded, sizeof(encoded)); | 101 | ret = vnc_client_read_buf(vs, encoded, sizeof(encoded)); |
102 | if (!ret) | 102 | if (!ret) |
103 | - return 0; | 103 | + return 0; |
104 | 104 | ||
105 | err = sasl_decode(vs->sasl.conn, | 105 | err = sasl_decode(vs->sasl.conn, |
106 | - (char *)encoded, ret, | ||
107 | - &decoded, &decodedLen); | 106 | + (char *)encoded, ret, |
107 | + &decoded, &decodedLen); | ||
108 | 108 | ||
109 | if (err != SASL_OK) | 109 | if (err != SASL_OK) |
110 | - return vnc_client_io_error(vs, -1, -EIO); | 110 | + return vnc_client_io_error(vs, -1, -EIO); |
111 | VNC_DEBUG("Read SASL Encoded %p size %ld Decoded %p size %d\n", | 111 | VNC_DEBUG("Read SASL Encoded %p size %ld Decoded %p size %d\n", |
112 | - encoded, ret, decoded, decodedLen); | 112 | + encoded, ret, decoded, decodedLen); |
113 | buffer_reserve(&vs->input, decodedLen); | 113 | buffer_reserve(&vs->input, decodedLen); |
114 | buffer_append(&vs->input, decoded, decodedLen); | 114 | buffer_append(&vs->input, decoded, decodedLen); |
115 | return decodedLen; | 115 | return decodedLen; |
@@ -124,27 +124,27 @@ static int vnc_auth_sasl_check_access(VncState *vs) | @@ -124,27 +124,27 @@ static int vnc_auth_sasl_check_access(VncState *vs) | ||
124 | 124 | ||
125 | err = sasl_getprop(vs->sasl.conn, SASL_USERNAME, &val); | 125 | err = sasl_getprop(vs->sasl.conn, SASL_USERNAME, &val); |
126 | if (err != SASL_OK) { | 126 | if (err != SASL_OK) { |
127 | - VNC_DEBUG("cannot query SASL username on connection %d (%s), denying access\n", | ||
128 | - err, sasl_errstring(err, NULL, NULL)); | ||
129 | - return -1; | 127 | + VNC_DEBUG("cannot query SASL username on connection %d (%s), denying access\n", |
128 | + err, sasl_errstring(err, NULL, NULL)); | ||
129 | + return -1; | ||
130 | } | 130 | } |
131 | if (val == NULL) { | 131 | if (val == NULL) { |
132 | - VNC_DEBUG("no client username was found, denying access\n"); | ||
133 | - return -1; | 132 | + VNC_DEBUG("no client username was found, denying access\n"); |
133 | + return -1; | ||
134 | } | 134 | } |
135 | VNC_DEBUG("SASL client username %s\n", (const char *)val); | 135 | VNC_DEBUG("SASL client username %s\n", (const char *)val); |
136 | 136 | ||
137 | vs->sasl.username = qemu_strdup((const char*)val); | 137 | vs->sasl.username = qemu_strdup((const char*)val); |
138 | 138 | ||
139 | if (vs->vd->sasl.acl == NULL) { | 139 | if (vs->vd->sasl.acl == NULL) { |
140 | - VNC_DEBUG("no ACL activated, allowing access\n"); | ||
141 | - return 0; | 140 | + VNC_DEBUG("no ACL activated, allowing access\n"); |
141 | + return 0; | ||
142 | } | 142 | } |
143 | 143 | ||
144 | allow = qemu_acl_party_is_allowed(vs->vd->sasl.acl, vs->sasl.username); | 144 | allow = qemu_acl_party_is_allowed(vs->vd->sasl.acl, vs->sasl.username); |
145 | 145 | ||
146 | VNC_DEBUG("SASL client %s %s by ACL\n", vs->sasl.username, | 146 | VNC_DEBUG("SASL client %s %s by ACL\n", vs->sasl.username, |
147 | - allow ? "allowed" : "denied"); | 147 | + allow ? "allowed" : "denied"); |
148 | return allow ? 0 : -1; | 148 | return allow ? 0 : -1; |
149 | } | 149 | } |
150 | 150 | ||
@@ -154,16 +154,16 @@ static int vnc_auth_sasl_check_ssf(VncState *vs) | @@ -154,16 +154,16 @@ static int vnc_auth_sasl_check_ssf(VncState *vs) | ||
154 | int err, ssf; | 154 | int err, ssf; |
155 | 155 | ||
156 | if (!vs->sasl.wantSSF) | 156 | if (!vs->sasl.wantSSF) |
157 | - return 1; | 157 | + return 1; |
158 | 158 | ||
159 | err = sasl_getprop(vs->sasl.conn, SASL_SSF, &val); | 159 | err = sasl_getprop(vs->sasl.conn, SASL_SSF, &val); |
160 | if (err != SASL_OK) | 160 | if (err != SASL_OK) |
161 | - return 0; | 161 | + return 0; |
162 | 162 | ||
163 | ssf = *(const int *)val; | 163 | ssf = *(const int *)val; |
164 | VNC_DEBUG("negotiated an SSF of %d\n", ssf); | 164 | VNC_DEBUG("negotiated an SSF of %d\n", ssf); |
165 | if (ssf < 56) | 165 | if (ssf < 56) |
166 | - return 0; /* 56 is good for Kerberos */ | 166 | + return 0; /* 56 is good for Kerberos */ |
167 | 167 | ||
168 | /* Only setup for read initially, because we're about to send an RPC | 168 | /* Only setup for read initially, because we're about to send an RPC |
169 | * reply which must be in plain text. When the next incoming RPC | 169 | * reply which must be in plain text. When the next incoming RPC |
@@ -204,73 +204,73 @@ static int protocol_client_auth_sasl_step(VncState *vs, uint8_t *data, size_t le | @@ -204,73 +204,73 @@ static int protocol_client_auth_sasl_step(VncState *vs, uint8_t *data, size_t le | ||
204 | 204 | ||
205 | /* NB, distinction of NULL vs "" is *critical* in SASL */ | 205 | /* NB, distinction of NULL vs "" is *critical* in SASL */ |
206 | if (datalen) { | 206 | if (datalen) { |
207 | - clientdata = (char*)data; | ||
208 | - clientdata[datalen-1] = '\0'; /* Wire includes '\0', but make sure */ | ||
209 | - datalen--; /* Don't count NULL byte when passing to _start() */ | 207 | + clientdata = (char*)data; |
208 | + clientdata[datalen-1] = '\0'; /* Wire includes '\0', but make sure */ | ||
209 | + datalen--; /* Don't count NULL byte when passing to _start() */ | ||
210 | } | 210 | } |
211 | 211 | ||
212 | VNC_DEBUG("Step using SASL Data %p (%d bytes)\n", | 212 | VNC_DEBUG("Step using SASL Data %p (%d bytes)\n", |
213 | - clientdata, datalen); | 213 | + clientdata, datalen); |
214 | err = sasl_server_step(vs->sasl.conn, | 214 | err = sasl_server_step(vs->sasl.conn, |
215 | - clientdata, | ||
216 | - datalen, | ||
217 | - &serverout, | ||
218 | - &serveroutlen); | 215 | + clientdata, |
216 | + datalen, | ||
217 | + &serverout, | ||
218 | + &serveroutlen); | ||
219 | if (err != SASL_OK && | 219 | if (err != SASL_OK && |
220 | - err != SASL_CONTINUE) { | ||
221 | - VNC_DEBUG("sasl step failed %d (%s)\n", | ||
222 | - err, sasl_errdetail(vs->sasl.conn)); | ||
223 | - sasl_dispose(&vs->sasl.conn); | ||
224 | - vs->sasl.conn = NULL; | ||
225 | - goto authabort; | 220 | + err != SASL_CONTINUE) { |
221 | + VNC_DEBUG("sasl step failed %d (%s)\n", | ||
222 | + err, sasl_errdetail(vs->sasl.conn)); | ||
223 | + sasl_dispose(&vs->sasl.conn); | ||
224 | + vs->sasl.conn = NULL; | ||
225 | + goto authabort; | ||
226 | } | 226 | } |
227 | 227 | ||
228 | if (serveroutlen > SASL_DATA_MAX_LEN) { | 228 | if (serveroutlen > SASL_DATA_MAX_LEN) { |
229 | - VNC_DEBUG("sasl step reply data too long %d\n", | ||
230 | - serveroutlen); | ||
231 | - sasl_dispose(&vs->sasl.conn); | ||
232 | - vs->sasl.conn = NULL; | ||
233 | - goto authabort; | 229 | + VNC_DEBUG("sasl step reply data too long %d\n", |
230 | + serveroutlen); | ||
231 | + sasl_dispose(&vs->sasl.conn); | ||
232 | + vs->sasl.conn = NULL; | ||
233 | + goto authabort; | ||
234 | } | 234 | } |
235 | 235 | ||
236 | VNC_DEBUG("SASL return data %d bytes, nil; %d\n", | 236 | VNC_DEBUG("SASL return data %d bytes, nil; %d\n", |
237 | - serveroutlen, serverout ? 0 : 1); | 237 | + serveroutlen, serverout ? 0 : 1); |
238 | 238 | ||
239 | if (serveroutlen) { | 239 | if (serveroutlen) { |
240 | - vnc_write_u32(vs, serveroutlen + 1); | ||
241 | - vnc_write(vs, serverout, serveroutlen + 1); | 240 | + vnc_write_u32(vs, serveroutlen + 1); |
241 | + vnc_write(vs, serverout, serveroutlen + 1); | ||
242 | } else { | 242 | } else { |
243 | - vnc_write_u32(vs, 0); | 243 | + vnc_write_u32(vs, 0); |
244 | } | 244 | } |
245 | 245 | ||
246 | /* Whether auth is complete */ | 246 | /* Whether auth is complete */ |
247 | vnc_write_u8(vs, err == SASL_CONTINUE ? 0 : 1); | 247 | vnc_write_u8(vs, err == SASL_CONTINUE ? 0 : 1); |
248 | 248 | ||
249 | if (err == SASL_CONTINUE) { | 249 | if (err == SASL_CONTINUE) { |
250 | - VNC_DEBUG("%s", "Authentication must continue\n"); | ||
251 | - /* Wait for step length */ | ||
252 | - vnc_read_when(vs, protocol_client_auth_sasl_step_len, 4); | 250 | + VNC_DEBUG("%s", "Authentication must continue\n"); |
251 | + /* Wait for step length */ | ||
252 | + vnc_read_when(vs, protocol_client_auth_sasl_step_len, 4); | ||
253 | } else { | 253 | } else { |
254 | - if (!vnc_auth_sasl_check_ssf(vs)) { | ||
255 | - VNC_DEBUG("Authentication rejected for weak SSF %d\n", vs->csock); | ||
256 | - goto authreject; | ||
257 | - } | ||
258 | - | ||
259 | - /* Check username whitelist ACL */ | ||
260 | - if (vnc_auth_sasl_check_access(vs) < 0) { | ||
261 | - VNC_DEBUG("Authentication rejected for ACL %d\n", vs->csock); | ||
262 | - goto authreject; | ||
263 | - } | ||
264 | - | ||
265 | - VNC_DEBUG("Authentication successful %d\n", vs->csock); | ||
266 | - vnc_write_u32(vs, 0); /* Accept auth */ | ||
267 | - /* | ||
268 | - * Delay writing in SSF encoded mode until pending output | ||
269 | - * buffer is written | ||
270 | - */ | ||
271 | - if (vs->sasl.runSSF) | ||
272 | - vs->sasl.waitWriteSSF = vs->output.offset; | ||
273 | - start_client_init(vs); | 254 | + if (!vnc_auth_sasl_check_ssf(vs)) { |
255 | + VNC_DEBUG("Authentication rejected for weak SSF %d\n", vs->csock); | ||
256 | + goto authreject; | ||
257 | + } | ||
258 | + | ||
259 | + /* Check username whitelist ACL */ | ||
260 | + if (vnc_auth_sasl_check_access(vs) < 0) { | ||
261 | + VNC_DEBUG("Authentication rejected for ACL %d\n", vs->csock); | ||
262 | + goto authreject; | ||
263 | + } | ||
264 | + | ||
265 | + VNC_DEBUG("Authentication successful %d\n", vs->csock); | ||
266 | + vnc_write_u32(vs, 0); /* Accept auth */ | ||
267 | + /* | ||
268 | + * Delay writing in SSF encoded mode until pending output | ||
269 | + * buffer is written | ||
270 | + */ | ||
271 | + if (vs->sasl.runSSF) | ||
272 | + vs->sasl.waitWriteSSF = vs->output.offset; | ||
273 | + start_client_init(vs); | ||
274 | } | 274 | } |
275 | 275 | ||
276 | return 0; | 276 | return 0; |
@@ -293,15 +293,15 @@ static int protocol_client_auth_sasl_step_len(VncState *vs, uint8_t *data, size_ | @@ -293,15 +293,15 @@ static int protocol_client_auth_sasl_step_len(VncState *vs, uint8_t *data, size_ | ||
293 | uint32_t steplen = read_u32(data, 0); | 293 | uint32_t steplen = read_u32(data, 0); |
294 | VNC_DEBUG("Got client step len %d\n", steplen); | 294 | VNC_DEBUG("Got client step len %d\n", steplen); |
295 | if (steplen > SASL_DATA_MAX_LEN) { | 295 | if (steplen > SASL_DATA_MAX_LEN) { |
296 | - VNC_DEBUG("Too much SASL data %d\n", steplen); | ||
297 | - vnc_client_error(vs); | ||
298 | - return -1; | 296 | + VNC_DEBUG("Too much SASL data %d\n", steplen); |
297 | + vnc_client_error(vs); | ||
298 | + return -1; | ||
299 | } | 299 | } |
300 | 300 | ||
301 | if (steplen == 0) | 301 | if (steplen == 0) |
302 | - return protocol_client_auth_sasl_step(vs, NULL, 0); | 302 | + return protocol_client_auth_sasl_step(vs, NULL, 0); |
303 | else | 303 | else |
304 | - vnc_read_when(vs, protocol_client_auth_sasl_step, steplen); | 304 | + vnc_read_when(vs, protocol_client_auth_sasl_step, steplen); |
305 | return 0; | 305 | return 0; |
306 | } | 306 | } |
307 | 307 | ||
@@ -332,67 +332,67 @@ static int protocol_client_auth_sasl_start(VncState *vs, uint8_t *data, size_t l | @@ -332,67 +332,67 @@ static int protocol_client_auth_sasl_start(VncState *vs, uint8_t *data, size_t l | ||
332 | 332 | ||
333 | /* NB, distinction of NULL vs "" is *critical* in SASL */ | 333 | /* NB, distinction of NULL vs "" is *critical* in SASL */ |
334 | if (datalen) { | 334 | if (datalen) { |
335 | - clientdata = (char*)data; | ||
336 | - clientdata[datalen-1] = '\0'; /* Should be on wire, but make sure */ | ||
337 | - datalen--; /* Don't count NULL byte when passing to _start() */ | 335 | + clientdata = (char*)data; |
336 | + clientdata[datalen-1] = '\0'; /* Should be on wire, but make sure */ | ||
337 | + datalen--; /* Don't count NULL byte when passing to _start() */ | ||
338 | } | 338 | } |
339 | 339 | ||
340 | VNC_DEBUG("Start SASL auth with mechanism %s. Data %p (%d bytes)\n", | 340 | VNC_DEBUG("Start SASL auth with mechanism %s. Data %p (%d bytes)\n", |
341 | - vs->sasl.mechlist, clientdata, datalen); | 341 | + vs->sasl.mechlist, clientdata, datalen); |
342 | err = sasl_server_start(vs->sasl.conn, | 342 | err = sasl_server_start(vs->sasl.conn, |
343 | - vs->sasl.mechlist, | ||
344 | - clientdata, | ||
345 | - datalen, | ||
346 | - &serverout, | ||
347 | - &serveroutlen); | 343 | + vs->sasl.mechlist, |
344 | + clientdata, | ||
345 | + datalen, | ||
346 | + &serverout, | ||
347 | + &serveroutlen); | ||
348 | if (err != SASL_OK && | 348 | if (err != SASL_OK && |
349 | - err != SASL_CONTINUE) { | ||
350 | - VNC_DEBUG("sasl start failed %d (%s)\n", | ||
351 | - err, sasl_errdetail(vs->sasl.conn)); | ||
352 | - sasl_dispose(&vs->sasl.conn); | ||
353 | - vs->sasl.conn = NULL; | ||
354 | - goto authabort; | 349 | + err != SASL_CONTINUE) { |
350 | + VNC_DEBUG("sasl start failed %d (%s)\n", | ||
351 | + err, sasl_errdetail(vs->sasl.conn)); | ||
352 | + sasl_dispose(&vs->sasl.conn); | ||
353 | + vs->sasl.conn = NULL; | ||
354 | + goto authabort; | ||
355 | } | 355 | } |
356 | if (serveroutlen > SASL_DATA_MAX_LEN) { | 356 | if (serveroutlen > SASL_DATA_MAX_LEN) { |
357 | - VNC_DEBUG("sasl start reply data too long %d\n", | ||
358 | - serveroutlen); | ||
359 | - sasl_dispose(&vs->sasl.conn); | ||
360 | - vs->sasl.conn = NULL; | ||
361 | - goto authabort; | 357 | + VNC_DEBUG("sasl start reply data too long %d\n", |
358 | + serveroutlen); | ||
359 | + sasl_dispose(&vs->sasl.conn); | ||
360 | + vs->sasl.conn = NULL; | ||
361 | + goto authabort; | ||
362 | } | 362 | } |
363 | 363 | ||
364 | VNC_DEBUG("SASL return data %d bytes, nil; %d\n", | 364 | VNC_DEBUG("SASL return data %d bytes, nil; %d\n", |
365 | - serveroutlen, serverout ? 0 : 1); | 365 | + serveroutlen, serverout ? 0 : 1); |
366 | 366 | ||
367 | if (serveroutlen) { | 367 | if (serveroutlen) { |
368 | - vnc_write_u32(vs, serveroutlen + 1); | ||
369 | - vnc_write(vs, serverout, serveroutlen + 1); | 368 | + vnc_write_u32(vs, serveroutlen + 1); |
369 | + vnc_write(vs, serverout, serveroutlen + 1); | ||
370 | } else { | 370 | } else { |
371 | - vnc_write_u32(vs, 0); | 371 | + vnc_write_u32(vs, 0); |
372 | } | 372 | } |
373 | 373 | ||
374 | /* Whether auth is complete */ | 374 | /* Whether auth is complete */ |
375 | vnc_write_u8(vs, err == SASL_CONTINUE ? 0 : 1); | 375 | vnc_write_u8(vs, err == SASL_CONTINUE ? 0 : 1); |
376 | 376 | ||
377 | if (err == SASL_CONTINUE) { | 377 | if (err == SASL_CONTINUE) { |
378 | - VNC_DEBUG("%s", "Authentication must continue\n"); | ||
379 | - /* Wait for step length */ | ||
380 | - vnc_read_when(vs, protocol_client_auth_sasl_step_len, 4); | 378 | + VNC_DEBUG("%s", "Authentication must continue\n"); |
379 | + /* Wait for step length */ | ||
380 | + vnc_read_when(vs, protocol_client_auth_sasl_step_len, 4); | ||
381 | } else { | 381 | } else { |
382 | - if (!vnc_auth_sasl_check_ssf(vs)) { | ||
383 | - VNC_DEBUG("Authentication rejected for weak SSF %d\n", vs->csock); | ||
384 | - goto authreject; | ||
385 | - } | ||
386 | - | ||
387 | - /* Check username whitelist ACL */ | ||
388 | - if (vnc_auth_sasl_check_access(vs) < 0) { | ||
389 | - VNC_DEBUG("Authentication rejected for ACL %d\n", vs->csock); | ||
390 | - goto authreject; | ||
391 | - } | ||
392 | - | ||
393 | - VNC_DEBUG("Authentication successful %d\n", vs->csock); | ||
394 | - vnc_write_u32(vs, 0); /* Accept auth */ | ||
395 | - start_client_init(vs); | 382 | + if (!vnc_auth_sasl_check_ssf(vs)) { |
383 | + VNC_DEBUG("Authentication rejected for weak SSF %d\n", vs->csock); | ||
384 | + goto authreject; | ||
385 | + } | ||
386 | + | ||
387 | + /* Check username whitelist ACL */ | ||
388 | + if (vnc_auth_sasl_check_access(vs) < 0) { | ||
389 | + VNC_DEBUG("Authentication rejected for ACL %d\n", vs->csock); | ||
390 | + goto authreject; | ||
391 | + } | ||
392 | + | ||
393 | + VNC_DEBUG("Authentication successful %d\n", vs->csock); | ||
394 | + vnc_write_u32(vs, 0); /* Accept auth */ | ||
395 | + start_client_init(vs); | ||
396 | } | 396 | } |
397 | 397 | ||
398 | return 0; | 398 | return 0; |
@@ -415,13 +415,13 @@ static int protocol_client_auth_sasl_start_len(VncState *vs, uint8_t *data, size | @@ -415,13 +415,13 @@ static int protocol_client_auth_sasl_start_len(VncState *vs, uint8_t *data, size | ||
415 | uint32_t startlen = read_u32(data, 0); | 415 | uint32_t startlen = read_u32(data, 0); |
416 | VNC_DEBUG("Got client start len %d\n", startlen); | 416 | VNC_DEBUG("Got client start len %d\n", startlen); |
417 | if (startlen > SASL_DATA_MAX_LEN) { | 417 | if (startlen > SASL_DATA_MAX_LEN) { |
418 | - VNC_DEBUG("Too much SASL data %d\n", startlen); | ||
419 | - vnc_client_error(vs); | ||
420 | - return -1; | 418 | + VNC_DEBUG("Too much SASL data %d\n", startlen); |
419 | + vnc_client_error(vs); | ||
420 | + return -1; | ||
421 | } | 421 | } |
422 | 422 | ||
423 | if (startlen == 0) | 423 | if (startlen == 0) |
424 | - return protocol_client_auth_sasl_start(vs, NULL, 0); | 424 | + return protocol_client_auth_sasl_start(vs, NULL, 0); |
425 | 425 | ||
426 | vnc_read_when(vs, protocol_client_auth_sasl_start, startlen); | 426 | vnc_read_when(vs, protocol_client_auth_sasl_start, startlen); |
427 | return 0; | 427 | return 0; |
@@ -431,35 +431,35 @@ static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_ | @@ -431,35 +431,35 @@ static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_ | ||
431 | { | 431 | { |
432 | char *mechname = malloc(len + 1); | 432 | char *mechname = malloc(len + 1); |
433 | if (!mechname) { | 433 | if (!mechname) { |
434 | - VNC_DEBUG("Out of memory reading mechname\n"); | ||
435 | - vnc_client_error(vs); | 434 | + VNC_DEBUG("Out of memory reading mechname\n"); |
435 | + vnc_client_error(vs); | ||
436 | } | 436 | } |
437 | strncpy(mechname, (char*)data, len); | 437 | strncpy(mechname, (char*)data, len); |
438 | mechname[len] = '\0'; | 438 | mechname[len] = '\0'; |
439 | VNC_DEBUG("Got client mechname '%s' check against '%s'\n", | 439 | VNC_DEBUG("Got client mechname '%s' check against '%s'\n", |
440 | - mechname, vs->sasl.mechlist); | 440 | + mechname, vs->sasl.mechlist); |
441 | 441 | ||
442 | if (strncmp(vs->sasl.mechlist, mechname, len) == 0) { | 442 | if (strncmp(vs->sasl.mechlist, mechname, len) == 0) { |
443 | - if (vs->sasl.mechlist[len] != '\0' && | ||
444 | - vs->sasl.mechlist[len] != ',') { | ||
445 | - VNC_DEBUG("One %d", vs->sasl.mechlist[len]); | ||
446 | - vnc_client_error(vs); | ||
447 | - return -1; | ||
448 | - } | 443 | + if (vs->sasl.mechlist[len] != '\0' && |
444 | + vs->sasl.mechlist[len] != ',') { | ||
445 | + VNC_DEBUG("One %d", vs->sasl.mechlist[len]); | ||
446 | + vnc_client_error(vs); | ||
447 | + return -1; | ||
448 | + } | ||
449 | } else { | 449 | } else { |
450 | - char *offset = strstr(vs->sasl.mechlist, mechname); | ||
451 | - VNC_DEBUG("Two %p\n", offset); | ||
452 | - if (!offset) { | ||
453 | - vnc_client_error(vs); | ||
454 | - return -1; | ||
455 | - } | ||
456 | - VNC_DEBUG("Two '%s'\n", offset); | ||
457 | - if (offset[-1] != ',' || | ||
458 | - (offset[len] != '\0'&& | ||
459 | - offset[len] != ',')) { | ||
460 | - vnc_client_error(vs); | ||
461 | - return -1; | ||
462 | - } | 450 | + char *offset = strstr(vs->sasl.mechlist, mechname); |
451 | + VNC_DEBUG("Two %p\n", offset); | ||
452 | + if (!offset) { | ||
453 | + vnc_client_error(vs); | ||
454 | + return -1; | ||
455 | + } | ||
456 | + VNC_DEBUG("Two '%s'\n", offset); | ||
457 | + if (offset[-1] != ',' || | ||
458 | + (offset[len] != '\0'&& | ||
459 | + offset[len] != ',')) { | ||
460 | + vnc_client_error(vs); | ||
461 | + return -1; | ||
462 | + } | ||
463 | } | 463 | } |
464 | 464 | ||
465 | free(vs->sasl.mechlist); | 465 | free(vs->sasl.mechlist); |
@@ -475,20 +475,20 @@ static int protocol_client_auth_sasl_mechname_len(VncState *vs, uint8_t *data, s | @@ -475,20 +475,20 @@ static int protocol_client_auth_sasl_mechname_len(VncState *vs, uint8_t *data, s | ||
475 | uint32_t mechlen = read_u32(data, 0); | 475 | uint32_t mechlen = read_u32(data, 0); |
476 | VNC_DEBUG("Got client mechname len %d\n", mechlen); | 476 | VNC_DEBUG("Got client mechname len %d\n", mechlen); |
477 | if (mechlen > 100) { | 477 | if (mechlen > 100) { |
478 | - VNC_DEBUG("Too long SASL mechname data %d\n", mechlen); | ||
479 | - vnc_client_error(vs); | ||
480 | - return -1; | 478 | + VNC_DEBUG("Too long SASL mechname data %d\n", mechlen); |
479 | + vnc_client_error(vs); | ||
480 | + return -1; | ||
481 | } | 481 | } |
482 | if (mechlen < 1) { | 482 | if (mechlen < 1) { |
483 | - VNC_DEBUG("Too short SASL mechname %d\n", mechlen); | ||
484 | - vnc_client_error(vs); | ||
485 | - return -1; | 483 | + VNC_DEBUG("Too short SASL mechname %d\n", mechlen); |
484 | + vnc_client_error(vs); | ||
485 | + return -1; | ||
486 | } | 486 | } |
487 | vnc_read_when(vs, protocol_client_auth_sasl_mechname,mechlen); | 487 | vnc_read_when(vs, protocol_client_auth_sasl_mechname,mechlen); |
488 | return 0; | 488 | return 0; |
489 | } | 489 | } |
490 | 490 | ||
491 | -#define USES_X509_AUTH(vs) \ | 491 | +#define USES_X509_AUTH(vs) \ |
492 | ((vs)->subauth == VNC_AUTH_VENCRYPT_X509NONE || \ | 492 | ((vs)->subauth == VNC_AUTH_VENCRYPT_X509NONE || \ |
493 | (vs)->subauth == VNC_AUTH_VENCRYPT_X509VNC || \ | 493 | (vs)->subauth == VNC_AUTH_VENCRYPT_X509VNC || \ |
494 | (vs)->subauth == VNC_AUTH_VENCRYPT_X509PLAIN || \ | 494 | (vs)->subauth == VNC_AUTH_VENCRYPT_X509PLAIN || \ |
@@ -507,116 +507,116 @@ void start_auth_sasl(VncState *vs) | @@ -507,116 +507,116 @@ void start_auth_sasl(VncState *vs) | ||
507 | 507 | ||
508 | /* Get local & remote client addresses in form IPADDR;PORT */ | 508 | /* Get local & remote client addresses in form IPADDR;PORT */ |
509 | if (!(localAddr = vnc_socket_local_addr("%s;%s", vs->csock))) | 509 | if (!(localAddr = vnc_socket_local_addr("%s;%s", vs->csock))) |
510 | - goto authabort; | 510 | + goto authabort; |
511 | 511 | ||
512 | if (!(remoteAddr = vnc_socket_remote_addr("%s;%s", vs->csock))) { | 512 | if (!(remoteAddr = vnc_socket_remote_addr("%s;%s", vs->csock))) { |
513 | - free(localAddr); | ||
514 | - goto authabort; | 513 | + free(localAddr); |
514 | + goto authabort; | ||
515 | } | 515 | } |
516 | 516 | ||
517 | err = sasl_server_new("vnc", | 517 | err = sasl_server_new("vnc", |
518 | - NULL, /* FQDN - just delegates to gethostname */ | ||
519 | - NULL, /* User realm */ | ||
520 | - localAddr, | ||
521 | - remoteAddr, | ||
522 | - NULL, /* Callbacks, not needed */ | ||
523 | - SASL_SUCCESS_DATA, | ||
524 | - &vs->sasl.conn); | 518 | + NULL, /* FQDN - just delegates to gethostname */ |
519 | + NULL, /* User realm */ | ||
520 | + localAddr, | ||
521 | + remoteAddr, | ||
522 | + NULL, /* Callbacks, not needed */ | ||
523 | + SASL_SUCCESS_DATA, | ||
524 | + &vs->sasl.conn); | ||
525 | free(localAddr); | 525 | free(localAddr); |
526 | free(remoteAddr); | 526 | free(remoteAddr); |
527 | localAddr = remoteAddr = NULL; | 527 | localAddr = remoteAddr = NULL; |
528 | 528 | ||
529 | if (err != SASL_OK) { | 529 | if (err != SASL_OK) { |
530 | - VNC_DEBUG("sasl context setup failed %d (%s)", | ||
531 | - err, sasl_errstring(err, NULL, NULL)); | ||
532 | - vs->sasl.conn = NULL; | ||
533 | - goto authabort; | 530 | + VNC_DEBUG("sasl context setup failed %d (%s)", |
531 | + err, sasl_errstring(err, NULL, NULL)); | ||
532 | + vs->sasl.conn = NULL; | ||
533 | + goto authabort; | ||
534 | } | 534 | } |
535 | 535 | ||
536 | #ifdef CONFIG_VNC_TLS | 536 | #ifdef CONFIG_VNC_TLS |
537 | /* Inform SASL that we've got an external SSF layer from TLS/x509 */ | 537 | /* Inform SASL that we've got an external SSF layer from TLS/x509 */ |
538 | if (vs->vd->auth == VNC_AUTH_VENCRYPT && | 538 | if (vs->vd->auth == VNC_AUTH_VENCRYPT && |
539 | - vs->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL) { | ||
540 | - gnutls_cipher_algorithm_t cipher; | ||
541 | - sasl_ssf_t ssf; | ||
542 | - | ||
543 | - cipher = gnutls_cipher_get(vs->tls.session); | ||
544 | - if (!(ssf = (sasl_ssf_t)gnutls_cipher_get_key_size(cipher))) { | ||
545 | - VNC_DEBUG("%s", "cannot TLS get cipher size\n"); | ||
546 | - sasl_dispose(&vs->sasl.conn); | ||
547 | - vs->sasl.conn = NULL; | ||
548 | - goto authabort; | ||
549 | - } | ||
550 | - ssf *= 8; /* tls key size is bytes, sasl wants bits */ | ||
551 | - | ||
552 | - err = sasl_setprop(vs->sasl.conn, SASL_SSF_EXTERNAL, &ssf); | ||
553 | - if (err != SASL_OK) { | ||
554 | - VNC_DEBUG("cannot set SASL external SSF %d (%s)\n", | ||
555 | - err, sasl_errstring(err, NULL, NULL)); | ||
556 | - sasl_dispose(&vs->sasl.conn); | ||
557 | - vs->sasl.conn = NULL; | ||
558 | - goto authabort; | ||
559 | - } | 539 | + vs->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL) { |
540 | + gnutls_cipher_algorithm_t cipher; | ||
541 | + sasl_ssf_t ssf; | ||
542 | + | ||
543 | + cipher = gnutls_cipher_get(vs->tls.session); | ||
544 | + if (!(ssf = (sasl_ssf_t)gnutls_cipher_get_key_size(cipher))) { | ||
545 | + VNC_DEBUG("%s", "cannot TLS get cipher size\n"); | ||
546 | + sasl_dispose(&vs->sasl.conn); | ||
547 | + vs->sasl.conn = NULL; | ||
548 | + goto authabort; | ||
549 | + } | ||
550 | + ssf *= 8; /* tls key size is bytes, sasl wants bits */ | ||
551 | + | ||
552 | + err = sasl_setprop(vs->sasl.conn, SASL_SSF_EXTERNAL, &ssf); | ||
553 | + if (err != SASL_OK) { | ||
554 | + VNC_DEBUG("cannot set SASL external SSF %d (%s)\n", | ||
555 | + err, sasl_errstring(err, NULL, NULL)); | ||
556 | + sasl_dispose(&vs->sasl.conn); | ||
557 | + vs->sasl.conn = NULL; | ||
558 | + goto authabort; | ||
559 | + } | ||
560 | } else | 560 | } else |
561 | #endif /* CONFIG_VNC_TLS */ | 561 | #endif /* CONFIG_VNC_TLS */ |
562 | - vs->sasl.wantSSF = 1; | 562 | + vs->sasl.wantSSF = 1; |
563 | 563 | ||
564 | memset (&secprops, 0, sizeof secprops); | 564 | memset (&secprops, 0, sizeof secprops); |
565 | /* Inform SASL that we've got an external SSF layer from TLS */ | 565 | /* Inform SASL that we've got an external SSF layer from TLS */ |
566 | if (strncmp(vs->vd->display, "unix:", 5) == 0 | 566 | if (strncmp(vs->vd->display, "unix:", 5) == 0 |
567 | #ifdef CONFIG_VNC_TLS | 567 | #ifdef CONFIG_VNC_TLS |
568 | - /* Disable SSF, if using TLS+x509+SASL only. TLS without x509 | ||
569 | - is not sufficiently strong */ | ||
570 | - || (vs->vd->auth == VNC_AUTH_VENCRYPT && | ||
571 | - vs->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL) | 568 | + /* Disable SSF, if using TLS+x509+SASL only. TLS without x509 |
569 | + is not sufficiently strong */ | ||
570 | + || (vs->vd->auth == VNC_AUTH_VENCRYPT && | ||
571 | + vs->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL) | ||
572 | #endif /* CONFIG_VNC_TLS */ | 572 | #endif /* CONFIG_VNC_TLS */ |
573 | - ) { | ||
574 | - /* If we've got TLS or UNIX domain sock, we don't care about SSF */ | ||
575 | - secprops.min_ssf = 0; | ||
576 | - secprops.max_ssf = 0; | ||
577 | - secprops.maxbufsize = 8192; | ||
578 | - secprops.security_flags = 0; | 573 | + ) { |
574 | + /* If we've got TLS or UNIX domain sock, we don't care about SSF */ | ||
575 | + secprops.min_ssf = 0; | ||
576 | + secprops.max_ssf = 0; | ||
577 | + secprops.maxbufsize = 8192; | ||
578 | + secprops.security_flags = 0; | ||
579 | } else { | 579 | } else { |
580 | - /* Plain TCP, better get an SSF layer */ | ||
581 | - secprops.min_ssf = 56; /* Good enough to require kerberos */ | ||
582 | - secprops.max_ssf = 100000; /* Arbitrary big number */ | ||
583 | - secprops.maxbufsize = 8192; | ||
584 | - /* Forbid any anonymous or trivially crackable auth */ | ||
585 | - secprops.security_flags = | ||
586 | - SASL_SEC_NOANONYMOUS | SASL_SEC_NOPLAINTEXT; | 580 | + /* Plain TCP, better get an SSF layer */ |
581 | + secprops.min_ssf = 56; /* Good enough to require kerberos */ | ||
582 | + secprops.max_ssf = 100000; /* Arbitrary big number */ | ||
583 | + secprops.maxbufsize = 8192; | ||
584 | + /* Forbid any anonymous or trivially crackable auth */ | ||
585 | + secprops.security_flags = | ||
586 | + SASL_SEC_NOANONYMOUS | SASL_SEC_NOPLAINTEXT; | ||
587 | } | 587 | } |
588 | 588 | ||
589 | err = sasl_setprop(vs->sasl.conn, SASL_SEC_PROPS, &secprops); | 589 | err = sasl_setprop(vs->sasl.conn, SASL_SEC_PROPS, &secprops); |
590 | if (err != SASL_OK) { | 590 | if (err != SASL_OK) { |
591 | - VNC_DEBUG("cannot set SASL security props %d (%s)\n", | ||
592 | - err, sasl_errstring(err, NULL, NULL)); | ||
593 | - sasl_dispose(&vs->sasl.conn); | ||
594 | - vs->sasl.conn = NULL; | ||
595 | - goto authabort; | 591 | + VNC_DEBUG("cannot set SASL security props %d (%s)\n", |
592 | + err, sasl_errstring(err, NULL, NULL)); | ||
593 | + sasl_dispose(&vs->sasl.conn); | ||
594 | + vs->sasl.conn = NULL; | ||
595 | + goto authabort; | ||
596 | } | 596 | } |
597 | 597 | ||
598 | err = sasl_listmech(vs->sasl.conn, | 598 | err = sasl_listmech(vs->sasl.conn, |
599 | - NULL, /* Don't need to set user */ | ||
600 | - "", /* Prefix */ | ||
601 | - ",", /* Separator */ | ||
602 | - "", /* Suffix */ | ||
603 | - &mechlist, | ||
604 | - NULL, | ||
605 | - NULL); | 599 | + NULL, /* Don't need to set user */ |
600 | + "", /* Prefix */ | ||
601 | + ",", /* Separator */ | ||
602 | + "", /* Suffix */ | ||
603 | + &mechlist, | ||
604 | + NULL, | ||
605 | + NULL); | ||
606 | if (err != SASL_OK) { | 606 | if (err != SASL_OK) { |
607 | - VNC_DEBUG("cannot list SASL mechanisms %d (%s)\n", | ||
608 | - err, sasl_errdetail(vs->sasl.conn)); | ||
609 | - sasl_dispose(&vs->sasl.conn); | ||
610 | - vs->sasl.conn = NULL; | ||
611 | - goto authabort; | 607 | + VNC_DEBUG("cannot list SASL mechanisms %d (%s)\n", |
608 | + err, sasl_errdetail(vs->sasl.conn)); | ||
609 | + sasl_dispose(&vs->sasl.conn); | ||
610 | + vs->sasl.conn = NULL; | ||
611 | + goto authabort; | ||
612 | } | 612 | } |
613 | VNC_DEBUG("Available mechanisms for client: '%s'\n", mechlist); | 613 | VNC_DEBUG("Available mechanisms for client: '%s'\n", mechlist); |
614 | 614 | ||
615 | if (!(vs->sasl.mechlist = strdup(mechlist))) { | 615 | if (!(vs->sasl.mechlist = strdup(mechlist))) { |
616 | - VNC_DEBUG("Out of memory"); | ||
617 | - sasl_dispose(&vs->sasl.conn); | ||
618 | - vs->sasl.conn = NULL; | ||
619 | - goto authabort; | 616 | + VNC_DEBUG("Out of memory"); |
617 | + sasl_dispose(&vs->sasl.conn); | ||
618 | + vs->sasl.conn = NULL; | ||
619 | + goto authabort; | ||
620 | } | 620 | } |
621 | mechlistlen = strlen(mechlist); | 621 | mechlistlen = strlen(mechlist); |
622 | vnc_write_u32(vs, mechlistlen); | 622 | vnc_write_u32(vs, mechlistlen); |
vnc.c
@@ -128,10 +128,10 @@ static const char *vnc_auth_name(VncDisplay *vd) { | @@ -128,10 +128,10 @@ static const char *vnc_auth_name(VncDisplay *vd) { | ||
128 | return "vencrypt+x509+vnc"; | 128 | return "vencrypt+x509+vnc"; |
129 | case VNC_AUTH_VENCRYPT_X509PLAIN: | 129 | case VNC_AUTH_VENCRYPT_X509PLAIN: |
130 | return "vencrypt+x509+plain"; | 130 | return "vencrypt+x509+plain"; |
131 | - case VNC_AUTH_VENCRYPT_TLSSASL: | ||
132 | - return "vencrypt+tls+sasl"; | ||
133 | - case VNC_AUTH_VENCRYPT_X509SASL: | ||
134 | - return "vencrypt+x509+sasl"; | 131 | + case VNC_AUTH_VENCRYPT_TLSSASL: |
132 | + return "vencrypt+tls+sasl"; | ||
133 | + case VNC_AUTH_VENCRYPT_X509SASL: | ||
134 | + return "vencrypt+x509+sasl"; | ||
135 | default: | 135 | default: |
136 | return "vencrypt"; | 136 | return "vencrypt"; |
137 | } | 137 | } |
@@ -139,7 +139,7 @@ static const char *vnc_auth_name(VncDisplay *vd) { | @@ -139,7 +139,7 @@ static const char *vnc_auth_name(VncDisplay *vd) { | ||
139 | return "vencrypt"; | 139 | return "vencrypt"; |
140 | #endif | 140 | #endif |
141 | case VNC_AUTH_SASL: | 141 | case VNC_AUTH_SASL: |
142 | - return "sasl"; | 142 | + return "sasl"; |
143 | } | 143 | } |
144 | return "unknown"; | 144 | return "unknown"; |
145 | } | 145 | } |
@@ -160,17 +160,17 @@ static void do_info_vnc_client(Monitor *mon, VncState *client) | @@ -160,17 +160,17 @@ static void do_info_vnc_client(Monitor *mon, VncState *client) | ||
160 | 160 | ||
161 | #ifdef CONFIG_VNC_TLS | 161 | #ifdef CONFIG_VNC_TLS |
162 | if (client->tls.session && | 162 | if (client->tls.session && |
163 | - client->tls.dname) | ||
164 | - monitor_printf(mon, " x509 dname: %s\n", client->tls.dname); | 163 | + client->tls.dname) |
164 | + monitor_printf(mon, " x509 dname: %s\n", client->tls.dname); | ||
165 | else | 165 | else |
166 | - monitor_printf(mon, " x509 dname: none\n"); | 166 | + monitor_printf(mon, " x509 dname: none\n"); |
167 | #endif | 167 | #endif |
168 | #ifdef CONFIG_VNC_SASL | 168 | #ifdef CONFIG_VNC_SASL |
169 | if (client->sasl.conn && | 169 | if (client->sasl.conn && |
170 | - client->sasl.username) | ||
171 | - monitor_printf(mon, " username: %s\n", client->sasl.username); | 170 | + client->sasl.username) |
171 | + monitor_printf(mon, " username: %s\n", client->sasl.username); | ||
172 | else | 172 | else |
173 | - monitor_printf(mon, " username: none\n"); | 173 | + monitor_printf(mon, " username: none\n"); |
174 | #endif | 174 | #endif |
175 | } | 175 | } |
176 | 176 | ||
@@ -277,8 +277,8 @@ static void vnc_update(VncState *vs, int x, int y, int w, int h) | @@ -277,8 +277,8 @@ static void vnc_update(VncState *vs, int x, int y, int w, int h) | ||
277 | h = MIN(h, vs->serverds.height); | 277 | h = MIN(h, vs->serverds.height); |
278 | 278 | ||
279 | for (; y < h; y++) | 279 | for (; y < h; y++) |
280 | - for (i = 0; i < w; i += 16) | ||
281 | - vnc_set_bit(vs->dirty_row[y], (x + i) / 16); | 280 | + for (i = 0; i < w; i += 16) |
281 | + vnc_set_bit(vs->dirty_row[y], (x + i) / 16); | ||
282 | } | 282 | } |
283 | 283 | ||
284 | static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h) | 284 | static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h) |
@@ -292,7 +292,7 @@ static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h) | @@ -292,7 +292,7 @@ static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h) | ||
292 | } | 292 | } |
293 | 293 | ||
294 | static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, | 294 | static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, |
295 | - int32_t encoding) | 295 | + int32_t encoding) |
296 | { | 296 | { |
297 | vnc_write_u16(vs, x); | 297 | vnc_write_u16(vs, x); |
298 | vnc_write_u16(vs, y); | 298 | vnc_write_u16(vs, y); |
@@ -305,12 +305,12 @@ static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, | @@ -305,12 +305,12 @@ static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, | ||
305 | void buffer_reserve(Buffer *buffer, size_t len) | 305 | void buffer_reserve(Buffer *buffer, size_t len) |
306 | { | 306 | { |
307 | if ((buffer->capacity - buffer->offset) < len) { | 307 | if ((buffer->capacity - buffer->offset) < len) { |
308 | - buffer->capacity += (len + 1024); | ||
309 | - buffer->buffer = qemu_realloc(buffer->buffer, buffer->capacity); | ||
310 | - if (buffer->buffer == NULL) { | ||
311 | - fprintf(stderr, "vnc: out of memory\n"); | ||
312 | - exit(1); | ||
313 | - } | 308 | + buffer->capacity += (len + 1024); |
309 | + buffer->buffer = qemu_realloc(buffer->buffer, buffer->capacity); | ||
310 | + if (buffer->buffer == NULL) { | ||
311 | + fprintf(stderr, "vnc: out of memory\n"); | ||
312 | + exit(1); | ||
313 | + } | ||
314 | } | 314 | } |
315 | } | 315 | } |
316 | 316 | ||
@@ -326,7 +326,7 @@ uint8_t *buffer_end(Buffer *buffer) | @@ -326,7 +326,7 @@ uint8_t *buffer_end(Buffer *buffer) | ||
326 | 326 | ||
327 | void buffer_reset(Buffer *buffer) | 327 | void buffer_reset(Buffer *buffer) |
328 | { | 328 | { |
329 | - buffer->offset = 0; | 329 | + buffer->offset = 0; |
330 | } | 330 | } |
331 | 331 | ||
332 | void buffer_append(Buffer *buffer, const void *data, size_t len) | 332 | void buffer_append(Buffer *buffer, const void *data, size_t len) |
@@ -344,8 +344,8 @@ static void vnc_resize(VncState *vs) | @@ -344,8 +344,8 @@ static void vnc_resize(VncState *vs) | ||
344 | vs->old_data = qemu_realloc(vs->old_data, ds_get_linesize(ds) * ds_get_height(ds)); | 344 | vs->old_data = qemu_realloc(vs->old_data, ds_get_linesize(ds) * ds_get_height(ds)); |
345 | 345 | ||
346 | if (vs->old_data == NULL) { | 346 | if (vs->old_data == NULL) { |
347 | - fprintf(stderr, "vnc: memory allocation failed\n"); | ||
348 | - exit(1); | 347 | + fprintf(stderr, "vnc: memory allocation failed\n"); |
348 | + exit(1); | ||
349 | } | 349 | } |
350 | 350 | ||
351 | if (ds_get_bytes_per_pixel(ds) != vs->serverds.pf.bytes_per_pixel) | 351 | if (ds_get_bytes_per_pixel(ds) != vs->serverds.pf.bytes_per_pixel) |
@@ -469,8 +469,8 @@ static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h | @@ -469,8 +469,8 @@ static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h | ||
469 | 469 | ||
470 | row = ds_get_data(vs->ds) + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds); | 470 | row = ds_get_data(vs->ds) + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds); |
471 | for (i = 0; i < h; i++) { | 471 | for (i = 0; i < h; i++) { |
472 | - vs->write_pixels(vs, row, w * ds_get_bytes_per_pixel(vs->ds)); | ||
473 | - row += ds_get_linesize(vs->ds); | 472 | + vs->write_pixels(vs, row, w * ds_get_bytes_per_pixel(vs->ds)); |
473 | + row += ds_get_linesize(vs->ds); | ||
474 | } | 474 | } |
475 | } | 475 | } |
476 | 476 | ||
@@ -520,11 +520,11 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i | @@ -520,11 +520,11 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i | ||
520 | last_bg = (uint8_t *) qemu_malloc(vs->serverds.pf.bytes_per_pixel); | 520 | last_bg = (uint8_t *) qemu_malloc(vs->serverds.pf.bytes_per_pixel); |
521 | has_fg = has_bg = 0; | 521 | has_fg = has_bg = 0; |
522 | for (j = y; j < (y + h); j += 16) { | 522 | for (j = y; j < (y + h); j += 16) { |
523 | - for (i = x; i < (x + w); i += 16) { | 523 | + for (i = x; i < (x + w); i += 16) { |
524 | vs->send_hextile_tile(vs, i, j, | 524 | vs->send_hextile_tile(vs, i, j, |
525 | MIN(16, x + w - i), MIN(16, y + h - j), | 525 | MIN(16, x + w - i), MIN(16, y + h - j), |
526 | last_bg, last_fg, &has_bg, &has_fg); | 526 | last_bg, last_fg, &has_bg, &has_fg); |
527 | - } | 527 | + } |
528 | } | 528 | } |
529 | free(last_fg); | 529 | free(last_fg); |
530 | free(last_bg); | 530 | free(last_bg); |
@@ -630,17 +630,17 @@ static void send_framebuffer_update_zlib(VncState *vs, int x, int y, int w, int | @@ -630,17 +630,17 @@ static void send_framebuffer_update_zlib(VncState *vs, int x, int y, int w, int | ||
630 | static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h) | 630 | static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h) |
631 | { | 631 | { |
632 | switch(vs->vnc_encoding) { | 632 | switch(vs->vnc_encoding) { |
633 | - case VNC_ENCODING_ZLIB: | ||
634 | - send_framebuffer_update_zlib(vs, x, y, w, h); | ||
635 | - break; | ||
636 | - case VNC_ENCODING_HEXTILE: | ||
637 | - vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_HEXTILE); | ||
638 | - send_framebuffer_update_hextile(vs, x, y, w, h); | ||
639 | - break; | ||
640 | - default: | ||
641 | - vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW); | ||
642 | - send_framebuffer_update_raw(vs, x, y, w, h); | ||
643 | - break; | 633 | + case VNC_ENCODING_ZLIB: |
634 | + send_framebuffer_update_zlib(vs, x, y, w, h); | ||
635 | + break; | ||
636 | + case VNC_ENCODING_HEXTILE: | ||
637 | + vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_HEXTILE); | ||
638 | + send_framebuffer_update_hextile(vs, x, y, w, h); | ||
639 | + break; | ||
640 | + default: | ||
641 | + vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW); | ||
642 | + send_framebuffer_update_raw(vs, x, y, w, h); | ||
643 | + break; | ||
644 | } | 644 | } |
645 | } | 645 | } |
646 | 646 | ||
@@ -675,11 +675,11 @@ static int find_dirty_height(VncState *vs, int y, int last_x, int x) | @@ -675,11 +675,11 @@ static int find_dirty_height(VncState *vs, int y, int last_x, int x) | ||
675 | int h; | 675 | int h; |
676 | 676 | ||
677 | for (h = 1; h < (vs->serverds.height - y); h++) { | 677 | for (h = 1; h < (vs->serverds.height - y); h++) { |
678 | - int tmp_x; | ||
679 | - if (!vnc_get_bit(vs->dirty_row[y + h], last_x)) | ||
680 | - break; | ||
681 | - for (tmp_x = last_x; tmp_x < x; tmp_x++) | ||
682 | - vnc_clear_bit(vs->dirty_row[y + h], tmp_x); | 678 | + int tmp_x; |
679 | + if (!vnc_get_bit(vs->dirty_row[y + h], last_x)) | ||
680 | + break; | ||
681 | + for (tmp_x = last_x; tmp_x < x; tmp_x++) | ||
682 | + vnc_clear_bit(vs->dirty_row[y + h], tmp_x); | ||
683 | } | 683 | } |
684 | 684 | ||
685 | return h; | 685 | return h; |
@@ -689,88 +689,88 @@ static void vnc_update_client(void *opaque) | @@ -689,88 +689,88 @@ static void vnc_update_client(void *opaque) | ||
689 | { | 689 | { |
690 | VncState *vs = opaque; | 690 | VncState *vs = opaque; |
691 | if (vs->need_update && vs->csock != -1) { | 691 | if (vs->need_update && vs->csock != -1) { |
692 | - int y; | ||
693 | - uint8_t *row; | ||
694 | - char *old_row; | ||
695 | - uint32_t width_mask[VNC_DIRTY_WORDS]; | ||
696 | - int n_rectangles; | ||
697 | - int saved_offset; | ||
698 | - int has_dirty = 0; | 692 | + int y; |
693 | + uint8_t *row; | ||
694 | + char *old_row; | ||
695 | + uint32_t width_mask[VNC_DIRTY_WORDS]; | ||
696 | + int n_rectangles; | ||
697 | + int saved_offset; | ||
698 | + int has_dirty = 0; | ||
699 | 699 | ||
700 | vga_hw_update(); | 700 | vga_hw_update(); |
701 | 701 | ||
702 | vnc_set_bits(width_mask, (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS); | 702 | vnc_set_bits(width_mask, (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS); |
703 | 703 | ||
704 | - /* Walk through the dirty map and eliminate tiles that | ||
705 | - really aren't dirty */ | ||
706 | - row = ds_get_data(vs->ds); | ||
707 | - old_row = vs->old_data; | ||
708 | - | ||
709 | - for (y = 0; y < ds_get_height(vs->ds); y++) { | ||
710 | - if (vnc_and_bits(vs->dirty_row[y], width_mask, VNC_DIRTY_WORDS)) { | ||
711 | - int x; | ||
712 | - uint8_t *ptr; | ||
713 | - char *old_ptr; | ||
714 | - | ||
715 | - ptr = row; | ||
716 | - old_ptr = (char*)old_row; | ||
717 | - | ||
718 | - for (x = 0; x < ds_get_width(vs->ds); x += 16) { | ||
719 | - if (memcmp(old_ptr, ptr, 16 * ds_get_bytes_per_pixel(vs->ds)) == 0) { | ||
720 | - vnc_clear_bit(vs->dirty_row[y], (x / 16)); | ||
721 | - } else { | ||
722 | - has_dirty = 1; | ||
723 | - memcpy(old_ptr, ptr, 16 * ds_get_bytes_per_pixel(vs->ds)); | ||
724 | - } | ||
725 | - | ||
726 | - ptr += 16 * ds_get_bytes_per_pixel(vs->ds); | ||
727 | - old_ptr += 16 * ds_get_bytes_per_pixel(vs->ds); | ||
728 | - } | ||
729 | - } | ||
730 | - | ||
731 | - row += ds_get_linesize(vs->ds); | ||
732 | - old_row += ds_get_linesize(vs->ds); | ||
733 | - } | ||
734 | - | ||
735 | - if (!has_dirty && !vs->audio_cap) { | ||
736 | - qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL); | ||
737 | - return; | ||
738 | - } | ||
739 | - | ||
740 | - /* Count rectangles */ | ||
741 | - n_rectangles = 0; | ||
742 | - vnc_write_u8(vs, 0); /* msg id */ | ||
743 | - vnc_write_u8(vs, 0); | ||
744 | - saved_offset = vs->output.offset; | ||
745 | - vnc_write_u16(vs, 0); | ||
746 | - | ||
747 | - for (y = 0; y < vs->serverds.height; y++) { | ||
748 | - int x; | ||
749 | - int last_x = -1; | ||
750 | - for (x = 0; x < vs->serverds.width / 16; x++) { | ||
751 | - if (vnc_get_bit(vs->dirty_row[y], x)) { | ||
752 | - if (last_x == -1) { | ||
753 | - last_x = x; | ||
754 | - } | ||
755 | - vnc_clear_bit(vs->dirty_row[y], x); | ||
756 | - } else { | ||
757 | - if (last_x != -1) { | ||
758 | - int h = find_dirty_height(vs, y, last_x, x); | ||
759 | - send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h); | ||
760 | - n_rectangles++; | ||
761 | - } | ||
762 | - last_x = -1; | ||
763 | - } | ||
764 | - } | ||
765 | - if (last_x != -1) { | ||
766 | - int h = find_dirty_height(vs, y, last_x, x); | ||
767 | - send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h); | ||
768 | - n_rectangles++; | ||
769 | - } | ||
770 | - } | ||
771 | - vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF; | ||
772 | - vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF; | ||
773 | - vnc_flush(vs); | 704 | + /* Walk through the dirty map and eliminate tiles that |
705 | + really aren't dirty */ | ||
706 | + row = ds_get_data(vs->ds); | ||
707 | + old_row = vs->old_data; | ||
708 | + | ||
709 | + for (y = 0; y < ds_get_height(vs->ds); y++) { | ||
710 | + if (vnc_and_bits(vs->dirty_row[y], width_mask, VNC_DIRTY_WORDS)) { | ||
711 | + int x; | ||
712 | + uint8_t *ptr; | ||
713 | + char *old_ptr; | ||
714 | + | ||
715 | + ptr = row; | ||
716 | + old_ptr = (char*)old_row; | ||
717 | + | ||
718 | + for (x = 0; x < ds_get_width(vs->ds); x += 16) { | ||
719 | + if (memcmp(old_ptr, ptr, 16 * ds_get_bytes_per_pixel(vs->ds)) == 0) { | ||
720 | + vnc_clear_bit(vs->dirty_row[y], (x / 16)); | ||
721 | + } else { | ||
722 | + has_dirty = 1; | ||
723 | + memcpy(old_ptr, ptr, 16 * ds_get_bytes_per_pixel(vs->ds)); | ||
724 | + } | ||
725 | + | ||
726 | + ptr += 16 * ds_get_bytes_per_pixel(vs->ds); | ||
727 | + old_ptr += 16 * ds_get_bytes_per_pixel(vs->ds); | ||
728 | + } | ||
729 | + } | ||
730 | + | ||
731 | + row += ds_get_linesize(vs->ds); | ||
732 | + old_row += ds_get_linesize(vs->ds); | ||
733 | + } | ||
734 | + | ||
735 | + if (!has_dirty && !vs->audio_cap) { | ||
736 | + qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL); | ||
737 | + return; | ||
738 | + } | ||
739 | + | ||
740 | + /* Count rectangles */ | ||
741 | + n_rectangles = 0; | ||
742 | + vnc_write_u8(vs, 0); /* msg id */ | ||
743 | + vnc_write_u8(vs, 0); | ||
744 | + saved_offset = vs->output.offset; | ||
745 | + vnc_write_u16(vs, 0); | ||
746 | + | ||
747 | + for (y = 0; y < vs->serverds.height; y++) { | ||
748 | + int x; | ||
749 | + int last_x = -1; | ||
750 | + for (x = 0; x < vs->serverds.width / 16; x++) { | ||
751 | + if (vnc_get_bit(vs->dirty_row[y], x)) { | ||
752 | + if (last_x == -1) { | ||
753 | + last_x = x; | ||
754 | + } | ||
755 | + vnc_clear_bit(vs->dirty_row[y], x); | ||
756 | + } else { | ||
757 | + if (last_x != -1) { | ||
758 | + int h = find_dirty_height(vs, y, last_x, x); | ||
759 | + send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h); | ||
760 | + n_rectangles++; | ||
761 | + } | ||
762 | + last_x = -1; | ||
763 | + } | ||
764 | + } | ||
765 | + if (last_x != -1) { | ||
766 | + int h = find_dirty_height(vs, y, last_x, x); | ||
767 | + send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h); | ||
768 | + n_rectangles++; | ||
769 | + } | ||
770 | + } | ||
771 | + vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF; | ||
772 | + vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF; | ||
773 | + vnc_flush(vs); | ||
774 | 774 | ||
775 | } | 775 | } |
776 | 776 | ||
@@ -863,15 +863,15 @@ int vnc_client_io_error(VncState *vs, int ret, int last_errno) | @@ -863,15 +863,15 @@ int vnc_client_io_error(VncState *vs, int ret, int last_errno) | ||
863 | } | 863 | } |
864 | } | 864 | } |
865 | 865 | ||
866 | - VNC_DEBUG("Closing down client sock %d %d\n", ret, ret < 0 ? last_errno : 0); | ||
867 | - qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL); | ||
868 | - closesocket(vs->csock); | 866 | + VNC_DEBUG("Closing down client sock %d %d\n", ret, ret < 0 ? last_errno : 0); |
867 | + qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL); | ||
868 | + closesocket(vs->csock); | ||
869 | qemu_del_timer(vs->timer); | 869 | qemu_del_timer(vs->timer); |
870 | qemu_free_timer(vs->timer); | 870 | qemu_free_timer(vs->timer); |
871 | if (vs->input.buffer) qemu_free(vs->input.buffer); | 871 | if (vs->input.buffer) qemu_free(vs->input.buffer); |
872 | if (vs->output.buffer) qemu_free(vs->output.buffer); | 872 | if (vs->output.buffer) qemu_free(vs->output.buffer); |
873 | #ifdef CONFIG_VNC_TLS | 873 | #ifdef CONFIG_VNC_TLS |
874 | - vnc_tls_client_cleanup(vs); | 874 | + vnc_tls_client_cleanup(vs); |
875 | #endif /* CONFIG_VNC_TLS */ | 875 | #endif /* CONFIG_VNC_TLS */ |
876 | #ifdef CONFIG_VNC_SASL | 876 | #ifdef CONFIG_VNC_SASL |
877 | vnc_sasl_client_cleanup(vs); | 877 | vnc_sasl_client_cleanup(vs); |
@@ -895,7 +895,7 @@ int vnc_client_io_error(VncState *vs, int ret, int last_errno) | @@ -895,7 +895,7 @@ int vnc_client_io_error(VncState *vs, int ret, int last_errno) | ||
895 | qemu_free(vs->old_data); | 895 | qemu_free(vs->old_data); |
896 | qemu_free(vs); | 896 | qemu_free(vs); |
897 | 897 | ||
898 | - return 0; | 898 | + return 0; |
899 | } | 899 | } |
900 | return ret; | 900 | return ret; |
901 | } | 901 | } |
@@ -927,17 +927,17 @@ long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen) | @@ -927,17 +927,17 @@ long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen) | ||
927 | long ret; | 927 | long ret; |
928 | #ifdef CONFIG_VNC_TLS | 928 | #ifdef CONFIG_VNC_TLS |
929 | if (vs->tls.session) { | 929 | if (vs->tls.session) { |
930 | - ret = gnutls_write(vs->tls.session, data, datalen); | ||
931 | - if (ret < 0) { | ||
932 | - if (ret == GNUTLS_E_AGAIN) | ||
933 | - errno = EAGAIN; | ||
934 | - else | ||
935 | - errno = EIO; | ||
936 | - ret = -1; | ||
937 | - } | 930 | + ret = gnutls_write(vs->tls.session, data, datalen); |
931 | + if (ret < 0) { | ||
932 | + if (ret == GNUTLS_E_AGAIN) | ||
933 | + errno = EAGAIN; | ||
934 | + else | ||
935 | + errno = EIO; | ||
936 | + ret = -1; | ||
937 | + } | ||
938 | } else | 938 | } else |
939 | #endif /* CONFIG_VNC_TLS */ | 939 | #endif /* CONFIG_VNC_TLS */ |
940 | - ret = send(vs->csock, data, datalen, 0); | 940 | + ret = send(vs->csock, data, datalen, 0); |
941 | VNC_DEBUG("Wrote wire %p %d -> %ld\n", data, datalen, ret); | 941 | VNC_DEBUG("Wrote wire %p %d -> %ld\n", data, datalen, ret); |
942 | return vnc_client_io_error(vs, ret, socket_error()); | 942 | return vnc_client_io_error(vs, ret, socket_error()); |
943 | } | 943 | } |
@@ -978,7 +978,7 @@ static long vnc_client_write_plain(VncState *vs) | @@ -978,7 +978,7 @@ static long vnc_client_write_plain(VncState *vs) | ||
978 | vs->output.offset -= ret; | 978 | vs->output.offset -= ret; |
979 | 979 | ||
980 | if (vs->output.offset == 0) { | 980 | if (vs->output.offset == 0) { |
981 | - qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); | 981 | + qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); |
982 | } | 982 | } |
983 | 983 | ||
984 | return ret; | 984 | return ret; |
@@ -1032,17 +1032,17 @@ long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen) | @@ -1032,17 +1032,17 @@ long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen) | ||
1032 | long ret; | 1032 | long ret; |
1033 | #ifdef CONFIG_VNC_TLS | 1033 | #ifdef CONFIG_VNC_TLS |
1034 | if (vs->tls.session) { | 1034 | if (vs->tls.session) { |
1035 | - ret = gnutls_read(vs->tls.session, data, datalen); | ||
1036 | - if (ret < 0) { | ||
1037 | - if (ret == GNUTLS_E_AGAIN) | ||
1038 | - errno = EAGAIN; | ||
1039 | - else | ||
1040 | - errno = EIO; | ||
1041 | - ret = -1; | ||
1042 | - } | 1035 | + ret = gnutls_read(vs->tls.session, data, datalen); |
1036 | + if (ret < 0) { | ||
1037 | + if (ret == GNUTLS_E_AGAIN) | ||
1038 | + errno = EAGAIN; | ||
1039 | + else | ||
1040 | + errno = EIO; | ||
1041 | + ret = -1; | ||
1042 | + } | ||
1043 | } else | 1043 | } else |
1044 | #endif /* CONFIG_VNC_TLS */ | 1044 | #endif /* CONFIG_VNC_TLS */ |
1045 | - ret = recv(vs->csock, data, datalen, 0); | 1045 | + ret = recv(vs->csock, data, datalen, 0); |
1046 | VNC_DEBUG("Read wire %p %d -> %ld\n", data, datalen, ret); | 1046 | VNC_DEBUG("Read wire %p %d -> %ld\n", data, datalen, ret); |
1047 | return vnc_client_io_error(vs, ret, socket_error()); | 1047 | return vnc_client_io_error(vs, ret, socket_error()); |
1048 | } | 1048 | } |
@@ -1087,22 +1087,22 @@ void vnc_client_read(void *opaque) | @@ -1087,22 +1087,22 @@ void vnc_client_read(void *opaque) | ||
1087 | #endif /* CONFIG_VNC_SASL */ | 1087 | #endif /* CONFIG_VNC_SASL */ |
1088 | ret = vnc_client_read_plain(vs); | 1088 | ret = vnc_client_read_plain(vs); |
1089 | if (!ret) | 1089 | if (!ret) |
1090 | - return; | 1090 | + return; |
1091 | 1091 | ||
1092 | while (vs->read_handler && vs->input.offset >= vs->read_handler_expect) { | 1092 | while (vs->read_handler && vs->input.offset >= vs->read_handler_expect) { |
1093 | - size_t len = vs->read_handler_expect; | ||
1094 | - int ret; | ||
1095 | - | ||
1096 | - ret = vs->read_handler(vs, vs->input.buffer, len); | ||
1097 | - if (vs->csock == -1) | ||
1098 | - return; | ||
1099 | - | ||
1100 | - if (!ret) { | ||
1101 | - memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len)); | ||
1102 | - vs->input.offset -= len; | ||
1103 | - } else { | ||
1104 | - vs->read_handler_expect = ret; | ||
1105 | - } | 1093 | + size_t len = vs->read_handler_expect; |
1094 | + int ret; | ||
1095 | + | ||
1096 | + ret = vs->read_handler(vs, vs->input.buffer, len); | ||
1097 | + if (vs->csock == -1) | ||
1098 | + return; | ||
1099 | + | ||
1100 | + if (!ret) { | ||
1101 | + memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len)); | ||
1102 | + vs->input.offset -= len; | ||
1103 | + } else { | ||
1104 | + vs->read_handler_expect = ret; | ||
1105 | + } | ||
1106 | } | 1106 | } |
1107 | } | 1107 | } |
1108 | 1108 | ||
@@ -1111,7 +1111,7 @@ void vnc_write(VncState *vs, const void *data, size_t len) | @@ -1111,7 +1111,7 @@ void vnc_write(VncState *vs, const void *data, size_t len) | ||
1111 | buffer_reserve(&vs->output, len); | 1111 | buffer_reserve(&vs->output, len); |
1112 | 1112 | ||
1113 | if (buffer_empty(&vs->output)) { | 1113 | if (buffer_empty(&vs->output)) { |
1114 | - qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs); | 1114 | + qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs); |
1115 | } | 1115 | } |
1116 | 1116 | ||
1117 | buffer_append(&vs->output, data, len); | 1117 | buffer_append(&vs->output, data, len); |
@@ -1152,7 +1152,7 @@ void vnc_write_u8(VncState *vs, uint8_t value) | @@ -1152,7 +1152,7 @@ void vnc_write_u8(VncState *vs, uint8_t value) | ||
1152 | void vnc_flush(VncState *vs) | 1152 | void vnc_flush(VncState *vs) |
1153 | { | 1153 | { |
1154 | if (vs->output.offset) | 1154 | if (vs->output.offset) |
1155 | - vnc_client_write(vs); | 1155 | + vnc_client_write(vs); |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | uint8_t read_u8(uint8_t *data, size_t offset) | 1158 | uint8_t read_u8(uint8_t *data, size_t offset) |
@@ -1168,13 +1168,13 @@ uint16_t read_u16(uint8_t *data, size_t offset) | @@ -1168,13 +1168,13 @@ uint16_t read_u16(uint8_t *data, size_t offset) | ||
1168 | int32_t read_s32(uint8_t *data, size_t offset) | 1168 | int32_t read_s32(uint8_t *data, size_t offset) |
1169 | { | 1169 | { |
1170 | return (int32_t)((data[offset] << 24) | (data[offset + 1] << 16) | | 1170 | return (int32_t)((data[offset] << 24) | (data[offset + 1] << 16) | |
1171 | - (data[offset + 2] << 8) | data[offset + 3]); | 1171 | + (data[offset + 2] << 8) | data[offset + 3]); |
1172 | } | 1172 | } |
1173 | 1173 | ||
1174 | uint32_t read_u32(uint8_t *data, size_t offset) | 1174 | uint32_t read_u32(uint8_t *data, size_t offset) |
1175 | { | 1175 | { |
1176 | return ((data[offset] << 24) | (data[offset + 1] << 16) | | 1176 | return ((data[offset] << 24) | (data[offset + 1] << 16) | |
1177 | - (data[offset + 2] << 8) | data[offset + 3]); | 1177 | + (data[offset + 2] << 8) | data[offset + 3]); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | static void client_cut_text(VncState *vs, size_t len, uint8_t *text) | 1180 | static void client_cut_text(VncState *vs, size_t len, uint8_t *text) |
@@ -1184,13 +1184,13 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text) | @@ -1184,13 +1184,13 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text) | ||
1184 | static void check_pointer_type_change(VncState *vs, int absolute) | 1184 | static void check_pointer_type_change(VncState *vs, int absolute) |
1185 | { | 1185 | { |
1186 | if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) { | 1186 | if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) { |
1187 | - vnc_write_u8(vs, 0); | ||
1188 | - vnc_write_u8(vs, 0); | ||
1189 | - vnc_write_u16(vs, 1); | ||
1190 | - vnc_framebuffer_update(vs, absolute, 0, | ||
1191 | - ds_get_width(vs->ds), ds_get_height(vs->ds), | 1187 | + vnc_write_u8(vs, 0); |
1188 | + vnc_write_u8(vs, 0); | ||
1189 | + vnc_write_u16(vs, 1); | ||
1190 | + vnc_framebuffer_update(vs, absolute, 0, | ||
1191 | + ds_get_width(vs->ds), ds_get_height(vs->ds), | ||
1192 | VNC_ENCODING_POINTER_TYPE_CHANGE); | 1192 | VNC_ENCODING_POINTER_TYPE_CHANGE); |
1193 | - vnc_flush(vs); | 1193 | + vnc_flush(vs); |
1194 | } | 1194 | } |
1195 | vs->absolute = absolute; | 1195 | vs->absolute = absolute; |
1196 | } | 1196 | } |
@@ -1201,32 +1201,32 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y) | @@ -1201,32 +1201,32 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y) | ||
1201 | int dz = 0; | 1201 | int dz = 0; |
1202 | 1202 | ||
1203 | if (button_mask & 0x01) | 1203 | if (button_mask & 0x01) |
1204 | - buttons |= MOUSE_EVENT_LBUTTON; | 1204 | + buttons |= MOUSE_EVENT_LBUTTON; |
1205 | if (button_mask & 0x02) | 1205 | if (button_mask & 0x02) |
1206 | - buttons |= MOUSE_EVENT_MBUTTON; | 1206 | + buttons |= MOUSE_EVENT_MBUTTON; |
1207 | if (button_mask & 0x04) | 1207 | if (button_mask & 0x04) |
1208 | - buttons |= MOUSE_EVENT_RBUTTON; | 1208 | + buttons |= MOUSE_EVENT_RBUTTON; |
1209 | if (button_mask & 0x08) | 1209 | if (button_mask & 0x08) |
1210 | - dz = -1; | 1210 | + dz = -1; |
1211 | if (button_mask & 0x10) | 1211 | if (button_mask & 0x10) |
1212 | - dz = 1; | 1212 | + dz = 1; |
1213 | 1213 | ||
1214 | if (vs->absolute) { | 1214 | if (vs->absolute) { |
1215 | - kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1), | ||
1216 | - y * 0x7FFF / (ds_get_height(vs->ds) - 1), | ||
1217 | - dz, buttons); | 1215 | + kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1), |
1216 | + y * 0x7FFF / (ds_get_height(vs->ds) - 1), | ||
1217 | + dz, buttons); | ||
1218 | } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) { | 1218 | } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) { |
1219 | - x -= 0x7FFF; | ||
1220 | - y -= 0x7FFF; | 1219 | + x -= 0x7FFF; |
1220 | + y -= 0x7FFF; | ||
1221 | 1221 | ||
1222 | - kbd_mouse_event(x, y, dz, buttons); | 1222 | + kbd_mouse_event(x, y, dz, buttons); |
1223 | } else { | 1223 | } else { |
1224 | - if (vs->last_x != -1) | ||
1225 | - kbd_mouse_event(x - vs->last_x, | ||
1226 | - y - vs->last_y, | ||
1227 | - dz, buttons); | ||
1228 | - vs->last_x = x; | ||
1229 | - vs->last_y = y; | 1224 | + if (vs->last_x != -1) |
1225 | + kbd_mouse_event(x - vs->last_x, | ||
1226 | + y - vs->last_y, | ||
1227 | + dz, buttons); | ||
1228 | + vs->last_x = x; | ||
1229 | + vs->last_y = y; | ||
1230 | } | 1230 | } |
1231 | 1231 | ||
1232 | check_pointer_type_change(vs, kbd_mouse_is_absolute()); | 1232 | check_pointer_type_change(vs, kbd_mouse_is_absolute()); |
@@ -1274,8 +1274,8 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) | @@ -1274,8 +1274,8 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) | ||
1274 | return; | 1274 | return; |
1275 | } | 1275 | } |
1276 | break; | 1276 | break; |
1277 | - case 0x3a: /* CapsLock */ | ||
1278 | - case 0x45: /* NumLock */ | 1277 | + case 0x3a: /* CapsLock */ |
1278 | + case 0x45: /* NumLock */ | ||
1279 | if (!down) | 1279 | if (!down) |
1280 | vs->modifiers_state[keycode] ^= 1; | 1280 | vs->modifiers_state[keycode] ^= 1; |
1281 | break; | 1281 | break; |
@@ -1357,7 +1357,7 @@ static void key_event(VncState *vs, int down, uint32_t sym) | @@ -1357,7 +1357,7 @@ static void key_event(VncState *vs, int down, uint32_t sym) | ||
1357 | int keycode; | 1357 | int keycode; |
1358 | 1358 | ||
1359 | if (sym >= 'A' && sym <= 'Z' && is_graphic_console()) | 1359 | if (sym >= 'A' && sym <= 'Z' && is_graphic_console()) |
1360 | - sym = sym - 'A' + 'a'; | 1360 | + sym = sym - 'A' + 'a'; |
1361 | 1361 | ||
1362 | keycode = keysym2scancode(vs->vd->kbd_layout, sym & 0xFFFF); | 1362 | keycode = keysym2scancode(vs->vd->kbd_layout, sym & 0xFFFF); |
1363 | do_key_event(vs, down, keycode, sym); | 1363 | do_key_event(vs, down, keycode, sym); |
@@ -1374,8 +1374,8 @@ static void ext_key_event(VncState *vs, int down, | @@ -1374,8 +1374,8 @@ static void ext_key_event(VncState *vs, int down, | ||
1374 | } | 1374 | } |
1375 | 1375 | ||
1376 | static void framebuffer_update_request(VncState *vs, int incremental, | 1376 | static void framebuffer_update_request(VncState *vs, int incremental, |
1377 | - int x_position, int y_position, | ||
1378 | - int w, int h) | 1377 | + int x_position, int y_position, |
1378 | + int w, int h) | ||
1379 | { | 1379 | { |
1380 | if (x_position > ds_get_width(vs->ds)) | 1380 | if (x_position > ds_get_width(vs->ds)) |
1381 | x_position = ds_get_width(vs->ds); | 1381 | x_position = ds_get_width(vs->ds); |
@@ -1389,14 +1389,14 @@ static void framebuffer_update_request(VncState *vs, int incremental, | @@ -1389,14 +1389,14 @@ static void framebuffer_update_request(VncState *vs, int incremental, | ||
1389 | int i; | 1389 | int i; |
1390 | vs->need_update = 1; | 1390 | vs->need_update = 1; |
1391 | if (!incremental) { | 1391 | if (!incremental) { |
1392 | - char *old_row = vs->old_data + y_position * ds_get_linesize(vs->ds); | 1392 | + char *old_row = vs->old_data + y_position * ds_get_linesize(vs->ds); |
1393 | 1393 | ||
1394 | - for (i = 0; i < h; i++) { | 1394 | + for (i = 0; i < h; i++) { |
1395 | vnc_set_bits(vs->dirty_row[y_position + i], | 1395 | vnc_set_bits(vs->dirty_row[y_position + i], |
1396 | (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS); | 1396 | (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS); |
1397 | - memset(old_row, 42, ds_get_width(vs->ds) * ds_get_bytes_per_pixel(vs->ds)); | ||
1398 | - old_row += ds_get_linesize(vs->ds); | ||
1399 | - } | 1397 | + memset(old_row, 42, ds_get_width(vs->ds) * ds_get_bytes_per_pixel(vs->ds)); |
1398 | + old_row += ds_get_linesize(vs->ds); | ||
1399 | + } | ||
1400 | } | 1400 | } |
1401 | } | 1401 | } |
1402 | 1402 | ||
@@ -1513,13 +1513,13 @@ static void set_pixel_conversion(VncState *vs) | @@ -1513,13 +1513,13 @@ static void set_pixel_conversion(VncState *vs) | ||
1513 | } | 1513 | } |
1514 | 1514 | ||
1515 | static void set_pixel_format(VncState *vs, | 1515 | static void set_pixel_format(VncState *vs, |
1516 | - int bits_per_pixel, int depth, | ||
1517 | - int big_endian_flag, int true_color_flag, | ||
1518 | - int red_max, int green_max, int blue_max, | ||
1519 | - int red_shift, int green_shift, int blue_shift) | 1516 | + int bits_per_pixel, int depth, |
1517 | + int big_endian_flag, int true_color_flag, | ||
1518 | + int red_max, int green_max, int blue_max, | ||
1519 | + int red_shift, int green_shift, int blue_shift) | ||
1520 | { | 1520 | { |
1521 | if (!true_color_flag) { | 1521 | if (!true_color_flag) { |
1522 | - vnc_client_error(vs); | 1522 | + vnc_client_error(vs); |
1523 | return; | 1523 | return; |
1524 | } | 1524 | } |
1525 | 1525 | ||
@@ -1606,65 +1606,65 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) | @@ -1606,65 +1606,65 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) | ||
1606 | 1606 | ||
1607 | switch (data[0]) { | 1607 | switch (data[0]) { |
1608 | case 0: | 1608 | case 0: |
1609 | - if (len == 1) | ||
1610 | - return 20; | ||
1611 | - | ||
1612 | - set_pixel_format(vs, read_u8(data, 4), read_u8(data, 5), | ||
1613 | - read_u8(data, 6), read_u8(data, 7), | ||
1614 | - read_u16(data, 8), read_u16(data, 10), | ||
1615 | - read_u16(data, 12), read_u8(data, 14), | ||
1616 | - read_u8(data, 15), read_u8(data, 16)); | ||
1617 | - break; | 1609 | + if (len == 1) |
1610 | + return 20; | ||
1611 | + | ||
1612 | + set_pixel_format(vs, read_u8(data, 4), read_u8(data, 5), | ||
1613 | + read_u8(data, 6), read_u8(data, 7), | ||
1614 | + read_u16(data, 8), read_u16(data, 10), | ||
1615 | + read_u16(data, 12), read_u8(data, 14), | ||
1616 | + read_u8(data, 15), read_u8(data, 16)); | ||
1617 | + break; | ||
1618 | case 2: | 1618 | case 2: |
1619 | - if (len == 1) | ||
1620 | - return 4; | 1619 | + if (len == 1) |
1620 | + return 4; | ||
1621 | 1621 | ||
1622 | - if (len == 4) { | 1622 | + if (len == 4) { |
1623 | limit = read_u16(data, 2); | 1623 | limit = read_u16(data, 2); |
1624 | if (limit > 0) | 1624 | if (limit > 0) |
1625 | return 4 + (limit * 4); | 1625 | return 4 + (limit * 4); |
1626 | } else | 1626 | } else |
1627 | limit = read_u16(data, 2); | 1627 | limit = read_u16(data, 2); |
1628 | 1628 | ||
1629 | - for (i = 0; i < limit; i++) { | ||
1630 | - int32_t val = read_s32(data, 4 + (i * 4)); | ||
1631 | - memcpy(data + 4 + (i * 4), &val, sizeof(val)); | ||
1632 | - } | 1629 | + for (i = 0; i < limit; i++) { |
1630 | + int32_t val = read_s32(data, 4 + (i * 4)); | ||
1631 | + memcpy(data + 4 + (i * 4), &val, sizeof(val)); | ||
1632 | + } | ||
1633 | 1633 | ||
1634 | - set_encodings(vs, (int32_t *)(data + 4), limit); | ||
1635 | - break; | 1634 | + set_encodings(vs, (int32_t *)(data + 4), limit); |
1635 | + break; | ||
1636 | case 3: | 1636 | case 3: |
1637 | - if (len == 1) | ||
1638 | - return 10; | 1637 | + if (len == 1) |
1638 | + return 10; | ||
1639 | 1639 | ||
1640 | - framebuffer_update_request(vs, | ||
1641 | - read_u8(data, 1), read_u16(data, 2), read_u16(data, 4), | ||
1642 | - read_u16(data, 6), read_u16(data, 8)); | ||
1643 | - break; | 1640 | + framebuffer_update_request(vs, |
1641 | + read_u8(data, 1), read_u16(data, 2), read_u16(data, 4), | ||
1642 | + read_u16(data, 6), read_u16(data, 8)); | ||
1643 | + break; | ||
1644 | case 4: | 1644 | case 4: |
1645 | - if (len == 1) | ||
1646 | - return 8; | 1645 | + if (len == 1) |
1646 | + return 8; | ||
1647 | 1647 | ||
1648 | - key_event(vs, read_u8(data, 1), read_u32(data, 4)); | ||
1649 | - break; | 1648 | + key_event(vs, read_u8(data, 1), read_u32(data, 4)); |
1649 | + break; | ||
1650 | case 5: | 1650 | case 5: |
1651 | - if (len == 1) | ||
1652 | - return 6; | 1651 | + if (len == 1) |
1652 | + return 6; | ||
1653 | 1653 | ||
1654 | - pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4)); | ||
1655 | - break; | 1654 | + pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4)); |
1655 | + break; | ||
1656 | case 6: | 1656 | case 6: |
1657 | - if (len == 1) | ||
1658 | - return 8; | 1657 | + if (len == 1) |
1658 | + return 8; | ||
1659 | 1659 | ||
1660 | - if (len == 8) { | 1660 | + if (len == 8) { |
1661 | uint32_t dlen = read_u32(data, 4); | 1661 | uint32_t dlen = read_u32(data, 4); |
1662 | if (dlen > 0) | 1662 | if (dlen > 0) |
1663 | return 8 + dlen; | 1663 | return 8 + dlen; |
1664 | } | 1664 | } |
1665 | 1665 | ||
1666 | - client_cut_text(vs, read_u32(data, 4), data + 8); | ||
1667 | - break; | 1666 | + client_cut_text(vs, read_u32(data, 4), data + 8); |
1667 | + break; | ||
1668 | case 255: | 1668 | case 255: |
1669 | if (len == 1) | 1669 | if (len == 1) |
1670 | return 2; | 1670 | return 2; |
@@ -1726,9 +1726,9 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) | @@ -1726,9 +1726,9 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) | ||
1726 | } | 1726 | } |
1727 | break; | 1727 | break; |
1728 | default: | 1728 | default: |
1729 | - printf("Msg: %d\n", data[0]); | ||
1730 | - vnc_client_error(vs); | ||
1731 | - break; | 1729 | + printf("Msg: %d\n", data[0]); |
1730 | + vnc_client_error(vs); | ||
1731 | + break; | ||
1732 | } | 1732 | } |
1733 | 1733 | ||
1734 | vnc_read_when(vs, protocol_client_msg, 1); | 1734 | vnc_read_when(vs, protocol_client_msg, 1); |
@@ -1781,16 +1781,16 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) | @@ -1781,16 +1781,16 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) | ||
1781 | unsigned char key[8]; | 1781 | unsigned char key[8]; |
1782 | 1782 | ||
1783 | if (!vs->vd->password || !vs->vd->password[0]) { | 1783 | if (!vs->vd->password || !vs->vd->password[0]) { |
1784 | - VNC_DEBUG("No password configured on server"); | ||
1785 | - vnc_write_u32(vs, 1); /* Reject auth */ | ||
1786 | - if (vs->minor >= 8) { | ||
1787 | - static const char err[] = "Authentication failed"; | ||
1788 | - vnc_write_u32(vs, sizeof(err)); | ||
1789 | - vnc_write(vs, err, sizeof(err)); | ||
1790 | - } | ||
1791 | - vnc_flush(vs); | ||
1792 | - vnc_client_error(vs); | ||
1793 | - return 0; | 1784 | + VNC_DEBUG("No password configured on server"); |
1785 | + vnc_write_u32(vs, 1); /* Reject auth */ | ||
1786 | + if (vs->minor >= 8) { | ||
1787 | + static const char err[] = "Authentication failed"; | ||
1788 | + vnc_write_u32(vs, sizeof(err)); | ||
1789 | + vnc_write(vs, err, sizeof(err)); | ||
1790 | + } | ||
1791 | + vnc_flush(vs); | ||
1792 | + vnc_client_error(vs); | ||
1793 | + return 0; | ||
1794 | } | 1794 | } |
1795 | 1795 | ||
1796 | memcpy(response, vs->challenge, VNC_AUTH_CHALLENGE_SIZE); | 1796 | memcpy(response, vs->challenge, VNC_AUTH_CHALLENGE_SIZE); |
@@ -1805,19 +1805,19 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) | @@ -1805,19 +1805,19 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) | ||
1805 | 1805 | ||
1806 | /* Compare expected vs actual challenge response */ | 1806 | /* Compare expected vs actual challenge response */ |
1807 | if (memcmp(response, data, VNC_AUTH_CHALLENGE_SIZE) != 0) { | 1807 | if (memcmp(response, data, VNC_AUTH_CHALLENGE_SIZE) != 0) { |
1808 | - VNC_DEBUG("Client challenge reponse did not match\n"); | ||
1809 | - vnc_write_u32(vs, 1); /* Reject auth */ | ||
1810 | - if (vs->minor >= 8) { | ||
1811 | - static const char err[] = "Authentication failed"; | ||
1812 | - vnc_write_u32(vs, sizeof(err)); | ||
1813 | - vnc_write(vs, err, sizeof(err)); | ||
1814 | - } | ||
1815 | - vnc_flush(vs); | ||
1816 | - vnc_client_error(vs); | 1808 | + VNC_DEBUG("Client challenge reponse did not match\n"); |
1809 | + vnc_write_u32(vs, 1); /* Reject auth */ | ||
1810 | + if (vs->minor >= 8) { | ||
1811 | + static const char err[] = "Authentication failed"; | ||
1812 | + vnc_write_u32(vs, sizeof(err)); | ||
1813 | + vnc_write(vs, err, sizeof(err)); | ||
1814 | + } | ||
1815 | + vnc_flush(vs); | ||
1816 | + vnc_client_error(vs); | ||
1817 | } else { | 1817 | } else { |
1818 | - VNC_DEBUG("Accepting VNC challenge response\n"); | ||
1819 | - vnc_write_u32(vs, 0); /* Accept auth */ | ||
1820 | - vnc_flush(vs); | 1818 | + VNC_DEBUG("Accepting VNC challenge response\n"); |
1819 | + vnc_write_u32(vs, 0); /* Accept auth */ | ||
1820 | + vnc_flush(vs); | ||
1821 | 1821 | ||
1822 | start_client_init(vs); | 1822 | start_client_init(vs); |
1823 | } | 1823 | } |
@@ -1901,35 +1901,35 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len) | @@ -1901,35 +1901,35 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len) | ||
1901 | local[12] = 0; | 1901 | local[12] = 0; |
1902 | 1902 | ||
1903 | if (sscanf(local, "RFB %03d.%03d\n", &vs->major, &vs->minor) != 2) { | 1903 | if (sscanf(local, "RFB %03d.%03d\n", &vs->major, &vs->minor) != 2) { |
1904 | - VNC_DEBUG("Malformed protocol version %s\n", local); | ||
1905 | - vnc_client_error(vs); | ||
1906 | - return 0; | 1904 | + VNC_DEBUG("Malformed protocol version %s\n", local); |
1905 | + vnc_client_error(vs); | ||
1906 | + return 0; | ||
1907 | } | 1907 | } |
1908 | VNC_DEBUG("Client request protocol version %d.%d\n", vs->major, vs->minor); | 1908 | VNC_DEBUG("Client request protocol version %d.%d\n", vs->major, vs->minor); |
1909 | if (vs->major != 3 || | 1909 | if (vs->major != 3 || |
1910 | - (vs->minor != 3 && | ||
1911 | - vs->minor != 4 && | ||
1912 | - vs->minor != 5 && | ||
1913 | - vs->minor != 7 && | ||
1914 | - vs->minor != 8)) { | ||
1915 | - VNC_DEBUG("Unsupported client version\n"); | ||
1916 | - vnc_write_u32(vs, VNC_AUTH_INVALID); | ||
1917 | - vnc_flush(vs); | ||
1918 | - vnc_client_error(vs); | ||
1919 | - return 0; | 1910 | + (vs->minor != 3 && |
1911 | + vs->minor != 4 && | ||
1912 | + vs->minor != 5 && | ||
1913 | + vs->minor != 7 && | ||
1914 | + vs->minor != 8)) { | ||
1915 | + VNC_DEBUG("Unsupported client version\n"); | ||
1916 | + vnc_write_u32(vs, VNC_AUTH_INVALID); | ||
1917 | + vnc_flush(vs); | ||
1918 | + vnc_client_error(vs); | ||
1919 | + return 0; | ||
1920 | } | 1920 | } |
1921 | /* Some broken clients report v3.4 or v3.5, which spec requires to be treated | 1921 | /* Some broken clients report v3.4 or v3.5, which spec requires to be treated |
1922 | * as equivalent to v3.3 by servers | 1922 | * as equivalent to v3.3 by servers |
1923 | */ | 1923 | */ |
1924 | if (vs->minor == 4 || vs->minor == 5) | 1924 | if (vs->minor == 4 || vs->minor == 5) |
1925 | - vs->minor = 3; | 1925 | + vs->minor = 3; |
1926 | 1926 | ||
1927 | if (vs->minor == 3) { | 1927 | if (vs->minor == 3) { |
1928 | - if (vs->vd->auth == VNC_AUTH_NONE) { | 1928 | + if (vs->vd->auth == VNC_AUTH_NONE) { |
1929 | VNC_DEBUG("Tell client auth none\n"); | 1929 | VNC_DEBUG("Tell client auth none\n"); |
1930 | vnc_write_u32(vs, vs->vd->auth); | 1930 | vnc_write_u32(vs, vs->vd->auth); |
1931 | vnc_flush(vs); | 1931 | vnc_flush(vs); |
1932 | - start_client_init(vs); | 1932 | + start_client_init(vs); |
1933 | } else if (vs->vd->auth == VNC_AUTH_VNC) { | 1933 | } else if (vs->vd->auth == VNC_AUTH_VNC) { |
1934 | VNC_DEBUG("Tell client VNC auth\n"); | 1934 | VNC_DEBUG("Tell client VNC auth\n"); |
1935 | vnc_write_u32(vs, vs->vd->auth); | 1935 | vnc_write_u32(vs, vs->vd->auth); |
@@ -1942,11 +1942,11 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len) | @@ -1942,11 +1942,11 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len) | ||
1942 | vnc_client_error(vs); | 1942 | vnc_client_error(vs); |
1943 | } | 1943 | } |
1944 | } else { | 1944 | } else { |
1945 | - VNC_DEBUG("Telling client we support auth %d\n", vs->vd->auth); | ||
1946 | - vnc_write_u8(vs, 1); /* num auth */ | ||
1947 | - vnc_write_u8(vs, vs->vd->auth); | ||
1948 | - vnc_read_when(vs, protocol_client_auth, 1); | ||
1949 | - vnc_flush(vs); | 1945 | + VNC_DEBUG("Telling client we support auth %d\n", vs->vd->auth); |
1946 | + vnc_write_u8(vs, 1); /* num auth */ | ||
1947 | + vnc_write_u8(vs, vs->vd->auth); | ||
1948 | + vnc_read_when(vs, protocol_client_auth, 1); | ||
1949 | + vnc_flush(vs); | ||
1950 | } | 1950 | } |
1951 | 1951 | ||
1952 | return 0; | 1952 | return 0; |
@@ -2022,7 +2022,7 @@ void vnc_display_init(DisplayState *ds) | @@ -2022,7 +2022,7 @@ void vnc_display_init(DisplayState *ds) | ||
2022 | vs->kbd_layout = init_keyboard_layout(name2keysym, "en-us"); | 2022 | vs->kbd_layout = init_keyboard_layout(name2keysym, "en-us"); |
2023 | 2023 | ||
2024 | if (!vs->kbd_layout) | 2024 | if (!vs->kbd_layout) |
2025 | - exit(1); | 2025 | + exit(1); |
2026 | 2026 | ||
2027 | dcl->dpy_copy = vnc_dpy_copy; | 2027 | dcl->dpy_copy = vnc_dpy_copy; |
2028 | dcl->dpy_update = vnc_dpy_update; | 2028 | dcl->dpy_update = vnc_dpy_update; |
@@ -2039,13 +2039,13 @@ void vnc_display_close(DisplayState *ds) | @@ -2039,13 +2039,13 @@ void vnc_display_close(DisplayState *ds) | ||
2039 | if (!vs) | 2039 | if (!vs) |
2040 | return; | 2040 | return; |
2041 | if (vs->display) { | 2041 | if (vs->display) { |
2042 | - qemu_free(vs->display); | ||
2043 | - vs->display = NULL; | 2042 | + qemu_free(vs->display); |
2043 | + vs->display = NULL; | ||
2044 | } | 2044 | } |
2045 | if (vs->lsock != -1) { | 2045 | if (vs->lsock != -1) { |
2046 | - qemu_set_fd_handler2(vs->lsock, NULL, NULL, NULL, NULL); | ||
2047 | - close(vs->lsock); | ||
2048 | - vs->lsock = -1; | 2046 | + qemu_set_fd_handler2(vs->lsock, NULL, NULL, NULL, NULL); |
2047 | + close(vs->lsock); | ||
2048 | + vs->lsock = -1; | ||
2049 | } | 2049 | } |
2050 | vs->auth = VNC_AUTH_INVALID; | 2050 | vs->auth = VNC_AUTH_INVALID; |
2051 | #ifdef CONFIG_VNC_TLS | 2051 | #ifdef CONFIG_VNC_TLS |
@@ -2059,12 +2059,12 @@ int vnc_display_password(DisplayState *ds, const char *password) | @@ -2059,12 +2059,12 @@ int vnc_display_password(DisplayState *ds, const char *password) | ||
2059 | VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display; | 2059 | VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display; |
2060 | 2060 | ||
2061 | if (vs->password) { | 2061 | if (vs->password) { |
2062 | - qemu_free(vs->password); | ||
2063 | - vs->password = NULL; | 2062 | + qemu_free(vs->password); |
2063 | + vs->password = NULL; | ||
2064 | } | 2064 | } |
2065 | if (password && password[0]) { | 2065 | if (password && password[0]) { |
2066 | - if (!(vs->password = qemu_strdup(password))) | ||
2067 | - return -1; | 2066 | + if (!(vs->password = qemu_strdup(password))) |
2067 | + return -1; | ||
2068 | } | 2068 | } |
2069 | 2069 | ||
2070 | return 0; | 2070 | return 0; |
@@ -2090,76 +2090,76 @@ int vnc_display_open(DisplayState *ds, const char *display) | @@ -2090,76 +2090,76 @@ int vnc_display_open(DisplayState *ds, const char *display) | ||
2090 | return -1; | 2090 | return -1; |
2091 | vnc_display_close(ds); | 2091 | vnc_display_close(ds); |
2092 | if (strcmp(display, "none") == 0) | 2092 | if (strcmp(display, "none") == 0) |
2093 | - return 0; | 2093 | + return 0; |
2094 | 2094 | ||
2095 | if (!(vs->display = strdup(display))) | 2095 | if (!(vs->display = strdup(display))) |
2096 | - return -1; | 2096 | + return -1; |
2097 | 2097 | ||
2098 | options = display; | 2098 | options = display; |
2099 | while ((options = strchr(options, ','))) { | 2099 | while ((options = strchr(options, ','))) { |
2100 | - options++; | ||
2101 | - if (strncmp(options, "password", 8) == 0) { | ||
2102 | - password = 1; /* Require password auth */ | ||
2103 | - } else if (strncmp(options, "reverse", 7) == 0) { | ||
2104 | - reverse = 1; | ||
2105 | - } else if (strncmp(options, "to=", 3) == 0) { | 2100 | + options++; |
2101 | + if (strncmp(options, "password", 8) == 0) { | ||
2102 | + password = 1; /* Require password auth */ | ||
2103 | + } else if (strncmp(options, "reverse", 7) == 0) { | ||
2104 | + reverse = 1; | ||
2105 | + } else if (strncmp(options, "to=", 3) == 0) { | ||
2106 | to_port = atoi(options+3) + 5900; | 2106 | to_port = atoi(options+3) + 5900; |
2107 | #ifdef CONFIG_VNC_SASL | 2107 | #ifdef CONFIG_VNC_SASL |
2108 | - } else if (strncmp(options, "sasl", 4) == 0) { | ||
2109 | - sasl = 1; /* Require SASL auth */ | 2108 | + } else if (strncmp(options, "sasl", 4) == 0) { |
2109 | + sasl = 1; /* Require SASL auth */ | ||
2110 | #endif | 2110 | #endif |
2111 | #ifdef CONFIG_VNC_TLS | 2111 | #ifdef CONFIG_VNC_TLS |
2112 | - } else if (strncmp(options, "tls", 3) == 0) { | ||
2113 | - tls = 1; /* Require TLS */ | ||
2114 | - } else if (strncmp(options, "x509", 4) == 0) { | ||
2115 | - char *start, *end; | ||
2116 | - x509 = 1; /* Require x509 certificates */ | ||
2117 | - if (strncmp(options, "x509verify", 10) == 0) | ||
2118 | - vs->tls.x509verify = 1; /* ...and verify client certs */ | ||
2119 | - | ||
2120 | - /* Now check for 'x509=/some/path' postfix | ||
2121 | - * and use that to setup x509 certificate/key paths */ | ||
2122 | - start = strchr(options, '='); | ||
2123 | - end = strchr(options, ','); | ||
2124 | - if (start && (!end || (start < end))) { | ||
2125 | - int len = end ? end-(start+1) : strlen(start+1); | ||
2126 | - char *path = qemu_strndup(start + 1, len); | ||
2127 | - | ||
2128 | - VNC_DEBUG("Trying certificate path '%s'\n", path); | ||
2129 | - if (vnc_tls_set_x509_creds_dir(vs, path) < 0) { | ||
2130 | - fprintf(stderr, "Failed to find x509 certificates/keys in %s\n", path); | ||
2131 | - qemu_free(path); | ||
2132 | - qemu_free(vs->display); | ||
2133 | - vs->display = NULL; | ||
2134 | - return -1; | ||
2135 | - } | ||
2136 | - qemu_free(path); | ||
2137 | - } else { | ||
2138 | - fprintf(stderr, "No certificate path provided\n"); | ||
2139 | - qemu_free(vs->display); | ||
2140 | - vs->display = NULL; | ||
2141 | - return -1; | ||
2142 | - } | 2112 | + } else if (strncmp(options, "tls", 3) == 0) { |
2113 | + tls = 1; /* Require TLS */ | ||
2114 | + } else if (strncmp(options, "x509", 4) == 0) { | ||
2115 | + char *start, *end; | ||
2116 | + x509 = 1; /* Require x509 certificates */ | ||
2117 | + if (strncmp(options, "x509verify", 10) == 0) | ||
2118 | + vs->tls.x509verify = 1; /* ...and verify client certs */ | ||
2119 | + | ||
2120 | + /* Now check for 'x509=/some/path' postfix | ||
2121 | + * and use that to setup x509 certificate/key paths */ | ||
2122 | + start = strchr(options, '='); | ||
2123 | + end = strchr(options, ','); | ||
2124 | + if (start && (!end || (start < end))) { | ||
2125 | + int len = end ? end-(start+1) : strlen(start+1); | ||
2126 | + char *path = qemu_strndup(start + 1, len); | ||
2127 | + | ||
2128 | + VNC_DEBUG("Trying certificate path '%s'\n", path); | ||
2129 | + if (vnc_tls_set_x509_creds_dir(vs, path) < 0) { | ||
2130 | + fprintf(stderr, "Failed to find x509 certificates/keys in %s\n", path); | ||
2131 | + qemu_free(path); | ||
2132 | + qemu_free(vs->display); | ||
2133 | + vs->display = NULL; | ||
2134 | + return -1; | ||
2135 | + } | ||
2136 | + qemu_free(path); | ||
2137 | + } else { | ||
2138 | + fprintf(stderr, "No certificate path provided\n"); | ||
2139 | + qemu_free(vs->display); | ||
2140 | + vs->display = NULL; | ||
2141 | + return -1; | ||
2142 | + } | ||
2143 | #endif | 2143 | #endif |
2144 | - } else if (strncmp(options, "acl", 3) == 0) { | ||
2145 | - acl = 1; | ||
2146 | - } | 2144 | + } else if (strncmp(options, "acl", 3) == 0) { |
2145 | + acl = 1; | ||
2146 | + } | ||
2147 | } | 2147 | } |
2148 | 2148 | ||
2149 | #ifdef CONFIG_VNC_TLS | 2149 | #ifdef CONFIG_VNC_TLS |
2150 | if (acl && x509 && vs->tls.x509verify) { | 2150 | if (acl && x509 && vs->tls.x509verify) { |
2151 | - if (!(vs->tls.acl = qemu_acl_init("vnc.x509dname"))) { | ||
2152 | - fprintf(stderr, "Failed to create x509 dname ACL\n"); | ||
2153 | - exit(1); | ||
2154 | - } | 2151 | + if (!(vs->tls.acl = qemu_acl_init("vnc.x509dname"))) { |
2152 | + fprintf(stderr, "Failed to create x509 dname ACL\n"); | ||
2153 | + exit(1); | ||
2154 | + } | ||
2155 | } | 2155 | } |
2156 | #endif | 2156 | #endif |
2157 | #ifdef CONFIG_VNC_SASL | 2157 | #ifdef CONFIG_VNC_SASL |
2158 | if (acl && sasl) { | 2158 | if (acl && sasl) { |
2159 | - if (!(vs->sasl.acl = qemu_acl_init("vnc.username"))) { | ||
2160 | - fprintf(stderr, "Failed to create username ACL\n"); | ||
2161 | - exit(1); | ||
2162 | - } | 2159 | + if (!(vs->sasl.acl = qemu_acl_init("vnc.username"))) { |
2160 | + fprintf(stderr, "Failed to create username ACL\n"); | ||
2161 | + exit(1); | ||
2162 | + } | ||
2163 | } | 2163 | } |
2164 | #endif | 2164 | #endif |
2165 | 2165 | ||
@@ -2181,22 +2181,22 @@ int vnc_display_open(DisplayState *ds, const char *display) | @@ -2181,22 +2181,22 @@ int vnc_display_open(DisplayState *ds, const char *display) | ||
2181 | */ | 2181 | */ |
2182 | if (password) { | 2182 | if (password) { |
2183 | #ifdef CONFIG_VNC_TLS | 2183 | #ifdef CONFIG_VNC_TLS |
2184 | - if (tls) { | ||
2185 | - vs->auth = VNC_AUTH_VENCRYPT; | ||
2186 | - if (x509) { | ||
2187 | - VNC_DEBUG("Initializing VNC server with x509 password auth\n"); | ||
2188 | - vs->subauth = VNC_AUTH_VENCRYPT_X509VNC; | ||
2189 | - } else { | ||
2190 | - VNC_DEBUG("Initializing VNC server with TLS password auth\n"); | ||
2191 | - vs->subauth = VNC_AUTH_VENCRYPT_TLSVNC; | ||
2192 | - } | ||
2193 | - } else { | 2184 | + if (tls) { |
2185 | + vs->auth = VNC_AUTH_VENCRYPT; | ||
2186 | + if (x509) { | ||
2187 | + VNC_DEBUG("Initializing VNC server with x509 password auth\n"); | ||
2188 | + vs->subauth = VNC_AUTH_VENCRYPT_X509VNC; | ||
2189 | + } else { | ||
2190 | + VNC_DEBUG("Initializing VNC server with TLS password auth\n"); | ||
2191 | + vs->subauth = VNC_AUTH_VENCRYPT_TLSVNC; | ||
2192 | + } | ||
2193 | + } else { | ||
2194 | #endif /* CONFIG_VNC_TLS */ | 2194 | #endif /* CONFIG_VNC_TLS */ |
2195 | - VNC_DEBUG("Initializing VNC server with password auth\n"); | ||
2196 | - vs->auth = VNC_AUTH_VNC; | 2195 | + VNC_DEBUG("Initializing VNC server with password auth\n"); |
2196 | + vs->auth = VNC_AUTH_VNC; | ||
2197 | #ifdef CONFIG_VNC_TLS | 2197 | #ifdef CONFIG_VNC_TLS |
2198 | - vs->subauth = VNC_AUTH_INVALID; | ||
2199 | - } | 2198 | + vs->subauth = VNC_AUTH_INVALID; |
2199 | + } | ||
2200 | #endif /* CONFIG_VNC_TLS */ | 2200 | #endif /* CONFIG_VNC_TLS */ |
2201 | #ifdef CONFIG_VNC_SASL | 2201 | #ifdef CONFIG_VNC_SASL |
2202 | } else if (sasl) { | 2202 | } else if (sasl) { |
@@ -2204,15 +2204,15 @@ int vnc_display_open(DisplayState *ds, const char *display) | @@ -2204,15 +2204,15 @@ int vnc_display_open(DisplayState *ds, const char *display) | ||
2204 | if (tls) { | 2204 | if (tls) { |
2205 | vs->auth = VNC_AUTH_VENCRYPT; | 2205 | vs->auth = VNC_AUTH_VENCRYPT; |
2206 | if (x509) { | 2206 | if (x509) { |
2207 | - VNC_DEBUG("Initializing VNC server with x509 SASL auth\n"); | 2207 | + VNC_DEBUG("Initializing VNC server with x509 SASL auth\n"); |
2208 | vs->subauth = VNC_AUTH_VENCRYPT_X509SASL; | 2208 | vs->subauth = VNC_AUTH_VENCRYPT_X509SASL; |
2209 | } else { | 2209 | } else { |
2210 | - VNC_DEBUG("Initializing VNC server with TLS SASL auth\n"); | 2210 | + VNC_DEBUG("Initializing VNC server with TLS SASL auth\n"); |
2211 | vs->subauth = VNC_AUTH_VENCRYPT_TLSSASL; | 2211 | vs->subauth = VNC_AUTH_VENCRYPT_TLSSASL; |
2212 | } | 2212 | } |
2213 | } else { | 2213 | } else { |
2214 | #endif /* CONFIG_VNC_TLS */ | 2214 | #endif /* CONFIG_VNC_TLS */ |
2215 | - VNC_DEBUG("Initializing VNC server with SASL auth\n"); | 2215 | + VNC_DEBUG("Initializing VNC server with SASL auth\n"); |
2216 | vs->auth = VNC_AUTH_SASL; | 2216 | vs->auth = VNC_AUTH_SASL; |
2217 | #ifdef CONFIG_VNC_TLS | 2217 | #ifdef CONFIG_VNC_TLS |
2218 | vs->subauth = VNC_AUTH_INVALID; | 2218 | vs->subauth = VNC_AUTH_INVALID; |
@@ -2221,22 +2221,22 @@ int vnc_display_open(DisplayState *ds, const char *display) | @@ -2221,22 +2221,22 @@ int vnc_display_open(DisplayState *ds, const char *display) | ||
2221 | #endif /* CONFIG_VNC_SASL */ | 2221 | #endif /* CONFIG_VNC_SASL */ |
2222 | } else { | 2222 | } else { |
2223 | #ifdef CONFIG_VNC_TLS | 2223 | #ifdef CONFIG_VNC_TLS |
2224 | - if (tls) { | ||
2225 | - vs->auth = VNC_AUTH_VENCRYPT; | ||
2226 | - if (x509) { | ||
2227 | - VNC_DEBUG("Initializing VNC server with x509 no auth\n"); | ||
2228 | - vs->subauth = VNC_AUTH_VENCRYPT_X509NONE; | ||
2229 | - } else { | ||
2230 | - VNC_DEBUG("Initializing VNC server with TLS no auth\n"); | ||
2231 | - vs->subauth = VNC_AUTH_VENCRYPT_TLSNONE; | ||
2232 | - } | ||
2233 | - } else { | 2224 | + if (tls) { |
2225 | + vs->auth = VNC_AUTH_VENCRYPT; | ||
2226 | + if (x509) { | ||
2227 | + VNC_DEBUG("Initializing VNC server with x509 no auth\n"); | ||
2228 | + vs->subauth = VNC_AUTH_VENCRYPT_X509NONE; | ||
2229 | + } else { | ||
2230 | + VNC_DEBUG("Initializing VNC server with TLS no auth\n"); | ||
2231 | + vs->subauth = VNC_AUTH_VENCRYPT_TLSNONE; | ||
2232 | + } | ||
2233 | + } else { | ||
2234 | #endif | 2234 | #endif |
2235 | - VNC_DEBUG("Initializing VNC server with no auth\n"); | ||
2236 | - vs->auth = VNC_AUTH_NONE; | 2235 | + VNC_DEBUG("Initializing VNC server with no auth\n"); |
2236 | + vs->auth = VNC_AUTH_NONE; | ||
2237 | #ifdef CONFIG_VNC_TLS | 2237 | #ifdef CONFIG_VNC_TLS |
2238 | - vs->subauth = VNC_AUTH_INVALID; | ||
2239 | - } | 2238 | + vs->subauth = VNC_AUTH_INVALID; |
2239 | + } | ||
2240 | #endif | 2240 | #endif |
2241 | } | 2241 | } |
2242 | 2242 |