The SSH_PUBLIC_KEY line in OpenNebula's context can span multiple lines
This commit is contained in:
parent
0509d8d619
commit
99f8b2d2b0
1 changed files with 52 additions and 5 deletions
|
@ -34,6 +34,7 @@ opennebula(struct system_config *sc)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
const char *delim = "\\\\\0", *errstr;
|
const char *delim = "\\\\\0", *errstr;
|
||||||
char *line = NULL, *k, *v, *p, q;
|
char *line = NULL, *k, *v, *p, q;
|
||||||
|
char *value = NULL, *next = NULL, *last;
|
||||||
char *hname = NULL;
|
char *hname = NULL;
|
||||||
size_t len, lineno = 0, i;
|
size_t len, lineno = 0, i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
@ -72,19 +73,54 @@ opennebula(struct system_config *sc)
|
||||||
|
|
||||||
/* value is quoted */
|
/* value is quoted */
|
||||||
q = *v;
|
q = *v;
|
||||||
if (strspn(v, "\"'") == 0 || (p = strrchr(v, q)) == v) {
|
if (strspn(v, "\"'") == 0) {
|
||||||
free(line);
|
free(line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*v++ = '\0';
|
*v++ = '\0';
|
||||||
|
|
||||||
|
/* quoted value can be continued on multiple lines */
|
||||||
|
if ((value = strdup("")) == NULL) {
|
||||||
|
log_debug("%s: strdup", __func__);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
next = v;
|
||||||
|
do {
|
||||||
|
if ((p = strrchr(next, q)) != NULL)
|
||||||
|
*p++ = '\0';
|
||||||
|
if (*next) {
|
||||||
|
last = value;
|
||||||
|
if (asprintf(&value, "%s%s\n",
|
||||||
|
last, next) == -1) {
|
||||||
|
log_debug("%s: asprintf", __func__);
|
||||||
|
if (next != v)
|
||||||
|
free(next);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
free(last);
|
||||||
|
}
|
||||||
|
if (next != v)
|
||||||
|
free(next);
|
||||||
|
} while (p == NULL &&
|
||||||
|
(next = fparseln(fp, &len, &lineno,
|
||||||
|
delim, FPARSELN_UNESCALL)) != NULL);
|
||||||
|
next = NULL;
|
||||||
|
v = value;
|
||||||
|
|
||||||
|
/* strip trailing newline */
|
||||||
|
if ((p = strrchr(v, '\n')) != NULL)
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
/* continue if value is empty */
|
/* continue if value is empty */
|
||||||
if (*v == '\0') {
|
if (*v == '\0') {
|
||||||
free(line);
|
free(line);
|
||||||
|
free(value);
|
||||||
|
value = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* print key/value unless it is a multi-line value */
|
||||||
|
if (strcasecmp("SSH_PUBLIC_KEY", k) != 0)
|
||||||
log_debug("%s: %s = %s", __func__, k, v);
|
log_debug("%s: %s = %s", __func__, k, v);
|
||||||
|
|
||||||
if (strcasecmp("NETWORK", k) == 0) {
|
if (strcasecmp("NETWORK", k) == 0) {
|
||||||
|
@ -178,11 +214,21 @@ opennebula(struct system_config *sc)
|
||||||
if ((hname = strdup(v)) == NULL)
|
if ((hname = strdup(v)) == NULL)
|
||||||
log_warnx("failed to set hostname");
|
log_warnx("failed to set hostname");
|
||||||
} else if (strcasecmp("SSH_PUBLIC_KEY", k) == 0) {
|
} else if (strcasecmp("SSH_PUBLIC_KEY", k) == 0) {
|
||||||
if (agent_addpubkey(sc, v, NULL) != 0)
|
do {
|
||||||
|
p = v + strcspn(v, "\n");
|
||||||
|
*p++ = '\0';
|
||||||
|
if (*v)
|
||||||
|
log_debug("%s: %s = %s",
|
||||||
|
__func__, k, v);
|
||||||
|
if (*v && agent_addpubkey(sc, v, NULL) != 0)
|
||||||
log_warnx("failed to set ssh pubkey");
|
log_warnx("failed to set ssh pubkey");
|
||||||
|
v = p + strspn(p, "\n");
|
||||||
|
} while (*v != '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
|
free(value);
|
||||||
|
value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -216,5 +262,6 @@ opennebula(struct system_config *sc)
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
free(line);
|
free(line);
|
||||||
|
free(value);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue