2010-02-20 09:41:49 -05:00
|
|
|
/*
|
2019-04-29 07:21:51 -06:00
|
|
|
* SPDX-License-Identifier: ISC
|
|
|
|
*
|
2017-12-03 17:53:40 -07:00
|
|
|
* Copyright (c) 2010-2012, 2014-2015 Todd C. Miller <Todd.Miller@sudo.ws>
|
2010-02-20 09:41:49 -05:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2018-10-26 08:39:09 -06:00
|
|
|
/*
|
|
|
|
* This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
|
|
|
* PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
|
|
|
*/
|
2018-10-21 08:46:05 -06:00
|
|
|
|
2010-02-20 09:41:49 -05:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-06-19 14:29:27 -06:00
|
|
|
#include <stdlib.h>
|
2010-02-20 09:41:49 -05:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif /* HAVE_STRING_H */
|
2010-06-29 13:08:05 -04:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif /* HAVE_STRINGS_H */
|
2010-02-20 09:41:49 -05:00
|
|
|
|
2014-07-22 14:25:16 -06:00
|
|
|
#include "sudo_compat.h"
|
2011-10-22 14:40:21 -04:00
|
|
|
#include "sudo_debug.h"
|
2013-12-12 18:29:07 -07:00
|
|
|
#include "sudo_util.h"
|
2010-02-20 09:41:49 -05:00
|
|
|
|
|
|
|
/*
|
2014-06-26 15:51:15 -06:00
|
|
|
* Create a new key=value pair and return it.
|
|
|
|
* The caller is responsible for freeing the string.
|
2010-02-20 09:41:49 -05:00
|
|
|
*/
|
|
|
|
char *
|
2014-07-22 11:26:17 -06:00
|
|
|
sudo_new_key_val_v1(const char *key, const char *val)
|
2010-02-20 09:41:49 -05:00
|
|
|
{
|
2014-06-26 15:51:15 -06:00
|
|
|
size_t key_len = strlen(key);
|
2010-02-20 09:41:49 -05:00
|
|
|
size_t val_len = strlen(val);
|
|
|
|
char *cp, *str;
|
2015-02-01 08:24:49 -07:00
|
|
|
debug_decl(sudo_new_key_val, SUDO_DEBUG_UTIL)
|
2010-02-20 09:41:49 -05:00
|
|
|
|
2014-06-26 15:51:15 -06:00
|
|
|
cp = str = malloc(key_len + 1 + val_len + 1);
|
2018-10-19 13:35:20 -06:00
|
|
|
if (cp != NULL) {
|
2014-06-26 15:51:15 -06:00
|
|
|
memcpy(cp, key, key_len);
|
|
|
|
cp += key_len;
|
2010-03-06 14:29:04 -05:00
|
|
|
*cp++ = '=';
|
|
|
|
memcpy(cp, val, val_len);
|
|
|
|
cp += val_len;
|
|
|
|
*cp = '\0';
|
|
|
|
}
|
2010-02-20 09:41:49 -05:00
|
|
|
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_str(str);
|
2010-02-20 09:41:49 -05:00
|
|
|
}
|