user.h (3297B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#ifndef GUAC_COMMON_SSH_USER_H 21#define GUAC_COMMON_SSH_USER_H 22 23#include "key.h" 24 25/** 26 * Data describing an SSH user, including their credentials. 27 */ 28typedef struct guac_common_ssh_user { 29 30 /** 31 * The username of this user. 32 */ 33 char* username; 34 35 /** 36 * The password which should be used to authenticate this user, if any, or 37 * NULL if a private key will be used instead. 38 */ 39 char* password; 40 41 /** 42 * The private key which should be used to authenticate this user, if any, 43 * or NULL if a password will be used instead. 44 */ 45 guac_common_ssh_key* private_key; 46 47} guac_common_ssh_user; 48 49/** 50 * Creates a new SSH user with the given username. When additionally populated 51 * with a password or private key, this user can then be used for 52 * authentication. 53 * 54 * @param username 55 * The username of the user being created. 56 * 57 * @return 58 * A new SSH user having the given username, but no associated password 59 * or private key. 60 */ 61guac_common_ssh_user* guac_common_ssh_create_user(const char* username); 62 63/** 64 * Destroys the given user object, releasing all associated resources. 65 * 66 * @param user 67 * The user to destroy. 68 */ 69void guac_common_ssh_destroy_user(guac_common_ssh_user* user); 70 71/** 72 * Associates the given user with the given password, such that that password 73 * is used for future authentication attempts. 74 * 75 * @param user 76 * The user to associate with the given password. 77 * 78 * @param password 79 * The password to associate with the given user. 80 */ 81void guac_common_ssh_user_set_password(guac_common_ssh_user* user, 82 const char* password); 83 84/** 85 * Imports the given private key, associating that key with the given user. If 86 * necessary to decrypt the key, a passphrase may be specified. The private key 87 * must be provided in base64 form. If the private key is imported 88 * successfully, it will be used for future authentication attempts. 89 * 90 * @param user 91 * The user to associate with the given private key. 92 * 93 * @param private_key 94 * The base64-encoded private key to import. 95 * 96 * @param passphrase 97 * The passphrase to use to decrypt the given private key, or NULL if no 98 * passphrase should be used. 99 * 100 * @return 101 * Zero if the private key is successfully imported, or non-zero if the 102 * private key could not be imported due to an error. 103 */ 104int guac_common_ssh_user_import_key(guac_common_ssh_user* user, 105 char* private_key, char* passphrase); 106 107#endif 108