summaryrefslogtreecommitdiff
path: root/auth-options.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-09-03 08:32:11 +0000
committerDamien Miller <djm@mindrot.org>2019-09-03 18:39:31 +1000
commit5485f8d50a5bc46aeed829075ebf5d9c617027ea (patch)
treefaaa341e91f2e3006af62927fe484ab09fbc5b79 /auth-options.c
parentf8df0413f0a057b6a3d3dd7bd8bc7c5d80911d3a (diff)
upstream: move authorized_keys option parsing helpsers to misc.c
and make them public; ok markus@ OpenBSD-Commit-ID: c18bcb2a687227b3478377c981c2d56af2638ea2
Diffstat (limited to 'auth-options.c')
-rw-r--r--auth-options.c71
1 files changed, 1 insertions, 70 deletions
diff --git a/auth-options.c b/auth-options.c
index ca92f7a73..ac362e271 100644
--- a/auth-options.c
+++ b/auth-options.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth-options.c,v 1.86 2019/07/09 04:15:00 djm Exp $ */ 1/* $OpenBSD: auth-options.c,v 1.87 2019/09/03 08:32:11 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2018 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2018 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -40,75 +40,6 @@
40#include "ssh2.h" 40#include "ssh2.h"
41#include "auth-options.h" 41#include "auth-options.h"
42 42
43/*
44 * Match flag 'opt' in *optsp, and if allow_negate is set then also match
45 * 'no-opt'. Returns -1 if option not matched, 1 if option matches or 0
46 * if negated option matches.
47 * If the option or negated option matches, then *optsp is updated to
48 * point to the first character after the option.
49 */
50static int
51opt_flag(const char *opt, int allow_negate, const char **optsp)
52{
53 size_t opt_len = strlen(opt);
54 const char *opts = *optsp;
55 int negate = 0;
56
57 if (allow_negate && strncasecmp(opts, "no-", 3) == 0) {
58 opts += 3;
59 negate = 1;
60 }
61 if (strncasecmp(opts, opt, opt_len) == 0) {
62 *optsp = opts + opt_len;
63 return negate ? 0 : 1;
64 }
65 return -1;
66}
67
68static char *
69opt_dequote(const char **sp, const char **errstrp)
70{
71 const char *s = *sp;
72 char *ret;
73 size_t i;
74
75 *errstrp = NULL;
76 if (*s != '"') {
77 *errstrp = "missing start quote";
78 return NULL;
79 }
80 s++;
81 if ((ret = malloc(strlen((s)) + 1)) == NULL) {
82 *errstrp = "memory allocation failed";
83 return NULL;
84 }
85 for (i = 0; *s != '\0' && *s != '"';) {
86 if (s[0] == '\\' && s[1] == '"')
87 s++;
88 ret[i++] = *s++;
89 }
90 if (*s == '\0') {
91 *errstrp = "missing end quote";
92 free(ret);
93 return NULL;
94 }
95 ret[i] = '\0';
96 s++;
97 *sp = s;
98 return ret;
99}
100
101static int
102opt_match(const char **opts, const char *term)
103{
104 if (strncasecmp((*opts), term, strlen(term)) == 0 &&
105 (*opts)[strlen(term)] == '=') {
106 *opts += strlen(term) + 1;
107 return 1;
108 }
109 return 0;
110}
111
112static int 43static int
113dup_strings(char ***dstp, size_t *ndstp, char **src, size_t nsrc) 44dup_strings(char ***dstp, size_t *ndstp, char **src, size_t nsrc)
114{ 45{