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