summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2021-01-25 23:52:54 +0300
committerdefanor <defanor@uberspace.net>2021-01-25 23:52:54 +0300
commit8dd0fd4acbcf489f4040da6db6d211a598ac7b2c (patch)
tree0f63dbdd3590d08a3d9ea6fc0da5c8e951006802 /examples
parentf353b222dcb12ad1b1335c691508dc11da0abf9a (diff)
Use getline(3) for examples/basic.c password reading
It's not great, but a little less awkward than gets(3). May be nicer to use pinentry, or at least to disable echoing, but those come with additional dependencies, which are undesirable for a basic example.
Diffstat (limited to 'examples')
-rw-r--r--examples/basic.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/examples/basic.c b/examples/basic.c
index cd3d6e3..123225a 100644
--- a/examples/basic.c
+++ b/examples/basic.c
@@ -30,10 +30,17 @@ void my_logger (rexmpp_t *s, int priority, const char *fmt, va_list args) {
initial JID. */
int my_sasl_property_cb (rexmpp_t *s, Gsasl_property prop) {
if (prop == GSASL_PASSWORD) {
- char buf[4096];
+ char *buf = NULL;
+ size_t buf_len = 4096;
printf("password: ");
- gets(buf);
- gsasl_property_set (s->sasl_session, GSASL_PASSWORD, buf);
+ getline(&buf, &buf_len, stdin);
+ if (buf != NULL) {
+ if (buf[strlen(buf) - 1] == '\n') {
+ buf[strlen(buf) - 1] = '\0';
+ }
+ gsasl_property_set (s->sasl_session, GSASL_PASSWORD, buf);
+ free(buf);
+ }
return GSASL_OK;
}
if (prop == GSASL_AUTHID) {