-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathserver_config.h
More file actions
1513 lines (1390 loc) · 75.4 KB
/
Copy pathserver_config.h
File metadata and controls
1513 lines (1390 loc) · 75.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file server_config.h
* @author Roman Janota <janota@cesnet.cz>
* @brief libnetconf2 server configuration
*
* @copyright
* Copyright (c) 2023 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*/
#ifndef NC_CONFIG_SERVER_H_
#define NC_CONFIG_SERVER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
#include <stdint.h>
#include <libyang/libyang.h>
#include "session.h"
/**
* @defgroup server_config Server Configuration
* @ingroup server
*
* @brief Server-side configuration creation and application
* @{
*/
/**
* @} Server Configuration
*/
/**
* @defgroup server_config_functions Server Configuration Functions
* @ingroup server_config
*
* @brief Server-side configuration functions
* @{
*/
/**
* @brief Implements all the required modules and their features in the context.
* Needs to be called before any other configuration functions.
*
* If ctx is :
* - NULL: a new context will be created and if the call is successful you have to free it,
* - non NULL: modules will simply be implemented.
*
* Implemented modules: ietf-netconf-server, ietf-x509-cert-to-name, ietf-crypto-types,
* ietf-tcp-common, ietf-ssh-common, iana-ssh-encryption-algs, iana-ssh-key-exchange-algs,
* iana-ssh-mac-algs, iana-ssh-public-key-algs, ietf-keystore, ietf-ssh-server, ietf-truststore,
* ietf-tls-server and libnetconf2-netconf-server.
*
* Note that the SSH authentication depends on the value of the 'local-users-supported' feature in the ietf-ssh-server module.
* If the feature, and its dependent if-features, are disabled, the SSH authentication will use the system users.
* Otherwise, the SSH authentication will use the local users from the configuration (the default).
*
* @param[in, out] ctx Optional context in which the modules will be implemented. Created if *ctx is null.
* @return 0 on success, 1 on error.
*/
int nc_server_config_load_modules(struct ly_ctx **ctx);
/**
* @brief Configure server based on the given diff.
*
* Context must already have implemented the required modules, see ::nc_server_config_load_modules().
*
* @note All the implicit nodes, such as non-presence containers and
* leafs with default values, must be present in the diff.
*
* @param[in] diff YANG diff belonging to either ietf-netconf-server, ietf-keystore or ietf-truststore modules.
* The top level node HAS to have an operation (create, replace, delete or none).
* @return 0 on success, 1 on error.
*/
int nc_server_config_setup_diff(const struct lyd_node *diff);
/**
* @brief Configure server based on the given data.
*
* The current configuration will be completely replaced by the given data.
*
* Context must already have implemented the required modules, see ::nc_server_config_load_modules().
*
* @note All the implicit nodes, such as non-presence containers and
* leafs with default values, must be present in the data.
*
* @param[in] data YANG data belonging to either ietf-netconf-server, ietf-keystore or ietf-truststore modules.
* This data __must be valid__. No node can have an operation attribute.
* @return 0 on success, 1 on error.
*/
int nc_server_config_setup_data(const struct lyd_node *data);
/**
* @brief Configure server based on the given data stored in a file.
*
* Wrapper around ::nc_server_config_setup_data() hiding work with parsing the data.
* Context must already have implemented the required modules, see ::nc_server_config_load_modules().
*
* @param[in] ctx libyang context.
* @param[in] path Path to a file with ietf-netconf-server, ietf-keystore or ietf-truststore YANG data.
* This data __must be valid__. No node can have an operation attribute.
* @return 0 on success, 1 on error.
*/
int nc_server_config_setup_path(const struct ly_ctx *ctx, const char *path);
#ifdef NC_ENABLED_SSH_TLS
/**
* @brief Creates new YANG configuration data nodes for address and port.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents might be changed.
* @param[in] transport Either SSH or TLS transport for the given endpoint.
* @param[in] address New listening address.
* @param[in] port New listening port.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_address_port(const struct ly_ctx *ctx, const char *endpt_name, NC_TRANSPORT_IMPL transport,
const char *address, uint16_t port, struct lyd_node **config);
#endif /* NC_ENABLED_SSH_TLS */
/**
* @brief Deletes an endpoint from the YANG data.
*
* @param[in] endpt_name Optional identifier of an endpoint to be deleted.
* If NULL, all of the endpoints will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_endpt(const char *endpt_name, struct lyd_node **config);
/**
* @brief Creates new YANG data nodes for a UNIX socket endpoint.
*
* To learn how authentication works, look at ::nc_server_config_add_unix_user_mapping().
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents might be changed.
* @param[in] path Path to the UNIX socket. The parent directory must be writable by the server process.
* @param[in] mode Optional UNIX socket file mode in octal format (e.g., "0777").
* If NULL, the default value ("0660") will be used.
* @param[in] owner Optional owner of the UNIX socket file.
* If NULL, the owner will be set to the user running the server process.
* @param[in] group Optional group of the UNIX socket file.
* If NULL, the group will be set to the group of the user running the server process.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*
*/
int nc_server_config_add_unix_socket(const struct ly_ctx *ctx, const char *endpt_name, const char *path,
const char *mode, const char *owner, const char *group, struct lyd_node **config);
/**
* @brief Creates new YANG data nodes for a UNIX username mapping.
*
* Specifies who can connect to a UNIX socket endpoint. There are 3 following scenarios:
*
* 1) If no mappings are configured for the client @p system_user, then the client can
* only connect if its username matches @p netconf_user.
*
* 2) If a mapping for the client @p system_user is configured, but no @p netconf_user s
* are specified, then the client cannot connect with any username.
*
* 3) If a mapping for the client @p system_user is configured, and at least one @p netconf_user
* is specified, then the client can connect only with one of the specified usernames.
* If a wildcard value "*" is configured for @p netconf_user, then the client can connect
* with any NETCONF username.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents might be changed.
* @param[in] system_user System user name, who the mapping will be created for.
* @param[in] netconf_user Username that the @p system_user can use to connect to the endpoint.
* Special value "*" can be used to allow any username.
* If NULL, empty mapping will be created, which means that the @p system_user
* can not connect to the endpoint with any username.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_unix_user_mapping(const struct ly_ctx *ctx, const char *endpt_name,
const char *system_user, const char *netconf_user, struct lyd_node **config);
/**
* @brief Deletes a UNIX username mapping from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] system_user Optional identifier of a system user whose mapping will be deleted.
* If NULL, all of the mappings for the endpoint will be deleted.
* @param[in,out] config Configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_unix_user_mapping(const char *endpt_name, const char *system_user,
struct lyd_node **config);
#ifdef NC_ENABLED_SSH_TLS
/**
* @brief Creates new YANG data nodes for an asymmetric key in the keystore.
*
* @param[in] ctx libyang context.
* @param[in] ti Transport in which the key pair will be used. Either SSH or TLS.
* @param[in] asym_key_name Identifier of the asymmetric key pair.
* This identifier is used to reference the key pair.
* @param[in] privkey_path Path to a private key file.
* @param[in] pubkey_path Optional path a public key file.
* If not supplied, it will be generated from the private key.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_keystore_asym_key(const struct ly_ctx *ctx, NC_TRANSPORT_IMPL ti, const char *asym_key_name,
const char *privkey_path, const char *pubkey_path, struct lyd_node **config);
/**
* @brief Deletes a keystore's asymmetric key from the YANG data.
*
* @param[in] asym_key_name Optional identifier of the asymmetric key to be deleted.
* If NULL, all of the asymmetric keys in the keystore will be deleted.
* @param[in,out] config Configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_keystore_asym_key(const char *asym_key_name, struct lyd_node **config);
/**
* @brief Creates new YANG data nodes for a certificate in the keystore.
*
* A certificate can not exist without its asymmetric key, so you must create an asymmetric key
* with the same identifier you pass to this function.
*
* @param[in] ctx libyang context.
* @param[in] asym_key_name Arbitrary identifier of the asymmetric key.
* If an asymmetric key pair with this name already exists, its contents will be changed.
* @param[in] cert_name Arbitrary identifier of the key pair's certificate.
* If a certificate with this name already exists, its contents will be changed.
* @param[in] cert_path Path to the PEM encoded certificate file.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_keystore_cert(const struct ly_ctx *ctx, const char *asym_key_name, const char *cert_name,
const char *cert_path, struct lyd_node **config);
/**
* @brief Deletes a keystore's certificate from the YANG data.
*
* @param[in] asym_key_name Identifier of an existing asymmetric key pair.
* @param[in] cert_name Optional identifier of a certificate to be deleted.
* If NULL, all of the certificates belonging to the asymmetric key pair will be deleted.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_keystore_cert(const char *asym_key_name, const char *cert_name, struct lyd_node **config);
/**
* @brief Creates new YANG data nodes for a public key in the truststore.
*
* @param[in] ctx libyang context.
* @param[in] pub_bag_name Arbitrary identifier of the public key bag.
* This name is used to reference the public keys in the bag.
* If a public key bag with this name already exists, its contents will be changed.
* @param[in] pubkey_name Arbitrary identifier of the public key.
* If a public key with this name already exists in the given bag, its contents will be changed.
* @param[in] pubkey_path Path to a file containing a public key.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_truststore_pubkey(const struct ly_ctx *ctx, const char *pub_bag_name, const char *pubkey_name,
const char *pubkey_path, struct lyd_node **config);
/**
* @brief Deletes a truststore's public key from the YANG data.
*
* @param[in] pub_bag_name Identifier of an existing public key bag.
* @param[in] pubkey_name Optional identifier of a public key to be deleted.
* If NULL, all of the public keys in the given bag will be deleted.
* @param[in,out] config Configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_truststore_pubkey(const char *pub_bag_name, const char *pubkey_name, struct lyd_node **config);
/**
* @brief Creates new YANG data nodes for a certificate in the truststore.
*
* @param[in] ctx libyang context.
* @param[in] cert_bag_name Arbitrary identifier of the certificate bag.
* This name is used to reference the certificates in the bag.
* If a certificate bag with this name already exists, its contents will be changed.
* @param[in] cert_name Arbitrary identifier of the certificate.
* If a certificate with this name already exists in the given bag, its contents will be changed.
* @param[in] cert_path Path to a file containing a PEM encoded certificate.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_truststore_cert(const struct ly_ctx *ctx, const char *cert_bag_name, const char *cert_name,
const char *cert_path, struct lyd_node **config);
/**
* @brief Deletes a truststore's certificate from the YANG data.
*
* @param[in] cert_bag_name Identifier of an existing certificate bag.
* @param[in] cert_name Optional identifier of a certificate to be deleted.
* If NULL, all of the certificates in the given bag will be deleted.
* @param[in,out] config Configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_truststore_cert(const char *cert_bag_name,
const char *cert_name, struct lyd_node **config);
/**
* @brief Gets all the SSH transport algorithms supported by the server.
*
* @note Actual usable algorithms depend on the underlying libssh library version,
* the returned list is based on libssh v0.11.0.
*
* @param[in] ctx libyang context.
* @param[out] supported_algs Supported SSH transport algorithms.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_oper_get_supported_ssh_algs(const struct ly_ctx *ctx, struct lyd_node **supported_algs);
/**
* @brief Gets all the TLS transport cipher suites supported by the server.
*
* @note Actual usable cipher suites depend on the underlying TLS library and its version.
*
* @param[in] ctx libyang context.
* @param[out] supported_algs Supported cipher suites.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_oper_get_supported_tls_algs(const struct ly_ctx *ctx, struct lyd_node **supported_algs);
/**
* @brief Gets the last modified time of an SSH user's password.
*
* @param[in] ch_client Name of the call-home client the user is configured on. NULL if the user is on a listening endpoint.
* @param[in] endpoint Name of the endpoint the user is configured on. Can be either a listening or call-home endpoint.
* @param[in] username Name of the SSH user.
* @param[out] last_modified Time of the last password modification.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_oper_get_user_password_last_modified(const char *ch_client,
const char *endpoint, const char *username, time_t *last_modified);
/**
* @} Server Configuration Functions
*/
/**
* @defgroup server_config_ssh SSH Server Configuration
* @ingroup server_config
*
* @brief SSH server configuration creation and deletion
* @{
*/
/**
* @brief Creates new YANG configuration data nodes for a hostkey.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its hostkey might be changed.
* @param[in] hostkey_name Arbitrary identifier of the hostkey.
* If a hostkey with this identifier already exists, its contents will be changed.
* @param[in] privkey_path Path to a file containing a private key.
* The private key has to be in a PEM format. Only RSA and ECDSA keys are supported.
* @param[in] pubkey_path Optional path to a file containing a public key. If NULL, public key will be
* generated from the private key.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ssh_hostkey(const struct ly_ctx *ctx, const char *endpt_name, const char *hostkey_name,
const char *privkey_path, const char *pubkey_path, struct lyd_node **config);
/**
* @brief Deletes a hostkey from the YANG data.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] hostkey_name Optional identifier of the hostkey to be deleted.
* If NULL, all of the hostkeys on this endpoint will be deleted.
* @param[in,out] config Configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_hostkey(const struct ly_ctx *ctx, const char *endpt_name,
const char *hostkey_name, struct lyd_node **config);
/**
* @brief Creates new YANG data nodes for a reference to an asymmetric key located in the keystore.
*
* This asymmetric key pair will be used as the SSH hostkey.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of an endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] hostkey_name Arbitrary identifier of the endpoint's hostkey.
* If an endpoint's hostkey with this identifier already exists, its contents will be changed.
* @param[in] keystore_reference Name of the asymmetric key pair to be referenced and used as a hostkey.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ssh_keystore_ref(const struct ly_ctx *ctx, const char *endpt_name, const char *hostkey_name,
const char *keystore_reference, struct lyd_node **config);
/**
* @brief Deletes a keystore reference from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] hostkey_name Identifier of an existing hostkey on the given endpoint.
* @param[in,out] config Configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_keystore_ref(const char *endpt_name, const char *hostkey_name,
struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for an SSH user's public key authentication method.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its user might be changed.
* @param[in] user_name Arbitrary identifier of the user.
* If an user with this identifier already exists, its contents will be changed.
* @param[in] pubkey_name Arbitrary identifier of the user's public key.
* If a public key with this identifier already exists for this user, its contents will be changed.
* @param[in] pubkey_path Path to a file containing the user's public key.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ssh_user_pubkey(const struct ly_ctx *ctx, const char *endpt_name,
const char *user_name, const char *pubkey_name, const char *pubkey_path, struct lyd_node **config);
/**
* @brief Deletes an SSH user's public key from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] user_name Identifier of an existing user on the given endpoint.
* @param[in] pubkey_name Optional identifier of a public key to be deleted.
* If NULL, all of the users public keys will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_user_pubkey(const char *endpt_name, const char *user_name,
const char *pubkey_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for an SSH user that will use system's authorized_keys to authenticate.
*
* The path to the authorized_keys file must be configured to successfully
* authenticate, see ::nc_server_ssh_set_authkey_path_format().
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its user might be changed.
* @param[in] user_name Arbitrary identifier of the user.
* If an user with this identifier already exists, its contents will be changed.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ssh_user_authkey(const struct ly_ctx *ctx, const char *endpt_name,
const char *user_name, struct lyd_node **config);
/**
* @brief Deletes an SSH user's authorized_keys method from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] user_name Identifier of an existing user on the given endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_user_authkey(const char *endpt_name, const char *user_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for an SSH user's password authentication method.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its user might be changed.
* @param[in] user_name Arbitrary identifier of the user.
* If an user with this identifier already exists, its contents will be changed.
* @param[in] password Clear-text password to be set for the user. It will be hashed.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ssh_user_password(const struct ly_ctx *ctx, const char *endpt_name,
const char *user_name, const char *password, struct lyd_node **config);
/**
* @brief Deletes an SSH user's password from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] user_name Identifier of an existing user on the given endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_user_password(const char *endpt_name, const char *user_name,
struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for an SSH user's keyboard interactive authentication method.
*
* One of Linux PAM, local users, or user callback is used to authenticate users with this SSH method (see \ref ln2doc_kbdint "the documentation").
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its user might be changed.
* @param[in] user_name Arbitrary identifier of the user.
* If an user with this identifier already exists, its contents will be changed.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ssh_user_interactive(const struct ly_ctx *ctx, const char *endpt_name,
const char *user_name, struct lyd_node **config);
/**
* @brief Deletes an SSH user's keyboard interactive authentication from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] user_name Identifier of an existing user on the given endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_user_interactive(const char *endpt_name, const char *user_name,
struct lyd_node **config);
/**
* @brief Deletes an SSH user from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] user_name Optional identifier of an user to be deleted.
* If NULL, all of the users on this endpoint will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_user(const char *endpt_name,
const char *user_name, struct lyd_node **config);
/**
* @brief Creates new YANG data nodes for a reference to a public key bag located in the truststore.
*
* The public key's located in the bag will be used for client authentication.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of an endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] user_name Arbitrary identifier of the endpoint's user.
* If an endpoint's user with this identifier already exists, its contents will be changed.
* @param[in] truststore_reference Name of the public key bag to be referenced and used for authentication.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ssh_truststore_ref(const struct ly_ctx *ctx, const char *endpt_name, const char *user_name,
const char *truststore_reference, struct lyd_node **config);
/**
* @brief Deletes a truststore reference from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] user_name Identifier of an user on the given endpoint whose truststore reference will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_truststore_ref(const char *endpt_name, const char *user_name,
struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes, which will be a reference to another SSH endpoint's users.
*
* Whenever a client tries to connect to the referencing endpoint, all of its users will be tried first. If no match is
* found, the referenced endpoint's configured users will be tried.
*
* @param[in] ctx libyang context
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] referenced_endpt Identifier of an endpoint, which has to exist whenever this data
* is applied. The referenced endpoint can reference another one and so on, but there mustn't be a cycle.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ssh_endpoint_client_ref(const struct ly_ctx *ctx, const char *endpt_name,
const char *referenced_endpt, struct lyd_node **config);
/**
* @brief Deletes reference to another SSH endpoint's users from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ssh_endpoint_client_ref(const char *endpt_name, struct lyd_node **config);
/**
* @} SSH Server Configuration
*/
/**
* @defgroup server_config_tls TLS Server Configuration
* @ingroup server_config
*
* @brief TLS server configuration creation and deletion
* @{
*/
/**
* @brief Creates new YANG configuration data nodes for a server's certificate.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its server certificate will be changed.
* @param[in] privkey_path Path to the server's PEM encoded private key file.
* @param[in] pubkey_path Optional path to the server's public key file. If not provided,
* it will be generated from the private key.
* @param[in] cert_path Path to the server's certificate file.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_tls_server_cert(const struct ly_ctx *ctx, const char *endpt_name, const char *privkey_path,
const char *pubkey_path, const char *cert_path, struct lyd_node **config);
/**
* @brief Deletes the server's certificate from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_tls_server_cert(const char *endpt_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for a keystore reference to the TLS server's certificate.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] asym_key_ref Name of the asymmetric key pair in the keystore to be referenced.
* @param[in] cert_ref Name of the certificate, which must belong to the given asymmetric key pair, to be referenced.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_tls_keystore_ref(const struct ly_ctx *ctx, const char *endpt_name, const char *asym_key_ref,
const char *cert_ref, struct lyd_node **config);
/**
* @brief Deletes a TLS server certificate keystore reference from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_tls_keystore_ref(const char *endpt_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for a client's (end-entity) certificate.
*
* A client certificate is authenticated if it is an exact match to a configured client certificate.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] cert_name Arbitrary identifier of the client's certificate.
* If a client certificate with this identifier already exists, it will be changed.
* @param[in] cert_path Path to the client's certificate file.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_tls_client_cert(const struct ly_ctx *ctx, const char *endpt_name, const char *cert_name,
const char *cert_path, struct lyd_node **config);
/**
* @brief Deletes a client (end-entity) certificate from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] cert_name Optional name of a certificate to be deleted.
* If NULL, all of the end-entity certificates on the given endpoint will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_tls_client_cert(const char *endpt_name, const char *cert_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for a truststore reference to a set of client (end-entity) certificates.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] cert_bag_ref Identifier of the certificate bag in the truststore to be referenced.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_tls_client_cert_truststore_ref(const struct ly_ctx *ctx, const char *endpt_name,
const char *cert_bag_ref, struct lyd_node **config);
/**
* @brief Deletes a client (end-entity) certificates truststore reference from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_tls_client_cert_truststore_ref(const char *endpt_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for a client certificate authority (trust-anchor) certificate.
*
* A client certificate is authenticated if it has a valid chain of trust to any configured CA cert.
* The configured CA cert, up to which the valid chain of trust can be built, does not have to be
* self-signed (the root CA). That means that the chain may be incomplete, yet the client will be authenticated.
*
* For example assume a certificate chain
* A <- B <- C,
* where A is the root CA, then the client certificate C will be authenticated either
* if solely B is configured, or if both A and B are configured. C will not be authenticated
* if just A is configured as a CA certificate.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] cert_name Arbitrary identifier of the certificate authority certificate.
* If a CA with this identifier already exists, it will be changed.
* @param[in] cert_path Path to the CA certificate file.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_tls_ca_cert(const struct ly_ctx *ctx, const char *endpt_name, const char *cert_name,
const char *cert_path, struct lyd_node **config);
/**
* @brief Deletes a client certificate authority (trust-anchor) certificate from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] cert_name Optional name of a certificate to be deleted.
* If NULL, all of the CA certificates on the given endpoint will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_tls_ca_cert(const char *endpt_name, const char *cert_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for a truststore reference to a set of client certificate authority (trust-anchor) certificates.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] cert_bag_ref Identifier of the certificate bag in the truststore to be referenced.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_tls_ca_cert_truststore_ref(const struct ly_ctx *ctx, const char *endpt_name,
const char *cert_bag_ref, struct lyd_node **config);
/**
* @brief Deletes a client certificate authority (trust-anchor) certificates truststore reference from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_tls_ca_cert_truststore_ref(const char *endpt_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes, which will be a reference to another TLS endpoint's certificates.
*
* Whenever an user tries to connect to the referencing endpoint, all of its certificates will be tried first. If no match is
* found, the referenced endpoint's configured certificates will be tried. The same applies to cert-to-name entries.
*
* @param[in] ctx libyang context
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] referenced_endpt Identifier of an endpoint, which has to exist whenever this data
* is applied. The referenced endpoint can reference another one and so on, but there mustn't be a cycle.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_tls_endpoint_client_ref(const struct ly_ctx *ctx, const char *endpt_name,
const char *referenced_endpt, struct lyd_node **config);
/**
* @brief Deletes reference to another TLS endpoint's users from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_tls_endpoint_client_ref(const char *endpt_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for a cert-to-name entry.
*
* @param[in] ctx libyang context.
* @param[in] endpt_name Arbitrary identifier of the endpoint.
* If an endpoint with this identifier already exists, its contents will be changed.
* @param[in] id ID of the entry. The lower the ID, the higher the priority of the entry (it will be checked earlier).
* @param[in] fingerprint Optional fingerprint of the entry. The fingerprint should always be set, however if it is
* not set, it will match any certificate. Entry with no fingerprint should therefore be placed only as the last entry.
* @param[in] map_type Mapping username to the certificate option.
* @param[in] name Username for this cert-to-name entry. Mandatory if @p map_type is set to ::NC_TLS_CTN_SPECIFIED.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_tls_ctn(const struct ly_ctx *ctx, const char *endpt_name, uint32_t id, const char *fingerprint,
NC_TLS_CTN_MAPTYPE map_type, const char *name, struct lyd_node **config);
/**
* @brief Deletes a cert-to-name entry from the YANG data.
*
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in] id Optional ID of the CTN entry.
* If 0, all of the cert-to-name entries on the given endpoint will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_tls_ctn(const char *endpt_name, uint32_t id, struct lyd_node **config);
/**
* @} TLS Server Configuration
*/
/**
* @defgroup server_config_ch Call Home Server Configuration
* @ingroup server_config
*
* @brief Call Home server configuration creation and deletion
* @{
*/
/**
* @} Call Home Server Configuration
*/
/**
* @defgroup server_config_ch_functions Call Home Server Configuration Functions
* @ingroup server_config_ch
*
* @brief Call Home server configuration functions
* @{
*/
/**
* @brief Creates new YANG configuration data nodes for a Call Home client's address and port.
*
* @param[in] ctx libyang context.
* @param[in] client_name Arbitrary identifier of the Call Home client.
* If a Call Home client with this identifier already exists, its contents will be changed.
* @param[in] endpt_name Arbitrary identifier of the client's endpoint.
* If the client's endpoint with this identifier already exists, its contents will be changed.
* @param[in] transport Transport protocol to be used on this endpoint - either SSH or TLS.
* @param[in] address Address to connect to.
* @param[in] port Port to connect to.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ch_address_port(const struct ly_ctx *ctx, const char *client_name, const char *endpt_name,
NC_TRANSPORT_IMPL transport, const char *address, const char *port, struct lyd_node **config);
#endif /* NC_ENABLED_SSH_TLS */
/**
* @brief Deletes a Call Home client from the YANG data.
*
* @param[in] client_name Optional identifier of a client to be deleted.
* If NULL, all of the Call Home clients will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ch_client(const char *client_name, struct lyd_node **config);
/**
* @brief Deletes a Call Home endpoint from the YANG data.
*
* @param[in] client_name Identifier of an existing Call Home client.
* @param[in] endpt_name Optional identifier of a CH endpoint to be deleted.
* If NULL, all of the CH endpoints which belong to the given client will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ch_endpt(const char *client_name, const char *endpt_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for the Call Home persistent connection type.
*
* This is the default connection type. If periodic connection type was set before, it will be unset.
*
* @param[in] ctx libyang context.
* @param[in] client_name Arbitrary identifier of the Call Home client.
* If a Call Home client with this identifier already exists, its contents will be changed.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ch_persistent(const struct ly_ctx *ctx, const char *client_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for the period parameter of the Call Home periodic connection type.
*
* If called, the persistent connection type will be replaced by periodic.
*
* @param[in] ctx libyang context.
* @param[in] client_name Arbitrary identifier of the Call Home client.
* If a Call Home client with this identifier already exists, its contents will be changed.
* @param[in] period Duration between periodic connections in minutes.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ch_period(const struct ly_ctx *ctx, const char *client_name, uint16_t period,
struct lyd_node **config);
/**
* @brief Deletes the Call Home period parameter of the periodic connection type from the YANG data.
*
* This behaves the same as setting the period to 60 minutes, which is the default value of this node.
*
* @param[in] client_name Identifier of an existing Call Home client.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ch_period(const char *client_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for the anchor time parameter of the Call Home periodic connection type.
*
* If called, the persistent connection type will be replaced by periodic.
*
* @param[in] ctx libyang context.
* @param[in] client_name Arbitrary identifier of the Call Home client.
* If a Call Home client with this identifier already exists, its contents will be changed.
* @param[in] anchor_time Timestamp before or after which a series of periodic connections are determined.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ch_anchor_time(const struct ly_ctx *ctx, const char *client_name,
const char *anchor_time, struct lyd_node **config);
/**
* @brief Deletes the Call Home anchor time parameter of the periodic connection type from the YANG data.
*
* @param[in] client_name Identifier of an existing Call Home client.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_del_ch_anchor_time(const char *client_name, struct lyd_node **config);
/**
* @brief Creates new YANG configuration data nodes for the idle timeout parameter of the Call Home periodic connection type.
*
* If called, the persistent connection type will be replaced by periodic.
*
* @param[in] ctx libyang context.
* @param[in] client_name Arbitrary identifier of the Call Home client.
* If a Call Home client with this identifier already exists, its contents will be changed.
* @param[in] idle_timeout Specifies the maximum number of seconds that a session may remain idle.
* @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
* Otherwise the new YANG data will be added to the previous data and may override it.
* @return 0 on success, non-zero otherwise.
*/
int nc_server_config_add_ch_idle_timeout(const struct ly_ctx *ctx, const char *client_name,
uint16_t idle_timeout, struct lyd_node **config);
/**
* @brief Deletes the Call Home idle timeout parameter of the periodic connection type from the YANG data.
*
* This behaves the same as setting the timeout to 180 seconds, which is the default value of this node.
*
* @param[in] client_name Identifier of an existing Call Home client.