Change LGPL-2.1+ to LGPL-2.1-or-later
[platform/upstream/glib.git] / gio / gmountoperation.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
5  * SPDX-License-Identifier: LGPL-2.1-or-later
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General
18  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include "config.h"
24
25 #include <string.h>
26
27 #include "gmountoperation.h"
28 #include "gioenumtypes.h"
29 #include "glibintl.h"
30 #include "gmarshal-internal.h"
31
32
33 /**
34  * SECTION:gmountoperation
35  * @short_description: Object used for authentication and user interaction
36  * @include: gio/gio.h
37  *
38  * #GMountOperation provides a mechanism for interacting with the user.
39  * It can be used for authenticating mountable operations, such as loop
40  * mounting files, hard drive partitions or server locations. It can
41  * also be used to ask the user questions or show a list of applications
42  * preventing unmount or eject operations from completing.
43  *
44  * Note that #GMountOperation is used for more than just #GMount
45  * objects – for example it is also used in g_drive_start() and
46  * g_drive_stop().
47  *
48  * Users should instantiate a subclass of this that implements all the
49  * various callbacks to show the required dialogs, such as
50  * #GtkMountOperation. If no user interaction is desired (for example
51  * when automounting filesystems at login time), usually %NULL can be
52  * passed, see each method taking a #GMountOperation for details.
53  *
54  * The term ‘TCRYPT’ is used to mean ‘compatible with TrueCrypt and VeraCrypt’.
55  * [TrueCrypt](https://en.wikipedia.org/wiki/TrueCrypt) is a discontinued system for
56  * encrypting file containers, partitions or whole disks, typically used with Windows.
57  * [VeraCrypt](https://www.veracrypt.fr/) is a maintained fork of TrueCrypt with various
58  * improvements and auditing fixes.
59  */
60
61 enum {
62   ASK_PASSWORD,
63   ASK_QUESTION,
64   REPLY,
65   ABORTED,
66   SHOW_PROCESSES,
67   SHOW_UNMOUNT_PROGRESS,
68   LAST_SIGNAL
69 };
70
71 static guint signals[LAST_SIGNAL] = { 0 };
72
73 struct _GMountOperationPrivate {
74   char *password;
75   char *user;
76   char *domain;
77   gboolean anonymous;
78   GPasswordSave password_save;
79   int choice;
80   gboolean hidden_volume;
81   gboolean system_volume;
82   guint pim;
83 };
84
85 enum {
86   PROP_0,
87   PROP_USERNAME,
88   PROP_PASSWORD,
89   PROP_ANONYMOUS,
90   PROP_DOMAIN,
91   PROP_PASSWORD_SAVE,
92   PROP_CHOICE,
93   PROP_IS_TCRYPT_HIDDEN_VOLUME,
94   PROP_IS_TCRYPT_SYSTEM_VOLUME,
95   PROP_PIM
96 };
97
98 G_DEFINE_TYPE_WITH_PRIVATE (GMountOperation, g_mount_operation, G_TYPE_OBJECT)
99
100 static void 
101 g_mount_operation_set_property (GObject      *object,
102                                 guint         prop_id,
103                                 const GValue *value,
104                                 GParamSpec   *pspec)
105 {
106   GMountOperation *operation;
107
108   operation = G_MOUNT_OPERATION (object);
109
110   switch (prop_id)
111     {
112     case PROP_USERNAME:
113       g_mount_operation_set_username (operation, 
114                                       g_value_get_string (value));
115       break;
116    
117     case PROP_PASSWORD:
118       g_mount_operation_set_password (operation, 
119                                       g_value_get_string (value));
120       break;
121
122     case PROP_ANONYMOUS:
123       g_mount_operation_set_anonymous (operation, 
124                                        g_value_get_boolean (value));
125       break;
126
127     case PROP_DOMAIN:
128       g_mount_operation_set_domain (operation, 
129                                     g_value_get_string (value));
130       break;
131
132     case PROP_PASSWORD_SAVE:
133       g_mount_operation_set_password_save (operation, 
134                                            g_value_get_enum (value));
135       break;
136
137     case PROP_CHOICE:
138       g_mount_operation_set_choice (operation, 
139                                     g_value_get_int (value));
140       break;
141
142     case PROP_IS_TCRYPT_HIDDEN_VOLUME:
143       g_mount_operation_set_is_tcrypt_hidden_volume (operation,
144                                                      g_value_get_boolean (value));
145       break;
146
147     case PROP_IS_TCRYPT_SYSTEM_VOLUME:
148       g_mount_operation_set_is_tcrypt_system_volume (operation,
149                                                      g_value_get_boolean (value));
150       break;
151
152     case PROP_PIM:
153         g_mount_operation_set_pim (operation,
154                                    g_value_get_uint (value));
155         break;
156
157     default:
158       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
159       break;
160     }
161 }
162
163
164 static void 
165 g_mount_operation_get_property (GObject    *object,
166                                 guint       prop_id,
167                                 GValue     *value,
168                                 GParamSpec *pspec)
169 {
170   GMountOperation *operation;
171   GMountOperationPrivate *priv;
172
173   operation = G_MOUNT_OPERATION (object);
174   priv = operation->priv;
175   
176   switch (prop_id)
177     {
178     case PROP_USERNAME:
179       g_value_set_string (value, priv->user);
180       break;
181
182     case PROP_PASSWORD:
183       g_value_set_string (value, priv->password);
184       break;
185
186     case PROP_ANONYMOUS:
187       g_value_set_boolean (value, priv->anonymous);
188       break;
189
190     case PROP_DOMAIN:
191       g_value_set_string (value, priv->domain);
192       break;
193
194     case PROP_PASSWORD_SAVE:
195       g_value_set_enum (value, priv->password_save);
196       break;
197
198     case PROP_CHOICE:
199       g_value_set_int (value, priv->choice);
200       break;
201
202     case PROP_IS_TCRYPT_HIDDEN_VOLUME:
203       g_value_set_boolean (value, priv->hidden_volume);
204       break;
205
206     case PROP_IS_TCRYPT_SYSTEM_VOLUME:
207       g_value_set_boolean (value, priv->system_volume);
208       break;
209
210     case PROP_PIM:
211       g_value_set_uint (value, priv->pim);
212       break;
213
214     default:
215       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
216       break;
217     }
218 }
219
220
221 static void
222 g_mount_operation_finalize (GObject *object)
223 {
224   GMountOperation *operation;
225   GMountOperationPrivate *priv;
226
227   operation = G_MOUNT_OPERATION (object);
228
229   priv = operation->priv;
230   
231   g_free (priv->password);
232   g_free (priv->user);
233   g_free (priv->domain);
234
235   G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize (object);
236 }
237
238 static gboolean
239 reply_non_handled_in_idle (gpointer data)
240 {
241   GMountOperation *op = data;
242
243   g_mount_operation_reply (op, G_MOUNT_OPERATION_UNHANDLED);
244   return G_SOURCE_REMOVE;
245 }
246
247 static void
248 ask_password (GMountOperation *op,
249               const char      *message,
250               const char      *default_user,
251               const char      *default_domain,
252               GAskPasswordFlags flags)
253 {
254   g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
255                    reply_non_handled_in_idle,
256                    g_object_ref (op),
257                    g_object_unref);
258 }
259   
260 static void
261 ask_question (GMountOperation *op,
262               const char      *message,
263               const char      *choices[])
264 {
265   g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
266                    reply_non_handled_in_idle,
267                    g_object_ref (op),
268                    g_object_unref);
269 }
270
271 static void
272 show_processes (GMountOperation      *op,
273                 const gchar          *message,
274                 GArray               *processes,
275                 const gchar          *choices[])
276 {
277   g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
278                    reply_non_handled_in_idle,
279                    g_object_ref (op),
280                    g_object_unref);
281 }
282
283 static void
284 show_unmount_progress (GMountOperation *op,
285                        const gchar     *message,
286                        gint64           time_left,
287                        gint64           bytes_left)
288 {
289   /* nothing to do */
290 }
291
292 static void
293 g_mount_operation_class_init (GMountOperationClass *klass)
294 {
295   GObjectClass *object_class;
296  
297   object_class = G_OBJECT_CLASS (klass);
298   object_class->finalize = g_mount_operation_finalize;
299   object_class->get_property = g_mount_operation_get_property;
300   object_class->set_property = g_mount_operation_set_property;
301   
302   klass->ask_password = ask_password;
303   klass->ask_question = ask_question;
304   klass->show_processes = show_processes;
305   klass->show_unmount_progress = show_unmount_progress;
306   
307   /**
308    * GMountOperation::ask-password:
309    * @op: a #GMountOperation requesting a password.
310    * @message: string containing a message to display to the user.
311    * @default_user: string containing the default user name.
312    * @default_domain: string containing the default domain.
313    * @flags: a set of #GAskPasswordFlags.
314    *
315    * Emitted when a mount operation asks the user for a password.
316    *
317    * If the message contains a line break, the first line should be
318    * presented as a heading. For example, it may be used as the
319    * primary text in a #GtkMessageDialog.
320    */
321   signals[ASK_PASSWORD] =
322     g_signal_new (I_("ask-password"),
323                   G_TYPE_FROM_CLASS (object_class),
324                   G_SIGNAL_RUN_LAST,
325                   G_STRUCT_OFFSET (GMountOperationClass, ask_password),
326                   NULL, NULL,
327                   _g_cclosure_marshal_VOID__STRING_STRING_STRING_FLAGS,
328                   G_TYPE_NONE, 4,
329                   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_ASK_PASSWORD_FLAGS);
330   g_signal_set_va_marshaller (signals[ASK_PASSWORD],
331                               G_TYPE_FROM_CLASS (object_class),
332                               _g_cclosure_marshal_VOID__STRING_STRING_STRING_FLAGSv);
333                   
334   /**
335    * GMountOperation::ask-question:
336    * @op: a #GMountOperation asking a question.
337    * @message: string containing a message to display to the user.
338    * @choices: an array of strings for each possible choice.
339    *
340    * Emitted when asking the user a question and gives a list of
341    * choices for the user to choose from.
342    *
343    * If the message contains a line break, the first line should be
344    * presented as a heading. For example, it may be used as the
345    * primary text in a #GtkMessageDialog.
346    */
347   signals[ASK_QUESTION] =
348     g_signal_new (I_("ask-question"),
349                   G_TYPE_FROM_CLASS (object_class),
350                   G_SIGNAL_RUN_LAST,
351                   G_STRUCT_OFFSET (GMountOperationClass, ask_question),
352                   NULL, NULL,
353                   _g_cclosure_marshal_VOID__STRING_BOXED,
354                   G_TYPE_NONE, 2,
355                   G_TYPE_STRING, G_TYPE_STRV);
356   g_signal_set_va_marshaller (signals[ASK_QUESTION],
357                               G_TYPE_FROM_CLASS (object_class),
358                               _g_cclosure_marshal_VOID__STRING_BOXEDv);
359                   
360   /**
361    * GMountOperation::reply:
362    * @op: a #GMountOperation.
363    * @result: a #GMountOperationResult indicating how the request was handled
364    *
365    * Emitted when the user has replied to the mount operation.
366    */
367   signals[REPLY] =
368     g_signal_new (I_("reply"),
369                   G_TYPE_FROM_CLASS (object_class),
370                   G_SIGNAL_RUN_LAST,
371                   G_STRUCT_OFFSET (GMountOperationClass, reply),
372                   NULL, NULL,
373                   NULL,
374                   G_TYPE_NONE, 1,
375                   G_TYPE_MOUNT_OPERATION_RESULT);
376
377   /**
378    * GMountOperation::aborted:
379    *
380    * Emitted by the backend when e.g. a device becomes unavailable
381    * while a mount operation is in progress.
382    *
383    * Implementations of GMountOperation should handle this signal
384    * by dismissing open password dialogs.
385    *
386    * Since: 2.20
387    */
388   signals[ABORTED] =
389     g_signal_new (I_("aborted"),
390                   G_TYPE_FROM_CLASS (object_class),
391                   G_SIGNAL_RUN_LAST,
392                   G_STRUCT_OFFSET (GMountOperationClass, aborted),
393                   NULL, NULL,
394                   NULL,
395                   G_TYPE_NONE, 0);
396
397   /**
398    * GMountOperation::show-processes:
399    * @op: a #GMountOperation.
400    * @message: string containing a message to display to the user.
401    * @processes: (element-type GPid): an array of #GPid for processes
402    *   blocking the operation.
403    * @choices: an array of strings for each possible choice.
404    *
405    * Emitted when one or more processes are blocking an operation
406    * e.g. unmounting/ejecting a #GMount or stopping a #GDrive.
407    *
408    * Note that this signal may be emitted several times to update the
409    * list of blocking processes as processes close files. The
410    * application should only respond with g_mount_operation_reply() to
411    * the latest signal (setting #GMountOperation:choice to the choice
412    * the user made).
413    *
414    * If the message contains a line break, the first line should be
415    * presented as a heading. For example, it may be used as the
416    * primary text in a #GtkMessageDialog.
417    *
418    * Since: 2.22
419    */
420   signals[SHOW_PROCESSES] =
421     g_signal_new (I_("show-processes"),
422                   G_TYPE_FROM_CLASS (object_class),
423                   G_SIGNAL_RUN_LAST,
424                   G_STRUCT_OFFSET (GMountOperationClass, show_processes),
425                   NULL, NULL,
426                   _g_cclosure_marshal_VOID__STRING_BOXED_BOXED,
427                   G_TYPE_NONE, 3,
428                   G_TYPE_STRING, G_TYPE_ARRAY, G_TYPE_STRV);
429   g_signal_set_va_marshaller (signals[SHOW_PROCESSES],
430                               G_TYPE_FROM_CLASS (object_class),
431                               _g_cclosure_marshal_VOID__STRING_BOXED_BOXEDv);
432
433   /**
434    * GMountOperation::show-unmount-progress:
435    * @op: a #GMountOperation:
436    * @message: string containing a message to display to the user
437    * @time_left: the estimated time left before the operation completes,
438    *     in microseconds, or -1
439    * @bytes_left: the amount of bytes to be written before the operation
440    *     completes (or -1 if such amount is not known), or zero if the operation
441    *     is completed
442    *
443    * Emitted when an unmount operation has been busy for more than some time
444    * (typically 1.5 seconds).
445    *
446    * When unmounting or ejecting a volume, the kernel might need to flush
447    * pending data in its buffers to the volume stable storage, and this operation
448    * can take a considerable amount of time. This signal may be emitted several
449    * times as long as the unmount operation is outstanding, and then one
450    * last time when the operation is completed, with @bytes_left set to zero.
451    *
452    * Implementations of GMountOperation should handle this signal by
453    * showing an UI notification, and then dismiss it, or show another notification
454    * of completion, when @bytes_left reaches zero.
455    *
456    * If the message contains a line break, the first line should be
457    * presented as a heading. For example, it may be used as the
458    * primary text in a #GtkMessageDialog.
459    *
460    * Since: 2.34
461    */
462   signals[SHOW_UNMOUNT_PROGRESS] =
463     g_signal_new (I_("show-unmount-progress"),
464                   G_TYPE_FROM_CLASS (object_class),
465                   G_SIGNAL_RUN_LAST,
466                   G_STRUCT_OFFSET (GMountOperationClass, show_unmount_progress),
467                   NULL, NULL,
468                   _g_cclosure_marshal_VOID__STRING_INT64_INT64,
469                   G_TYPE_NONE, 3,
470                   G_TYPE_STRING, G_TYPE_INT64, G_TYPE_INT64);
471   g_signal_set_va_marshaller (signals[SHOW_UNMOUNT_PROGRESS],
472                               G_TYPE_FROM_CLASS (object_class),
473                               _g_cclosure_marshal_VOID__STRING_INT64_INT64v);
474
475   /**
476    * GMountOperation:username:
477    *
478    * The user name that is used for authentication when carrying out
479    * the mount operation.
480    */ 
481   g_object_class_install_property (object_class,
482                                    PROP_USERNAME,
483                                    g_param_spec_string ("username",
484                                                         P_("Username"),
485                                                         P_("The user name"),
486                                                         NULL,
487                                                         G_PARAM_READWRITE|
488                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
489
490   /**
491    * GMountOperation:password:
492    *
493    * The password that is used for authentication when carrying out
494    * the mount operation.
495    */ 
496   g_object_class_install_property (object_class,
497                                    PROP_PASSWORD,
498                                    g_param_spec_string ("password",
499                                                         P_("Password"),
500                                                         P_("The password"),
501                                                         NULL,
502                                                         G_PARAM_READWRITE|
503                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
504
505   /**
506    * GMountOperation:anonymous:
507    * 
508    * Whether to use an anonymous user when authenticating.
509    */
510   g_object_class_install_property (object_class,
511                                    PROP_ANONYMOUS,
512                                    g_param_spec_boolean ("anonymous",
513                                                          P_("Anonymous"),
514                                                          P_("Whether to use an anonymous user"),
515                                                          FALSE,
516                                                          G_PARAM_READWRITE|
517                                                          G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
518
519   /**
520    * GMountOperation:domain:
521    *
522    * The domain to use for the mount operation.
523    */ 
524   g_object_class_install_property (object_class,
525                                    PROP_DOMAIN,
526                                    g_param_spec_string ("domain",
527                                                         P_("Domain"),
528                                                         P_("The domain of the mount operation"),
529                                                         NULL,
530                                                         G_PARAM_READWRITE|
531                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
532
533   /**
534    * GMountOperation:password-save:
535    *
536    * Determines if and how the password information should be saved. 
537    */ 
538   g_object_class_install_property (object_class,
539                                    PROP_PASSWORD_SAVE,
540                                    g_param_spec_enum ("password-save",
541                                                       P_("Password save"),
542                                                       P_("How passwords should be saved"),
543                                                       G_TYPE_PASSWORD_SAVE,
544                                                       G_PASSWORD_SAVE_NEVER,
545                                                       G_PARAM_READWRITE|
546                                                       G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
547
548   /**
549    * GMountOperation:choice:
550    *
551    * The index of the user's choice when a question is asked during the 
552    * mount operation. See the #GMountOperation::ask-question signal.
553    */ 
554   g_object_class_install_property (object_class,
555                                    PROP_CHOICE,
556                                    g_param_spec_int ("choice",
557                                                      P_("Choice"),
558                                                      P_("The users choice"),
559                                                      0, G_MAXINT, 0,
560                                                      G_PARAM_READWRITE|
561                                                      G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
562
563   /**
564    * GMountOperation:is-tcrypt-hidden-volume:
565    *
566    * Whether the device to be unlocked is a TCRYPT hidden volume.
567    * See [the VeraCrypt documentation](https://www.veracrypt.fr/en/Hidden%20Volume.html).
568    *
569    * Since: 2.58
570    */
571   g_object_class_install_property (object_class,
572                                    PROP_IS_TCRYPT_HIDDEN_VOLUME,
573                                    g_param_spec_boolean ("is-tcrypt-hidden-volume",
574                                                          P_("TCRYPT Hidden Volume"),
575                                                          P_("Whether to unlock a TCRYPT hidden volume. See https://www.veracrypt.fr/en/Hidden%20Volume.html."),
576                                                          FALSE,
577                                                          G_PARAM_READWRITE|
578                                                          G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
579
580   /**
581   * GMountOperation:is-tcrypt-system-volume:
582   *
583   * Whether the device to be unlocked is a TCRYPT system volume.
584   * In this context, a system volume is a volume with a bootloader
585   * and operating system installed. This is only supported for Windows
586   * operating systems. For further documentation, see
587   * [the VeraCrypt documentation](https://www.veracrypt.fr/en/System%20Encryption.html).
588   *
589   * Since: 2.58
590   */
591   g_object_class_install_property (object_class,
592                                    PROP_IS_TCRYPT_SYSTEM_VOLUME,
593                                    g_param_spec_boolean ("is-tcrypt-system-volume",
594                                                          P_("TCRYPT System Volume"),
595                                                          P_("Whether to unlock a TCRYPT system volume. Only supported for unlocking Windows system volumes. See https://www.veracrypt.fr/en/System%20Encryption.html."),
596                                                          FALSE,
597                                                          G_PARAM_READWRITE|
598                                                          G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
599
600   /**
601   * GMountOperation:pim:
602   *
603   * The VeraCrypt PIM value, when unlocking a VeraCrypt volume. See
604   * [the VeraCrypt documentation](https://www.veracrypt.fr/en/Personal%20Iterations%20Multiplier%20(PIM).html).
605   *
606   * Since: 2.58
607   */
608   g_object_class_install_property (object_class,
609                                    PROP_PIM,
610                                    g_param_spec_uint ("pim",
611                                                       P_("PIM"),
612                                                       P_("The VeraCrypt PIM value"),
613                                                       0, G_MAXUINT, 0,
614                                                       G_PARAM_READWRITE|
615                                                       G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
616 }
617
618 static void
619 g_mount_operation_init (GMountOperation *operation)
620 {
621   operation->priv = g_mount_operation_get_instance_private (operation);
622 }
623
624 /**
625  * g_mount_operation_new:
626  * 
627  * Creates a new mount operation.
628  * 
629  * Returns: a #GMountOperation.
630  **/
631 GMountOperation *
632 g_mount_operation_new (void)
633 {
634   return g_object_new (G_TYPE_MOUNT_OPERATION, NULL);
635 }
636
637 /**
638  * g_mount_operation_get_username:
639  * @op: a #GMountOperation.
640  * 
641  * Get the user name from the mount operation.
642  *
643  * Returns: (nullable): a string containing the user name.
644  **/
645 const char *
646 g_mount_operation_get_username (GMountOperation *op)
647 {
648   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
649   return op->priv->user;
650 }
651
652 /**
653  * g_mount_operation_set_username:
654  * @op: a #GMountOperation.
655  * @username: (nullable): input username.
656  *
657  * Sets the user name within @op to @username.
658  **/
659 void
660 g_mount_operation_set_username (GMountOperation *op,
661                                 const char      *username)
662 {
663   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
664   g_free (op->priv->user);
665   op->priv->user = g_strdup (username);
666   g_object_notify (G_OBJECT (op), "username");
667 }
668
669 /**
670  * g_mount_operation_get_password:
671  * @op: a #GMountOperation.
672  *
673  * Gets a password from the mount operation. 
674  *
675  * Returns: (nullable): a string containing the password within @op.
676  **/
677 const char *
678 g_mount_operation_get_password (GMountOperation *op)
679 {
680   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
681   return op->priv->password;
682 }
683
684 /**
685  * g_mount_operation_set_password:
686  * @op: a #GMountOperation.
687  * @password: (nullable): password to set.
688  * 
689  * Sets the mount operation's password to @password.  
690  *
691  **/
692 void
693 g_mount_operation_set_password (GMountOperation *op,
694                                 const char      *password)
695 {
696   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
697   g_free (op->priv->password);
698   op->priv->password = g_strdup (password);
699   g_object_notify (G_OBJECT (op), "password");
700 }
701
702 /**
703  * g_mount_operation_get_anonymous:
704  * @op: a #GMountOperation.
705  * 
706  * Check to see whether the mount operation is being used 
707  * for an anonymous user.
708  * 
709  * Returns: %TRUE if mount operation is anonymous. 
710  **/
711 gboolean
712 g_mount_operation_get_anonymous (GMountOperation *op)
713 {
714   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
715   return op->priv->anonymous;
716 }
717
718 /**
719  * g_mount_operation_set_anonymous:
720  * @op: a #GMountOperation.
721  * @anonymous: boolean value.
722  * 
723  * Sets the mount operation to use an anonymous user if @anonymous is %TRUE.
724  **/  
725 void
726 g_mount_operation_set_anonymous (GMountOperation *op,
727                                  gboolean         anonymous)
728 {
729   GMountOperationPrivate *priv;
730   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
731   priv = op->priv;
732
733   if (priv->anonymous != anonymous)
734     {
735       priv->anonymous = anonymous;
736       g_object_notify (G_OBJECT (op), "anonymous");
737     }
738 }
739
740 /**
741  * g_mount_operation_get_domain:
742  * @op: a #GMountOperation.
743  * 
744  * Gets the domain of the mount operation.
745  * 
746  * Returns: (nullable): a string set to the domain.
747  **/
748 const char *
749 g_mount_operation_get_domain (GMountOperation *op)
750 {
751   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
752   return op->priv->domain;
753 }
754
755 /**
756  * g_mount_operation_set_domain:
757  * @op: a #GMountOperation.
758  * @domain: (nullable): the domain to set.
759  * 
760  * Sets the mount operation's domain. 
761  **/  
762 void
763 g_mount_operation_set_domain (GMountOperation *op,
764                               const char      *domain)
765 {
766   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
767   g_free (op->priv->domain);
768   op->priv->domain = g_strdup (domain);
769   g_object_notify (G_OBJECT (op), "domain");
770 }
771
772 /**
773  * g_mount_operation_get_password_save:
774  * @op: a #GMountOperation.
775  * 
776  * Gets the state of saving passwords for the mount operation.
777  *
778  * Returns: a #GPasswordSave flag. 
779  **/  
780
781 GPasswordSave
782 g_mount_operation_get_password_save (GMountOperation *op)
783 {
784   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), G_PASSWORD_SAVE_NEVER);
785   return op->priv->password_save;
786 }
787
788 /**
789  * g_mount_operation_set_password_save:
790  * @op: a #GMountOperation.
791  * @save: a set of #GPasswordSave flags.
792  * 
793  * Sets the state of saving passwords for the mount operation.
794  * 
795  **/   
796 void
797 g_mount_operation_set_password_save (GMountOperation *op,
798                                      GPasswordSave    save)
799 {
800   GMountOperationPrivate *priv;
801   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
802   priv = op->priv;
803  
804   if (priv->password_save != save)
805     {
806       priv->password_save = save;
807       g_object_notify (G_OBJECT (op), "password-save");
808     }
809 }
810
811 /**
812  * g_mount_operation_get_choice:
813  * @op: a #GMountOperation.
814  * 
815  * Gets a choice from the mount operation.
816  *
817  * Returns: an integer containing an index of the user's choice from 
818  * the choice's list, or `0`.
819  **/
820 int
821 g_mount_operation_get_choice (GMountOperation *op)
822 {
823   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), 0);
824   return op->priv->choice;
825 }
826
827 /**
828  * g_mount_operation_set_choice:
829  * @op: a #GMountOperation.
830  * @choice: an integer.
831  *
832  * Sets a default choice for the mount operation.
833  **/
834 void
835 g_mount_operation_set_choice (GMountOperation *op,
836                               int              choice)
837 {
838   GMountOperationPrivate *priv;
839   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
840   priv = op->priv;
841   if (priv->choice != choice)
842     {
843       priv->choice = choice;
844       g_object_notify (G_OBJECT (op), "choice");
845     }
846 }
847
848 /**
849  * g_mount_operation_get_is_tcrypt_hidden_volume:
850  * @op: a #GMountOperation.
851  *
852  * Check to see whether the mount operation is being used
853  * for a TCRYPT hidden volume.
854  *
855  * Returns: %TRUE if mount operation is for hidden volume.
856  *
857  * Since: 2.58
858  **/
859 gboolean
860 g_mount_operation_get_is_tcrypt_hidden_volume (GMountOperation *op)
861 {
862   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
863   return op->priv->hidden_volume;
864 }
865
866 /**
867  * g_mount_operation_set_is_tcrypt_hidden_volume:
868  * @op: a #GMountOperation.
869  * @hidden_volume: boolean value.
870  *
871  * Sets the mount operation to use a hidden volume if @hidden_volume is %TRUE.
872  *
873  * Since: 2.58
874  **/
875 void
876 g_mount_operation_set_is_tcrypt_hidden_volume (GMountOperation *op,
877                                                gboolean hidden_volume)
878 {
879   GMountOperationPrivate *priv;
880   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
881   priv = op->priv;
882
883   if (priv->hidden_volume != hidden_volume)
884     {
885       priv->hidden_volume = hidden_volume;
886       g_object_notify (G_OBJECT (op), "is-tcrypt-hidden-volume");
887     }
888 }
889
890 /**
891  * g_mount_operation_get_is_tcrypt_system_volume:
892  * @op: a #GMountOperation.
893  *
894  * Check to see whether the mount operation is being used
895  * for a TCRYPT system volume.
896  *
897  * Returns: %TRUE if mount operation is for system volume.
898  *
899  * Since: 2.58
900  **/
901 gboolean
902 g_mount_operation_get_is_tcrypt_system_volume (GMountOperation *op)
903 {
904   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
905   return op->priv->system_volume;
906 }
907
908 /**
909  * g_mount_operation_set_is_tcrypt_system_volume:
910  * @op: a #GMountOperation.
911  * @system_volume: boolean value.
912  *
913  * Sets the mount operation to use a system volume if @system_volume is %TRUE.
914  *
915  * Since: 2.58
916  **/
917 void
918 g_mount_operation_set_is_tcrypt_system_volume (GMountOperation *op,
919                                                gboolean system_volume)
920 {
921   GMountOperationPrivate *priv;
922   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
923   priv = op->priv;
924
925   if (priv->system_volume != system_volume)
926     {
927       priv->system_volume = system_volume;
928       g_object_notify (G_OBJECT (op), "is-tcrypt-system-volume");
929     }
930 }
931
932 /**
933  * g_mount_operation_get_pim:
934  * @op: a #GMountOperation.
935  *
936  * Gets a PIM from the mount operation.
937  *
938  * Returns: The VeraCrypt PIM within @op.
939  *
940  * Since: 2.58
941  **/
942 guint
943 g_mount_operation_get_pim (GMountOperation *op)
944 {
945   g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), 0);
946   return op->priv->pim;
947 }
948
949 /**
950  * g_mount_operation_set_pim:
951  * @op: a #GMountOperation.
952  * @pim: an unsigned integer.
953  *
954  * Sets the mount operation's PIM to @pim.
955  *
956  * Since: 2.58
957  **/
958 void
959 g_mount_operation_set_pim (GMountOperation *op,
960                            guint pim)
961 {
962   GMountOperationPrivate *priv;
963   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
964   priv = op->priv;
965   if (priv->pim != pim)
966     {
967       priv->pim = pim;
968       g_object_notify (G_OBJECT (op), "pim");
969     }
970 }
971
972 /**
973  * g_mount_operation_reply:
974  * @op: a #GMountOperation
975  * @result: a #GMountOperationResult
976  * 
977  * Emits the #GMountOperation::reply signal.
978  **/
979 void
980 g_mount_operation_reply (GMountOperation *op,
981                          GMountOperationResult result)
982 {
983   g_return_if_fail (G_IS_MOUNT_OPERATION (op));
984   g_signal_emit (op, signals[REPLY], 0, result);
985 }